事件初始化
parent
93d3f030b4
commit
d48903d8d6
|
@ -0,0 +1,50 @@
|
|||
package com.god.base.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @description: 历史轨迹实体类
|
||||
* @Author fst
|
||||
* @date 2023/12/6 10:28
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Builder
|
||||
@TableName(value = "t_his_path")
|
||||
public class HisPath {
|
||||
/**
|
||||
* 历史轨迹id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 车辆vin
|
||||
*/
|
||||
private String carVin;
|
||||
|
||||
/**
|
||||
* 轨迹
|
||||
*/
|
||||
private String path;
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private Date startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private Date endTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.god.base.server.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.god.base.domain.HisPath;
|
||||
|
||||
/**
|
||||
* 历史轨迹持久层
|
||||
* @Author fst
|
||||
* @date 2023/12/6 10:32
|
||||
*/
|
||||
public interface HisPathMapper extends BaseMapper<HisPath> {
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.god.base.server.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.god.base.domain.HisPath;
|
||||
|
||||
/**
|
||||
* 历史轨迹业务
|
||||
* @Author fst
|
||||
* @date 2023/12/6 10:26
|
||||
*/
|
||||
public interface HistoryPathService extends IService<HisPath> {
|
||||
|
||||
public void insertHisPath(HisPath hisPath);
|
||||
}
|
|
@ -21,5 +21,15 @@ public interface TopLineService extends IService<TopicCar> {
|
|||
*/
|
||||
String getTopic(GetTopicReq getTopicReq);
|
||||
|
||||
/**
|
||||
* 获取车辆vin集合
|
||||
* @return
|
||||
*/
|
||||
List<String> getCarVinList();
|
||||
|
||||
/**
|
||||
* 车辆下线
|
||||
* @param vin
|
||||
*/
|
||||
void downLine(String vin);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package com.god.base.server.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.god.base.domain.HisPath;
|
||||
import com.god.base.server.mapper.HisPathMapper;
|
||||
import com.god.base.server.service.HistoryPathService;
|
||||
import com.god.common.core.exception.ServiceException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 实时轨迹业务实现层
|
||||
* @Author fst
|
||||
* @date 2023/12/6 10:27
|
||||
*/
|
||||
@Service
|
||||
public class HistoryPathServiceImpl extends ServiceImpl<HisPathMapper, HisPath> implements HistoryPathService {
|
||||
@Autowired
|
||||
private HisPathMapper hisPathMapper;
|
||||
|
||||
/**
|
||||
* 插入历史轨迹
|
||||
* @param hisPath
|
||||
*/
|
||||
@Override
|
||||
public void insertHisPath(HisPath hisPath) {
|
||||
int insert = hisPathMapper.insert(hisPath);
|
||||
if (insert<1){
|
||||
throw new ServiceException("历史轨迹缓存失败");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package com.god.base.server.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.god.base.domain.Car;
|
||||
import com.god.base.domain.HisPath;
|
||||
import com.god.base.domain.TopicCar;
|
||||
import com.god.base.domain.request.GetTopicReq;
|
||||
import com.god.base.server.mapper.CarMapper;
|
||||
|
@ -11,11 +13,13 @@ import com.god.base.server.service.TopLineService;
|
|||
import com.god.common.core.exception.ServiceException;
|
||||
import com.god.common.core.utils.StringUtils;
|
||||
import com.god.common.core.utils.uuid.UUID;
|
||||
import com.god.common.redis.service.RedisService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -33,6 +37,17 @@ public class TopLineServiceImpl extends ServiceImpl<TopicCarMapper, TopicCar> i
|
|||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
@Autowired
|
||||
private HistoryPathServiceImpl historyPathService;
|
||||
|
||||
/**
|
||||
* 实时轨迹标识
|
||||
*/
|
||||
public static final String ALL_LOCUS_INFO = "all_locus_info";
|
||||
|
||||
/**
|
||||
* 车辆上线,同时返回主题
|
||||
* @param getTopicReq
|
||||
|
@ -63,7 +78,7 @@ public class TopLineServiceImpl extends ServiceImpl<TopicCarMapper, TopicCar> i
|
|||
return topicCar.getTopic();
|
||||
}catch (Exception e){
|
||||
log.info(e.getMessage());
|
||||
return "god";
|
||||
return "test";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -85,4 +100,37 @@ public class TopLineServiceImpl extends ServiceImpl<TopicCarMapper, TopicCar> i
|
|||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆下线
|
||||
* @param vin
|
||||
*/
|
||||
@Override
|
||||
public void downLine(String vin) {
|
||||
//修改状态为下线
|
||||
UpdateWrapper<TopicCar> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("car_vin_id", vin);
|
||||
updateWrapper.set("status", 0);
|
||||
int update = carMapper.update(null, updateWrapper);
|
||||
if (update<1){
|
||||
throw new ServiceException("下线失败");
|
||||
}
|
||||
log.info("下线成功");
|
||||
//从redis中获取本次车辆的轨迹信息
|
||||
if (redisService.hasKey(ALL_LOCUS_INFO)){
|
||||
String string = redisService.getCacheMapValue(ALL_LOCUS_INFO, vin).toString();
|
||||
//删除缓存
|
||||
if (StringUtils.isNotEmpty(string)){
|
||||
redisService.deleteCacheMapValue(ALL_LOCUS_INFO, vin);
|
||||
}
|
||||
//持久到数据库
|
||||
HisPath hisPath = new HisPath();
|
||||
hisPath.setPath(string);
|
||||
hisPath.setCarVin(vin);
|
||||
hisPath.setEndTime(new Date());
|
||||
hisPath.setStartTime(new Date());
|
||||
historyPathService.insertHisPath(hisPath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue