车辆围栏缓存改动

master
fst1996 2023-12-06 19:34:39 +08:00
parent 07f68c6f37
commit c30d7a4b92
2 changed files with 6 additions and 16 deletions

View File

@ -14,10 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList; import java.util.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/** /**
* *
@ -50,10 +47,10 @@ public class CarFenceMonitor {
if (dataCar.size() <= 0) { if (dataCar.size() <= 0) {
throw new RuntimeException("查无管理车辆"); throw new RuntimeException("查无管理车辆");
} }
//新建map集合存储车辆围栏
Map<String, Set<Fence>> map = new HashMap<>();
for (Car car : dataCar) { for (Car car : dataCar) {
//单线程获取车辆围栏信息 //单线程获取车辆围栏信息
new Thread(() -> {
FenceQueryRequest fenceQueryRequest = new FenceQueryRequest(); FenceQueryRequest fenceQueryRequest = new FenceQueryRequest();
fenceQueryRequest.setPage(1); fenceQueryRequest.setPage(1);
@ -62,25 +59,20 @@ public class CarFenceMonitor {
//获取车辆围栏信息 //获取车辆围栏信息
TableDataInfo<Fence> fenceTableDataInfo = fenceService.fenceListAndPage(fenceQueryRequest); TableDataInfo<Fence> fenceTableDataInfo = fenceService.fenceListAndPage(fenceQueryRequest);
List<Fence> rows = fenceTableDataInfo.getRows(); List<Fence> rows = fenceTableDataInfo.getRows();
if (rows.size() <= 0) { if (rows.size() <= 0) {
throw new RuntimeException("该车辆未绑定围栏"); throw new RuntimeException("该车辆未绑定围栏");
} }
//围栏对象集合 //围栏对象集合
Set<Fence> fences = new HashSet<>(); Set<Fence> fences = new HashSet<>();
for (Fence row : rows) { for (Fence row : rows) {
fences.add(row); fences.add(row);
} }
map.put(car.getCarVinId(), fences);
}
//存储redis //存储redis
redisService.setCacheSet("Fence"+car.getCarVinId(),fences); redisService.setCacheMap("FENCE", map);
}).start();
}
} }
} }

View File

@ -72,7 +72,6 @@
SELECt SELECt
t_car.car_vin_id , t_car.car_vin_id ,
t_car_type.car_type_name , t_car_type.car_type_name ,
t_fence.fence_name ,
t_car.battery_manufacturer , t_car.battery_manufacturer ,
t_car.motor_manufacturer , t_car.motor_manufacturer ,
t_car.motor_number , t_car.motor_number ,
@ -80,7 +79,6 @@
t_car.status t_car.status
FROM FROM
t_car t_car
JOIN t_fence ON t_car.fence_id = t_fence.fence_id
JOIN t_car_type ON t_car.car_type_id = t_car_type.id JOIN t_car_type ON t_car.car_type_id = t_car_type.id
<where> <where>
<if test="userId != null"> <if test="userId != null">