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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxPatchPrintService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesOuterPackageDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesPackageExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProduceSnExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.SxPrintTemplateModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.bu.QualityAssureIndiaModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
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 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.*;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN)
@Api(tags = "条码补打印")
public class SxPatchPrintController extends MesPcnBaseController {

    @Autowired
    private ISxPatchPrintService patchPrintService;

    @GetMapping(value = "/sx-patch/printer-cfg/query")
    @ApiOperation(value = "查询打印机集合")
    public ResultBean queryPrinterCfgList(String organizeCode) {
        try {
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.queryPrinterCfgList(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/sx-patch/prod-sn/query")
    @ApiOperation(value = "按条件分页查询产品条码补打印信息")
    public ResultBean queryPatchProdSnByPager(MesProduceSnExt produceSnExt, Pager pager) {
        try {
            ValidatorBean.beginValid(produceSnExt)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, produceSnExt.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(patchPrintService.queryPatchProdSnByPager(produceSnExt, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/sx-patch/prod-sn/batch-print")
    @ApiOperation(value = "产品条码补打")
    public ResultBean doPatchPrintProdSn(@RequestBody SxPrintTemplateModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, model.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.doPatchPrintProdSn(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/sx-patch/big-prod-sn/batch-print")
    @ApiOperation(value = "大本体标签补打")
    public ResultBean doPatchPrintBigProcess(@RequestBody SxPrintTemplateModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, model.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.doPatchPrintBigProcess(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/sx-patch/quality-assure/batch-print")
    @ApiOperation(value = "质保书补打")
    public ResultBean doPatchPrintQualityAssure(@RequestBody SxPrintTemplateModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, model.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.doPatchPrintQualityAssure(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/sx-patch/pack-sn/query")
    @ApiOperation(value = "按条件分页查询包装条码补打印信息")
    public ResultBean queryPatchPackSnByPager(MesPackageExt pack, Pager pager) {
        try {
            ValidatorBean.beginValid(pack)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, pack.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(patchPrintService.queryPatchPackSnByPager(pack, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/sx-patch/pack-sn/batch-print")
    @ApiOperation(value = "包装条码补打")
    public ResultBean doPatchPrintPackSn(@RequestBody SxPrintTemplateModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, model.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.doPatchPrintPackSn(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/sx-patch/quality-assure-india/batch-print")
    @ApiOperation(value = "印尼向质保书补打")
    public ResultBean doPatchPrintQualityAssureIndia(@RequestBody QualityAssureIndiaModel model) {
        try {
            /*SxPrintTemplateModel model = new SxPrintTemplateModel();
            model.setOrganizeCode("CKF1");
            model.setUserInfo("xxx");

            SxPrintTemplateModelIndia indiaModel = new SxPrintTemplateModelIndia();
            indiaModel.setSnStartNum("z00000001");
            indiaModel.setSnEndNum("z00000003");
            indiaModel.setProdSn("NH-1320191000001");
            model.setIndiaModel(indiaModel);*/
            ValidatorBean.beginValid(model)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, model.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.doPatchPrintQualityAssureIndia(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/sx-patch/big-pack-sn/batch-print")
    @ApiOperation(value = "大包装条码补打")
    public ResultBean doPatchPrintBigPackSn(@RequestBody SxPrintTemplateModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, model.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.doPatchPrintBigPackSn(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/sx-patch/big-pack-sn/query")
    @ApiOperation(value = "按条件分页查询大包装条码补打印信息")
    public ResultBean queryPatchPackSnByPager(MesOuterPackageDetail outerPackageDetail, Pager pager) {
        try {
            ValidatorBean.beginValid(outerPackageDetail)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, outerPackageDetail.getOrganizeCode());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(patchPrintService.queryPatchBigPackSnByPager(outerPackageDetail, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/sx-patch/big-pack-sn/pack-sn/query")
    @ApiOperation(value = "根据大包装条码分页查询小包装条码信息")
    public ResultBean queryPatchPackSnByOutPackSn(MesOuterPackageDetail outerPackageDetail) {
        try {
            ValidatorBean.beginValid(outerPackageDetail)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, outerPackageDetail.getOrganizeCode())
                    .notNull(MesPcnExtConstWords.OUTER_PACKAGE_NO, outerPackageDetail.getOuterPackageNo());
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(patchPrintService.queryPatchPackSnByOuterPackNo(outerPackageDetail));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
