package cn.estsh.i3plus.ext.mes.apiservice.controller.busi.jx;

import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxWorkOrderService;
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.MesBaseController;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
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 cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-10-30 15:26
 */
@RestController
@Api(tags = "嘉兴生产工单 控制层")
@RequestMapping(CommonConstWords.BASE_URL_MES + "/jx/work-order")
public class JxWorkOrderController extends MesBaseController {

    @Autowired
    private IJxWorkOrderService jxWorkOrderService;

    @PostMapping("/delete-rework-sn")
    @ApiOperation("删除返工条码")
    public ResultBean deleteProduceSnRepair(String workOrderNo, String[] snArr) {
        try {

            ValidatorBean.checkNotNull(workOrderNo, "工单号不能为空");
            ValidatorBean.checkNotNull(snArr, "条码不能为空");

            jxWorkOrderService.deleteSnRepairByType(workOrderNo, snArr, AuthUtil.getOrganize().getOrganizeCode(), AuthUtil.getSessionUser().getUserName());
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping("/query-repair-sn-by-pager")
    @ApiOperation("查询返工条码 组件/本体")
    public ResultBean deletePackageSnRepairByPager(String workOrderNo, String sn, Pager pager) {
        try {
            ValidatorBean.checkNotNull(workOrderNo, "工单号不能为空");
            return ResultBean.success("查询成功")
                    .setListPager(jxWorkOrderService.queryRepairSnByPager(workOrderNo, sn, AuthUtil.getOrganize().getOrganizeCode(), pager))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
