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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.recyclablepackage.IMesRecyclablePackageBindingService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesRecyclablePackageBindingModel;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description : 料箱绑定
 * @Reference :
 * @Author : junsheng.li
 * @CreateDate 2024/9/6 16:35
 * @Modify:
 **/

@RestController
@Api(tags = "料箱绑定")
@RequestMapping(MesCommonConstant.MES_YANFEN + "/recyclable-package-binding")
@Slf4j
public class MesRecyclablePackageBindingController {

    @Autowired
    private IMesRecyclablePackageBindingService mesRecyclablePackageBindingService;


    @GetMapping("/recyclable-package-binding-detail/query")
    @ApiOperation(value = "查询绑定信息")
    public ResultBean findMesRecyclablePackageBindingDetail(MesRecyclablePackageBindingModel mesRecyclablePackageBindingModel) {

        try {
            ValidatorBean.checkNotNull(mesRecyclablePackageBindingModel.getPackageSn(), "包条码不能为空");
            ValidatorBean.checkNotNull(mesRecyclablePackageBindingModel.getOrganizeCode(), "工厂代码不能为空");
            return ResultBean.success("查询成功").setResultList(mesRecyclablePackageBindingService.findMesRecyclablePackageBindingDetail(mesRecyclablePackageBindingModel));
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping("/doScan")
    @ApiOperation(value = "扫描信息")
    public ResultBean doScan(@RequestBody MesRecyclablePackageBindingModel mesRecyclablePackageBindingModel) {

        try {
            ValidatorBean.checkNotNull(mesRecyclablePackageBindingModel.getPackageSn(), "包条码不能为空");
            ValidatorBean.checkNotNull(mesRecyclablePackageBindingModel.getOrganizeCode(), "工厂代码不能为空");
            ValidatorBean.checkNotNull(mesRecyclablePackageBindingModel.getType(), "操作类型不能为空");
            ValidatorBean.checkNotNull(mesRecyclablePackageBindingModel.getUserName(), "操作人不能为空");
            return mesRecyclablePackageBindingService.doScan(mesRecyclablePackageBindingModel);
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
