zoukankan      html  css  js  c++  java
  • 基于内存进行缓存

    
    package com.izkml.energy.score.init;
    
    import com.izkml.energy.score.enums.WorkPropertyEnum;
    import com.izkml.energy.score.response.BatchResponse;
    import com.izkml.energy.score.response.OrganResponse;
    import com.izkml.energy.score.response.ScoreRulesResponse;
    import com.izkml.energy.score.response.SysAreaResponse;
    import com.izkml.energy.score.service.BatchService;
    import com.izkml.energy.score.service.OrganService;
    import com.izkml.energy.score.service.ScoreRulesService;
    import com.izkml.energy.score.service.SysAreaService;
    import org.apache.commons.collections4.CollectionUtils;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.boot.CommandLineRunner;
    import org.springframework.stereotype.Component;
    
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.stream.Collectors;
    
    /**
     * @Author: fyqing
     * @Date: 2020-41-04 10:41:43
     * @Desription:
     **/
    
    @Component
    public class InitData implements CommandLineRunner {
    
        @Autowired(required = false)
        BatchService batchService;
    
        @Autowired(required = false)
        ScoreRulesService scoreRulesService;
    
        @Autowired(required = false)
        OrganService organService;
    
        @Autowired
        SysAreaService sysAreaService;
    
        private static Map<Integer, String> batchProperties;
    
        private static List<ScoreRulesResponse> focusScoreRules;
    
        private static List<ScoreRulesResponse> aloneScoreRules;
    
        public static List<OrganResponse> allOrganResponse;
    
        public static List<SysAreaResponse> allArea;
    
        public static List<ScoreRulesResponse> getByWorkProperty(String workProperty) {
            return workProperty.equals(WorkPropertyEnum.FOCUS.toString()) ? focusScoreRules : aloneScoreRules;
        }
    
        public static String getBatchById(Integer id) {
            return batchProperties.get(id);
        }
    
        private static Map<Integer, OrganResponse> organProperties;
    
        private static Map<String, String> areaProperties;
    
        public static String getAreaNameById(String id){
            return areaProperties.get(id);
        }
    
        public static OrganResponse getOrganById(Integer id) {
            return organProperties.get(id);
        }
    
        public static void resetBatches(Map<Integer, String> batchInitDataMap) {
            batchProperties = batchInitDataMap;
        }
    
        public static void resetOrgans(List<OrganResponse> organResponses) {
            allOrganResponse = organResponses;
        }
    
        @Override
        public void run(String... args) throws Exception {
            if (batchProperties == null) {
                batchProperties = new HashMap<>(16);
            }
            List<BatchResponse> batchResponses = batchService.findList();
            if (CollectionUtils.isNotEmpty(batchResponses)) {
                Map<Integer, String> batchInitDataMap = batchResponses.stream().
                        collect(Collectors.toMap(BatchResponse::getId, a -> a.getName(), (k1, k2) -> k1));
                batchProperties = batchInitDataMap;
            }
            //初始化评分规则列表
            List<ScoreRulesResponse> scoreRulesList = scoreRulesService.findAllList();
            focusScoreRules = scoreRulesList.stream().filter(s -> s.getWorkProperty().equals(WorkPropertyEnum.FOCUS.toString())).collect(Collectors.toList());
            aloneScoreRules = scoreRulesList.stream().filter(s -> s.getWorkProperty().equals(WorkPropertyEnum.ALONE.toString())).collect(Collectors.toList());
            //把单位数据加载到内存
            List<OrganResponse> organResponses = organService.getAllOrgans();
            allOrganResponse = organResponses;
            if (CollectionUtils.isNotEmpty(organResponses)) {
                Map<Integer, OrganResponse> organInitDataMap = organResponses.stream().
                        collect(Collectors.toMap(OrganResponse::getId, o -> o));
                organProperties = organInitDataMap;
            }
    
            List<SysAreaResponse> areaResponses = sysAreaService.getAll();
            allArea = areaResponses;
            if (CollectionUtils.isNotEmpty(areaResponses)) {
                Map<String, String> areaInitDataMap = areaResponses.stream().
                        collect(Collectors.toMap(SysAreaResponse::getId, SysAreaResponse::getAreaName));
                areaProperties = areaInitDataMap;
            }
        }
    }
    
    
    
  • 相关阅读:
    MATLAB——sigmoid传递函数
    MATLAB——BP神经网络
    MATLAB——神经网络构造线性层函数linearlayer
    MATLAB——线性神经网络
    MTALAB——神经网络mae()、mse()、sse()
    详解 Java 中的三种代理模式!
    HTTP 无状态中的状态到底指的是什么?
    单例模式的 8 种写法,整理非常全!
    数据库连接池到底应该设多大?
    Spring 框架用到的 9 个设计模式汇总!
  • 原文地址:https://www.cnblogs.com/fangh816/p/13299353.html
Copyright © 2011-2022 走看看