From 28923b3d67c58b032bc4ff128aa1d5e62d73dba1 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Fri, 02 Feb 2024 10:07:58 +0800
Subject: [PATCH] fix:提交实时在线率接口
---
screen-api/src/main/java/com/moral/api/service/impl/DataDisplayServiceImpl.java | 240 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 239 insertions(+), 1 deletions(-)
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 b710fdc..e560813 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
@@ -5,21 +5,26 @@
import com.moral.api.entity.*;
import com.moral.api.mapper.DeviceMapper;
import com.moral.api.mapper.HistoryMonthlyMapper;
+import com.moral.api.mapper.OrganizationMapper;
+import com.moral.api.pojo.dto.dataDisplay.HeatMapDTO;
import com.moral.api.pojo.dto.dataDisplay.MonitorPointDataDisplayDTO;
import com.moral.api.pojo.dto.dataDisplay.SensorComparisonDisplayDTO;
import com.moral.api.pojo.form.dataDisplay.MonitorPointDataDisplayForm;
import com.moral.api.pojo.form.dataDisplay.SensorComparisonDisplayForm;
import com.moral.api.service.*;
+import com.moral.api.utils.GetCenterPointFromListOfCoordinates;
import com.moral.constant.Constants;
+import com.moral.constant.SeparateTableType;
import com.moral.pojo.AQI;
import com.moral.util.*;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.util.*;
+import java.util.stream.Collectors;
-import static com.moral.util.DateUtils.dateToDateString;
/**
* @ClassName DataDisplayServiceImpl
@@ -29,6 +34,7 @@
* @Version TODO
**/
@Service
+@Slf4j
public class DataDisplayServiceImpl implements DataDisplayService {
@Autowired
@@ -43,6 +49,8 @@
HistoryWeeklyService historyWeeklyService;
@Autowired
HistoryMonthlyService historyMonthlyService;
+ @Autowired
+ OrganizationMapper organizationMapper;
@Autowired
DeviceMapper deviceMapper;
@@ -384,6 +392,236 @@
}
/**
+ * ���������������
+ * @param code
+ * @param startTime
+ * @param type
+ * @return
+ */
+ @Override
+ public List<HeatMapDTO> getHeatMapData(String code, String startTime, String type, String form) {
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("start",startTime);
+ map.put("type","$."+ type);
+
+ ArrayList<Integer> list = new ArrayList<>();
+
+// ArrayList<Map<String, Object>> rsHeatMap = new ArrayList<>();
+ ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>();
+ if (form.equals("hour")){ //������
+ Date date1 = DateUtils.getDate(startTime, DateUtils.yyyy_MM_dd_HH_EN);
+ List<String> tableNames = MybatisPLUSUtils.getTableNamesByWrapper(date1, date1, SeparateTableType.MONTH);
+// for (Integer integer : list) {
+ map.put("organizationIds",list);
+ map.put("tableName",tableNames.get(0));
+// List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map);
+ List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map);
+ rsHeatMap.addAll(heatMap);
+// }
+
+ }else { //���
+// for (Integer integer : list) {
+ map.put("organizationIds",list);
+// List<Map<String, Object>> heatMap = deviceMapper.getHeatMap(map);
+ List<HeatMapDTO> heatMap = deviceMapper.getHeatMap(map);
+ rsHeatMap.addAll(heatMap);
+// }
+ }
+
+ return distrinList(rsHeatMap);
+ }
+
+ @Override
+ public List<HeatMapDTO> getHeatMapDataV2(Integer id, String startTime, String type, String form) {
+ HashMap<String, Object> map = new HashMap<>();
+ map.put("start",startTime);
+ map.put("type","$."+ type);
+ ArrayList<Integer> list = new ArrayList<>();
+ list.add(id);
+ ArrayList<HeatMapDTO> rsHeatMap = new ArrayList<>();
+ ArrayList<String> list1 = new ArrayList<>();
+ list1.add("���������������");
+ list1.add("���������������");
+ list1.add("���������������");
+ list1.add("���������������");
+ list1.add("������������������");
+
+ if (form.equals("hour")){ //������
+// String[] split = startTime.split("-");
+// String s = "_" + split[0] + split[1];
+ String dateString = DateUtils.stringToDateString(startTime, DateUtils.yyyy_MM_dd_HH_EN, DateUtils.yyyyMM_EN);
+ map.put("organizationIds",list);
+ map.put("tableName","_"+dateString);
+
+ List<HeatMapDTO> heatMap = deviceMapper.getHeatMapV1(map);
+ //������������
+ List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getTime() != null).collect(Collectors.toList());
+ if (ObjectUtils.isEmpty(collect1)){
+ return null;
+ }
+ for (HeatMapDTO heatMapDTO : heatMap) {
+// if (list1.contains(heatMapDTO.getName())){
+ if (type.equals("a34002") || type.equals("a21026")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?49.0:heatMapDTO.getCount());
+ }else if (type.equals("a34004")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?20.0:heatMapDTO.getCount());
+ }else if (type.equals("a21004")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?20.0:heatMapDTO.getCount());
+ }else if (type.equals("a21005")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?1.0:heatMapDTO.getCount());
+ }else if (type.equals("a05024")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?138.0:heatMapDTO.getCount());
+ }else {
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?0.2:heatMapDTO.getCount());
+ }
+// }else {
+// if (ObjectUtils.isEmpty(heatMapDTO.getCount())){
+// heatMapDTO.setCount(0.0);
+// }
+// }
+ }
+
+ getHeatMap(heatMap,type);
+ rsHeatMap.addAll(heatMap);
+ }else { //���
+ map.put("organizationIds",list);
+ List<HeatMapDTO> heatMap = deviceMapper.getHeatMapV1(map);
+ List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getTime() != null).collect(Collectors.toList());
+ if (ObjectUtils.isEmpty(collect1)){
+ return null;
+ }
+ for (HeatMapDTO heatMapDTO : heatMap) {
+ if (type.equals("a34002") || type.equals("a21026")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?49.0:heatMapDTO.getCount());
+ }else if (type.equals("a34004")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?34.0:heatMapDTO.getCount());
+ }else if (type.equals("a21004")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?39.0:heatMapDTO.getCount());
+ }else if (type.equals("a21005")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?1.9:heatMapDTO.getCount());
+ }else if (type.equals("a05024")){
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?100.0:heatMapDTO.getCount());
+ }else {
+ heatMapDTO.setCount(ObjectUtils.isEmpty(heatMapDTO.getCount())?0.4:heatMapDTO.getCount());
+ }
+ }
+ getHeatMap(heatMap,type);
+ rsHeatMap.addAll(heatMap);
+ }
+ for (int i = 0; i <6; i++) {
+ HeatMapDTO heatMapDTO = new HeatMapDTO();
+ heatMapDTO.setCount(0.0);
+ if (i==0){
+ heatMapDTO.setLat(40.590436);
+ heatMapDTO.setLng(122.861935);
+ heatMapDTO.setMac("1111");
+ heatMapDTO.setName("1111");
+ }else if (i==1){
+ heatMapDTO.setLat(40.636617);
+ heatMapDTO.setLng(123.101544);
+ heatMapDTO.setMac("2222");
+ heatMapDTO.setName("2222");
+ }else if (i==2){
+ heatMapDTO.setLat(40.890881);
+ heatMapDTO.setLng(122.910687);
+ heatMapDTO.setMac("3333");
+ heatMapDTO.setName("3333");
+ }else if (i==3){
+ heatMapDTO.setLat(40.682129);
+ heatMapDTO.setLng(123.105836);
+ heatMapDTO.setMac("4444");
+ heatMapDTO.setName("4444");
+ }else if (i==4){
+ heatMapDTO.setLat(40.890037);
+ heatMapDTO.setLng(123.021151);
+ heatMapDTO.setMac("5555");
+ heatMapDTO.setName("5555");
+ }else {
+ heatMapDTO.setLat(41.051333);
+ heatMapDTO.setLng(122.505864);
+ heatMapDTO.setMac("6666");
+ heatMapDTO.setName("6666");
+ }
+ rsHeatMap.add(heatMapDTO);
+ }
+
+ return distrinList(rsHeatMap);
+ }
+
+ //������������
+ private void getHeatMap(List<HeatMapDTO> heatMap,String type) {
+ //������������
+ List<HeatMapDTO> collect1 = heatMap.stream().filter(d -> d.getGroupId() != null).collect(Collectors.toList());
+ if (ObjectUtils.isEmpty(collect1)){
+ return;
+ }
+ //������������
+ Map<Integer, List<HeatMapDTO>> collect = collect1.parallelStream().collect(Collectors.groupingBy(o ->o.getGroupId()));
+ Set<Integer> integers = collect.keySet();
+ int i = 0 ;
+ for (Integer integer : integers) {
+ ArrayList<Double> doubleArrayList = new ArrayList<>();
+ ArrayList<GeoCoordinate> geoCoordinates = new ArrayList<>();
+ List<HeatMapDTO> heatMapDTOS = collect.get(integer);
+ for (HeatMapDTO heatMapDTO : heatMapDTOS) {
+ GeoCoordinate geoCoordinate = new GeoCoordinate();
+ doubleArrayList.add(heatMapDTO.getCount());
+// heatMapDTO.setCount(heatMapDTO.getCount());
+ if (type.equals("a21026")){
+ heatMapDTO.setCount(1.0);
+ }else {
+ heatMapDTO.setCount(0.0);
+ }
+
+ geoCoordinate.setLongitude(heatMapDTO.getLng());
+ geoCoordinate.setLatitude(heatMapDTO.getLat());
+ geoCoordinates.add(geoCoordinate);
+ }
+ if (!ObjectUtils.isEmpty(doubleArrayList)){
+ HeatMapDTO heatMapDTO = new HeatMapDTO();
+ //������������������
+ double asDouble = doubleArrayList.stream().mapToDouble(Double::valueOf).max().getAsDouble();
+ //���������������
+ GeoCoordinate centerPoint = GetCenterPointFromListOfCoordinates.getCenterPoint(geoCoordinates);
+// double rsCode = asDouble - (doubleArrayList.size()*10);
+ double rsCode = asDouble - doubleArrayList.size()-1;
+// log.info(asDouble+"-----"+rsCode);
+// heatMapDTO.setCount(rsCode);
+ heatMapDTO.setCount(rsCode);
+// heatMapDTO.setSum(asDouble);
+ heatMapDTO.setLng(centerPoint.getLongitude());
+ heatMapDTO.setLat(centerPoint.getLatitude());
+ heatMapDTO.setMac(i+"");
+ heatMapDTO.setName(integer+"");
+ heatMap.add(heatMapDTO);
+ i++;
+ }
+ }
+ }
+
+ /**
+ * ������������
+ * @param responseList
+ * @return
+ */
+ private List<HeatMapDTO> distrinList(List<HeatMapDTO> responseList){
+ List<HeatMapDTO> rsMap = new ArrayList<>();
+ Set<String> keysSet = new HashSet<String>();
+ for (HeatMapDTO heatMapDTO : responseList) {
+ String keys = String.valueOf(heatMapDTO.getMac());
+ int beforeSize = keysSet.size();
+ keysSet.add(keys);
+ int afterSize = keysSet.size();
+ if(afterSize == beforeSize + 1){
+ rsMap.add(heatMapDTO);
+ }
+ }
+ return rsMap;
+
+
+ }
+
+ /**
* @Description: ������������������������
* @Param: [timeValueMap, reportType]
* @return: java.util.Map<java.lang.String , java.lang.String>
--
Gitblit v1.8.0