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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesPartCheckDetailService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesPartCheckDetail;
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/01/18 13:33 下午
 * @Description:
 **/
@RestController
@Api(tags = "物料点检接口")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/part-check")
public class PartCheckDetailController extends MesPcnBaseController {
    @Autowired
    private IMesPartCheckDetailService mesPartCheckDetailService;

    @GetMapping("part-check/query")
    @ApiOperation(value = "按条件分页查询点检单明细")
    public ResultBean queryMesPartCheckDetail(MesPartCheckDetail detail, Pager pager) {
        try {
            return ResultBean.success("查询成功").setListPager(this.mesPartCheckDetailService.queryMesPartCheckDetail(detail, pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 物料点检作业
     *
     * @param detail
     * @return
     */
    @PutMapping("part-check/order-status-check/update")
    @ApiOperation(value = "物料点检作业")
    public ResultBean updateOrderStatusCheck(MesPartCheckDetail detail) {
        try {
            return ResultBean.success("扫描成功").setResultObject(this.mesPartCheckDetailService.updateOrderStatusCheck(detail))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * 提交物料点检
     *
     * @param orderNo
     * @param organizeCode
     * @param modifyUser
     * @return
     */
    @PutMapping("part-check/submit")
    @ApiOperation(value = "提交物料点检")
    public ResultBean partCheckSubmit(String orderNo, String organizeCode, String modifyUser) {
        try {
            return ResultBean.success("提交成功").setResultObject(this.mesPartCheckDetailService.partCheckSubmit(orderNo, organizeCode, modifyUser))
                    .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("part-check/cell/query")
    @ApiOperation(value = "通过单据编号查询工位")
    public ResultBean queryCellByOrderNo(String orderNo, String organizeCode) {
        try {
            return ResultBean.success("查询成功").setResultList(this.mesPartCheckDetailService.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
     * @param pager
     * @return
     */
    @GetMapping("part-check/by-cell/query")
    @ApiOperation(value = "分页查询工位下的物料点检单")
    public ResultBean queryPartCheckByCell(MesPartCheckDetail detail, Pager pager) {
        try {
            return ResultBean.success("查询成功").setListPager(this.mesPartCheckDetailService.queryPartCheckByCell(detail, pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
