事件初始化
parent
7db45963f5
commit
93d3f030b4
|
@ -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";
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
package com.god.base.domain;
|
package com.god.base.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.god.base.domain.request.CarRequest;
|
import com.god.base.domain.request.CarRequest;
|
||||||
|
@ -27,6 +28,7 @@ public class Car {
|
||||||
* 车辆Vin 主键
|
* 车辆Vin 主键
|
||||||
*/
|
*/
|
||||||
@Excel(name = "车辆carVibId")
|
@Excel(name = "车辆carVibId")
|
||||||
|
@TableId
|
||||||
private String carVinId;
|
private String carVinId;
|
||||||
/**
|
/**
|
||||||
* 单位id
|
* 单位id
|
||||||
|
|
|
@ -67,6 +67,7 @@ public class CarRequest extends PageQuery {
|
||||||
private String batteryNumber;
|
private String batteryNumber;
|
||||||
|
|
||||||
|
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -132,7 +132,6 @@ public class CarController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 导出车辆信息管理列表
|
* 导出车辆信息管理列表
|
||||||
*/
|
*/
|
||||||
@RequiresPermissions("car:car:export")
|
|
||||||
@Log(title = "导出车辆信息管理列表" , businessType = BusinessType.EXPORT) // 导出 跳转业务操作类型表中
|
@Log(title = "导出车辆信息管理列表" , businessType = BusinessType.EXPORT) // 导出 跳转业务操作类型表中
|
||||||
@PostMapping("/export")
|
@PostMapping("/export")
|
||||||
public void export(HttpServletResponse response , Car car , CarRequest carRequest)
|
public void export(HttpServletResponse response , Car car , CarRequest carRequest)
|
||||||
|
|
|
@ -8,10 +8,12 @@ package com.god.base.server.controller;
|
||||||
* @Description TODO
|
* @Description TODO
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
import com.god.base.common.constant.EventConstant;
|
||||||
import com.god.base.domain.Car;
|
import com.god.base.domain.Car;
|
||||||
import com.god.base.domain.Fence;
|
import com.god.base.domain.Fence;
|
||||||
import com.god.base.domain.request.FenceAddRequest;
|
import com.god.base.domain.request.FenceAddRequest;
|
||||||
import com.god.base.domain.request.FenceQueryRequest;
|
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.service.FenceService;
|
||||||
import com.god.base.server.utils.CarFenceMonitor;
|
import com.god.base.server.utils.CarFenceMonitor;
|
||||||
import com.god.common.core.web.page.TableDataInfo;
|
import com.god.common.core.web.page.TableDataInfo;
|
||||||
|
@ -37,6 +39,9 @@ public class FenceController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private FenceService fenceService;
|
private FenceService fenceService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EventInit eventInit;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 增添电子围栏
|
* 增添电子围栏
|
||||||
|
@ -50,6 +55,8 @@ public class FenceController {
|
||||||
carFenceMonitor.getCarFencesList();
|
carFenceMonitor.getCarFencesList();
|
||||||
//围栏添加
|
//围栏添加
|
||||||
fenceService.save(Fence.fenceBuildAdd(fenceAddRequest));
|
fenceService.save(Fence.fenceBuildAdd(fenceAddRequest));
|
||||||
|
//添加事件
|
||||||
|
eventInit.insertEvent(fenceAddRequest.getCarVinId(), EventConstant.FENCE);
|
||||||
return Result.success("","添加成功");
|
return Result.success("","添加成功");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
package com.god.base.server.controller;
|
package com.god.base.server.controller;
|
||||||
|
|
||||||
import com.god.base.domain.request.GetTopicReq;
|
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.base.server.service.impl.TopLineServiceImpl;
|
||||||
import com.god.common.core.domain.Result;
|
import com.god.common.core.domain.Result;
|
||||||
import com.god.common.log.annotation.Log;
|
import com.god.common.log.annotation.Log;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
import org.springframework.stereotype.Controller;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 车辆上线控制层
|
* 车辆上线控制层
|
||||||
* @Author fst
|
* @Author fst
|
||||||
* @date 2023/11/28 23:38
|
* @date 2023/11/28 23:38
|
||||||
*/
|
*/
|
||||||
|
@ -33,4 +33,11 @@ public class TopLineController {
|
||||||
String topic = topLineService.getTopic(getTopicReq);
|
String topic = topLineService.getTopic(getTopicReq);
|
||||||
return Result.success(topic);
|
return Result.success(topic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("getCarVinList")
|
||||||
|
@Log(title = "获取车辆vin列表")
|
||||||
|
public Result<List<String>> getCarVinList(){
|
||||||
|
List<String> carVinList = topLineService.getCarVinList();
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.god.base.domain.TopicCar;
|
import com.god.base.domain.TopicCar;
|
||||||
import com.god.base.domain.request.GetTopicReq;
|
import com.god.base.domain.request.GetTopicReq;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 车辆上线
|
* 车辆上线
|
||||||
* @Author fst
|
* @Author fst
|
||||||
|
@ -18,4 +20,6 @@ public interface TopLineService extends IService<TopicCar> {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
String getTopic(GetTopicReq getTopicReq);
|
String getTopic(GetTopicReq getTopicReq);
|
||||||
|
|
||||||
|
List<String> getCarVinList();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,4 +66,23 @@ public class TopLineServiceImpl extends ServiceImpl<TopicCarMapper, TopicCar> i
|
||||||
return "god";
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,10 +72,8 @@ public class CarFenceMonitor {
|
||||||
for (Fence row : rows) {
|
for (Fence row : rows) {
|
||||||
fences.add(row);
|
fences.add(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
//存储redis
|
//存储redis
|
||||||
redisService.setCacheSet("Fence"+car.getCarVinId(),fences);
|
redisService.setCacheSet("Fence"+car.getCarVinId(),fences);
|
||||||
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue