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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.bu3.ISxEsopCenterExtService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.bu3.SxEsopCenterDataModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesPcnBaseController;
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.RequestBody;
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_PCN)
@Api(tags = "BU三期工位端SOP")
public class SxEsopCenterExtController extends MesPcnBaseController {

    @Autowired
    private ISxEsopCenterExtService esopCenterExtService;

    @PostMapping(value = "/esop-center-ext/exec")
    @ApiOperation(value = "BU三期工位端SOP")
    public ResultBean queryBcEsop(@RequestBody SxEsopCenterDataModel data) {
        try {
            ValidatorBean.beginValid(data)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, data.getOrganizeCode())
                    .notNull(MesPcnExtConstWords.ACTION_TYPE, data.getActionType())
                    .notNull(MesPcnExtConstWords.AREA_CODE, data.getAreaCode())
                    .notNull(MesPcnExtConstWords.WORK_CENTER_CODE, data.getWorkCenterCode())
                    .notNull(MesPcnExtConstWords.WORK_CELL_CODE, data.getWorkCellCode());
            return ResultBean.success(esopCenterExtService.exec(data).getFeedBackMsg()).setResultObject(data).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
