diff --git a/src/main/java/com/hisense/monitormanage/controller/Controller.java b/src/main/java/com/hisense/monitormanage/controller/Controller.java index 99cf2a8..f6cab63 100644 --- a/src/main/java/com/hisense/monitormanage/controller/Controller.java +++ b/src/main/java/com/hisense/monitormanage/controller/Controller.java @@ -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 c = passengerFlowlMapper.selectPassenger(around[0], around[2], around[1], around[3],timeId); + List c = passengerFlowlMapper.selectPassenger(around[0], around[2], around[1], around[3],timeId); Result success = Result.success(c); return success; } diff --git a/src/main/java/com/hisense/monitormanage/dto/PassengerFlowDto.java b/src/main/java/com/hisense/monitormanage/dto/PassengerFlowDto.java new file mode 100644 index 0000000..4944a31 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/dto/PassengerFlowDto.java @@ -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; +} diff --git a/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowMapper.java b/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowMapper.java new file mode 100644 index 0000000..24d9c67 --- /dev/null +++ b/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowMapper.java @@ -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 { + void batchSave(List list); + PassengerFlow getByMaxId(); + + List 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 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/mapper/PassengerFlowlMapper.java b/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowlMapper.java deleted file mode 100644 index 44802e9..0000000 --- a/src/main/java/com/hisense/monitormanage/mapper/PassengerFlowlMapper.java +++ /dev/null @@ -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 { - 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 44db6a3..2133a49 100644 --- a/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java +++ b/src/main/java/com/hisense/monitormanage/service/PassengerFlowService.java @@ -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 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> 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 wrapper = new QueryWrapper<>(); + /*QueryWrapper 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 list = passengerFlowMapper.selectList(wrapper); - for(PassengerFlow p:list){ + double[] around = LongLatUtil.getAround(longitude, latitude, radius); + List 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()); diff --git a/src/main/resources/mapper/PassengerFlowlMapper.xml b/src/main/resources/mapper/PassengerFlowlMapper.xml index c4105eb..14dbeac 100644 --- a/src/main/resources/mapper/PassengerFlowlMapper.xml +++ b/src/main/resources/mapper/PassengerFlowlMapper.xml @@ -1,6 +1,6 @@ - + INSERT INTO t_passenger_flow