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

import cn.estsh.i3plus.ext.mes.api.base.jx.IJxProcessExtService;
import cn.estsh.i3plus.ext.mes.pojo.model.BatchIdModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SessionUser;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-13 17:18
 */
@RestController
@RequestMapping(MesExtConstWords.BASE_URL_MES_JX + "/process-flow")
@Api(tags = "嘉兴工序信息 控制层")
public class JxProcessController extends MesBaseController {

    @Autowired
    private IJxProcessExtService jxProcessExtService;

    @PutMapping(value = "/update-valid-batch")
    @ApiOperation(value = "批量禁用/启用详情", notes = "批量禁用/启用详情")
    public ResultBean updateProcessValid(@RequestBody BatchIdModel model) {
        try {
            ConvertBean.modelSafeArrayNumber(model.getIds(), true);
            //登陆用户
            SessionUser user = AuthUtil.getSessionUser();

            jxProcessExtService.updateProcessValid(model.getIds(), model.getStatus(), user.getUserName());
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @DeleteMapping(value = "/delete-batch")
    @ApiOperation(value = "批量删除", notes = "批量删除")
    public ResultBean deleteProcessByIds(@RequestBody BatchIdModel model) {
        try {
            ConvertBean.modelSafeArrayNumber(model.getIds(), true);
            //登陆用户
            SessionUser user = AuthUtil.getSessionUser();

            jxProcessExtService.deleteWeaklySProcessByIds(model.getIds(), user.getUserName());
            return ResultBean.success("修改成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
