添加查询半径范围内的人流格栅

This commit is contained in:
wuweida 2022-06-02 11:34:21 +08:00
parent aca1d4925a
commit aca19e8a4b
6 changed files with 145 additions and 14 deletions

View File

@ -65,6 +65,9 @@ public class Controller {
@Autowired @Autowired
private ChannelPictureMapper channelPictureMapper; private ChannelPictureMapper channelPictureMapper;
@Autowired
private PassengerFlowlMapper passengerFlowlMapper;
@GetMapping("all") @GetMapping("all")
public Object all(){ public Object all(){
@ -477,6 +480,29 @@ public class Controller {
return Result.success(passengerFlowService.passengerNums(longitude,latitude,radius,timeId)); 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<PassengerFlow> c = passengerFlowlMapper.selectPassenger(around[0], around[2], around[1], around[3],timeId);
Result success = Result.success(c);
return success;
}
//查询并保存环卫车轨迹到表t_trail_sanitation //查询并保存环卫车轨迹到表t_trail_sanitation
@GetMapping("saveTrailSanitation") @GetMapping("saveTrailSanitation")
@ApiOperation("保存环卫车轨迹到表t_trail_sanitation,根据后台updatetime调用接口") @ApiOperation("保存环卫车轨迹到表t_trail_sanitation,根据后台updatetime调用接口")

View File

@ -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<Double> vertX, List<Double> vertY,String timeId){
List<Double> list = new ArrayList<>();
Integer integer = passengerFlowService.pnpolyAlgorithm(vertX, vertY, timeId);
Result success = Result.success(integer);
return success;
}
}

View File

@ -22,9 +22,9 @@ public class PassengerFlow {
private Integer id; private Integer id;
private String hourId; private String hourId;
private String timeId; private String timeId;
private double longitude; private String longitude;
private double latitude; private String latitude;
private Integer allNums; private String allNums;
private Integer localNums; private String localNums;
private Integer nonlocalNums; private String nonlocalNums;
} }

View File

@ -3,6 +3,8 @@ package com.hisense.monitormanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hisense.monitormanage.entity.PassengerFlow; 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.List;
import java.util.Map; import java.util.Map;
@ -10,4 +12,14 @@ import java.util.Map;
public interface PassengerFlowlMapper extends BaseMapper<PassengerFlow> { public interface PassengerFlowlMapper extends BaseMapper<PassengerFlow> {
void batchSave(List<Map> list); void batchSave(List<Map> list);
PassengerFlow getByMaxId(); PassengerFlow getByMaxId();
List<PassengerFlow> 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<PassengerFlow> selectPassenger(@Param("longitude") Double longitude,
@Param("longitude1") Double longitude1,
@Param("latitude") Double latitude,
@Param("latitude1") Double latitude1,
@Param("timeId") String timeId);
} }

View File

@ -2,6 +2,7 @@ package com.hisense.monitormanage.service;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.hisense.monitormanage.entity.PassengerFlow; import com.hisense.monitormanage.entity.PassengerFlow;
@ -14,6 +15,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.DigestUtils; import org.springframework.util.DigestUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
@ -22,10 +24,7 @@ import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @author admin * @author admin
@ -172,8 +171,26 @@ public class PassengerFlowService {
if(jsonResult.getIntValue("code") == 0){ if(jsonResult.getIntValue("code") == 0){
JSONArray jsonArray = jsonResult.getJSONArray("result"); JSONArray jsonArray = jsonResult.getJSONArray("result");
list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class); list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class);
List<List<Map>> lists = Lists.partition(list,200); list.forEach(map1 -> {
lists.forEach(ll ->passengerFlowMapper.batchSave(ll)); QueryWrapper<PassengerFlow> 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){ } catch (Exception e){
@ -212,9 +229,10 @@ public class PassengerFlowService {
try{ try{
List<PassengerFlow> list = passengerFlowMapper.selectList(wrapper); List<PassengerFlow> list = passengerFlowMapper.selectList(wrapper);
for(PassengerFlow p:list){ for(PassengerFlow p:list){
allCount+=p.getAllNums();
localCount+=p.getLocalNums(); allCount+=Integer.parseInt(p.getAllNums());
nonLocalCount+=p.getNonlocalNums(); localCount+=Integer.parseInt(p.getLocalNums());
nonLocalCount+=Integer.parseInt(p.getNonlocalNums());
} }
result.put("local_nums",localCount); result.put("local_nums",localCount);
result.put("nonlocal_nums",nonLocalCount); result.put("nonlocal_nums",nonLocalCount);
@ -281,4 +299,45 @@ public class PassengerFlowService {
System.out.println("t1->"+t1+"...t2->"+t2); System.out.println("t1->"+t1+"...t2->"+t2);
return new String[]{t1,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<Double> vertX, List<Double> vertY,String timeId) {
List<PassengerFlow> 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;
}
} }

View File

@ -18,4 +18,8 @@
select * from t_passenger_flow ORDer by id desc limit 1 select * from t_passenger_flow ORDer by id desc limit 1
</select> </select>
<select id="selectByTime" resultType="com.hisense.monitormanage.entity.PassengerFlow">
select * from t_passenger_flow where time_id = #{timeId}
</select>
</mapper> </mapper>