CacheContext.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package com.gyee.benchmarkinghistroy.init;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.alibaba.fastjson.TypeReference;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.gyee.benchmarkinghistroy.model.auto.*;
  6. import com.gyee.benchmarkinghistroy.service.auto.*;
  7. import com.gyee.benchmarkinghistroy.util.redis.RedisService;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.boot.CommandLineRunner;
  12. import org.springframework.stereotype.Component;
  13. import javax.annotation.Resource;
  14. import java.util.*;
  15. /**
  16. * @ClassName : CacheContext
  17. * @Author : xieshengjie
  18. * @Date: 2021/9/29 17:33
  19. * @Description : 初始化
  20. */
  21. @Component
  22. public class CacheContext implements CommandLineRunner {
  23. private static final Logger log = LoggerFactory.getLogger(CacheContext.class);
  24. @Autowired
  25. private IWindturbineService windturbineService;
  26. @Autowired
  27. private IWindpowerstationService windpowerstationService;
  28. @Autowired
  29. private IProjectService projectService;
  30. @Autowired
  31. private ILineService lineService;
  32. @Autowired
  33. private IWindturbinetestingpointnewService windturbinetestingpointnewService;
  34. @Autowired
  35. private IWindpowerstationpointnewService windpowerstationpointnewService;
  36. @Resource
  37. private RedisService redisService;
  38. @Resource
  39. private IEquipmentmodelService equipmentmodelService;
  40. public static Map<String, List<Windturbine>> wtmap = new HashMap<>();
  41. public static Map<String,Windturbine> wmap = new HashMap<>();
  42. public static Map<String, Windpowerstation> wpmap = new HashMap<>();
  43. public static List<Windpowerstation> wplist = new ArrayList<>();
  44. public static List<Windturbine> wtls = new ArrayList<>();
  45. public static Map<String, Map<String, Windturbinetestingpointnew>> wtpAimap = new HashMap<>();// 风电机测点AI表
  46. public static Map<String,Map<String, Windpowerstationpointnew>> wppointmap =new HashMap<>();
  47. public static Map<String,Map<String, Windpowerstationpointnew>> pjPointmap =new HashMap<>();
  48. public static Map<String,Map<String, Windpowerstationpointnew>> lnPointmap =new HashMap<>();
  49. public static Map<String,Double> wtrlmap =new HashMap<>();
  50. public static List<Project> projects = new ArrayList<>();
  51. public static List<Line> lines = new ArrayList<>();
  52. @Override
  53. public void run(String... args) throws Exception {
  54. log.info("-------------------------------缓存开始--------------------------------------");
  55. wplist = windpowerstationService.list();
  56. wplist.stream().filter(i->i.getId().endsWith("FDC")).forEach(i->{
  57. wpmap.put(i.getId(),i);
  58. });
  59. projects = projectService.list();
  60. lines = lineService.list();
  61. wtls = windturbineService.list();
  62. wtls.stream().forEach(wt->{
  63. wmap.put(wt.getId(),wt);
  64. if (wtmap.containsKey(wt.getWindpowerstationid())){
  65. wtmap.get(wt.getWindpowerstationid()).add(wt);
  66. }else{
  67. List<Windturbine> wts = new ArrayList<>();
  68. wts.add(wt);
  69. wtmap.put(wt.getWindpowerstationid(),wts);
  70. }
  71. QueryWrapper<Equipmentmodel> queryWrapper= new QueryWrapper<>();
  72. queryWrapper.eq("id",wt.getModelid());
  73. Optional<Equipmentmodel> first = equipmentmodelService.list(queryWrapper).stream().findFirst();
  74. if (first.isPresent()){
  75. wtrlmap.put(wt.getId(),first.get().getPowerproduction());
  76. }
  77. });
  78. String wpString = redisService.get("PRODUCT-WP");
  79. wppointmap = JSONObject.parseObject(wpString, new TypeReference<Map<String, Map<String, Windpowerstationpointnew>>>() {
  80. });
  81. String pjString = redisService.get("PRODUCT-PJ");
  82. pjPointmap = JSONObject.parseObject(pjString, new TypeReference<Map<String, Map<String, Windpowerstationpointnew>>>() {
  83. });
  84. String lnString = redisService.get("PRODUCT-LN");
  85. lnPointmap = JSONObject.parseObject(lnString, new TypeReference<Map<String, Map<String, Windpowerstationpointnew>>>() {
  86. });
  87. String wtString = redisService.get("PRODUCT-WT");
  88. wtpAimap = JSONObject.parseObject(wtString, new TypeReference<Map<String, Map<String, Windturbinetestingpointnew>>>() {
  89. });
  90. log.info("-------------------------------缓存结束--------------------------------------");
  91. }
  92. }