AnalysisLogServiceImpl.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. package com.jiayue.biz.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  4. import com.jiayue.biz.domain.WindTowerInfo;
  5. import com.jiayue.biz.service.WindTowerInfoService;
  6. import com.jiayue.biz.util.DateTimeUtil;
  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.AnalysisLogMapper;
  11. import com.jiayue.biz.domain.AnalysisLog;
  12. import com.jiayue.biz.service.IAnalysisLogService;
  13. import java.util.*;
  14. /**
  15. * 【请填写功能名称】Service业务层处理
  16. *
  17. * @author L.ym
  18. * @date 2022-05-23
  19. */
  20. @Service
  21. public class AnalysisLogServiceImpl extends ServiceImpl<AnalysisLogMapper, AnalysisLog> implements IAnalysisLogService {
  22. @Autowired
  23. private WindTowerInfoService windTowerInfoService;
  24. /**
  25. * 根据时间范围和设备id查询数据
  26. *
  27. * @param startTime 开始时间
  28. * @param endTime 结束时间
  29. * @param equipmentId 设备id
  30. * @return
  31. */
  32. public List<AnalysisLog> getByBetweenTimeAndEquipmentId(Date startTime, Date endTime, String equipmentId) {
  33. QueryWrapper<AnalysisLog> wrapper = new QueryWrapper();
  34. if (startTime != null && endTime != null) {
  35. wrapper.between("time", startTime, endTime);
  36. }
  37. if (equipmentId != null && !equipmentId.equals("")) {
  38. wrapper.eq("equipment_id", equipmentId);
  39. }
  40. return baseMapper.selectList(wrapper);
  41. }
  42. //获取时间是昨天的所有设备的解析记录
  43. @Override
  44. public List<AnalysisLog> getAllList() {
  45. List list = new ArrayList();
  46. List<WindTowerInfo> windTowerInfoList = windTowerInfoService.list();
  47. if (windTowerInfoList.size() > 0) {
  48. for (WindTowerInfo windTowerInfo : windTowerInfoList) {
  49. Date startTime = DateTimeUtil.getDayStartTime(new Date().getTime() - 1000 * 60 * 60 * 24);
  50. Date endTime = DateTimeUtil.getDayLastTime(new Date().getTime() - 1000 * 60 * 60 * 24);
  51. Map map = new HashMap();
  52. List<AnalysisLog> analysisLogList = getByBetweenTimeAndEquipmentId(startTime, endTime, windTowerInfo.getEquipmentNo());
  53. if (analysisLogList.size() > 0) {
  54. //排序要降序
  55. analysisLogList.sort(Comparator.comparing(AnalysisLog::getTime));
  56. map.put("equipmentId", windTowerInfo.getEquipmentNo());
  57. map.put("status", analysisLogList.get(0).getStatus());
  58. map.put("time", analysisLogList.get(0).getTime());
  59. list.add(map);
  60. } else {
  61. map.put("equipmentId", windTowerInfo.getEquipmentNo());
  62. map.put("status", "0");
  63. map.put("time", "");
  64. list.add(map);
  65. }
  66. }
  67. }
  68. return list;
  69. }
  70. //根据解析的文件时间查看
  71. @Override
  72. public Page<AnalysisLog> findByTime(Integer current, Integer size, Long startTime, Long endTime, String equipmentId) {
  73. QueryWrapper<AnalysisLog> wrapper = new QueryWrapper();
  74. if (startTime != null && endTime != null) {
  75. wrapper.between("time", new Date(startTime), new Date(endTime));
  76. }
  77. if (equipmentId != null && !equipmentId.equals("")) {
  78. wrapper.eq("equipment_id", equipmentId);
  79. }
  80. /*根据时间排序*/
  81. wrapper.orderByAsc("time").orderByAsc("equipment_id");
  82. /*分页*/
  83. Page page = new Page(current, size);
  84. Page<AnalysisLog> analysisLogPage = page(page, wrapper);
  85. return analysisLogPage;
  86. }
  87. //当天开始时间
  88. public static Date getTodayStartTime() {
  89. Calendar todayStart = Calendar.getInstance();
  90. todayStart.set(Calendar.HOUR_OF_DAY, 0);
  91. todayStart.set(Calendar.MINUTE, 0);
  92. todayStart.set(Calendar.SECOND, 0);
  93. return todayStart.getTime();
  94. }
  95. //当天结束时间
  96. public static Date getTodayEndTime() {
  97. Calendar todayEnd = Calendar.getInstance();
  98. todayEnd.set(Calendar.HOUR_OF_DAY, 23);
  99. todayEnd.set(Calendar.MINUTE, 59);
  100. todayEnd.set(Calendar.SECOND, 59);
  101. return todayEnd.getTime();
  102. }
  103. /**
  104. * 根据条件删除
  105. *
  106. * @param startTime 开始时间
  107. * @param endTime 结束时间
  108. * @param equipmentId 设备编号
  109. * @return
  110. */
  111. public boolean removeByDate(Date startTime, Date endTime, String equipmentId) {
  112. QueryWrapper<AnalysisLog> wrapper = new QueryWrapper();
  113. if (startTime != null && endTime != null) {
  114. wrapper.between("time", startTime, endTime);
  115. }
  116. if (equipmentId != null) {
  117. wrapper.eq("equipment_id", equipmentId);
  118. }
  119. return super.remove(wrapper);
  120. }
  121. }