15928045575 пре 2 година
родитељ
комит
bf796009b9

+ 3 - 1
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/controller/backTrackController.java

@@ -18,6 +18,8 @@ import org.apache.http.HttpResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.text.ParseException;
+
 /**
  * @author s'k'y
  * @description 数据回溯controller
@@ -51,7 +53,7 @@ public class backTrackController {
     @Log(description = "返回设备折线图")
     //@RepeatSubmit(interval = 3000, message = "两次请求间隔未超过3秒")
     @RequestMapping(name = "返回设备折线图", value = "/getDeviceChart", method = RequestMethod.GET)
-    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd, @RequestParam("original") Integer original) {
+    public HttpResult getDeviceChart(@RequestParam("deviceId") String deviceId,@RequestParam("snCode") String snCode, @RequestParam("part") String part, @RequestParam("dateStart") String dateStart, @RequestParam("dateEnd") String dateEnd, @RequestParam("original") Integer original) throws ParseException {
         log.info("返回设备折线图 getDeviceChart param :{},part:{}",deviceId,part);
         return backTrackService.getDeviceChart(deviceId,snCode,part,dateStart,dateEnd,original);
     }

+ 7 - 3
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/BackTrackService.java

@@ -31,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 import com.sckw.slope.detection.dao.tdengine.InsTablesMapper;
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -114,7 +115,7 @@ public class BackTrackService {
         return HttpResult.ok(devices);
     }
 
-    public HttpResult getDeviceChart(String devicesId,String snCode, String parts, String dateStart,String dateEnd,Integer original) {
+    public HttpResult getDeviceChart(String devicesId,String snCode, String parts, String dateStart,String dateEnd,Integer original) throws ParseException {
         //先查询设备
         KwsDevice deviceHas = deviceMapper.selectOne(new LambdaQueryWrapper<KwsDevice>()
                 .eq(KwsDevice::getSnCode, snCode));
@@ -130,10 +131,13 @@ public class BackTrackService {
                 return HttpResult.ok(Collections.emptyList());
             }
             List<SlopeData> selectedData = slopeDataMapper.selectLineListByArray(snCode, arr, dateStart, dateEnd);
+            Map<String,List<Object>>  map = new HashMap<>();
+
             if (CollectionUtils.isEmpty(selectedData)) {
-               return HttpResult.ok(Collections.emptyList());
+                map = commonService.getDateByNull(dateStart,dateEnd,arr);
+                return HttpResult.ok(map);
             }
-            Map<String,List<Object>>  map = new HashMap<>();
+
             for(SlopeData slop : selectedData){
                 if(slop.getLine().equals(DictItemEnum.getData(slop.getLine()).getValue())){
                     List<Object> list = new ArrayList<>();

+ 29 - 0
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/CommonService.java

@@ -10,6 +10,7 @@ import com.sckw.core.model.enums.DictItemEnum;
 import com.sckw.core.model.enums.MessageLogEnum;
 import com.sckw.core.model.page.PageRes;
 import com.sckw.core.utils.IdWorker;
+import com.sckw.core.web.response.HttpResult;
 import com.sckw.core.web.response.PhpResult;
 
 import com.sckw.slope.detection.dao.mysql.KwsDeviceReferenceMapper;
@@ -30,7 +31,11 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.cloud.context.config.annotation.RefreshScope;
 import org.springframework.stereotype.Service;
 import com.sckw.slope.detection.dao.tdengine.SlopeDataMapper;
+import org.springframework.util.CollectionUtils;
+
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.*;
 
@@ -284,4 +289,28 @@ public class CommonService {
         }
         return 0;
     }
+
+    public Map<String,List<Object>> getDateByNull(String dateStart,String dateEnd,String[] arr) throws ParseException {
+        Map<String,List<Object>>  map = new HashMap<>();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date start = sdf.parse(dateStart);
+        Date end = sdf.parse(dateEnd);
+
+        for(String ar: arr){
+            Date temp = start;
+            Calendar calendar = Calendar.getInstance();
+            calendar.setTime(start);
+            List<Object> list = new ArrayList<>();
+
+            while(temp.getTime() < end.getTime()){
+                Map<Object,Object> map1 =  new HashMap<>();
+                temp = calendar.getTime();
+                map1.put("ts", sdf.format(temp.getTime()));
+                list.add(map1);
+                calendar.add(Calendar.HOUR_OF_DAY,24);
+            }
+            map.put(ar,list);
+        }
+        return map;
+    }
 }

+ 5 - 4
slope-modules/slope-detection/src/main/java/com/sckw/slope/detection/service/DeviceService.java

@@ -168,13 +168,14 @@ public class DeviceService {
                     }*/
                 }
             }
-            for (SystemDict value : deviceType.values()) {
-                if (vo.getDeviceType().toString().equals(value.getValue())) {
-                    vo.setDeviceTypeName(value.getLabel());
+            if(Objects.nonNull(vo.getDeviceType())){
+                for (SystemDict value : deviceType.values()) {
+                    if (vo.getDeviceType().toString().equals(value.getValue())) {
+                        vo.setDeviceTypeName(value.getLabel());
+                    }
                 }
             }
 
-
             KwsDeviceReference deviceHas = deviceReferenceMapper.selectOne(new LambdaQueryWrapper<KwsDeviceReference>()
                     .eq(KwsDeviceReference::getDeviceId, vo.getId())
                     .eq(KwsDeviceReference::getDelFlag, NumberConstant.ZERO)

+ 2 - 2
slope-modules/slope-detection/src/main/resources/mapper/mysql/KwsDeviceMapper.xml

@@ -52,11 +52,11 @@
              d.status,
             m.`name` as mName
       from kws_device as d
-               inner join kws_device_model as m on d.model_id = m.id
+      left join kws_device_model as m on d.model_id = m.id
                left join kws_project_device as pd on d.id = pd.device_id
                left join kws_project as p on pd.project_id = p.id
       WHERE d.del_flag = 0
-        and m.del_flag = 0
+
 
       <if test="deviceQuery.mountainId != null and deviceQuery.mountainId != ''">
           and d.mountain_id = #{deviceQuery.mountainId,jdbcType=BIGINT}