From aca19e8a4bdaee42b9e1c0e53c1a09b31d44920a Mon Sep 17 00:00:00 2001 From: wuweida <2918581207@qq.com> Date: Thu, 2 Jun 2022 11:34:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E5=8D=8A?= =?UTF-8?q?=E5=BE=84=E8=8C=83=E5=9B=B4=E5=86=85=E7=9A=84=E4=BA=BA=E6=B5=81?= =?UTF-8?q?=E6=A0=BC=E6=A0=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../monitormanage/controller/Controller.java | 26 +++++++ .../controller/PassengerFlowController.java | 30 ++++++++ .../monitormanage/entity/PassengerFlow.java | 10 +-- .../mapper/PassengerFlowlMapper.java | 12 +++ .../service/PassengerFlowService.java | 77 ++++++++++++++++--- .../resources/mapper/PassengerFlowlMapper.xml | 4 + 6 files changed, 145 insertions(+), 14 deletions(-) create mode 100644 src/main/java/com/hisense/monitormanage/controller/PassengerFlowController.java diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index e30c150..99cf2a8 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -65,6 +65,9 @@ public class Controller { @Autowired private ChannelPictureMapper channelPictureMapper; + @Autowired + private PassengerFlowlMapper passengerFlowlMapper; + @GetMapping("all") public Object all(){ @@ -477,6 +480,29 @@ public class Controller { return Result.success(passengerFlowService.passengerNums(longitude,latitude,radius,timeId)); } + /** + * 查询半径范围内格栅 + * @param longitude + * @param latitude + * @param radius + * @param timeId + * @return + */ + @GetMapping("selectPassenger") + @ApiOperation("查询半径范围内格栅,根据经纬度和半径米、timeId从表中查询") + @ApiImplicitParams({ + @ApiImplicitParam(name = "longitude", value = "经度", paramType = "query",required = false,dataType ="double"), + @ApiImplicitParam(name = "latitude", value = "纬度", paramType = "query",required = false,dataType ="double"), + @ApiImplicitParam(name = "radius", value = "半径,米", paramType = "query",required = false,dataType ="Integer"), + @ApiImplicitParam(name = "timeId", value = "时间点,202205101600", paramType = "query",required = true,dataType ="string"), + }) + public Result selectPassenger(Double longitude,Double latitude,Integer radius,String timeId){ + double[] around = LongLatUtil.getAround(longitude, latitude, radius); + List c = passengerFlowlMapper.selectPassenger(around[0], around[2], around[1], around[3],timeId); + Result success = Result.success(c); + return success; + } + //查询并保存环卫车轨迹到表t_trail_sanitation @GetMapping("saveTrailSanitation") @ApiOperation("保存环卫车轨迹到表t_trail_sanitation,根据后台updatetime调用接口") diff --git a/src/main/java/com/hisense/monitormanage/controller/PassengerFlowController.java b/src/main/java/com/hisense/monitormanage/controller/PassengerFlowController.java new file mode 100644 index 0000000..f7bd332 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/controller/PassengerFlowController.java @@ -0,0 +1,30 @@ +package com.hisense.monitormanage.controller; + +import com.hisense.monitormanage.entity.Result; +import com.hisense.monitormanage.service.PassengerFlowService; +import io.swagger.annotations.Api; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.ArrayList; +import java.util.List; + +@RestController +@Api("实时人流") +@RequestMapping("api/project/passenger") +public class PassengerFlowController { + + @Autowired + private PassengerFlowService passengerFlowService; + + @GetMapping("selectPassengerFlow") + public Result selectPassengerFlow(List vertX, List vertY,String timeId){ + List list = new ArrayList<>(); + + Integer integer = passengerFlowService.pnpolyAlgorithm(vertX, vertY, timeId); + Result success = Result.success(integer); + return success; + } +} diff --git a/src/main/java/com/hisense/monitormanage/entity/PassengerFlow.java b/src/main/java/com/hisense/monitormanage/entity/PassengerFlow.java index fdebebd..9179367 100644 --- a/src/main/java/com/hisense/monitormanage/entity/PassengerFlow.java +++ b/src/main/java/com/hisense/monitormanage/entity/PassengerFlow.java @@ -22,9 +22,9 @@ public class PassengerFlow { private Integer id; private String hourId; private String timeId; - private double longitude; - private double latitude; - private Integer allNums; - private Integer localNums; - private Integer nonlocalNums; + private String longitude; + private String latitude; + private String allNums; + private String localNums; + private String nonlocalNums; } diff --git a/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowlMapper.java b/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowlMapper.java index f272f44..44802e9 100644 --- a/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowlMapper.java +++ b/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowlMapper.java @@ -3,6 +3,8 @@ package com.hisense.monitormanage.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.hisense.monitormanage.entity.PassengerFlow; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import java.util.List; import java.util.Map; @@ -10,4 +12,14 @@ import java.util.Map; public interface PassengerFlowlMapper extends BaseMapper { void batchSave(List list); PassengerFlow getByMaxId(); + + List selectByTime(String timeId); + + @Select("select cc.* from t_passenger_flow cc " + + "where (longitude between #{longitude} and #{longitude1}) and (latitude between #{latitude} and #{latitude1} ) and time_id = #{timeId}") + List selectPassenger(@Param("longitude") Double longitude, + @Param("longitude1") Double longitude1, + @Param("latitude") Double latitude, + @Param("latitude1") Double latitude1, + @Param("timeId") String timeId); } diff --git a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java index 7571491..44db6a3 100644 --- a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java +++ b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java @@ -2,6 +2,7 @@ package com.hisense.monitormanage.service; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.google.common.collect.Lists; import com.hisense.monitormanage.entity.PassengerFlow; @@ -14,6 +15,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import org.springframework.util.DigestUtils; import org.springframework.util.StringUtils; import org.springframework.web.client.RestTemplate; @@ -22,10 +24,7 @@ import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.time.temporal.ChronoUnit; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author admin @@ -172,8 +171,26 @@ public class PassengerFlowService { if(jsonResult.getIntValue("code") == 0){ JSONArray jsonArray = jsonResult.getJSONArray("result"); list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class); - List> lists = Lists.partition(list,200); - lists.forEach(ll ->passengerFlowMapper.batchSave(ll)); + list.forEach(map1 -> { + QueryWrapper queryWrapper = new QueryWrapper<>(); + queryWrapper.eq("longitude",map1.get("longitude")); + queryWrapper.eq("latitude",map1.get("latitude")); + queryWrapper.eq("time_id",map1.get("time_id")); + PassengerFlow pf = passengerFlowMapper.selectOne(queryWrapper); + if (pf == null ){ + PassengerFlow passengerFlow = new PassengerFlow(); + passengerFlow.setHourId(map1.get("hour_id").toString()); + passengerFlow.setTimeId(map1.get("time_id").toString()); + passengerFlow.setLongitude(map1.get("longitude").toString()); + passengerFlow.setLatitude(map1.get("latitude").toString()); + passengerFlow.setAllNums(map1.get("all_nums").toString()); + passengerFlow.setLocalNums(map1.get("local_nums").toString()); + passengerFlow.setNonlocalNums(map1.get("nonlocal_nums").toString()); + System.out.println(passengerFlow); + passengerFlowMapper.insert(passengerFlow); + } + + }); } } } catch (Exception e){ @@ -212,9 +229,10 @@ public class PassengerFlowService { try{ List list = passengerFlowMapper.selectList(wrapper); for(PassengerFlow p:list){ - allCount+=p.getAllNums(); - localCount+=p.getLocalNums(); - nonLocalCount+=p.getNonlocalNums(); + + allCount+=Integer.parseInt(p.getAllNums()); + localCount+=Integer.parseInt(p.getLocalNums()); + nonLocalCount+=Integer.parseInt(p.getNonlocalNums()); } result.put("local_nums",localCount); result.put("nonlocal_nums",nonLocalCount); @@ -281,4 +299,45 @@ public class PassengerFlowService { System.out.println("t1->"+t1+"...t2->"+t2); return new String[]{t1,t2}; } + + + /** @param vertX polygon coordinates latitudes + * @param vertY polygon coordinates longitudes + * @return true indicate inside of the polygon, false indicate outside of the polygon + */ + public Integer pnpolyAlgorithm(List vertX, List vertY,String timeId) { + List passengerFlows = passengerFlowMapper.selectByTime(timeId); + int people = 0; + for (PassengerFlow passengerFlow: passengerFlows) { + double latitude = Double.parseDouble(passengerFlow.getLatitude()); + double longitude = Double.parseDouble(passengerFlow.getLongitude()); + if (CollectionUtils.isEmpty(vertX) || CollectionUtils.isEmpty(vertY)) { + return 0; + } + double maxX = vertX.stream().max(Comparator.comparingDouble(Double::doubleValue)).get(); + double maxY = vertY.stream().max(Comparator.comparingDouble(Double::doubleValue)).get(); + double minX = vertX.stream().min(Comparator.comparingDouble(Double::doubleValue)).get(); + double minY = vertY.stream().min(Comparator.comparingDouble(Double::doubleValue)).get(); + + if (longitude < minX || longitude > maxX || latitude < minY || latitude > maxY) { + continue; + } + int i, j; + boolean result = false; + int n = vertX.size(); + Double[] vertx = vertX.toArray(new Double[0]); + Double[] verty = vertY.toArray(new Double[0]); + for (i = 0, j = n - 1; i < n; j = i++) { + if ((verty[i] > latitude) != (verty[j] > latitude) && + (longitude < (vertx[j] - vertx[i]) * (latitude - verty[i]) / (verty[j] - verty[i]) + vertx[i])) { + result = !result; + } + } + if (result){ + Integer allNums = Integer.parseInt(passengerFlow.getAllNums()); + people += allNums; + } + } + return people; + } } diff --git a/src/main/resources/mapper/PassengerFlowlMapper.xml b/src/main/resources/mapper/PassengerFlowlMapper.xml index c798073..c4105eb 100644 --- a/src/main/resources/mapper/PassengerFlowlMapper.xml +++ b/src/main/resources/mapper/PassengerFlowlMapper.xml @@ -18,4 +18,8 @@ select * from t_passenger_flow ORDer by id desc limit 1 + + \ No newline at end of file