package org.springblade.estate.feign;

import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.utils.Func;
import org.springblade.estate.entity.Bills;
import org.springblade.estate.service.IBillsItemService;
import org.springblade.estate.service.IBillsService;
import org.springblade.estate.vo.BillsVO;
import org.springblade.estate.wrapper.BillsWrapper;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;

import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-04-23
 */

@AllArgsConstructor
@RestController
@RequestMapping("/feign/bills")

public class BillsClient implements IBillsClient {

    private final IBillsService billsService;
    private final IBillsItemService billsItemService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public BillsVO detail(@SpringQueryMap Bills bills) {
        Bills detail = billsService.getOne(Condition.getQueryWrapper(bills));
        return BillsWrapper.build(billsItemService).entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<BillsVO> list(@SpringQueryMap Bills bills) {
        return BillsWrapper.build(billsItemService).listVO(billsService.list(Condition.getQueryWrapper(bills)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Bills bills) {
        return billsService.save(bills);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Bills bills) {
        return billsService.updateById(bills);
        }

    /**
     * 新增或修改
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody Bills bills) {
        return billsService.saveOrUpdate(bills);
        }


    /**
     * 删除
     */
    @Override
    @PostMapping("/remove")
    public boolean remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
        return billsService.deleteLogic(Func.toLongList(ids));
        }


}
