增加数据存储redis

master
ZhiShuo_Lou 2023-11-29 22:09:07 +08:00
parent 13008cc2bb
commit 340691e8e1
2 changed files with 78 additions and 1 deletions

View File

@ -84,7 +84,7 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper , Fence> implement
// 将围栏坐标存储到redis中
// key 围栏编号
// value 围栏坐标信息
redisService.setCacheObject(entity.getFenceId()+"",fenceLocation);
// redisService.setCacheObject(entity.getFenceId()+"",fenceLocation);
boolean update = super.updateById(entity);
if (!update){
log.warn("编辑围栏[/-{}-/]未成功! 请求参数:{}",

View File

@ -0,0 +1,77 @@
package com.god.base.server.utils;
import com.god.base.domain.Car;
import com.god.base.domain.Fence;
import com.god.base.domain.request.FenceQueryRequest;
import com.god.base.server.service.CarService;
import com.god.base.server.service.FenceService;
import com.god.common.core.domain.Result;
import com.god.common.core.web.page.TableDataInfo;
import com.god.common.redis.service.RedisService;
import com.god.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
*
*
* @author LouZhiSHuo
* @Date 2023/11/29 21:31
**/
@Component
public class CarFenceMonitor {
@Autowired
private CarService carService;
@Autowired
private FenceService fenceService;
@Autowired
private RedisService redisService;
public void getCarFencesList(){
//获取车辆信息
Result<List<Car>> listResult = carService.carList(String.valueOf(SecurityUtils.getUserId()));
List<Car> dataCar = listResult.getData();
if (dataCar.size() <= 0) {
throw new RuntimeException("查无管理车辆");
}
for (Car car : dataCar) {
//单线程获取车辆围栏信息
new Thread(() -> {
FenceQueryRequest fenceQueryRequest = new FenceQueryRequest();
fenceQueryRequest.setCarVinId(car.getCarVinId());
//获取车辆围栏信息
TableDataInfo<Fence> fenceTableDataInfo = fenceService.fenceListAndPage(fenceQueryRequest);
List<Fence> rows = fenceTableDataInfo.getRows();
if (rows.size() <= 0) {
throw new RuntimeException("该车辆未绑定围栏");
}
//容器
List<String> locationList = new ArrayList<>();
for (Fence row : rows) {
locationList.add(row.getFenceLocation());
}
//存储redis
redisService.setCacheList(car.getCarVinId()+"fence",locationList);
}).start();
}
}
}