package org.springblade.estate.feign;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import javax.validation.Valid;

import org.springblade.common.utils.GenerateNum;
import org.springblade.core.mp.support.BladePage;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.estate.dto.RepairDTO;
import org.springblade.estate.entity.Car;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.Repair;
import org.springblade.estate.vo.RepairVO;
import org.springblade.estate.wrapper.RepairWrapper;
import org.springblade.estate.service.IRepairService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 * 报事工单 client
 *
 * @author lianghanqiang
 * @since 2021-03-30
 */

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

public class RepairClient implements IRepairClient {

    private final IRepairService repairService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public RepairVO detail(@SpringQueryMap Repair repair) {
        Repair detail = repairService.getOne(Condition.getQueryWrapper(repair));
        return RepairWrapper.build().entityVO(detail);
        }

    /**
     * 查询 报事工单
     */
    @Override
    @GetMapping("/list")
    public List<RepairVO> list(@SpringQueryMap Repair repair) {
        return RepairWrapper.build().listVO(repairService.list(Condition.getQueryWrapper(repair)));
        }



    /**
     * 新增 报事工单
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody Repair repair) {
        return repairService.save(repair);
        }

    /**
     * 修改 报事工单
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody Repair repair) {
        return repairService.updateById(repair);
        }

    /**
     * 新增或修改 报事工单
     */
    @Override
    @PostMapping("/submit")
    public boolean submit(@Valid @RequestBody Repair repair) {
		repair.setRepairNo(GenerateNum.generateNum());
        return repairService.saveOrUpdate(repair);
        }


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

	@Override
	@PostMapping("/page")
	public R<BladePage<RepairVO>> page(@RequestBody RepairDTO repairDTO) {
		Query query = new Query();
		Page<Repair> queryPage = repairDTO.getPage();
		query.setCurrent(queryPage.getCurrent());
		query.setSize(queryPage.getSize());
		IPage<Repair> repairIPage = this.repairService.page(Condition.getPage(query), Condition.getQueryWrapper(repairDTO));
		IPage<RepairVO> pageVO = RepairWrapper.build().pageVO(repairIPage);
		return R.data(BladePage.of(pageVO));
	}


}
