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

import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxCenterWorkingBoardService;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
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;

import java.util.Map;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES)
@Api(tags = "嘉兴产线运行看板")
public class JxCenterWorkingBoardController extends MesBaseController {

    @Autowired
    @Qualifier("jxCenterWorkingBoardDispatchService")
    private IJxCenterWorkingBoardService centerWorkingBoardService;

    @PostMapping(value = "/ext/jx/center-working-board/query")
    @ApiOperation(value = "嘉兴产线运行看板")
    public ResultBean queryCenterWorkingBoardData(@RequestBody Map<String, Object> dataMap) {
        try {
            if (!dataMap.containsKey(MesExtConstWords.FLAG))
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("参数缺失业务标志[flag]!")
                        .build();
            if (!dataMap.containsKey(MesExtConstWords.ORGANIZE_CODE)) dataMap.put(MesExtConstWords.ORGANIZE_CODE, AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultMap(centerWorkingBoardService.queryCenterWorkingBoardData(dataMap));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/ext/jx/center-working-board/delete-cached-data")
    @ApiOperation(value = "嘉兴产线运行看板缓存数据清除")
    public ResultBean deleteCachedCenterWorkingBoardData(String organizeCode) {
        try {
            centerWorkingBoardService.execCachedCenterWorkingBoardData(organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValueStr(), null, null);
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
