package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.base;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IExteriorScratchProofCheckService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesExteriorScratchProofDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesPartCheckDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProjectTourDetail;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesPcnBaseController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: xiangming.liao
 * @CreateDate: 2021/03/15 15:33 下午
 * @Description:
 **/
@RestController
@Api(tags = "外观防划伤点检接口")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/exterior-scratch-proof-check")
public class ExteriorScratchProofCheckController extends MesPcnBaseController {

    @Autowired
    private IExteriorScratchProofCheckService exteriorScratchProofCheckService;

    /**
     * 查询工位下的外观防划伤点检单
     *
     * @param orderNo
     * @param organizeCode
     * @return
     */
    @GetMapping("/by-cell/query")
    @ApiOperation(value = "查询工位下的外观防划伤点检单")
    public ResultBean queryExteriorScratchProofDetailByCell(String orderNo, String organizeCode, String workCellCode) {
        try {
            return ResultBean.success("查询成功").setResultList(exteriorScratchProofCheckService.queryExteriorScratchProofDetailByCell(orderNo, organizeCode, workCellCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 通过单据编号查询工位
     *
     * @param orderNo
     * @param organizeCode
     * @return
     */
    @GetMapping("/cell/query")
    @ApiOperation(value = "通过单据编号查询工位")
    public ResultBean queryCellByOrderNo(String orderNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(this.exteriorScratchProofCheckService.queryCellByOrderNo(orderNo, organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 外观防划伤点检作业
     *
     * @param detail
     * @return
     */
    @PostMapping(value = "/update")
    @ApiOperation(value = "外观防划伤点检作业")
    public ResultBean updateExteriorScratchProof(@RequestBody MesExteriorScratchProofDetail detail) {
        try {
            exteriorScratchProofCheckService.updateExteriorScratchProof(detail);
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
