CacheContext.java 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package com.gyee.datacenter.init;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.alibaba.fastjson.TypeReference;
  4. import com.gyee.common.model.StringUtils;
  5. import com.gyee.common.util.JSONUtil;
  6. import com.gyee.datacenter.model.auto.*;
  7. import com.gyee.datacenter.service.auto.IDatacenterService;
  8. import com.gyee.datacenter.service.auto.IUniformcodeService;
  9. import com.gyee.datacenter.service.auto.IWindpowerstationService;
  10. import com.gyee.datacenter.service.auto.IWindturbineService;
  11. import com.gyee.datacenter.util.redis.RedisService;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.boot.CommandLineRunner;
  15. import org.springframework.stereotype.Component;
  16. import javax.annotation.Resource;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.Map;
  21. /**
  22. * @ClassName : CacheContext
  23. * @Author : xieshengjie
  24. * @Date: 2022/2/21 18:20
  25. * @Description :
  26. */
  27. @Component
  28. public class CacheContext implements CommandLineRunner {
  29. private static final Logger log = LoggerFactory.getLogger(CacheContext.class);
  30. @Resource
  31. private RedisService redisService;
  32. @Resource
  33. private IUniformcodeService uniformcodeService;
  34. @Resource
  35. private IDatacenterService datacenterService;
  36. @Resource
  37. private IWindturbineService windturbineService;
  38. @Resource
  39. private IWindpowerstationService windpowerstationService;
  40. public static List<Datacenter> tableList = new ArrayList<>();
  41. public static Map<String, List<Datacenterpoint>> pointmap = new HashMap<>();
  42. public static Map<String,String> inmap = new HashMap<>();
  43. public static List<Uniformcode> codeList = new ArrayList<>();
  44. public static Map<String,String> codemap = new HashMap<>();
  45. public static Map<String,String> wpmap = new HashMap<>();
  46. public static Map<String, Map<String, Windturbinetestingpointnew>> wtpointmap = new HashMap<>();
  47. public static Map<String,String> wtmap = new HashMap<>();
  48. @Override
  49. public void run(String... args) throws Exception {
  50. log.info("-------------------------------缓存开始--------------------------------------");
  51. tableList = datacenterService.list();
  52. tableList.stream().forEach(i->{
  53. List<Datacenterpoint> realtimedataList = JSONUtil.jsonToList(redisService.get(i.getTableid()), Datacenterpoint.class);
  54. if(StringUtils.isNotNull(realtimedataList)){
  55. pointmap.put(i.getTableid(),realtimedataList);
  56. realtimedataList.stream().forEach(x->{
  57. inmap.put(x.getId(),x.getName());
  58. });
  59. }
  60. });
  61. List<Windpowerstation> wpls = windpowerstationService.list();
  62. wpls.stream().forEach(i->{
  63. wpmap.put(i.getId(),i.getName());
  64. });
  65. codeList = uniformcodeService.list();
  66. codeList.stream().forEach(i->{
  67. codemap.put(i.getCode(),i.getDescription());
  68. });
  69. List<Windturbine> wtls = windturbineService.list();
  70. wtls.stream().forEach(i->{
  71. wtmap.put(i.getId(),i.getName());
  72. });
  73. String wtjson = redisService.get("PRODUCT-WT");
  74. wtpointmap = JSONObject.parseObject(wtjson, new TypeReference<Map<String, Map<String, Windturbinetestingpointnew>>>() {
  75. });
  76. log.info("-------------------------------缓存结束--------------------------------------");
  77. }
  78. }