package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.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.pojo.base.enumutil.MesEnumUtil;
import cn.estsh.impp.framework.boot.util.ImppRedis;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;
import java.util.StringJoiner;

/**
 * @Author : wangjie
 * @CreateDate : 2022-02-15
 * @Modify:
 **/
@Slf4j
@Service
public class JxCenterWorkingBoardDispatchService implements IJxCenterWorkingBoardService {

    @Resource(name = MesExtConstWords.REDIS_MES)
    private ImppRedis redisMes;

    @Override
    public Map<String, Object> queryCenterWorkingBoardData(Map<String, Object> dataMap) {

        switch ((String) dataMap.get(MesExtConstWords.FLAG)) {

            case "center01":
                return new JxCenterWorkingBoardCenterOneService(new JxCenterWorkingBoardProxyCenterService(), new JxCenterWorkingBoardProxyWorkingStatusService(new JxCenterWorkingBoardProxySpcrService())).queryCenterWorkingBoardData(dataMap);

            case "center02":
                return new JxCenterWorkingBoardCenterTwoService(new JxCenterWorkingBoardProxyCenterService(), new JxCenterWorkingBoardProxyStandardWorkService(),
                        new JxCenterWorkingBoardProxyEnergyRateService(new JxCenterWorkingBoardProxyOrderService(new JxCenterWorkingBoardProxyOutPutService(new JxCenterWorkingBoardProxyRepairService(new JxCenterWorkingBoardProxySpcrService()))))).queryCenterWorkingBoardData(dataMap);

            case "center03":
                return new JxCenterWorkingBoardCenterThreeService(new JxCenterWorkingBoardProxyCenterService(), new JxCenterWorkingBoardProxyOrderService(new JxCenterWorkingBoardProxyOutPutService(new JxCenterWorkingBoardProxyTimeSegmentService()))).queryCenterWorkingBoardData(dataMap);

            case "monitor01":
                return new JxCenterWorkingBoardMonitorOneService(
                        new JxCenterWorkingBoardProxyAllCenterService(), new JxCenterWorkingBoardProxyStandardWorkService(), new JxCenterWorkingBoardProxyWorkingStatusService(), new JxCenterWorkingBoardProxyEnergyRateService(),
                        new JxCenterWorkingBoardProxyOrderService(new JxCenterWorkingBoardProxyOutPutService(new JxCenterWorkingBoardProxyRepairService(new JxCenterWorkingBoardProxySpcrService())))).queryCenterWorkingBoardData(dataMap);

            default:
                return dataMap;
        }
    }

    @Override
    public Object execCachedCenterWorkingBoardData(String organizeCode, String flag, String item, Object data) {

        String key = new StringJoiner(MesExtConstWords.COLON).add(organizeCode).add("JX_BOARD_DATA").toString();

        switch (flag) {
            case "0" :
                return redisMes.getHash(key, item);
            case "1" :
                return redisMes.putHash(key, item, data, MesEnumUtil.EXPIRE_TIME.NEVER.getValue());
            case "2" :
            default:
                redisMes.deleteKey(key);
                return true;
        }

    }

}