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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesPartShippingGroupService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesPartShippingGroup;
import cn.estsh.i3plus.pojo.mes.bean.shipping.MesShippingOrderManagement;
import cn.estsh.i3plus.pojo.mes.model.MesShippingOrderManagementModel;
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.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description :
 * @Reference :
 * @Author :
 * @CreateDate : 2024-05-06 16:25
 * @Modify:
 **/

@Api("零件发运组")
@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/part-shipping-group")
public class MesPartShippingGroupController {

    @Autowired
    private IMesPartShippingGroupService shippingGroupService;

    @GetMapping("/list")
    @ApiOperation(value = "查询所有")
    public ResultBean list(MesPartShippingGroup partShippingGroup) {
        try {
            if (StringUtils.isEmpty(partShippingGroup.getOrganizeCode())) partShippingGroup.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setResultList(shippingGroupService.findAll(partShippingGroup));
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/doPrint")
    @ApiOperation(value = "打印未打印发运单后修改状态")
    public ResultBean doMesMesShippingOrderManagementPrint(@RequestBody MesShippingOrderManagement model) {
        try {
            // 数据校验
            ValidatorBean.checkNotNull(model.getShippingGroupCode(), "发运组代码不能为空");
            return shippingGroupService.doMesMesShippingOrderManagementPrint(model);
        } catch (ImppBusiException e) {
            return ResultBean.fail(e).build();
        } catch (Exception e) {
            return ResultBean.fail(e);
        }
    }
}
