Jelajahi Sumber

修改查询时间方法--获取没有创建表异常

hxf 1 tahun lalu
induk
melakukan
8ce43e0b6b

+ 6 - 0
neim-biz/src/main/java/com/jiayue/biz/job/AirDensityJob.java

@@ -103,6 +103,12 @@ public class AirDensityJob {
                     startDate = new Date(lastTime);
                 }
 
+            }else {
+                List<Entity> firstRealData = prophaseWeatherDataService.getFirstData(windTowerInfo.getEquipmentNo());
+                if(firstRealData.size() > 0){
+                    startDate = (Timestamp) firstRealData.get(0).get("first (ts)");
+                }
+
             }
             //传入时间的月初
             Date startMonthDate = DateTimeUtil.beginOfMonth(startDate);

+ 30 - 8
neim-biz/src/main/java/com/jiayue/biz/service/impl/ProphaseWeatherDataServiceImpl.java

@@ -3,13 +3,19 @@ package com.jiayue.biz.service.impl;
 import cn.hutool.db.Entity;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jiayue.biz.domain.ProphaseWeatherData;
+import com.jiayue.biz.domain.StatisticsSituation;
 import com.jiayue.biz.mapper.ProphaseWeatherDataMapper;
 import com.jiayue.biz.service.ProphaseWeatherDataService;
+import com.jiayue.biz.service.StatisticsSituationService;
 import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.ibatis.annotations.Param;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.sql.Timestamp;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
@@ -17,20 +23,36 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 @Service
-@AllArgsConstructor
+@Slf4j
 public class ProphaseWeatherDataServiceImpl extends ServiceImpl<ProphaseWeatherDataMapper, ProphaseWeatherData> implements ProphaseWeatherDataService {
 
+
+    @Lazy
+    @Resource
+    StatisticsSituationService statisticsSituationService;
     //获取测风塔起止时间
     public Map<String, Long> getDataTimeStartAndEnd(String equipmentNo) {
+        List<StatisticsSituation> statisticsSituationList = statisticsSituationService.list();
         HashMap<String, Long> hashMap = new HashMap<>();
-        List<Entity> lastData = baseMapper.getLastData(equipmentNo);
-        List<Entity> firstData = baseMapper.getFirstData(equipmentNo);
-        if (!lastData.isEmpty() && !firstData.isEmpty()) {
-            Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)");
-            Timestamp timeStart = (Timestamp) firstData.get(0).get("first (ts)");
-            hashMap.put("startTime", timeStart.getTime());
-            hashMap.put("endTime", timeEnd.getTime());
+        try {
+            List<Entity> lastData = baseMapper.getLastData(equipmentNo);
+            List<Entity> firstData = baseMapper.getFirstData(equipmentNo);
+            if (!lastData.isEmpty() && !firstData.isEmpty()) {
+                Timestamp timeEnd = (Timestamp) lastData.get(0).get("last (ts)");
+                Timestamp timeStart = (Timestamp) firstData.get(0).get("first (ts)");
+                hashMap.put("startTime", timeStart.getTime());
+                hashMap.put("endTime", timeEnd.getTime());
+            }
+        } catch (Exception e) {
+            List<StatisticsSituation> collect = statisticsSituationList.stream().filter(s -> s.getEquipmentId().equals(equipmentNo)).collect(Collectors.toList());
+            if(collect.size() != 0){
+                String[] timeArr = collect.get(0).getStartTimeAndEndTime().split(",");
+                hashMap.put("startTime", Long.parseLong(timeArr[0]));
+                hashMap.put("endTime", Long.parseLong(timeArr[1]));
+            }
+            log.error("{}此测风塔没有表",equipmentNo);
         }
+
         return hashMap;
     }