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

import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxManageCodeMcRecordService;
import cn.estsh.i3plus.ext.mes.pojo.model.jx.JxManageCodeModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
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.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
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-12-21 14:12
 */
@RestController
@RequestMapping(MesExtConstWords.BASE_URL_MES_JX + "/report")
@Api(tags = "管理码占用报表")
public class JxManageCodeMcRecordController {

    @Autowired
    private IJxManageCodeMcRecordService manageCodeMcRecordService;

    @GetMapping(value = "/manage-code-mc-record/query")
    @ApiOperation(value = "管理码占用查询报表")
    public ResultBean queryManageCodeMcRecordReport(JxManageCodeModel manageCodeModel, Pager pager) {
        try {
            manageCodeModel.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(manageCodeMcRecordService.queryManageCodeMcRecordReportByPager(manageCodeModel, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/manage-code-mc-record/unbind")
    @ApiOperation(value = "强制下线管理码")
    public ResultBean doUnbindManageCodeMcRecord(JxManageCodeModel manageCodeModel) {
        try {
            manageCodeModel.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            manageCodeMcRecordService.doUnbindManageCodeMcRecord(manageCodeModel);
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
