diff --git a/pom.xml b/pom.xml index 49455f2..3558a4b 100644 --- a/pom.xml +++ b/pom.xml @@ -25,6 +25,7 @@ fastjson 1.2.72 + com.baomidou mybatis-plus-boot-starter @@ -41,6 +42,11 @@ lombok true + + com.google.guava + guava + 21.0 + org.springframework.boot spring-boot-starter-test diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index 0cc966a..1a83d25 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -6,11 +6,14 @@ import com.hisense.monitormanage.dto.ScenicCameraDto; import com.hisense.monitormanage.entity.*; import com.hisense.monitormanage.mapper.*; import com.hisense.monitormanage.service.MonitorService; +import com.hisense.monitormanage.service.SedimentTrailService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.lang.reflect.Method; import java.time.Clock; import java.time.LocalDateTime; import java.util.HashMap; @@ -33,6 +36,9 @@ public class Controller { @Autowired private MonitorService monitorService; + @Autowired + private SedimentTrailService sedimentTrailService; + @Autowired private CameraChannelMapper cameraChannelMapper; @@ -184,58 +190,6 @@ public class Controller { return monitorService.suggest(map); } - //根据用户已输入的文字请求匹配的地址信息 - //singleLine:用户输入的文字性地名地址信息,必填 - //maxSuggestions:最大建议数量,0~10,默认2 - //magicKey:地名地址唯一ID,Suggest操作返回的JSON数组中包含的magicKey - //outSR:坐标系信息,包含"wkid"属性,是表示空间参考的ID,示例:{ "wkid":4490 } - @RequestMapping("geocode") - public Result geocode( - @RequestParam(value="singleLine") String singleLine, - @RequestParam(value = "maxSuggestions",required = false,defaultValue = "2") Integer maxSuggestions, - @RequestParam(value = "magicKey",required = false,defaultValue = "") String magicKey, - @RequestParam(value = "outSR",required = false,defaultValue = "") String outSR - ){ - Map map = new HashMap<>(); - map.put("SingleLine",singleLine); - map.put("maxSuggestions",maxSuggestions); - map.put("magicKey",magicKey); - map.put("outSR",outSR); - return monitorService.geocode(map); - } - - //根据用户已输入的坐标请求附近的地址信息 - //location:坐标,必填,请注意编码,示例:{"x":120.40632244540544,"y":36.08136665300961,"spatialReference":{"wkid":4490,"latestWkid":4490}} - @RequestMapping("reverseGeocode") - public Result reverseGeocode( - @RequestParam(value="location") String location - ){ - Map map = new HashMap<>(); - map.put("location",location); - return monitorService.reverseGeocode(map); - } - - //查询视频点播巡检结果,只取异常的 - @RequestMapping("listChannelPlayStates") - public Result listChannelPlayStates( - @RequestParam(value="page",required = false,defaultValue = "1") Integer page, - @RequestParam(value="pageSize",required = false,defaultValue = "20") String pageSize - ){ - Map condition = new HashMap<>(); - LocalDateTime localDateTime = LocalDateTime.now(Clock.systemUTC()); - - LocalDateTime startTime = localDateTime.minusDays(7); - condition.put("checkStatus",0); - condition.put("startTime",startTime.toString()); - condition.put("endTime",localDateTime.toString()); - - Map map = new HashMap<>(); - map.put("condition",condition); - map.put("page",page); - map.put("pageSize",pageSize); - monitorService.listChannelPlayStates(map); - return null; - } //道路统计数据与排名 @RequestMapping("roadData") @@ -284,7 +238,23 @@ public class Controller { return monitorService.resCatalogApplyHJWSRoad(); } + //获取渣土车轨迹并保存到t_trail_sediment + @RequestMapping(value = "saveResCatalogApplyZTYS") + public boolean resCatalogApplyZTYS(){ + return sedimentTrailService.batchSaveSedimentTrail(); + } - + //根据输入的经纬度和查询的半径(米)时间查询范围内的渣土车轨迹信息 + @RequestMapping(value = "listSedimentTrailByPoints") + public List listSedimentTrailByPoints( + @RequestParam(value="longitude") double longitude, + @RequestParam(value="latitude") double latitude, + @RequestParam(value="raidus") Integer raidus, + @RequestParam(value="start") String start, + @RequestParam(value = "end") String end + ){ + System.out.println("listSedimentTrailByPoints......"); + return sedimentTrailService.listSedimentTrailByPoints(longitude,latitude,raidus,start,end); + } } diff --git a/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java b/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java new file mode 100644 index 0000000..ba6474f --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/entity/SedimentTrail.java @@ -0,0 +1,41 @@ +package com.hisense.monitormanage.entity; + +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.Serializable; +import java.time.LocalDateTime; + +/** + * @author admin + * @version 1.0.0 + * @ClassName SedimentTrail.java + * @Description 渣土车轨迹 + * @createTime 2022年05月09日 13:47:00 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +@TableName("t_trail_sediment") +public class SedimentTrail{ + @TableId + private Integer id; + private double speed; + private String simCardNum; + private LocalDateTime uploadtime; + private double coordinateX; + private double coordinateY; + private double longitude; + private double latitude; + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + private LocalDateTime recordTime; + private double angle; + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss",timezone = "GMT+8") + private LocalDateTime updateTime; + private String status; + private double fuel; +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/SedimentTrailMapper.java b/src/main/java/com/hisense/monitormanage/mapper/SedimentTrailMapper.java new file mode 100644 index 0000000..4ad2e8f --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/SedimentTrailMapper.java @@ -0,0 +1,18 @@ +package com.hisense.monitormanage.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hisense.monitormanage.entity.SedimentTrail; + +import java.util.List; +import java.util.Map; + +/** + * @author admin + * @version 1.0.0 + * @ClassName sedimentTrailMapper.java + * @Description TODO + * @createTime 2022年05月09日 13:59:00 + */ +public interface SedimentTrailMapper extends BaseMapper { + public void batchaSave(List list); +} diff --git a/src/main/java/com/hisense/monitormanage/service/MonitorService.java b/src/main/java/com/hisense/monitormanage/service/MonitorService.java index 1c61709..560d7d7 100644 --- a/src/main/java/com/hisense/monitormanage/service/MonitorService.java +++ b/src/main/java/com/hisense/monitormanage/service/MonitorService.java @@ -582,15 +582,15 @@ public class MonitorService { HttpHeaders headers = new HttpHeaders(); headers.add("Authorization", "Bearer " + token); -// Map map = new HashMap<>(); -// JSONObject search = new JSONObject(); -// search.put("opt","LIKE"); -// search.put("key","updatetime"); -// search.put("val",this.dateStr()); + Map map = new HashMap<>(); + JSONObject search = new JSONObject(); + search.put("opt","LIKE"); + search.put("key","updatetime"); + search.put("val",this.dateStr()); // search.put("opt","EQ"); // search.put("key","SSDQ"); // search.put("val","西海岸新区"); -// map.put("json",search); + map.put("json",search); HttpEntity> request = new HttpEntity<>(null, headers); ResponseEntity responseEntity; diff --git a/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java new file mode 100644 index 0000000..a5bec9c --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/service/SedimentTrailService.java @@ -0,0 +1,59 @@ +package com.hisense.monitormanage.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.google.common.collect.Lists; +import com.hisense.monitormanage.entity.SedimentTrail; +import com.hisense.monitormanage.mapper.SedimentTrailMapper; +import com.hisense.monitormanage.utils.LongLatUtil; +import lombok.extern.log4j.Log4j2; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.List; +import java.util.Map; + +/** + * @author admin + * @version 1.0.0 + * @ClassName SedimentTrailService.java + * @Description TODO + * @createTime 2022年05月09日 14:01:00 + */ +@Service +@Log4j2 +public class SedimentTrailService { + @Autowired + private SedimentTrailMapper sedimentTrailMapper; + + @Autowired + private MonitorService monitorService; + + //获取渣土车轨迹并保存到表t_trail_sediment + @Transactional(rollbackFor = Exception.class) + public boolean batchSaveSedimentTrail(){ + try{ + List maps = monitorService.resCatalogApplyZTYS(); + Lists.partition(maps,200).forEach( + item-> sedimentTrailMapper.batchaSave(item) + ); + return true; + }catch (Exception e){ + log.error("[batchSaveSedimentTrail] exception:{}",e.getMessage()); + return false; + } + } + + /** + * 根据输入的经纬度和查询的半径(米)查询范围内的渣土车轨迹信息 + * @param longitude(经度) latitude(纬度) raidus(米) start(时间) end(时间) + * + */ + public List listSedimentTrailByPoints(double longitude, double latitude, Integer raidus,String start,String end){ + double[] points = LongLatUtil.getAround(longitude,latitude,raidus); + QueryWrapper wrapper = new QueryWrapper<>(); + wrapper.between("update_time",start,end).between("longitude",points[0],points[2]).between("latitude",points[1],points[3]); + return sedimentTrailMapper.selectList(wrapper); + } +} diff --git a/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java b/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java new file mode 100644 index 0000000..23ac6a7 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/utils/LongLatUtil.java @@ -0,0 +1,63 @@ +package com.hisense.monitormanage.utils; + +/** + * @author admin + * @version 1.0.0 + * @ClassName LongLatUtil.java + * @Description TODO + * @createTime 2022年05月09日 09:54:00 + */ +public class LongLatUtil { + private static final double PI = 3.1415926; + /** + * 计算地球上任意两点(经纬度)距离 + * + * @param long1 第一点经度 + * @param lat1 第一点纬度 + * @param long2 第二点经度 + * @param lat2 第二点纬度 + * @return 返回距离 单位:米 + */ + public static double distanceByLongNLat(double long1, double lat1, double long2, double lat2) { + double a, b, R; + R = 6378137;//地球半径 + lat1 = lat1 * Math.PI / 180.0; + lat2 = lat2 * Math.PI / 180.0; + a = lat1 - lat2; + b = (long1 - long2) * Math.PI / 180.0; + double d; + double sa2, sb2; + sa2 = Math.sin(a / 2.0); + sb2 = Math.sin(b / 2.0); + d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2)); + return d; + } + + /** + * 根据经纬度和半径计算经纬度范围 + * + * @param raidus 单位米 + * @return minLat, minLng, maxLat, maxLng + */ + public static double[] getAround(double lon,double lat, int raidus) { + + Double latitude = lat; + Double longitude = lon; + + Double degree = (24901 * 1609) / 360.0; + double raidusMile = raidus; + + Double dpmLat = 1 / degree; + Double radiusLat = dpmLat * raidusMile; + Double minLat = latitude - radiusLat; + Double maxLat = latitude + radiusLat; + + Double mpdLng = degree * Math.cos(latitude * (PI / 180)); + Double dpmLng = 1 / mpdLng; + Double radiusLng = dpmLng * raidusMile; + Double minLng = longitude - radiusLng; + Double maxLng = longitude + radiusLng; + return new double[]{minLng,minLat, maxLng, maxLat}; + } + +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index fd66928..1e7e95e 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,12 +10,15 @@ spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # 数据源名称 spring.datasource.name=defaultDataSource # 数据库连接地址 +#spring.datasource.url=jdbc:mysql://15.72.183.91:3306/monitor_manage?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 spring.datasource.url=jdbc:mysql://15.72.183.91:3306/monitor_manage?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # 数据库用户名&密码: spring.datasource.username=root spring.datasource.password=w@CmM1mBVQkPhdrc +#spring.datasource.password=123456 hwx.file.work-path=/Users/huangweixiong/Downloads/ hwx.file.pic-host=http://127.0.0.1:7009 spring.resources.static-locations=classpath:/static,classpath:/public,file:${hwx.file.work-path} +mybatis-plus.mapper-locations=classpath*:/mapper/*.xml diff --git a/src/main/resources/mapper/SedimentTrailMapper.xml b/src/main/resources/mapper/SedimentTrailMapper.xml new file mode 100644 index 0000000..f963255 --- /dev/null +++ b/src/main/resources/mapper/SedimentTrailMapper.xml @@ -0,0 +1,19 @@ + + + + + + + INSERT INTO t_trail_sediment + (speed,sim_card_num,uploadtime,coordinate_x,coordinate_y, + longitude,latitude,record_time,angle,update_time,status,fuel) + VALUES + ( + #{item.SPEED},#{item.SIMCARDNUM},#{item.UPLOADTIME},#{item.COORDINATEX},#{item.COORDINATEY}, + #{item.LONGITUDE},#{item.LATITUDE},#{item.RECORDTIME},#{item.ANGEL},#{item.updatetime}, + #{item.STATUS},#{item.FUEL} + ) + + + + \ No newline at end of file