WindTowerInfoServiceImpl.java 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. package com.jiayue.biz.service.impl;
  2. import cn.hutool.core.util.StrUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.jiayue.biz.domain.StatisticsSituation;
  6. import com.jiayue.common.core.redis.RedisCache;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Service;
  9. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  10. import com.jiayue.biz.mapper.WindTowerInfoMapper;
  11. import com.jiayue.biz.domain.WindTowerInfo;
  12. import com.jiayue.biz.service.WindTowerInfoService;
  13. import java.sql.Struct;
  14. import java.text.SimpleDateFormat;
  15. import java.util.*;
  16. import java.util.concurrent.TimeUnit;
  17. import java.util.stream.Collectors;
  18. /**
  19. * 测风塔信息Service业务层处理
  20. *
  21. * @author L.ym
  22. * @date 2022-05-11
  23. */
  24. @Service
  25. public class WindTowerInfoServiceImpl extends ServiceImpl<WindTowerInfoMapper, WindTowerInfo> implements WindTowerInfoService {
  26. @Autowired
  27. StatisticsSituationServiceImpl statisticsSituationService;
  28. @Autowired
  29. RedisCache redisCache;
  30. @Override
  31. public List<WindTowerInfo> getDashAllWindInfo() {
  32. List list = new ArrayList();
  33. List<WindTowerInfo> windTowerInfos = this.list();
  34. if (windTowerInfos.size() > 0) {
  35. for (WindTowerInfo windTowerInfo : windTowerInfos) {
  36. Map map = new HashMap();
  37. map.put("name", windTowerInfo.getName());
  38. map.put("lon", windTowerInfo.getLongitude());
  39. map.put("lat", windTowerInfo.getLatitude());
  40. list.add(map);
  41. }
  42. }
  43. return list;
  44. }
  45. //获取所有测风塔信息
  46. public List<WindTowerInfo> getAllWindTower(){
  47. return this.lambdaQuery().list();
  48. }
  49. /**
  50. * 新建测风塔时生成对应的测风塔表
  51. *
  52. * @param windTowerInfo
  53. * @return
  54. */
  55. public boolean saveWindTowerInfo(WindTowerInfo windTowerInfo) {
  56. baseMapper.createCalculationTable("wind_tower_calculation_data_" + windTowerInfo.getEquipmentNo());
  57. boolean save = this.save(windTowerInfo);
  58. return save;
  59. }
  60. public boolean update(WindTowerInfo windTowerInfo){
  61. boolean b = this.updateById(windTowerInfo);
  62. return b;
  63. }
  64. /**
  65. * 删除塔时删除表
  66. *
  67. * @param ids
  68. * @return
  69. */
  70. public boolean deleteWindTowerInfo(List<String> ids) {
  71. for (String id : ids) {
  72. WindTowerInfo w = this.getById(id);
  73. baseMapper.deleteCalculationTable("wind_tower_calculation_data_" + w.getEquipmentNo());
  74. }
  75. boolean b = this.removeByIds(ids);
  76. return b;
  77. }
  78. /*
  79. * 根据设备编号查询测风塔信息
  80. */
  81. public List<WindTowerInfo> getByEquipmentNo(String equipmentNo) {
  82. List<WindTowerInfo> allWindTower = getAllWindTower();
  83. return allWindTower.stream().filter(w -> w.getEquipmentNo().equals(equipmentNo)).collect(Collectors.toList());
  84. }
  85. /*
  86. * 根据设备编号查询测风塔信息
  87. */
  88. public List<WindTowerInfo> getByProjectId(String projectId) {
  89. QueryWrapper<WindTowerInfo> wrapper = new QueryWrapper();
  90. if (projectId != null && !projectId.equals("")) {
  91. wrapper.eq("project_id", projectId);
  92. }
  93. return baseMapper.selectList(wrapper);
  94. }
  95. /*
  96. * 分页查询设备编号查询测风塔信息
  97. */
  98. @Override
  99. public Page pageByEquipmentNo(Integer current, Integer size, String equipmentNo) {
  100. QueryWrapper<WindTowerInfo> wrapper = new QueryWrapper();
  101. if (equipmentNo != null && !equipmentNo.equals("")) {
  102. wrapper.eq("equipment_no", equipmentNo);
  103. }
  104. wrapper.orderByAsc("equipment_no");
  105. Page page = new Page(current, size);
  106. return page(page, wrapper);
  107. }
  108. public List<Map<String, String>> listEquipmentIdAndDataTime() {
  109. //TODO韩雪峰 新建的塔没有统计概述的时候无法显示 需要考虑到这种情况
  110. List<WindTowerInfo> windTowerInfoList = this.list();
  111. List<StatisticsSituation> statisticsSituationList = statisticsSituationService.list();
  112. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  113. List<Map<String, String>> mapList = new ArrayList<>();
  114. List<Map<String, String>> statusMapList = new ArrayList<>();
  115. //List<WindTowerInfo> windTowerInfoListCollect = windTowerInfoList.stream().sorted(Comparator.comparing(WindTowerInfo::getEquipmentNo)).collect(Collectors.toList());
  116. Map<String, Long> maps = new HashMap<>();
  117. for (StatisticsSituation s : statisticsSituationList) {
  118. maps.put(s.getEquipmentId(), Long.parseLong(s.getStartTimeAndEndTime().split(",")[1]));
  119. }
  120. List<Map.Entry<String, Long>> lstEntry = new ArrayList<>(maps.entrySet());
  121. //根据value 排序 降序
  122. lstEntry.sort(((o1, o2) -> o2.getValue().compareTo(o1.getValue())));
  123. List<WindTowerInfo> windTowerInfos = new ArrayList<>();
  124. lstEntry.forEach(o -> {
  125. //lstEntry 已经是排完序的了 for循环对比设备编号 添加到windTowerInfoList里 结果就是根据统计概述的数据截止时间从大到小的结果
  126. for (WindTowerInfo w : windTowerInfoList) {
  127. if (w.getEquipmentNo().equals(o.getKey())) {
  128. windTowerInfos.add(w);
  129. }
  130. }
  131. });
  132. if (windTowerInfoList.size() != windTowerInfos.size()) {
  133. for (WindTowerInfo w : windTowerInfoList) {
  134. if (windTowerInfos.stream().filter(wt -> wt.getId().equals(w.getId())).collect(Collectors.toList()).isEmpty()) {
  135. windTowerInfos.add(w);
  136. }
  137. }
  138. }
  139. Map<String, String> map;
  140. for (WindTowerInfo w : windTowerInfos) {
  141. map = new HashMap<>();
  142. map.put("value", w.getEquipmentNo());
  143. map.put("label", w.getName());
  144. map.put("wdHeights", w.getWdHeights());
  145. map.put("heights", w.getHeights());
  146. map.put("status", w.getStatus());
  147. List<StatisticsSituation> collect = statisticsSituationList.stream().filter(s -> s.getEquipmentId().equals(w.getEquipmentNo())).collect(Collectors.toList());
  148. if (!collect.isEmpty()) {
  149. //collect.get(0).getStartTimeAndEndTime().split(",") = "1638288000000,1638373800000"
  150. String[] strings = collect.get(0).getStartTimeAndEndTime().split(",");
  151. String str = sdf.format(new Date(Long.parseLong(strings[0]))) + "-" + sdf.format(new Date(Long.parseLong(strings[1])));
  152. map.put("date", str);
  153. }
  154. if (w.getStatus() == null || w.getStatus().equals("")) {
  155. statusMapList.add(map);
  156. } else {
  157. mapList.add(map);
  158. }
  159. }
  160. mapList.addAll(statusMapList);
  161. //redisCache.setCacheObject("listEquipmentIdAndDataTime", mapList, 1, TimeUnit.HOURS);
  162. return mapList;
  163. }
  164. /**
  165. * TODO 需要改的地方过多 重写list
  166. *
  167. * @return List<WindTowerInfo>
  168. */
  169. // public List<WindTowerInfo> list() {
  170. // return this.lambdaQuery().eq(WindTowerInfo::getType, "1").list();
  171. // }
  172. //获取测风塔层高
  173. public String getWsHeights(String equipmentId) {
  174. String wsHeights = "";
  175. try {
  176. if (StrUtil.isNotBlank(equipmentId)) {
  177. List<WindTowerInfo> equipmentNo = this.getByEquipmentNo(equipmentId);
  178. if (!equipmentNo.isEmpty()) {
  179. wsHeights = equipmentNo.get(0).getHeights();
  180. }
  181. }
  182. } catch (Exception e) {
  183. log.error("测风塔编号错误");
  184. throw new RuntimeException(e);
  185. }
  186. return wsHeights;
  187. }
  188. }