screen-api/src/main/java/com/moral/api/controller/CruiserController.java
@@ -1,11 +1,13 @@ package com.moral.api.controller; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; @@ -16,6 +18,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; import java.text.ParseException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -89,21 +92,36 @@ return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response); } @GetMapping("carTrajectoryNewAvg") @ApiOperation(value = "走航车轨迹均值", notes = "走航车轨迹均值") @ApiOperation(value = "走航车轨迹", notes = "走航车轨迹") @ApiImplicitParams(value = { @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String"), @ApiImplicitParam(name = "mac", value = "设备mac", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "time1", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "time2", value = "时间,2021-08-18", required = true, paramType = "query", dataType = "String"), @ApiImplicitParam(name = "type", value = "type", required = true, paramType = "query", dataType = "String") @ApiImplicitParam(name = "type", value = "采集因子", required = true, paramType = "query", dataType = "String") }) public ResultMessage carTrajectoryNewAvg(HttpServletRequest request) { long stime = System.currentTimeMillis(); Map<String, Object> params = WebUtils.getParametersStartingWith(request, null); if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("time2")|| !params.containsKey("type")) { if (!params.containsKey("mac") || !params.containsKey("time1")|| !params.containsKey("type")|| !params.containsKey("time2")) { return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); } List<Map<String, Object>> response = specialDeviceService.carTrajectory(params,false); return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response); List<HistorySecondCruiserResultDTO> response = specialDeviceService.carTrajectoryNewAvg(params); if(CollectionUtils.isEmpty(response)){ return ObjectUtils.isEmpty(response) ? ResultMessage.ok() : ResultMessage.ok(response); } long etime = System.currentTimeMillis(); Map<Integer,HistorySecondCruiserResultDTO> map = new HashMap<>(); for(int i = 0 ;i<response.size();i++){ map.put(i,response.get(i)); } //计算执行时间 System.out.printf("执行时长:%d 毫秒.", (etime - stime)); return ResultMessage.ok(map); } /** screen-api/src/main/java/com/moral/api/exception/consumer/CruiserDataConsumer.java
File was renamed from screen-api/src/main/java/com/moral/api/kafka/consumer/CruiserDataConsumer.java @@ -1,4 +1,4 @@ package com.moral.api.kafka.consumer; package com.moral.api.exception.consumer; import com.moral.api.utils.AdjustDataUtils; import com.moral.api.utils.UnitConvertUtils; screen-api/src/main/java/com/moral/api/exception/consumer/KafkaConsumer.java
File was renamed from screen-api/src/main/java/com/moral/api/kafka/consumer/KafkaConsumer.java @@ -1,4 +1,4 @@ package com.moral.api.kafka.consumer; package com.moral.api.exception.consumer; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; screen-api/src/main/java/com/moral/api/exception/consumer/SecondDataConsumer.java
File was renamed from screen-api/src/main/java/com/moral/api/kafka/consumer/SecondDataConsumer.java @@ -1,4 +1,4 @@ package com.moral.api.kafka.consumer; package com.moral.api.exception.consumer; import com.alibaba.fastjson.JSON; import com.moral.api.entity.Device; screen-api/src/main/java/com/moral/api/mapper/HistorySecondCruiserMapper.java
@@ -5,6 +5,7 @@ import com.moral.api.entity.HistorySecondCruiser; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserListDTO; /** * <p> @@ -18,6 +19,8 @@ List<Map<String,Object>> getCruiserData(Map<String,Object> params); List<HistorySecondCruiserListDTO> getCruiserDataNewAvg(Map<String,Object> params); List<String> getDates(Map<String,Object> params); screen-api/src/main/java/com/moral/api/pojo/dto/historySecondCruiser/HistorySecondCruiserListDTO.java
New file @@ -0,0 +1,48 @@ package com.moral.api.pojo.dto.historySecondCruiser; import lombok.Data; import java.math.BigDecimal; import java.util.List; /** * @ClassName HistorySecondCruiserListDTO * @Description TODO * @Author @lizijie * @Date 2023-06-29 8:33 * @Version 1.0 */ @Data public class HistorySecondCruiserListDTO { /** * 数据时间 */ private String time; /** * 纬度 */ private Double flyLat; /** * 经度 */ private Double flyLon; /** * 数据 */ private BigDecimal num; private List<BigDecimal> numList; /** * 均值数据 */ private BigDecimal avgNum; } screen-api/src/main/java/com/moral/api/pojo/dto/historySecondCruiser/HistorySecondCruiserResultCountDTO.java
New file @@ -0,0 +1,27 @@ package com.moral.api.pojo.dto.historySecondCruiser; import lombok.Data; import lombok.EqualsAndHashCode; import java.math.BigDecimal; /** * @ClassName HistorySecondCruiserResultDTO * @Description TODO * @Author @lizijie * @Date 2023-06-29 8:32 * @Version 1.0 */ @Data public class HistorySecondCruiserResultCountDTO { /** * 数据 */ private BigDecimal sumNum = BigDecimal.ZERO; /** * 计数 */ private Integer contNum = 0; } screen-api/src/main/java/com/moral/api/pojo/dto/historySecondCruiser/HistorySecondCruiserResultDTO.java
New file @@ -0,0 +1,85 @@ package com.moral.api.pojo.dto.historySecondCruiser; import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.math.BigDecimal; /** * @ClassName HistorySecondCruiserResultDTO * @Description TODO * @Author @lizijie * @Date 2023-06-29 8:32 * @Version 1.0 */ @Data public class HistorySecondCruiserResultDTO { /** * 数据时间 */ private String time; /** * 纬度 */ private Double flyLat; /** * 经度 */ private Double flyLon; /** * 均值数据 */ private BigDecimal a34004; private BigDecimal a34002; private BigDecimal a21026; private BigDecimal a21004; private BigDecimal a21005; private BigDecimal a05024; private BigDecimal a99054; private BigDecimal dustld; private BigDecimal avgNum; public BigDecimal getA34004() { return avgNum; } public BigDecimal getA34002() { return avgNum; } public BigDecimal getA21026() { return avgNum; } public BigDecimal getA21004() { return avgNum; } public BigDecimal getA21005() { return avgNum; } public BigDecimal getA05024() { return avgNum; } public BigDecimal getA99054() { return avgNum; } public BigDecimal getDustld() { return avgNum; } } screen-api/src/main/java/com/moral/api/service/SpecialDeviceService.java
@@ -1,5 +1,6 @@ package com.moral.api.service; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO; import org.springframework.web.multipart.MultipartFile; import java.text.ParseException; @@ -27,6 +28,7 @@ //走航车轨迹 List<Map<String, Object>> carTrajectory(Map<String, Object> params,boolean type); List<HistorySecondCruiserResultDTO> carTrajectoryNewAvg(Map<String, Object> params); /** * @Description: 根据mac号获取无人机数据 screen-api/src/main/java/com/moral/api/service/impl/SpecialDeviceServiceImpl.java
@@ -13,6 +13,9 @@ import com.moral.api.mapper.HistorySecondCruiserMapper; import com.moral.api.mapper.SpecialDeviceMapper; import com.moral.api.pojo.bo.ExcelBO; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserListDTO; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultCountDTO; import com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserResultDTO; import com.moral.api.pojo.vo.excel.DailyVo; import com.moral.api.service.OrganizationService; import com.moral.api.service.SpecialDeviceHistoryService; @@ -26,6 +29,7 @@ import com.moral.util.GeodesyUtils; import com.moral.util.TokenUtils; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.system.ApplicationHome; @@ -36,16 +40,10 @@ import org.springframework.web.multipart.MultipartFile; import java.io.File; import java.math.BigDecimal; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.*; import java.util.stream.Collectors; /** @@ -84,6 +82,9 @@ RedisTemplate redisTemplate; private final static Double dis = 50d; private final static Double DIS_NEW = 100d; @Override public List<Map<String, Object>> selectCruisers() { @@ -147,6 +148,33 @@ map.put("a21004",String.valueOf(Double.parseDouble(a21004) / 10)); }*/ return filterData(data); } @Override public List<HistorySecondCruiserResultDTO> carTrajectoryNewAvg(Map<String, Object> params) { params.put("dateFormat", "%Y-%m-%d %H:%i:%s"); Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo(); Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization"); Integer orgId = (Integer) orgInfo.get("id"); params.put("orgId", orgId); params.put("type","$."+params.get("type")); //从秒数据表获取走航车数据 List<HistorySecondCruiserListDTO> data = HistorySecondCruiserMapper.getCruiserDataNewAvg(params); data.removeIf(o->{ if (ObjectUtils.isEmpty(o.getFlyLon()) || ObjectUtils.isEmpty(o.getFlyLat())) { return true; } double lon = o.getFlyLon(); double lat = o.getFlyLat(); if (lon < 70 || lon > 150 || lat < 20 || lat > 60) { return true; } return false; }); if(CollectionUtils.isEmpty(data)){ return null; } return filterDataNew(data); } @Override public SpecialDevice getSpecialDeviceMapByMac(String mac) { @@ -528,5 +556,110 @@ return list; } //根据距离筛选数据 private List<HistorySecondCruiserResultDTO> filterDataNew(List<HistorySecondCruiserListDTO> data) { List<HistorySecondCruiserListDTO> list = new ArrayList<>(); Map<Integer, HistorySecondCruiserResultCountDTO> map = new HashMap<>(); Map<String, BigDecimal> mapTest = new HashMap<>(); Integer integer = 1; HistorySecondCruiserResultCountDTO countDTO = new HistorySecondCruiserResultCountDTO(); countDTO.setSumNum(data.get(0).getNum()); countDTO.setContNum(1); map.put(integer,countDTO); list.add(0,data.remove(0)); mapTest.put(data.get(0).getFlyLon()+"_"+data.get(0).getFlyLat(),data.get(0).getNum()); int k =1; for (HistorySecondCruiserListDTO d : data) { boolean flag = true; for (HistorySecondCruiserListDTO l : list) { double distance = GeodesyUtils.getDistance(d.getFlyLat(), d.getFlyLon(), l.getFlyLat(), l.getFlyLon()); if (distance < DIS_NEW) { flag = false; if(integer.equals(list.size())&& !mapTest.containsKey(d.getFlyLon()+"_"+d.getFlyLat())){ HistorySecondCruiserResultCountDTO countResultDTO = Objects.isNull(map.get(integer))?new HistorySecondCruiserResultCountDTO():map.get(integer); countResultDTO.setContNum(countResultDTO.getContNum()+1); countResultDTO.setSumNum(countResultDTO.getSumNum().add(d.getNum())); map.put(integer,countResultDTO); mapTest.put(d.getFlyLon()+"_"+d.getFlyLat(),d.getNum()); k++; } } } if (flag) { if(!list.contains(d)){ list.add(d); integer++; } } } if(!list.contains(data.get(data.size()-1))){ HistorySecondCruiserListDTO result = data.get(data.size()-1); list.add(result); integer++; HistorySecondCruiserResultCountDTO countResultDTO = new HistorySecondCruiserResultCountDTO(); countResultDTO.setContNum(1); countResultDTO.setSumNum(result.getNum()); map.put(integer,countResultDTO); } return filterDataNe(list,map); } private List<HistorySecondCruiserResultDTO> filterDataNe(List<HistorySecondCruiserListDTO> list,Map<Integer, HistorySecondCruiserResultCountDTO> map){ List<HistorySecondCruiserResultDTO> listResult = new ArrayList<>(); for(Map.Entry<Integer, HistorySecondCruiserResultCountDTO> entry : map.entrySet()){ Integer mapKey = entry.getKey(); HistorySecondCruiserResultCountDTO mapValue = entry.getValue(); BigDecimal avgNum = mapValue.getSumNum().divide(BigDecimal.valueOf(mapValue.getContNum()),2,BigDecimal.ROUND_HALF_UP); HistorySecondCruiserResultDTO resultDTO = new HistorySecondCruiserResultDTO(); resultDTO.setTime(list.get(mapKey-1).getTime()); resultDTO.setAvgNum(avgNum); resultDTO.setFlyLon(list.get(mapKey-1).getFlyLon()); resultDTO.setFlyLat(list.get(mapKey-1).getFlyLat()); listResult.add(resultDTO); } return listResult; } private List<HistorySecondCruiserResultDTO> filterDataNew(List<HistorySecondCruiserListDTO> data, List<HistorySecondCruiserListDTO> list) { List<HistorySecondCruiserResultDTO> listResult = new ArrayList<>(); List<HistorySecondCruiserListDTO> filter = new ArrayList<>(); for (HistorySecondCruiserListDTO d : data) { for (HistorySecondCruiserListDTO l : list) { double distance = GeodesyUtils.getDistance(d.getFlyLat(), d.getFlyLon(), l.getFlyLat(), l.getFlyLon()); if (filter.contains(d)) { break; } if (distance < DIS_NEW ) { List<BigDecimal> numList = new ArrayList<>(CollectionUtils.isEmpty(l.getNumList()) ? Arrays.asList(l.getNum()) : l.getNumList()); numList.add(d.getNum()); l.setNumList(numList); filter.add(d); break; } } } int k = 0; for(int j =0;j<list.size(); j++){ HistorySecondCruiserListDTO l = list.get(j); HistorySecondCruiserResultDTO resultDTO = new HistorySecondCruiserResultDTO(); resultDTO.setFlyLat(l.getFlyLat()); resultDTO.setTime(l.getTime()); resultDTO.setFlyLon(l.getFlyLon()); BigDecimal num = BigDecimal.ZERO; int count = l.getNumList().size(); for(int i = 0;i < count; i++) { num = num.add(l.getNumList().get(i)); } k = k+count; resultDTO.setAvgNum(num.divide(BigDecimal.valueOf(count),2,BigDecimal.ROUND_HALF_UP)); listResult.add(resultDTO); } System.out.println("sss>>>>:"+ (k++)); System.out.println("sss>>>>:"+ (filter.size())+">>>>:"+data.size()); int z = 0 ; return listResult; } } screen-api/src/main/resources/mapper/HistorySecondCruiserMapper.xml
@@ -31,6 +31,16 @@ AND organization_id = #{orgId} </select> <select id="getCruiserDataNewAvg" resultType="com.moral.api.pojo.dto.historySecondCruiser.HistorySecondCruiserListDTO"> select DATE_FORMAT(`time`, #{dateFormat}) AS time,value ->>'$.flylat' as flyLat,value ->>'$.flylon' as flyLon , value ->> #{type} as num from history_second_cruiser WHERE mac = #{mac} AND `time` <![CDATA[>=]]> #{time1} AND `time` <![CDATA[<=]]> #{time2} AND organization_id = #{orgId} order by time </select> <select id="getDaily" resultType="java.lang.String"> select AVG(JSON_EXTRACT(value,'$.dustld'))