package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.base.jx;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IShiftExtService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
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 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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-06 16:23
 */
@RestController
@RequestMapping(MesPcnExtConstWords.BASE_URL_MES_PCN_JX)
@Api(tags = "班次信息")
public class JxShiftExtController extends MesPcnBaseController {

    @Autowired
    private IShiftExtService shiftExtService;

    @GetMapping(value = "/shift/query")
    @ApiOperation(value = "按条件分页查询业务配置信息")
    public ResultBean getBusiConfigMap(String workCenterCode, String organizeCode) {
        try {
            if (StringUtils.isEmpty(workCenterCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺失必要参数[workCenterCode]")
                        .build();
            }

            if (StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺失必要参数[organizeCode]")
                        .build();
            }

            return ResultBean.success("查询成功").setResultList(shiftExtService.getShiftListbyCenterCode(organizeCode, workCenterCode)).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
