From 0ac36f61bfbb42c4867afda00e8528ecec60ef74 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Wed, 13 Dec 2023 17:13:12 +0800
Subject: [PATCH] chore:测试提交

---
 screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java |    3 
 screen-api/src/main/java/com/moral/api/controller/HeatMapController.java        |  146 ++++++++++++++++++++++++++++++++++++
 screen-api/src/main/java/com/moral/api/vo/HeatMapVo.java                        |   30 +++++++
 screen-api/src/main/resources/mapper/DeviceMapper.xml                           |   29 +++++++
 4 files changed, 205 insertions(+), 3 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java b/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java
index 07de00c..9c74b97 100644
--- a/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/HeatMapController.java
@@ -4,6 +4,7 @@
 import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.ObjectUtils;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -12,12 +13,21 @@
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import com.moral.api.service.DataDisplayService;
+import com.moral.api.vo.HeatMapVo;
+import com.moral.api.vo.TimeHourVo;
 import com.moral.constant.ResultMessage;
+import com.moral.util.DateUtils;
 
 /**
  * Description //todo
@@ -46,4 +56,140 @@
          ArrayList<Map<String, Object>> heatMapData = dataDisplayService.getHeatMapData(code, startTime, type, form);
          return ResultMessage.ok(ObjectUtils.isEmpty(heatMapData)?"0":heatMapData);
      }
+    @GetMapping("queryTime")
+    @ApiOperation("������������")
+    public ResultMessage  getHeatMap(@RequestParam @ApiParam(value = "startTime",name = "������������") String startTime,
+                                     @RequestParam @ApiParam(value = "endTime",name= "������������") String endTime,
+                                     @RequestParam @ApiParam(value = "type",name= "������������") String type){
+        ArrayList<HeatMapVo> heatMapVos = new ArrayList<>();
+        if (type.equals("day")){
+            ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
+            String[] splitStart = startTime.split("-");
+            String[] splitEnd = endTime.split("-");
+            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]), Integer.parseInt(splitStart[2]));
+            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]), Integer.parseInt(splitEnd[2]));
+            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
+            for (int i = 0; i <= daysBetween; i++) {
+                HeatMapVo heatMapVo = new HeatMapVo();
+                LocalDate date = startDate.plusDays(i);
+                heatMapVo.setId(i);
+                heatMapVo.setName(date.toString());
+                heatMapVo.setHourListTime(timeHourVos);
+                heatMapVos.add(heatMapVo);
+            }
+        }else if (type.equals("month")){
+            ArrayList<TimeHourVo> timeHourVos = new ArrayList<>();
+            String[] splitStart = startTime.split("-");
+            String[] splitEnd = endTime.split("-");
+            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]),1);
+            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]),30);
+            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
+            for (int i = 0; i <= daysBetween; i++) {
+                HeatMapVo heatMapVo = new HeatMapVo();
+                LocalDate date = startDate.plusDays(i);
+                heatMapVo.setId(i);
+                heatMapVo.setName(date.toString());
+                heatMapVo.setHourListTime(timeHourVos);
+                heatMapVos.add(heatMapVo);
+            }
+        }else {
+            int id = 0;
+            int idHour = -1;
+            Date ks = DateUtils.getDate(startTime,"yyyy-MM-dd HH");
+            Date js = DateUtils.getDateAddHour(DateUtils.getDate(endTime,"yyyy-MM-dd HH"),1);
+            String name =  DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_EN);
+            List<TimeHourVo> hourListTime = new ArrayList<>();
+            while (DateUtils.isTimeBefor(js,ks)){
+                idHour++;
+                HeatMapVo heatMapVo = new HeatMapVo();
+                String nameEndTime =  DateUtils.dateToDateString(ks,DateUtils.yyyy_MM_dd_EN);
+                String time =  DateUtils.dateToDateString(ks,"HH");
+                String ksTime =  DateUtils.dateToDateString(ks,"yyyy-MM-dd HH");
+                TimeHourVo hourVo = new TimeHourVo();
+                heatMapVo.setName(name);
+                heatMapVo.setId(id);
+                if(name.equals(nameEndTime)){
+                    heatMapVo.setId(id);
+                    heatMapVo.setName(name);
+                    hourVo.setName(time);
+                    hourVo.setId(idHour);
+                    hourListTime.add(hourVo);
+                    if(ksTime.equals(endTime)){
+                        heatMapVo.setHourListTime(hourListTime);
+                        heatMapVos.add(heatMapVo);
+                    }
+                }else {
+                    id++;
+                    if(ksTime.equals(endTime)){
+                        heatMapVo.setHourListTime(hourListTime);
+                        heatMapVos.add(heatMapVo);
+                        hourListTime = new ArrayList<>();
+                        hourVo = new TimeHourVo();
+                        heatMapVo = new HeatMapVo();
+                        hourVo.setName("00");
+                        hourVo.setId(idHour++);
+                        hourListTime.add(hourVo);
+                        heatMapVo.setId(id);
+                        heatMapVo.setName(nameEndTime);
+                        heatMapVo.setHourListTime(hourListTime);
+                        heatMapVos.add(heatMapVo);
+                    }else {
+                        name = nameEndTime;
+                        heatMapVo.setHourListTime(hourListTime);
+                        heatMapVos.add(heatMapVo);
+                        hourListTime = new ArrayList<>();
+                        hourVo.setName(time);
+                        hourVo.setId(idHour);
+                        hourListTime.add(hourVo);
+                    }
+                }
+                ks = DateUtils.getDateAddHour(ks,1);
+            }
+            if(CollectionUtils.isNotEmpty(heatMapVos)){
+                heatMapVos.get(0).setIdLength(idHour);
+            }
+/*
+
+
+
+            String[] splitStart = startTime.split("-");
+            String[] s1 = splitStart[2].split(" ");
+            String[] splitEnd = endTime.split("-");
+            String[] s2 = splitEnd[2].split(" ");
+            //���������������
+            LocalDate startDate = LocalDate.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]),Integer.parseInt(s1[0]));
+            LocalDate endDate = LocalDate.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]),Integer.parseInt(s2[0]));
+            long daysBetween = ChronoUnit.DAYS.between(startDate, endDate);
+            //������������
+            LocalDateTime startDateTime = LocalDateTime.of(Integer.parseInt(splitStart[0]), Integer.parseInt(splitStart[1]), Integer.parseInt(s1[0]), Integer.parseInt(s1[1]), 0);
+            LocalDateTime endDateTime = LocalDateTime.of(Integer.parseInt(splitEnd[0]), Integer.parseInt(splitEnd[1]), Integer.parseInt(s2[0]), Integer.parseInt(s2[1]), 0);
+            List<String> hourList = new ArrayList<>();
+            LocalDateTime currentDateTime = startDateTime;
+            while (currentDateTime.isBefore(endDateTime) || currentDateTime.equals(endDateTime)) {
+                hourList.add(currentDateTime.toString());
+                currentDateTime = currentDateTime.plusHours(1);
+            }
+            for (int i = 0; i <= daysBetween; i++) {
+
+                ArrayList<Map<String,Object>> list = new ArrayList<>();
+                HeatMapVo heatMapVo = new HeatMapVo();
+                LocalDate date = startDate.plusDays(i);
+                heatMapVo.setId(i);
+                heatMapVo.setName(date.toString());
+                for (int i1 = 0; i1 < hourList.size(); i1++) {
+                    HashMap<String, Object> map = new HashMap<>();
+                    if (hourList.get(i).contains(date.toString())){
+                        map.put("name",hourList.get(i).substring(11,16));
+                        list.add(map);
+                    }
+                }
+                heatMapVo.setHourList(list);
+                heatMapVos.add(heatMapVo);
+            }*/
+
+        }
+
+        return ResultMessage.ok(ObjectUtils.isEmpty(heatMapVos)?"0":heatMapVos);
+    }
+
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
index f52c8b8..1280620 100644
--- a/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
+++ b/screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java
@@ -406,9 +406,6 @@
         HashMap<String, Object> map = new HashMap<>();
         map.put("start",startTime);
         map.put("type","$."+ type);
