对人流接口进行去重
This commit is contained in:
parent
aca19e8a4b
commit
4729c661a5
|
@ -66,7 +66,7 @@ public class Controller {
|
|||
private ChannelPictureMapper channelPictureMapper;
|
||||
|
||||
@Autowired
|
||||
private PassengerFlowlMapper passengerFlowlMapper;
|
||||
private PassengerFlowMapper passengerFlowlMapper;
|
||||
|
||||
|
||||
@GetMapping("all")
|
||||
|
@ -498,7 +498,7 @@ public class Controller {
|
|||
})
|
||||
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);
|
||||
List<PassengerFlowDto> c = passengerFlowlMapper.selectPassenger(around[0], around[2], around[1], around[3],timeId);
|
||||
Result success = Result.success(c);
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package com.hisense.monitormanage.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class PassengerFlowDto {
|
||||
private String hourId;
|
||||
private String timeId;
|
||||
private String longitude;
|
||||
private String latitude;
|
||||
private String allNums;
|
||||
private String localNums;
|
||||
private String nonlocalNums;
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.hisense.monitormanage.mapper;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.hisense.monitormanage.dto.PassengerFlowDto;
|
||||
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;
|
||||
|
||||
public interface PassengerFlowMapper extends BaseMapper<PassengerFlow> {
|
||||
void batchSave(List<Map> list);
|
||||
PassengerFlow getByMaxId();
|
||||
|
||||
List<PassengerFlow> selectByTime(String timeId);
|
||||
|
||||
@Select("select distinct pf.hour_id,pf.time_id,pf.longitude,pf.latitude,pf.all_nums,pf.local_nums,pf.nonlocal_nums from t_passenger_flow pf " +
|
||||
"where (longitude between #{longitude} and #{longitude1}) and (latitude between #{latitude} and #{latitude1} ) and time_id = #{timeId}")
|
||||
List<PassengerFlowDto> selectPassenger(@Param("longitude") Double longitude,
|
||||
@Param("longitude1") Double longitude1,
|
||||
@Param("latitude") Double latitude,
|
||||
@Param("latitude1") Double latitude1,
|
||||
@Param("timeId") String timeId);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
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;
|
||||
|
||||
public interface PassengerFlowlMapper extends BaseMapper<PassengerFlow> {
|
||||
void batchSave(List<Map> list);
|
||||
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);
|
||||
}
|
|
@ -2,11 +2,11 @@ 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.dto.PassengerFlowDto;
|
||||
import com.hisense.monitormanage.entity.PassengerFlow;
|
||||
import com.hisense.monitormanage.mapper.PassengerFlowlMapper;
|
||||
import com.hisense.monitormanage.mapper.PassengerFlowMapper;
|
||||
import com.hisense.monitormanage.utils.LongLatUtil;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -17,7 +17,6 @@ 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;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
@ -37,7 +36,7 @@ import java.util.*;
|
|||
@Log4j2
|
||||
public class PassengerFlowService {
|
||||
@Autowired
|
||||
private PassengerFlowlMapper passengerFlowMapper;
|
||||
private PassengerFlowMapper passengerFlowMapper;
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
@ -171,26 +170,8 @@ public class PassengerFlowService {
|
|||
if(jsonResult.getIntValue("code") == 0){
|
||||
JSONArray jsonArray = jsonResult.getJSONArray("result");
|
||||
list = JSONObject.parseArray(JSONObject.toJSONString(jsonArray),Map.class);
|
||||
list.forEach(map1 -> {
|
||||
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);
|
||||
}
|
||||
|
||||
});
|
||||
List<List<Map>> lists = Lists.partition(list,200);
|
||||
lists.forEach(ll ->passengerFlowMapper.batchSave(ll));
|
||||
}
|
||||
}
|
||||
} catch (Exception e){
|
||||
|
@ -213,13 +194,13 @@ public class PassengerFlowService {
|
|||
|
||||
//根据半径,一个经纬度和timeId查询游客总数
|
||||
public JSONObject passengerNums(double longitude, double latitude, Integer radius,String timeId){
|
||||
QueryWrapper<PassengerFlow> wrapper = new QueryWrapper<>();
|
||||
/*QueryWrapper<PassengerFlow> wrapper = new QueryWrapper<>();
|
||||
if(Double.doubleToLongBits(longitude) == Double.doubleToLongBits(0.00) || Double.doubleToLongBits(latitude) == Double.doubleToLongBits(0.00)){
|
||||
wrapper.eq("time_id",timeId);
|
||||
}else{
|
||||
double[] points = LongLatUtil.getAround(longitude,latitude,radius);
|
||||
wrapper.eq("time_id",timeId).between("longitude",points[0],points[2]).between("latitude",points[1],points[3]);
|
||||
}
|
||||
}*/
|
||||
|
||||
int allCount = 0;
|
||||
int localCount = 0;
|
||||
|
@ -227,8 +208,9 @@ public class PassengerFlowService {
|
|||
JSONObject result = new JSONObject();
|
||||
|
||||
try{
|
||||
List<PassengerFlow> list = passengerFlowMapper.selectList(wrapper);
|
||||
for(PassengerFlow p:list){
|
||||
double[] around = LongLatUtil.getAround(longitude, latitude, radius);
|
||||
List<PassengerFlowDto> list = passengerFlowMapper.selectPassenger(around[0], around[2], around[1], around[3],timeId);
|
||||
for(PassengerFlowDto p:list){
|
||||
|
||||
allCount+=Integer.parseInt(p.getAllNums());
|
||||
localCount+=Integer.parseInt(p.getLocalNums());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.hisense.monitormanage.mapper.PassengerFlowlMapper">
|
||||
<mapper namespace="com.hisense.monitormanage.mapper.PassengerFlowMapper">
|
||||
|
||||
<insert id="batchSave" parameterType="java.util.List">
|
||||
INSERT INTO t_passenger_flow
|
||||
|
|
Loading…
Reference in New Issue