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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ep.IEpCustomsPartService;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
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 org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 文件描述 海关商品料号
 *
 * @author xiangming.liao
 * @date 2022年01月18日 10:45
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/customs-part")
@Api(tags = "海关商品料号")
public class EpCustomsPartController {
    public static final Logger LOGGER = LoggerFactory.getLogger(EpCustomsPartController.class);

    @Autowired
    private IEpCustomsPartService epCustomsPartService;

    @GetMapping("/query")
    public ResultBean getCustomsPartByPartNo(String organizeCode, String partNo) {
        try {
            LOGGER.info("[getCustomsPartByPartNo] partNo:{}", partNo);
            //todo 调用MES接口，MES调用CDM海关系统接口查询海关物料信息


            return ResultBean.success("查询成功").setResultObject(true)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping("/update")
    public ResultBean updateCustomsPartByPartNo(String organizeCode, String partNo, String userInfo) {
        try {
            LOGGER.info("[updateCustomsPartByPartNo] partNo:{}", partNo);
            //todo 调用MES接口，MES调用CDM海关系统接口修改海关物料信息
            return ResultBean.success("修改成功").setResultObject(epCustomsPartService.updateCustomsPartByPartNo(organizeCode, partNo, userInfo))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
