package com.gyee.backconfig.config; import com.gyee.backconfig.model.auto.*; import com.gyee.backconfig.service.auto.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * @ClassName : CacheContext * @Author : wang * @Date: 2022/9/26 9:35 * @Description : 缓存 */ @Component public class CacheContext implements CommandLineRunner { @Resource private IProBasicEnergyGroupService proBasicEnergyGroupService;//集团 @Autowired private IProBasicRegionService proBasicRegionService;//区域 @Resource private IProBasicCompanyService proBasicCompanyService;//公司 @Resource private IProBasicPowerstationService proBasicPowerstationService;//场站 @Resource private IProBasicProjectService proBasicProjectService;//期次 @Resource private IProBasicLineService proBasicLineService;//线路 @Autowired private IProBasicEquipmentService proBasicEquipmentService;//风机 @Autowired private IProBasicSubStationService proBasicSubStationServicel;//变电所 @Autowired private IProBasicSquareService proBasicSquareService; //集团 public static Map energymap = new HashMap<>(); public static List groups = new ArrayList<>(); //区域 public static Map regionmap = new HashMap<>(); public static List regions = new ArrayList<>(); //公司 public static Map companymap = new HashMap<>(); public static List companys = new ArrayList<>(); //场站 public static Map wpmap = new HashMap<>(); public static List wpls = new ArrayList<>(); public static Map> wpmapGroupGCRegion = new HashMap<>(); public static Map> wpmapGroupGCCompany = new HashMap<>(); public static Map> wpmapGroupFCRegion = new HashMap<>(); public static Map> wpmapGroupFCCompany = new HashMap<>(); //期次 public static Map promap = new HashMap<>(); public static List prols = new ArrayList<>(); //线路 public static Map linemap = new HashMap<>(); public static List lines = new ArrayList<>(); //风机 public static Map equipmentmap = new HashMap<>(); public static List equipments = new ArrayList<>(); public static Map> poequipmentmap = new HashMap<>(); public static Map> pjequipmentmap = new HashMap<>(); public static Map> liequipmentmap = new HashMap<>(); //变电所 public static List subStations = new ArrayList<>(); public static Map subStationMap = new HashMap<>(); public static Map> poSubStationMap = new HashMap<>();//更据场站分组 //方阵 public static List squares = new ArrayList<>(); public static Map squareMap = new HashMap<>(); @Override public void run(String... args) throws Exception { System.out.println(">>>>>>>>>>>>>>>服务启动,正在缓存数据<<<<<<<<<<<<<<"); //集团 initGroupList(); //区域 initSegionList(); //公司 initCompanyList(); //场站 initPowerstationList(); //期次 initProjectList(); //线路 initLineList(); //发电设备 initEquipmentList(); //变电所 initSubStationList(); //方阵 initSquaresList(); System.out.println(">>>>>>>>>>>>>>>数据缓存完成<<<<<<<<<<<<<<"); } /** * 初始化集团表 */ public void initGroupList(){ //清理集合中的数据 groups.clear(); energymap.clear(); //重新加载集合数据 groups = proBasicEnergyGroupService.list(); groups.stream().forEach(energy -> { energymap.put(energy.getId(), energy); }); } /** * 初始化区域数据 */ public void initSegionList(){ //清理集合中的数据 regions.clear(); regionmap.clear(); regions = proBasicRegionService.list(); regions.stream().forEach(region -> { regionmap.put(region.getId(), region); }); } /** * 初始化公司数据 */ public void initCompanyList(){ //清理集合中的数据 companys.clear(); companymap.clear(); companys = proBasicCompanyService.list(); companys.stream().forEach(Companys -> { companymap.put(Companys.getId(), Companys); }); } /** * 初始化场站数据 */ public void initPowerstationList(){ //清理集合数据 wpls.clear(); wpmap.clear(); wpmapGroupGCCompany.clear(); wpmapGroupFCCompany.clear(); wpmapGroupGCRegion.clear(); wpmapGroupFCRegion.clear(); wpls = proBasicPowerstationService.list(); wpls.stream().forEach(windpowerstation -> { wpmap.put(windpowerstation.getId(), windpowerstation); }); wpmapGroupGCRegion = wpls.stream().filter(p-> p.getId().indexOf("_GDC_") >= 0).collect(Collectors.groupingBy(ProBasicPowerstation::getRegionId)); wpmapGroupFCRegion = wpls.stream().filter(p-> p.getId().indexOf("_FDC_") >= 0).collect(Collectors.groupingBy(ProBasicPowerstation::getRegionId)); wpmapGroupGCCompany = wpls.stream().filter(p-> p.getId().indexOf("_GDC_") >= 0).collect(Collectors.groupingBy(ProBasicPowerstation::getCompanyId)); wpmapGroupFCCompany = wpls.stream().filter(p-> p.getId().indexOf("_FDC_") >= 0).collect(Collectors.groupingBy(ProBasicPowerstation::getCompanyId)); } /** * 初始化期次工程数据 */ public void initProjectList(){ //请立集合数据 prols.clear(); promap.clear(); prols = proBasicProjectService.list(); prols.stream().forEach(Project -> { promap.put(Project.getId(), Project); }); } /** * 初始化线路数据 */ public void initLineList(){ lines.clear(); linemap.clear(); lines = proBasicLineService.list(); lines.stream().forEach(line -> { linemap.put(line.getId(), line); }); } /** * 初始化线路数据 */ public void initEquipmentList(){ //清理集合数据 equipments.clear(); equipmentmap.clear(); poequipmentmap.clear(); pjequipmentmap.clear(); liequipmentmap.clear(); equipments = proBasicEquipmentService.list(); equipments.stream().forEach(windturbine -> { equipmentmap.put(windturbine.getId(), windturbine); }); poequipmentmap = equipments.stream().collect(Collectors.groupingBy(ProBasicEquipment::getWindpowerstationId)); pjequipmentmap = equipments.stream().collect(Collectors.groupingBy(ProBasicEquipment::getProjectId)); liequipmentmap = equipments.stream().collect(Collectors.groupingBy(ProBasicEquipment::getLineId)); } /** * 初始化线路数据 */ public void initSubStationList(){ //清理集合数据 subStations.clear(); subStationMap.clear(); poSubStationMap.clear(); subStations = proBasicSubStationServicel.list(); subStations.stream().forEach(s->{ subStationMap.put(s.getId(),s); }); poSubStationMap = subStations.stream().collect(Collectors.groupingBy(ProBasicSubStation::getWindpowerstationId)); } /** * 初始化方阵数据 */ public void initSquaresList(){ squares.clear(); squareMap.clear(); squares = proBasicSquareService.list(); squares.stream().forEach(i->{ squareMap.put(i.getId(),i); }); } }