增加数据存储redis
parent
13008cc2bb
commit
340691e8e1
|
@ -84,7 +84,7 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper , Fence> implement
|
||||||
// 将围栏坐标存储到redis中
|
// 将围栏坐标存储到redis中
|
||||||
// key 围栏编号
|
// key 围栏编号
|
||||||
// value 围栏坐标信息
|
// value 围栏坐标信息
|
||||||
redisService.setCacheObject(entity.getFenceId()+"",fenceLocation);
|
// redisService.setCacheObject(entity.getFenceId()+"",fenceLocation);
|
||||||
boolean update = super.updateById(entity);
|
boolean update = super.updateById(entity);
|
||||||
if (!update){
|
if (!update){
|
||||||
log.warn("编辑围栏[/-{}-/]未成功! 请求参数:{}",
|
log.warn("编辑围栏[/-{}-/]未成功! 请求参数:{}",
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue