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.apiservice.dao.IPartExtDao;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.impp.framework.boot.util.SpringContextsUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author : wangjie
 * @CreateDate : 2022-02-15
 * @Modify:
 **/
@Slf4j
public class JxCenterWorkingBoardProxyStandardWorkService extends JxCenterWorkingBoardCommonService implements IJxCenterWorkingBoardService {

    private IPartExtDao partExtDao;

    public JxCenterWorkingBoardProxyStandardWorkService() {
        this.partExtDao = (IPartExtDao) SpringContextsUtil.getBean("partExtDao");
    }

    @Override
    public Map<String, Object> queryCenterWorkingBoardData(Map<String, Object> dataMap) {
        String organizeCode = (String) dataMap.get(MesExtConstWords.ORGANIZE_CODE);
        String partStandardWorkMap4Cached = (String) execCachedCenterWorkingBoardData(organizeCode, MesExtConstWords.ZERO_STR, MesExtConstWords.STANDARD_WORK, null);
        Map<String, String> partStandardWorkMap = !StringUtils.isEmpty(partStandardWorkMap4Cached) ? JSONObject.parseObject(partStandardWorkMap4Cached, Map.class) : execPartExtStandardWorkMap(organizeCode);
        dataMap.put(MesExtConstWords.STANDARD_WORK, partStandardWorkMap);
        return dataMap;
    }

    private Map<String, String> execPartExtStandardWorkMap(String organizeCode) {
        Map<String, String> partStandardWorkMap = partExtDao.queryPartExtStandardWorkStrMap(organizeCode);
        if (CollectionUtils.isEmpty(partStandardWorkMap)) partStandardWorkMap = new HashMap<>();
        execCachedCenterWorkingBoardData(organizeCode, CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValueStr(), MesExtConstWords.STANDARD_WORK,  JSONObject.toJSONString(partStandardWorkMap));
        return partStandardWorkMap;
    }

}