4.9更新
parent
d0c2928c8e
commit
4b015fc830
|
@ -116,15 +116,12 @@
|
|||
<artifactId>muyu-common-event</artifactId>
|
||||
<version>3.6.3</version>
|
||||
</dependency>
|
||||
<!-- <!–MQ–>-->
|
||||
<!--MQ-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.springframework.boot</groupId>-->
|
||||
<!-- <artifactId>spring-boot-starter-amqp</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>org.apache.tomcat.embed</groupId>-->
|
||||
<!-- <artifactId>tomcat-embed-core</artifactId>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -35,16 +35,6 @@ public class Consumer {
|
|||
@Autowired
|
||||
private VehicleEventCache vehicleEventCache;
|
||||
|
||||
|
||||
// List<String> list = new ArrayList<>();
|
||||
|
||||
// {
|
||||
// list.add("breakdown");
|
||||
// list.add("realTime");
|
||||
// list.add("storedEvent");
|
||||
// list.add("fenceAlarm");
|
||||
// }
|
||||
|
||||
/**
|
||||
* kafka消费者--监听 kafka主题 test
|
||||
* @param msg
|
||||
|
@ -53,24 +43,18 @@ public class Consumer {
|
|||
@KafkaListener(topics = "test")
|
||||
public void getMessage(String msg) {
|
||||
VehicleData analyze = AnalyzeUtils.analyze(msg);
|
||||
log.info("。。。。。。。。。。。。非静止画面");
|
||||
|
||||
Set<String> eventList = vehicleEventCache.getEventList(analyze.getVin());
|
||||
|
||||
List<Fence> fenceVin=vehicleMapper.selectFenceList();
|
||||
|
||||
for (Fence fence : fenceVin) {
|
||||
if (analyze.getVin().equals(fence.getCarVin())){
|
||||
|
||||
for (String s : eventList) {
|
||||
VehicleService vehicleService = SpringUtils.getBean(s);
|
||||
vehicleService.eventResolution(analyze);
|
||||
}
|
||||
}else {
|
||||
log.info("编号:"+analyze.getVin()+",不是登记车辆");
|
||||
}
|
||||
// List<Fence> fenceVin=vehicleMapper.selectFenceList();
|
||||
|
||||
for (String s : eventList) {
|
||||
VehicleService vehicleService = SpringUtils.getBean(s);
|
||||
vehicleService.eventResolution(analyze);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
//package com.muyu.analyze.consumer;
|
||||
//
|
||||
///**
|
||||
// * @ProjectName: cloud-vehicles
|
||||
// * @PackageName: com.muyu.analyze.consumer
|
||||
// * @Description TODO
|
||||
// * @Author HuangDaJu
|
||||
// * @Date 2024/4/8 21:43
|
||||
// * @Version 1.0
|
||||
// */
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//import com.muyu.common.redis.service.RedisService;
|
||||
//import com.rabbitmq.client.Channel;
|
||||
//import lombok.extern.log4j.Log4j2;
|
||||
//import org.springframework.amqp.core.Message;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
//import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//
|
||||
//
|
||||
//@Component
|
||||
//@RabbitListener(queues = "queue")
|
||||
//@Log4j2
|
||||
//public class RabbitMqConsumer {
|
||||
//
|
||||
//
|
||||
// @Autowired
|
||||
// private RedisService redisService;
|
||||
//
|
||||
// @RabbitHandler
|
||||
// public void take(String msg, Channel channel, Message message) throws IOException {
|
||||
//
|
||||
//
|
||||
// long deliveryTag = message.getMessageProperties().getDeliveryTag();
|
||||
// System.out.println("MQ消费:"+msg);
|
||||
// channel.basicAck(deliveryTag,false);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
//
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.analyze.mapper;
|
||||
|
||||
import com.muyu.business.domain.Fence;
|
||||
import com.muyu.system.common.domain.Car;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
@ -24,5 +25,7 @@ public interface VehicleMapper{
|
|||
List<Fence> selectFenceList();
|
||||
|
||||
|
||||
Car selectCarList(String vin);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ public class BreakdownImpl implements VehicleService{
|
|||
@Override
|
||||
public void eventResolution(VehicleData vehicleData) {
|
||||
|
||||
log.info("故障事件解析");
|
||||
|
||||
|
||||
//判断故障
|
||||
if (StateConstant.VEHICLE_STATUS != vehicleData.getVehicleStatus()
|
||||
|
@ -62,6 +62,7 @@ public class BreakdownImpl implements VehicleService{
|
|||
|| StateConstant.DCDC_STATUS != vehicleData.getDcdcStatus()
|
||||
|| StateConstant.CHG_STATUS != vehicleData.getChgStatus()) {
|
||||
|
||||
log.info("车辆VIN:"+vehicleData.getVin()+"发生故障,故障事件解析");
|
||||
|
||||
FaultLogs faultLogsAddReq = new FaultLogs();
|
||||
|
||||
|
@ -220,10 +221,14 @@ public class BreakdownImpl implements VehicleService{
|
|||
// 设置过期时间
|
||||
redisService.expire(key, 20, TimeUnit.MINUTES);
|
||||
|
||||
|
||||
log.info("车辆VIN:"+vehicleData.getVin()+"故障事件已记录");
|
||||
log.info("故障事件结束");
|
||||
}else{
|
||||
log.info("车辆VIN:"+vehicleData.getVin()+"没有故障,状态正常");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package com.muyu.analyze.service.impl;
|
|||
|
||||
import com.muyu.analyze.mapper.VehicleMapper;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.business.domain.AlarmLogs;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.business.domain.Fence;
|
||||
import com.muyu.system.common.domain.Car;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -13,6 +15,7 @@ import org.springframework.stereotype.Service;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static java.lang.Double.parseDouble;
|
||||
|
@ -39,7 +42,7 @@ public class FenceAlarmImpl implements VehicleService {
|
|||
|
||||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
|
||||
Fence fence = new Fence();
|
||||
//车的vin
|
||||
String vin = analyze.getVin();
|
||||
|
||||
|
@ -51,62 +54,64 @@ public class FenceAlarmImpl implements VehicleService {
|
|||
|
||||
//这里修改为1对多的 电子围栏 目前是一对一
|
||||
|
||||
List<Fence> list=vehicleMapper.selectFenceList();
|
||||
Car car =vehicleMapper.selectCarList(vin);
|
||||
|
||||
String carFenceId = car.getCarFenceId();
|
||||
|
||||
String[] split1 = carFenceId.split(",");
|
||||
|
||||
|
||||
Map<String, Object> fence1 = redisService.getCacheMap("fence");
|
||||
|
||||
|
||||
|
||||
for (Map.Entry<String, Object> entry : fence1.entrySet()) {
|
||||
for (String s : split1) {
|
||||
String key = entry.getKey();
|
||||
if (s.equals(key)){
|
||||
String value = (String) entry.getValue();
|
||||
|
||||
for (Fence fence : list) {
|
||||
String[] split = value.split(";");
|
||||
|
||||
if (fence.getCarVin().equals(vin)){
|
||||
boolean withinFence = isWithinFence(pointLat, pointLng, Arrays.asList(split));
|
||||
|
||||
//39.958897,116.179075; 39.950476,116.330823; 39.865149,116.290311; 39.881485,116.083631
|
||||
if (withinFence){
|
||||
log.info("车辆vin:"+vin+"------在电子围栏"+key+"---正常行驶---");
|
||||
}else {
|
||||
log.info("车辆vin:"+vin+"------驶出电子围栏"+key+"---报警---");
|
||||
|
||||
String[] split = fence.getFenceRadius().split(";");
|
||||
String key1 = "fenceType1";
|
||||
|
||||
boolean withinFence = isWithinFence(pointLat, pointLng, Arrays.asList(split));
|
||||
HashSet<Fence> hashSet = new HashSet<>();
|
||||
fence.setCarVin(vin);
|
||||
fence.setFenceType("驶出");
|
||||
fence.setFenceId(Integer.valueOf(key));
|
||||
|
||||
hashSet.add(fence);
|
||||
redisService.setCacheSet(key1,hashSet);
|
||||
redisService.expire(key1, 20, TimeUnit.MINUTES); // 设置过期时间
|
||||
}
|
||||
|
||||
//false是除了围栏要报警
|
||||
// if (withinFence){
|
||||
// log.info("车辆vin:"+vin+"------驶入禁行区----报警");
|
||||
//
|
||||
// String key1 = "fenceType1";
|
||||
// HashSet<Fence> hashSet = new HashSet<>();
|
||||
// fence.setCarVin(vin);
|
||||
// fence.setFenceType("驶入");
|
||||
// fence.setFenceId(Integer.valueOf(key));
|
||||
// hashSet.add(fence);
|
||||
// redisService.setCacheSet(key1,hashSet);
|
||||
// redisService.expire(key1, 20, TimeUnit.MINUTES); // 设置过期时间
|
||||
//
|
||||
// }else{
|
||||
// log.info("车辆vin:"+vin+"------在安全区");
|
||||
// }
|
||||
|
||||
if (fence.getFenceType().equals("驶出")){
|
||||
if (withinFence){
|
||||
log.info("车辆vin:"+vin+"------在安全区");
|
||||
}else {
|
||||
log.info("车辆vin:"+vin+"------驶出围栏---报警");
|
||||
|
||||
|
||||
String key = "fenceType1";
|
||||
HashSet<Fence> hashSet = new HashSet<>();
|
||||
hashSet.add(fence);
|
||||
redisService.setCacheSet(key,hashSet);
|
||||
redisService.expire(key, 20, TimeUnit.MINUTES); // 设置过期时间
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (fence.getFenceType().equals("驶入")){
|
||||
if (withinFence){
|
||||
log.info("车辆vin:"+vin+"------驶入禁行区----报警");
|
||||
|
||||
String key = "fenceType1";
|
||||
HashSet<Fence> hashSet = new HashSet<>();
|
||||
hashSet.add(fence);
|
||||
redisService.setCacheSet(key,hashSet);
|
||||
redisService.expire(key, 20, TimeUnit.MINUTES); // 设置过期时间
|
||||
|
||||
}else{
|
||||
log.info("车辆vin:"+vin+"------在安全区");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//false是除了围栏要报警
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.analyze.service.impl;
|
|||
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
|
@ -12,7 +13,9 @@ import org.springframework.stereotype.Service;
|
|||
* @Author HuangDaJu
|
||||
* @Date 2024/4/4 09:35
|
||||
* @Version 1.0
|
||||
*/@Service("realTime")
|
||||
*/
|
||||
@Service("realTime")
|
||||
@Slf4j
|
||||
public class RealTimeDataEventImpl implements VehicleService {
|
||||
|
||||
|
||||
|
@ -33,7 +36,7 @@ public class RealTimeDataEventImpl implements VehicleService {
|
|||
public void eventResolution(VehicleData analyze) {
|
||||
// 处理实时数据,并存储在realTimeData变量中
|
||||
this.realTimeData = analyze;
|
||||
System.out.println("我是实时数据");
|
||||
log.info("我是实时数据");
|
||||
// System.out.println(analyze);
|
||||
// return analyze;
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
|
||||
import com.muyu.analyze.mapper.VehicleMapper;
|
||||
import com.muyu.analyze.service.VehicleService;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.system.common.domain.VehicleData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -28,6 +29,8 @@ public class StoredEventImpl implements VehicleService {
|
|||
|
||||
@Autowired
|
||||
private VehicleMapper vehicleMapper;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
private final ArrayList<VehicleData> list = new ArrayList<>();
|
||||
|
||||
|
@ -35,8 +38,12 @@ public class StoredEventImpl implements VehicleService {
|
|||
@Override
|
||||
public void eventResolution(VehicleData analyze) {
|
||||
|
||||
list.add(analyze);
|
||||
|
||||
Integer id = (Integer)redisService.getCacheObject("records:info:" + analyze.getVin());
|
||||
analyze.setRecordsId(id);
|
||||
|
||||
|
||||
list.add(analyze);
|
||||
if (list.size() >= 50) {
|
||||
log.info("集合满50,存储事件开始");
|
||||
Boolean i= vehicleMapper.addVehicleStoredEvent(list);
|
||||
|
@ -44,15 +51,7 @@ public class StoredEventImpl implements VehicleService {
|
|||
if (i) {
|
||||
list.clear();
|
||||
log.info("存储事件结束");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -6,14 +6,17 @@
|
|||
<mapper namespace="com.muyu.analyze.mapper.VehicleMapper">
|
||||
|
||||
<insert id="addVehicleStoredEvent">
|
||||
INSERT INTO vehicle_data (vin, date_time, speed, longitude, latitude, single_battery_min_voltage, motor_voltage, motor_speed, self_check_counter, voltage, gear, remaining_battery, motor_current, brake_pedal, current, single_battery_max_voltage, fuel_consumption_rate, resistance, maximum_feedback_power, single_battery_max_temperature)
|
||||
INSERT INTO vehicle_data (vin, date_time, speed, longitude, latitude, single_battery_min_voltage, motor_voltage, motor_speed, self_check_counter, voltage, gear, remaining_battery, motor_current, brake_pedal, current, single_battery_max_voltage, fuel_consumption_rate, resistance, maximum_feedback_power, single_battery_max_temperature,records_id)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" index="index" separator=",">
|
||||
(#{item.vin}, #{item.dateTime}, #{item.speed}, #{item.longitude}, #{item.latitude}, #{item.singleBatteryMinVoltage}, #{item.motorVoltage}, #{item.motorSpeed}, #{item.selfCheckCounter}, #{item.voltage}, #{item.gear}, #{item.remainingBattery}, #{item.motorCurrent}, #{item.brakePedal}, #{item.current}, #{item.singleBatteryMaxVoltage}, #{item.fuelConsumptionRate}, #{item.resistance}, #{item.maximumFeedbackPower}, #{item.singleBatteryMaxTemperature})
|
||||
(#{item.vin}, #{item.dateTime}, #{item.speed}, #{item.longitude}, #{item.latitude}, #{item.singleBatteryMinVoltage}, #{item.motorVoltage}, #{item.motorSpeed}, #{item.selfCheckCounter}, #{item.voltage}, #{item.gear}, #{item.remainingBattery}, #{item.motorCurrent}, #{item.brakePedal}, #{item.current}, #{item.singleBatteryMaxVoltage}, #{item.fuelConsumptionRate}, #{item.resistance}, #{item.maximumFeedbackPower}, #{item.singleBatteryMaxTemperature},#{item.recordsId})
|
||||
</foreach>
|
||||
|
||||
</insert>
|
||||
<select id="selectFenceList" resultType="com.muyu.business.domain.Fence">
|
||||
select car_vin,fence_encoding,fence_id,fence_type,fence_radius from car left join fence on car.car_fence_id=fence.fence_id
|
||||
</select>
|
||||
<select id="selectCarList" resultType="com.muyu.system.common.domain.Car">
|
||||
select car_fence_id from car where car_vin=#{vin}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
package com.muyu.business.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -14,8 +19,12 @@ import java.util.Date;
|
|||
* Version 1.0
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Records {
|
||||
|
||||
@TableId(value = "records_id",type = IdType.AUTO)
|
||||
private Integer recordsId;
|
||||
|
||||
private String vin;
|
||||
|
|
|
@ -46,4 +46,19 @@ public class RecordsController extends BaseController
|
|||
{
|
||||
return toAjax(recordsService.deleteRecords(recordsId));
|
||||
}
|
||||
|
||||
@PostMapping("/insert/{vin}")
|
||||
@Log(title = "车辆历史轨迹", businessType = BusinessType.INSERT)
|
||||
public Result<Integer> insert(@PathVariable("vin") String vin){
|
||||
return Result.success(recordsService.insert(vin));
|
||||
}
|
||||
|
||||
@PostMapping("/update/{recordsId}")
|
||||
@Log(title = "车辆历史轨迹", businessType = BusinessType.UPDATE)
|
||||
public Result update(@PathVariable("recordsId") Integer recordsId) {
|
||||
return toAjax(recordsService.updateRecords(recordsId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,4 +28,10 @@ public interface IRecordsService extends IService<Records>
|
|||
* @param recordsId
|
||||
*/
|
||||
int deleteRecords(Integer recordsId);
|
||||
|
||||
|
||||
int insert(String vin);
|
||||
|
||||
int updateRecords(Integer recordsId);
|
||||
|
||||
}
|
||||
|
|
|
@ -15,9 +15,13 @@ import com.muyu.common.core.domain.Result;
|
|||
import com.muyu.common.core.utils.StringUtils;
|
||||
import com.muyu.common.core.utils.uuid.IdUtils;
|
||||
import com.muyu.business.domain.Fence;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.cache.CacheProperties;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -32,6 +36,8 @@ public class FenceInfoServiceImpl extends ServiceImpl<FenceInfoMapper, Fence>
|
|||
{
|
||||
@Autowired
|
||||
private FenceInfoMapper fenceInfoMapper;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
|
||||
|
@ -150,6 +156,11 @@ public class FenceInfoServiceImpl extends ServiceImpl<FenceInfoMapper, Fence>
|
|||
|
||||
fence.setFenceRadius(result.toString());
|
||||
|
||||
HashMap<String, String> hashMap = new HashMap<>();
|
||||
hashMap.put(mapRequest.getFenceId().toString(),fence.getFenceRadius());
|
||||
redisService.setCacheMap("fence",hashMap);
|
||||
|
||||
|
||||
return fenceInfoMapper.update(fence,updateWrapper);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.muyu.business.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
@ -15,6 +16,7 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -71,6 +73,36 @@ public class RecordsServiceImpl extends ServiceImpl<RecordsMapper,Records>
|
|||
|
||||
return recordsMapper.deleteById(recordsId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int insert(String vin) {
|
||||
|
||||
Records records = new Records();
|
||||
|
||||
records.setVin(vin);
|
||||
|
||||
records.setStartTime(new Date());
|
||||
|
||||
recordsMapper.insert(records);
|
||||
|
||||
return records.getRecordsId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateRecords(Integer recordsId) {
|
||||
|
||||
UpdateWrapper<Records> updateWrapper = new UpdateWrapper<>();
|
||||
|
||||
updateWrapper.eq("records_id",recordsId);
|
||||
|
||||
Records records = new Records();
|
||||
|
||||
records.setOverTime(new Date());
|
||||
|
||||
return recordsMapper.update(records,updateWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,7 +25,9 @@ public class VehicleData{
|
|||
|
||||
|
||||
private Long id;
|
||||
private Long recordsId;
|
||||
|
||||
|
||||
private Integer recordsId;
|
||||
/**
|
||||
* VIN
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.muyu.system.feign;
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.log.annotation.Log;
|
||||
import com.muyu.common.log.enums.BusinessType;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
/**
|
||||
* @ClassName RecordsFeign
|
||||
* @Description TODO
|
||||
* @Author YinYuYang
|
||||
* @Date 2024/4/9 14:45
|
||||
* Version 1.0
|
||||
*/
|
||||
@FeignClient("muyu-business")
|
||||
public interface RecordsFeign {
|
||||
|
||||
@PostMapping("/records/insert/{vin}")
|
||||
Result<Integer> insert(@PathVariable("vin") String vin);
|
||||
|
||||
@PostMapping("/records/update/{recordsId}")
|
||||
Result update(@PathVariable("recordsId") Integer recordsId);
|
||||
}
|
|
@ -16,12 +16,14 @@ import com.muyu.common.core.utils.StringUtils;
|
|||
import com.muyu.common.core.utils.uuid.IdUtils;
|
||||
import com.muyu.common.event.cache.VehicleEventCache;
|
||||
import com.muyu.common.event.constants.VehicleEventConstants;
|
||||
import com.muyu.common.redis.service.RedisService;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.system.common.VehicleCreateAddReq;
|
||||
import com.muyu.system.common.domain.Car;
|
||||
import com.muyu.business.domain.Fence;
|
||||
import com.muyu.system.common.domain.req.CarInfoAddReq;
|
||||
import com.muyu.system.common.domain.vo.CarVo;
|
||||
import com.muyu.system.feign.RecordsFeign;
|
||||
import com.muyu.system.mapper.CarMapper;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
|
@ -45,6 +47,10 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
|
|||
private RestTemplate restTemplate;
|
||||
@Autowired
|
||||
private VehicleEventCache vehicleEventCache;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
@Autowired
|
||||
private RecordsFeign recordsFeign;
|
||||
|
||||
/**
|
||||
* 查询车辆信息
|
||||
|
@ -135,6 +141,7 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
|
|||
// redisTemplate.opsForSet().add(car.getCarVin(),"fenceAlarm");
|
||||
|
||||
vehicleEventCache.addEvent(car.getCarVin(), VehicleEventConstants.WEI_LAN);
|
||||
vehicleEventCache.addEvent(car.getCarVin(), VehicleEventConstants.GU_ZHANG);
|
||||
|
||||
vehicleEventCache.addEvent(car.getCarVin(), VehicleEventConstants.CUN_CU);
|
||||
|
||||
|
@ -223,6 +230,15 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
|
|||
carInfoAddReq.setVin(car.getCarVin());
|
||||
carInfoAddReq.setInfoOpenDate(new Date());
|
||||
carMapper.insertCarInfo(carInfoAddReq);
|
||||
|
||||
// 修改
|
||||
if (!redisService.hasKey("records:info:"+carVin)){
|
||||
Result<Integer> insert = recordsFeign.insert(carVin);
|
||||
Integer recordsId = insert.getData();
|
||||
redisService.setCacheObject("records:info:"+carVin,recordsId);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -241,12 +257,36 @@ public class CarServiceImpl extends ServiceImpl<CarMapper,Car> implements CarSer
|
|||
carInfoAddReq.setVin(car.getCarVin());
|
||||
carInfoAddReq.setInfoCloseDate(new Date());
|
||||
carMapper.insertCarInfo(carInfoAddReq);
|
||||
|
||||
|
||||
if (redisService.hasKey("records:info:"+carVin)){
|
||||
Object cacheObject = redisService.getCacheObject("records:info:" + carVin);
|
||||
if (cacheObject != null){
|
||||
Integer recordsId = (Integer) cacheObject;
|
||||
recordsFeign.update(recordsId);
|
||||
}
|
||||
redisService.deleteObject("records:info:"+carVin);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int deleteByVin(String carVin) {
|
||||
String url="http://127.0.0.1:81/vehicle/" +carVin;
|
||||
restTemplate.delete(url);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return carMapper.deleteByVin(carVin);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue