事件初始化

master
fst1996 2023-12-06 13:23:57 +08:00
parent 93d3f030b4
commit d48903d8d6
6 changed files with 167 additions and 1 deletions

View File

@ -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;
}

View File

@ -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> {
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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("历史轨迹缓存失败");
}
}
}

View File

@ -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);
}
}
}