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

import cn.estsh.i3plus.ext.mes.api.base.ep.IEpWorkCenterContainerLocationService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesWorkCenterContainerLocation;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
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.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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES)
@Api(tags = "EP产线托盘位置控制层")
public class EpWorkCenterContainerLocationController extends MesBaseController {

    @Autowired
    private IEpWorkCenterContainerLocationService workCenterContainerLocationService;

    @PostMapping(value = "/ep/work-center-container-location/insert")
    @ApiOperation(value = "新增产线托盘位置信息")
    public ResultBean insertWorkCenterContainerLocation(MesWorkCenterContainerLocation workCenterContainerLocation) {
        try {
            ValidatorBean.beginValid(workCenterContainerLocation)
                    .notNull(MesExtConstWords.WORK_CENTER_CODE, workCenterContainerLocation.getWorkCenterCode())
                    .notNull(MesExtConstWords.CT_LOCATION_NO, workCenterContainerLocation.getCtLocationNo());

            workCenterContainerLocation.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            workCenterContainerLocation.setCreateUser(AuthUtil.getSessionUser().getUserName());
            workCenterContainerLocationService.insertWorkCenterContainerLocation(workCenterContainerLocation);

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

}
