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

import cn.estsh.i3plus.ext.mes.api.base.ep.IEpPackageService;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesBaseController;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2022-02-14 9:12
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES)
@Api(tags = "包装条码")
public class EpPackageSnController {

    @Autowired
    private IEpPackageService packageService;

    @GetMapping(value = "/ep/package/check")
    @ApiOperation(value = "校验包装信息是否存在")
    public ResultBean checkPackageExistBySn(String organizeCode, String packageNo){
        try {
            return ResultBean.success("操作成功").setResultObject(packageService.getPackageByNo(organizeCode, packageNo))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/ep/package/query")
    @ApiOperation(value = "获取包装信息")
    public ResultBean getPackageBySn(String organizeCode, String packageNo){
        try {
            return ResultBean.success("操作成功").setResultObject(packageService.getPackageByNo(organizeCode, packageNo))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