-        map.put("sensorCode","count");
-        map.put("regionCode",null);
-        map.put("region",null);
 
         //������������������
         Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo();
diff --git a/screen-api/src/main/java/com/moral/api/vo/HeatMapVo.java b/screen-api/src/main/java/com/moral/api/vo/HeatMapVo.java
new file mode 100644
index 0000000..03a540b
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/vo/HeatMapVo.java
@@ -0,0 +1,30 @@
+package com.moral.api.vo;
+
+import lombok.Data;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Description //todo
+ *
+ * @author swb
+ * @ClassName HeatMapVo
+ * @date 2023.12.13 12:44
+ */
+@Data
+public class HeatMapVo {
+
+
+    private  Integer id ;
+
+    private String name;
+
+//    private List<Map<String,Object>> hourList;
+
+    private List<TimeHourVo> hourListTime;
+
+    private  Integer idLength;
+}
diff --git a/screen-api/src/main/resources/mapper/DeviceMapper.xml b/screen-api/src/main/resources/mapper/DeviceMapper.xml
index 959ae30..7cf8024 100644
--- a/screen-api/src/main/resources/mapper/DeviceMapper.xml
+++ b/screen-api/src/main/resources/mapper/DeviceMapper.xml
@@ -208,4 +208,33 @@
         </if>
           and mac LIKE "%"#{mac}"%" AND is_delete = 0
     </select>
+
+
+    <select id="getHeatMap" resultType="java.util.Map">
+        SELECT
+        d.latitude as lat,
+        d.longitude as lng,
+        d.mac as mac,
+        d.name as name,
+        (hd.value ->> '$.a34002' )+0 as count,
+        hd.time
+        FROM
+        device as d
+        inner JOIN organization o on o.id = d.organization_id and o.is_delete = 0
+        <if test="organizationIds != null and organizationIds.size !=0">
+            and organization_id in
+            <foreach collection="organizationIds" item="id" index="index" open="(" close=")" separator=",">
+                #{id}
+            </foreach>
+        </if>
+        <if test="tableName !=null">
+            left join history_hourly${tableName} hd on hd.time = #{start}  and d.mac = hd.mac
+        </if>
+        <if test="tableName ==null ">
+            left join history_daily hd on hd.time = #{start}   and d.mac = hd.mac
+        </if>
+        WHERE
+         d.is_delete = 0
+        order by hd.mac
+    </select>
 </mapper>
\ No newline at end of file

--
Gitblit v1.8.0