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.feign.IWorkOrderClient;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springblade.estate.entity.WorkOrder;
import org.springblade.estate.vo.WorkOrderVO;
import org.springblade.estate.wrapper.WorkOrderWrapper;
import org.springblade.estate.service.IWorkOrderService;
import org.springblade.core.boot.ctrl.BladeController;
import java.util.List;
/**
 *  client
 *
 * @author lianghanqiang
 * @since 2021-12-28
 */

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

public class WorkOrderClient implements IWorkOrderClient {

    private final IWorkOrderService workOrderService;

        /**
     * 详情
     */
    @Override
    @GetMapping("/detail")
    public WorkOrderVO detail(WorkOrder workOrder) {
        WorkOrder detail = workOrderService.getOne(Condition.getQueryWrapper(workOrder));
        return WorkOrderWrapper.build().entityVO(detail);
        }

    /**
     * 查询
     */
    @Override
    @GetMapping("/list")
    public List<WorkOrderVO> list(WorkOrder workOrder) {
        return WorkOrderWrapper.build().listVO(workOrderService.list(Condition.getQueryWrapper(workOrder)));
        }



    /**
     * 新增
     */
    @Override
    @PostMapping("/save")
    public boolean save(@Valid @RequestBody WorkOrder workOrder) {
        return workOrderService.save(workOrder);
        }

    /**
     * 修改
     */
    @Override
    @PostMapping("/update")
    public boolean update(@Valid @RequestBody WorkOrder workOrder) {
        return workOrderService.updateById(workOrder);
        }

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


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


}
