ProphaseWeatherDataServiceImpl.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.jiayue.biz.service.impl;
  2. import cn.hutool.db.Entity;
  3. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  4. import com.jiayue.biz.domain.ProphaseWeatherData;
  5. import com.jiayue.biz.domain.StatisticsSituation;
  6. import com.jiayue.biz.mapper.ProphaseWeatherDataMapper;
  7. import com.jiayue.biz.service.ProphaseWeatherDataService;
  8. import com.jiayue.biz.service.StatisticsSituationService;
  9. import com.jiayue.common.core.text.Convert;
  10. import lombok.AllArgsConstructor;
  11. import lombok.extern.slf4j.Slf4j;
  12. import org.apache.ibatis.annotations.Param;
  13. import org.springframework.context.annotation.Lazy;
  14. import org.springframework.stereotype.Service;
  15. import javax.annotation.Resource;
  16. import java.sql.Timestamp;
  17. import java.text.SimpleDateFormat;
  18. import java.util.*;
  19. import java.util.stream.Collectors;
  20. @Service
  21. @Slf4j
  22. public class ProphaseWeatherDataServiceImpl extends ServiceImpl<ProphaseWeatherDataMapper, ProphaseWeatherData> implements ProphaseWeatherDataService {
  23. @Lazy
  24. @Resource
  25. StatisticsSituationService statisticsSituationService;
  26. //获取测风塔起止时间
  27. public Map<String, Long> getDataTimeStartAndEnd(String equipmentNo) {
  28. HashMap<String, Long> hashMap = new HashMap<>();
  29. hashMap.put("startTime", 0l);
  30. hashMap.put("endTime", 0l);
  31. try {
  32. List<Entity> lastData = baseMapper.getLastData(equipmentNo);
  33. List<Entity> firstData = baseMapper.getFirstData(equipmentNo);
  34. if (!lastData.isEmpty() && !firstData.isEmpty()) {
  35. Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)");
  36. Timestamp timeStart = (Timestamp) firstData.get(0).get("first (ts)");
  37. hashMap.put("startTime", timeStart.getTime());
  38. hashMap.put("endTime", timeEnd.getTime());
  39. }
  40. } catch (Exception e) {
  41. List<StatisticsSituation> statisticsSituationList = statisticsSituationService.list();
  42. List<StatisticsSituation> collect = statisticsSituationList.stream().filter(s -> s.getEquipmentId().equals(equipmentNo)).collect(Collectors.toList());
  43. if(collect.size() != 0){
  44. String[] timeArr = collect.get(0).getStartTimeAndEndTime().split(",");
  45. hashMap.put("startTime", Long.parseLong(timeArr[0]));
  46. hashMap.put("endTime", Long.parseLong(timeArr[1]));
  47. }
  48. log.error("{} 此测风塔没有表,创建表",equipmentNo);
  49. try {
  50. createTable(equipmentNo);
  51. }catch (Exception e1){
  52. log.error("创建测风塔设备:{} 的环境表数据失败:{}",equipmentNo,e1);
  53. }
  54. }
  55. return hashMap;
  56. }
  57. //根据设备编号取出所有条数
  58. /*
  59. td engine 取出的时间需要截取字段
  60. String wstart = entity.get("_wstart").toString().substring(0, 10);
  61. formatMap.put(wstart, entity.get("count(*)"));
  62. */
  63. public List<Entity> selectCount(String equipmentNo) {
  64. return baseMapper.selectCount(equipmentNo);
  65. }
  66. //查询温度平均值、压强平均值、空气密度
  67. public List<ProphaseWeatherData> selectTAveAndPaAveAndAir(String equipmentId, Timestamp startTime, Timestamp endTime) {
  68. return baseMapper.selectTAveAndPaAveAndAir(equipmentId, startTime, endTime);
  69. }
  70. //查询空气密度
  71. public List<ProphaseWeatherData> selectAir(String equipmentId, Timestamp startTime, Timestamp endTime) {
  72. List<ProphaseWeatherData> weatherDataList = baseMapper.selectAir(equipmentId, startTime, endTime);
  73. return weatherDataList.stream().filter(w -> Convert.toFloat(w.getAirDensity(),0f) > 0).collect(Collectors.toList());
  74. }
  75. //查询最开始一条记录
  76. public List<Entity> getFirstData(String equipmentId) {
  77. return baseMapper.getFirstData(equipmentId);
  78. }
  79. //查询最后一条记录
  80. public List<Entity> getLastData(String equipmentId) {
  81. return baseMapper.getLastData(equipmentId);
  82. }
  83. //批量保存
  84. public int insertSplice(List<ProphaseWeatherData> prophaseWeatherDataList, String equipmentId) {
  85. return baseMapper.insertSplice(prophaseWeatherDataList, equipmentId);
  86. }
  87. //查询所有数据
  88. public List<ProphaseWeatherData> selectPublicData(String equipmentId, Timestamp startTime, Timestamp endTime) {
  89. return baseMapper.selectPublicData(equipmentId, startTime, endTime);
  90. }
  91. //删除时间段内数据
  92. public void deleteData(String equipmentId, Timestamp startTime, Timestamp endTime) {
  93. baseMapper.deleteData(equipmentId, startTime, endTime);
  94. }
  95. public void insertOne(ProphaseWeatherData prophaseWeatherData){
  96. baseMapper.insertOneWithNew(prophaseWeatherData);
  97. }
  98. /**
  99. * 创建不存在的环境数据表
  100. * @param equipmentId
  101. */
  102. public void createTable(String equipmentId){
  103. baseMapper.createTable(equipmentId);
  104. }
  105. /**
  106. * 待改造
  107. * @return
  108. */
  109. }