车辆管理模块 加注释 增删改,触发刷新缓存 增加缓存时间

server_five_dongxiaodong
liuyunhu 2024-04-08 14:44:03 +08:00
parent 1b9c777a87
commit be2e99af0c
3 changed files with 54 additions and 23 deletions

View File

@ -1,5 +1,6 @@
package com.couplet.analyze.msg.model; package com.couplet.analyze.msg.model;
import com.couplet.analyze.common.event.AnalyzeEventCache;
import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService; import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.common.core.exception.vehicle.VehicleException; import com.couplet.common.core.exception.vehicle.VehicleException;

View File

@ -22,9 +22,11 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* @ProjectName: five-groups-couplet * @ProjectName: five-groups-couplet
@ -140,6 +142,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
* @Return: java.lang.String * @Return: java.lang.String
**/ **/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public String editById(VehicleEditParams editParams) { public String editById(VehicleEditParams editParams) {
String result = ""; String result = "";
@ -200,6 +203,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
* @Return: java.lang.String * @Return: java.lang.String
**/ **/
@Override @Override
@Transactional(rollbackFor = Exception.class)
public String insert(VehicleInsertParams insertParams) { public String insert(VehicleInsertParams insertParams) {
String result = ""; String result = "";
@ -303,7 +307,13 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
} }
//通过vin修改车辆上下线的状态 /*
* @Author: LiuYunHu
* @Date: 2024/4/8 14:11
* @Description: vin线
* @Param: [vin, status]
* @Return: java.lang.Integer
**/
@Override @Override
public Integer onOrOutLineByVIN(String vin, int status) { public Integer onOrOutLineByVIN(String vin, int status) {
@ -315,6 +325,13 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
return vehicleMapper.addVehicle(userId, vehicleIds); return vehicleMapper.addVehicle(userId, vehicleIds);
} }
/*
* @Author: LiuYunHu
* @Date: 2024/4/8 14:11
* @Description: vinplusList
* @Param: [vin]
* @Return: java.util.List<com.couplet.common.domain.Vehicle>
**/
@Override @Override
public List<Vehicle> findByVIN(String vin) { public List<Vehicle> findByVIN(String vin) {
@ -330,19 +347,19 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
} }
// @Scheduled(cron = "0/1 * * * * *") /*
// public void aa() { * @Author: LiuYunHu
// System.out.println("********************************************************"); * @Date: 2024/4/8 14:12
// } * @Description: 线
* @Param: []
//判断车辆是否下线 * @Return: void
**/
@Scheduled(cron = "0/1 * * * * *") @Scheduled(cron = "0/1 * * * * *")
public void downLine() { public void downLine() {
log.info("定时器启动"); log.info("定时器启动");
//先查询车辆列表 //先查询车辆列表
List<Vehicle> list = this.list(new VehicleListParams(null, null, null, null)); List<Vehicle> list = this.list(new VehicleListParams(null, null, null, null));
list.forEach(vehicle -> { list.forEach(vehicle -> {
try { try {
//只针对已经上线的车辆 //只针对已经上线的车辆
@ -372,30 +389,43 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
} }
/* /*
* * @Author: LiuYunHu
* */ * @Date: 2024/4/8 14:14
* @Description:
* @Param: []
* @Return: void
**/
@Scheduled(cron = "0/3 * * * * *") @Scheduled(cron = "0/3 * * * * *")
public void reCache() { public void reCache() {
//先获取所有车辆的信息 //刷新缓存执行开始
//先获取所有车辆的信息
List<Vehicle> list = list(new VehicleListParams()); List<Vehicle> list = list(new VehicleListParams());
//通过车辆的id获取对应的标识
list.forEach(vehicle -> { list.forEach(vehicle -> {
//通过车辆的id获取对应的标识集合
List<Long> bindLogoById = getBindLogoById(vehicle.getVehicleId()); List<Long> bindLogoById = getBindLogoById(vehicle.getVehicleId());
//遍历标识集合
bindLogoById.forEach(logoId -> { bindLogoById.forEach(logoId -> {
//存标识id
//存标识id 的set
HashSet<Long> logos = new HashSet<>(); HashSet<Long> logos = new HashSet<>();
logos.add(logoId); logos.add(logoId);
//存入redis
redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos); redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos);
redis.expire("车辆vin和标识:" + vehicle.getVin(), 2, TimeUnit.MINUTES);
//存围栏id //通过标识id获取标识绑定的电子围栏集合
List<Fence> fences = fenAndLogoService.findFencesByLogoId(logoId); List<Fence> fences = fenAndLogoService.findFencesByLogoId(logoId);
//遍历电子围栏集合
fences.forEach(fence -> { fences.forEach(fence -> {
HashSet<Fence> fanceSet = new HashSet<>(); HashSet<Fence> fanceSet = new HashSet<>();
fanceSet.add(fence); fanceSet.add(fence);
//存入redis
redis.setCacheSet("车辆vin和电子围栏:" + vehicle.getVin(), fanceSet); redis.setCacheSet("车辆vin和电子围栏:" + vehicle.getVin(), fanceSet);
redis.expire("车辆vin和电子围栏:" + vehicle.getVin(), 2, TimeUnit.MINUTES);
}); });
}); });
}); });

View File

@ -35,15 +35,15 @@ logging:
com.couplet.system.mapper: DEBUG com.couplet.system.mapper: DEBUG
# 订阅端配置 # 订阅端配置
mqtt: #mqtt:
server: # server:
broker: tcp://8.130.181.16:1883 # broker: tcp://8.130.181.16:1883
# broker: tcp://115.159.47.13:1883 ## broker: tcp://115.159.47.13:1883
username: # username:
password: # password:
clientid: mqttx # clientid: mqttx
qos: 0 # qos: 0
topic: test # topic: test
# RabbitMQ配置 # RabbitMQ配置
mq: mq: