事件初始化

master
fst1996 2023-12-05 14:24:56 +08:00
parent 7db45963f5
commit 93d3f030b4
11 changed files with 164 additions and 9 deletions

View File

@ -0,0 +1,17 @@
package com.god.base.common.constant;
/**
* @description:
* @Author fst
* @date 2023/12/5 10:48
*/
public class EventConstant {
//电子围栏事件
public static final String FENCE = "Fence";
//故障报警事件
public static final String FAULT = "FaultAlarm";
//实时轨迹事件
public static final String REAL = "RealTimeTrajectory";
}

View File

@ -1,5 +1,6 @@
package com.god.base.domain;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.god.base.domain.request.CarRequest;
@ -27,6 +28,7 @@ public class Car {
* Vin
*/
@Excel(name = "车辆carVibId")
@TableId
private String carVinId;
/**
* id

View File

@ -67,6 +67,7 @@ public class CarRequest extends PageQuery {
private String batteryNumber;
private Long userId;
}

View File

@ -0,0 +1,26 @@
package com.god.base.domain.request;
import lombok.Data;
/**
* @description:
* @Author fst
* @date 2023/12/5 10:27
*/
@Data
public class QueryCarRequest {
/**
* vin
*/
private String carVinId;
/**
* id
*/
private Long userId;
/**
* 0线 1线
*/
private Integer status;
}

View File

@ -0,0 +1,75 @@
package com.god.base.server.config;
import com.god.base.common.constant.EventConstant;
import com.god.base.domain.Car;
import com.god.base.domain.request.QueryCarRequest;
import com.god.base.server.service.impl.TopLineServiceImpl;
import com.god.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
/**
*
* @Author fst
* @date 2023/12/5 10:10
*/
@Configuration
public class EventInit {
@Autowired
private RedisService redisService;
@Autowired
private TopLineServiceImpl topLineService;
/**
*
*/
@Bean
public void init(){
//初始化故障码车辆事件
HashSet<String> set = new HashSet<>();
set.add(EventConstant.FAULT);
Map<String, HashSet<String>> map = new HashMap<>();
//获取所有车辆vin列表
List<String> carVinList = topLineService.getCarVinList();
//循环在map中添加事件set
carVinList.forEach(carVinId -> {
map.put(carVinId,set);
});
redisService.setCacheMap("EVENT",map);
}
/**
*
* @param carVinId
* @param event
*/
public void insertEvent(String carVinId,String event){
//获取车辆事件集合
HashSet<String> set = redisService.getCacheMapValue("EVENT", carVinId);
//添加事件
set.add(event);
//更新事件
redisService.setCacheMapValue("EVENT",carVinId,set);
}
/**
*
* @param carVinId
* @param event
*/
public void delEvent(String carVinId,String event){
//获取车辆事件集合
HashSet<String> set = redisService.getCacheMapValue("EVENT", carVinId);
//添加事件
set.remove(event);
//更新事件
redisService.setCacheMapValue("EVENT",carVinId,set);
}
}

View File

@ -132,7 +132,6 @@ public class CarController extends BaseController {
/**
*
*/
@RequiresPermissions("car:car:export")
@Log(title = "导出车辆信息管理列表" , businessType = BusinessType.EXPORT) // 导出 跳转业务操作类型表中
@PostMapping("/export")
public void export(HttpServletResponse response , Car car , CarRequest carRequest)

View File

@ -8,10 +8,12 @@ package com.god.base.server.controller;
* @Description TODO
**/
import com.god.base.common.constant.EventConstant;
import com.god.base.domain.Car;
import com.god.base.domain.Fence;
import com.god.base.domain.request.FenceAddRequest;
import com.god.base.domain.request.FenceQueryRequest;
import com.god.base.server.config.EventInit;
import com.god.base.server.service.FenceService;
import com.god.base.server.utils.CarFenceMonitor;
import com.god.common.core.web.page.TableDataInfo;
@ -37,6 +39,9 @@ public class FenceController {
@Autowired
private FenceService fenceService;
@Autowired
private EventInit eventInit;
/**
*
@ -48,9 +53,11 @@ public class FenceController {
public Result<String> insertFence(@RequestBody @Validated FenceAddRequest fenceAddRequest){
//更新实时数据
carFenceMonitor.getCarFencesList();
//围栏添加
fenceService.save(Fence.fenceBuildAdd(fenceAddRequest));
return Result.success("","添加成功");
//围栏添加
fenceService.save(Fence.fenceBuildAdd(fenceAddRequest));
//添加事件
eventInit.insertEvent(fenceAddRequest.getCarVinId(), EventConstant.FENCE);
return Result.success("","添加成功");
}

View File

@ -1,18 +1,18 @@
package com.god.base.server.controller;
import com.god.base.domain.request.GetTopicReq;
import com.god.base.server.service.TopLineService;
import com.god.base.server.service.impl.TopLineServiceImpl;
import com.god.common.core.domain.Result;
import com.god.common.log.annotation.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
* @description: 线
* 线
* @Author fst
* @date 2023/11/28 23:38
*/
@ -33,4 +33,11 @@ public class TopLineController {
String topic = topLineService.getTopic(getTopicReq);
return Result.success(topic);
}
@GetMapping("getCarVinList")
@Log(title = "获取车辆vin列表")
public Result<List<String>> getCarVinList(){
List<String> carVinList = topLineService.getCarVinList();
return Result.success();
}
}

View File

@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.god.base.domain.TopicCar;
import com.god.base.domain.request.GetTopicReq;
import java.util.List;
/**
* 线
* @Author fst
@ -18,4 +20,6 @@ public interface TopLineService extends IService<TopicCar> {
* @return
*/
String getTopic(GetTopicReq getTopicReq);
List<String> getCarVinList();
}

View File

@ -66,4 +66,23 @@ public class TopLineServiceImpl extends ServiceImpl<TopicCarMapper, TopicCar> i
return "god";
}
}
/**
* vin
* @return
*/
@Override
public List<String> getCarVinList() {
List<TopicCar> topicCars = carMapper.selectList(new QueryWrapper<TopicCar>());
//转换为车辆集合
try {
if (StringUtils.isEmpty(topicCars)){
throw new ServiceException("车辆信息不存在");
}
return topicCars.stream().map(TopicCar::getCarVinId).toList();
}catch (Exception e){
log.info(e.getMessage());
throw new ServiceException(e.getMessage());
}
}
}

View File

@ -72,10 +72,8 @@ public class CarFenceMonitor {
for (Fence row : rows) {
fences.add(row);
}
//存储redis
redisService.setCacheSet("Fence"+car.getCarVinId(),fences);
}).start();
}