Merge branch 'server_five' of https://gitea.qinmian.online/five-groups/five-groups-couplet into server_five_dongxiaodong

# Conflicts:
#	couplet-modules/couplet-analyze/couplet-analyze-msg/pom.xml
server_five_dongxiaodong
dongxiaodong 2024-04-09 18:47:05 +08:00
commit deece927c5
32 changed files with 225 additions and 193 deletions

View File

@ -6,6 +6,7 @@ import lombok.NoArgsConstructor;
import lombok.ToString;
import java.io.Serializable;
import java.util.List;
/**
* @author fufanrui
@ -20,7 +21,7 @@ import java.io.Serializable;
public class RealTimeDataRequest implements Serializable {
private Long userId;
private List<Long> userId;
private String vin;

View File

@ -10,21 +10,12 @@ import org.springframework.stereotype.Component;
*/
public interface AnalyzeEventContents {
/**
*
*/
//故障
static final String BREAKDOWN = "breakdown";
/**
*
*/
static final String ELECTRONIC_FENCE = "electronic-fence";
/**
*
*/
static final String REAL_TIME_DATA = "real-time-data";
/**
*
*/
static final String STORED_EVENT = "stored-event";
//电子围栏
static final String ELECTRONIC_FENCE = "electronic_fence";
//实时数据
static final String REAL_TIME_DATA = "real_time_data";
//存储
static final String STORED_EVENT = "stored_event";
}

View File

@ -3,6 +3,7 @@ package com.couplet.analyze.common.event;
import com.couplet.common.domain.request.RealTimeDataRequest;
import com.couplet.common.redis.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Set;
@ -12,6 +13,7 @@ import java.util.Set;
* @Description:
*/
@Component
public class AnalyzeEventCache {
@Autowired

View File

@ -33,5 +33,6 @@
<artifactId>couplet-common-business</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -23,17 +23,13 @@ public class RedisService {
public RedisTemplate redisTemplate;
public List<CoupletVehicleData> getList () {
return redisTemplate.opsForList().range("coupletMsgData", 0, -1);
}
// ... 其他已有方法 ...
/**
* truefalse
*
* @param setKey
* @param value
* @param value
* @return truefalse
*/
public boolean addToSetIfNotExists(String setKey, String value) {
@ -47,7 +43,7 @@ public class RedisService {
* @param key
* @param value
*/
public <T> void setCacheObject (final String key, final T value) {
public <T> void setCacheObject(final String key, final T value) {
redisTemplate.opsForValue().set(key, value);
}
@ -59,7 +55,7 @@ public class RedisService {
* @param timeout
* @param timeUnit
*/
public <T> void setCacheObject (final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
public <T> void setCacheObject(final String key, final T value, final Long timeout, final TimeUnit timeUnit) {
redisTemplate.opsForValue().set(key, value, timeout, timeUnit);
}
@ -68,10 +64,9 @@ public class RedisService {
*
* @param key Redis
* @param timeout
*
* @return true=false=
*/
public boolean expire (final String key, final long timeout) {
public boolean expire(final String key, final long timeout) {
return expire(key, timeout, TimeUnit.SECONDS);
}
@ -81,10 +76,9 @@ public class RedisService {
* @param key Redis
* @param timeout
* @param unit
*
* @return true=false=
*/
public boolean expire (final String key, final long timeout, final TimeUnit unit) {
public boolean expire(final String key, final long timeout, final TimeUnit unit) {
return redisTemplate.expire(key, timeout, unit);
}
@ -92,10 +86,9 @@ public class RedisService {
*
*
* @param key Redis
*
* @return
*/
public long getExpire (final String key) {
public long getExpire(final String key) {
return redisTemplate.getExpire(key);
}
@ -103,10 +96,9 @@ public class RedisService {
* key
*
* @param key
*
* @return true false
*/
public Boolean hasKey (String key) {
public Boolean hasKey(String key) {
return redisTemplate.hasKey(key);
}
@ -114,10 +106,9 @@ public class RedisService {
*
*
* @param key
*
* @return
*/
public <T> T getCacheObject (final String key) {
public <T> T getCacheObject(final String key) {
ValueOperations<String, T> operation = redisTemplate.opsForValue();
return operation.get(key);
}
@ -127,7 +118,7 @@ public class RedisService {
*
* @param key
*/
public boolean deleteObject (final String key) {
public boolean deleteObject(final String key) {
return redisTemplate.delete(key);
}
@ -135,10 +126,9 @@ public class RedisService {
*
*
* @param collection
*
* @return
*/
public boolean deleteObject (final Collection collection) {
public boolean deleteObject(final Collection collection) {
return redisTemplate.delete(collection) > 0;
}
@ -147,10 +137,9 @@ public class RedisService {
*
* @param key
* @param dataList List
*
* @return
*/
public <T> long setCacheList (final String key, final List<T> dataList) {
public <T> long setCacheList(final String key, final List<T> dataList) {
Long count = redisTemplate.opsForList().rightPushAll(key, dataList);
return count == null ? 0 : count;
}
@ -159,10 +148,9 @@ public class RedisService {
* list
*
* @param key
*
* @return
*/
public <T> List<T> getCacheList (final String key) {
public <T> List<T> getCacheList(final String key) {
return redisTemplate.opsForList().range(key, 0, -1);
}
@ -171,10 +159,9 @@ public class RedisService {
*
* @param key
* @param dataSet
*
* @return
*/
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final Set<T> dataSet) {
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final Set<T> dataSet) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
Iterator<T> it = dataSet.iterator();
while (it.hasNext()) {
@ -182,25 +169,25 @@ public class RedisService {
}
return setOperation;
}
/**
* Set
*
* @param key
* @param key
* @param setValue
*
* @return
*/
public <T> BoundSetOperations<String, T> setCacheSet (final String key, final T setValue) {
public <T> BoundSetOperations<String, T> setCacheSet(final String key, final T setValue) {
BoundSetOperations<String, T> setOperation = redisTemplate.boundSetOps(key);
setOperation.add(setValue);
return setOperation;
}
/**
* Set
*
* @param key
* @param key
* @param setValue
*
* @return
*/
public <T> void deleteSet(String key, String setValue) {
@ -208,26 +195,25 @@ public class RedisService {
BoundSetOperations setOperations = redisTemplate.boundSetOps(key);
setOperations.remove(setValue);
}
/**
* set
*
* @param key
*
* @return
*/
public <T> Set<T> getCacheSet (final String key) {
public <T> Set<T> getCacheSet(final String key) {
return redisTemplate.opsForSet().members(key);
}
/**
* Map
*
* @param key
* @param dataMap
*/
public <T> void setCacheMap (final String key, final Map<String, T> dataMap) {
public <T> void setCacheMap(final String key, final Map<String, T> dataMap) {
if (dataMap != null) {
redisTemplate.opsForHash().putAll(key, dataMap);
}
@ -237,10 +223,9 @@ public class RedisService {
* Map
*
* @param key
*
* @return
*/
public <T> Map<String, T> getCacheMap (final String key) {
public <T> Map<String, T> getCacheMap(final String key) {
return redisTemplate.opsForHash().entries(key);
}
@ -251,7 +236,7 @@ public class RedisService {
* @param hKey Hash
* @param value
*/
public <T> void setCacheMapValue (final String key, final String hKey, final T value) {
public <T> void setCacheMapValue(final String key, final String hKey, final T value) {
redisTemplate.opsForHash().put(key, hKey, value);
}
@ -260,10 +245,9 @@ public class RedisService {
*
* @param key Redis
* @param hKey Hash
*
* @return Hash
*/
public <T> T getCacheMapValue (final String key, final String hKey) {
public <T> T getCacheMapValue(final String key, final String hKey) {
HashOperations<String, String, T> opsForHash = redisTemplate.opsForHash();
return opsForHash.get(key, hKey);
}
@ -273,10 +257,9 @@ public class RedisService {
*
* @param key Redis
* @param hKeys Hash
*
* @return Hash
*/
public <T> List<T> getMultiCacheMapValue (final String key, final Collection<Object> hKeys) {
public <T> List<T> getMultiCacheMapValue(final String key, final Collection<Object> hKeys) {
return redisTemplate.opsForHash().multiGet(key, hKeys);
}
@ -285,10 +268,9 @@ public class RedisService {
*
* @param key Redis
* @param hKey Hash
*
* @return
*/
public boolean deleteCacheMapValue (final String key, final String hKey) {
public boolean deleteCacheMapValue(final String key, final String hKey) {
return redisTemplate.opsForHash().delete(key, hKey) > 0;
}
@ -296,21 +278,20 @@ public class RedisService {
*
*
* @param pattern
*
* @return
*/
public Collection<String> keys (final String pattern) {
public Collection<String> keys(final String pattern) {
return redisTemplate.keys(pattern);
}
public void setVinAndUserId(RealTimeDataRequest realTimeDataRequest) {
String key = "vin:"+realTimeDataRequest.getVin();
redisTemplate.opsForValue().set(key, realTimeDataRequest);
String key = "vin:" + realTimeDataRequest.getVin();
redisTemplate.opsForSet().add(key, realTimeDataRequest);
}
public void stopViewingData(String vin) {
String key = "vin:"+vin;
String key = "vin:" + vin;
redisTemplate.delete(key);
}
}

View File

@ -15,14 +15,12 @@ import org.springframework.scheduling.annotation.EnableScheduling;
*/
@SpringBootApplication(scanBasePackages = "com.couplet")
@EnableScheduling
@EnableFeignClients(basePackages = "com.couplet.**")
@EnableFeignClients(basePackages = "com.couplet")
public class CoupletMsgApplication {
public static void main(String[] args) {
SpringApplication.run(CoupletMsgApplication.class);
System.out.println("解析系统启动成功");
// new ModelsKafkaMessage().initKafkaConsumer();
new ModelsKafkaMessage().initKafkaConsumer();
}

View File

@ -11,6 +11,8 @@ import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
@ -26,6 +28,7 @@ import static com.couplet.analyze.msg.utils.MsgUtils.hexToString;
import static com.couplet.analyze.msg.utils.MsgUtils.sendMsg;
import static java.lang.Thread.sleep;
/**
* @author DongXiaoDong
* @version 1.0
@ -35,7 +38,7 @@ import static java.lang.Thread.sleep;
@Component
@Slf4j
public class ModelsKafkaMessage {
private static final String TOPIC_NAME = "dong";
private static final String TOPIC_NAME = "topic_lyh";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
@ -55,7 +58,7 @@ public class ModelsKafkaMessage {
Properties props = new Properties();
props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, BOOTSTRAP_SERVERS);
// props.put(ConsumerConfig.GROUP_ID_CONFIG, "my-consumer-group");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "ddd");
props.put(ConsumerConfig.GROUP_ID_CONFIG, "group");
props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.StringDeserializer");
@ -102,12 +105,6 @@ public class ModelsKafkaMessage {
// message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
// return message;
// });
try {
sleep(100);
} catch (Exception e) {
throw new VehicleException("睡眠失败" + e);
}
}
});
}

View File

@ -1,6 +1,7 @@
package com.couplet.analyze.msg.service.impl;
import com.alibaba.fastjson.JSON;
import com.couplet.analyze.common.contents.AnalyzeEventContents;
import com.couplet.analyze.msg.contents.StateConstant;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService;
@ -26,7 +27,7 @@ import java.util.concurrent.TimeUnit;
* @Date: 2024/4/2
* @Description:
*/
@Service("breakdown")
@Service(AnalyzeEventContents.BREAKDOWN)
public class BreakdownServiceImpl extends KeyExpirationEventMessageListener implements IncidentService {
/**
@ -93,7 +94,7 @@ public class BreakdownServiceImpl extends KeyExpirationEventMessageListener impl
*/
@Override
public String getName() {
return "breakdown";
return AnalyzeEventContents.BREAKDOWN;
}
public void scheduledRedis() {

View File

@ -1,9 +1,11 @@
package com.couplet.analyze.msg.service.impl;
import com.alibaba.fastjson.JSON;
import com.couplet.analyze.common.contents.AnalyzeEventContents;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.common.core.text.Convert;
import com.couplet.common.core.utils.StringUtils;
import com.couplet.common.domain.Fence;
import com.couplet.common.domain.request.FenceAndLogeRequest;
import com.couplet.common.redis.service.RedisService;
@ -22,7 +24,7 @@ import java.util.Set;
* @Date: 2024/4/2
* @Description:
*/
@Service("electronic_fence")
@Service(AnalyzeEventContents.ELECTRONIC_FENCE)
@Log4j2
public class ElectronicFenceServiceImpl implements IncidentService {
@ -45,12 +47,11 @@ public class ElectronicFenceServiceImpl implements IncidentService {
if (redisService.hasKey(fenceKey)) {
Set<Fence> cacheSet = redisService.getCacheSet(fenceKey);
log.info("电子围栏事件redis存在.......");
// jingdu;
// longitude;
// weidu;
// latitude;
for (Fence fence : cacheSet) {
String fenceLongitudeLatitude = fence.getFenceLongitudeLatitude();
if (!StringUtils.isEmpty(fenceLongitudeLatitude)){
log.info("电子围栏没有数据鸭...");
}
/**
*
*/
@ -86,7 +87,7 @@ public class ElectronicFenceServiceImpl implements IncidentService {
*/
@Override
public String getName() {
return "electronic-fence";
return AnalyzeEventContents.ELECTRONIC_FENCE;
}

View File

@ -1,9 +1,11 @@
package com.couplet.analyze.msg.service.impl;
import com.couplet.analyze.common.contents.AnalyzeEventContents;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.mapper.IncidentMapper;
import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.analyze.msg.service.impl.realTimeData.RealTimeJudge;
import com.couplet.common.core.utils.StringUtils;
import com.couplet.common.domain.request.RealTimeDataRequest;
import com.couplet.common.redis.service.RedisService;
import com.couplet.remote.RemoteRealTimeService;
@ -11,6 +13,8 @@ import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
@ -18,16 +22,10 @@ import java.util.concurrent.TimeUnit;
* @Date: 2024/4/2
* @Description:
*/
@Service("real_time_data")
@Service(AnalyzeEventContents.REAL_TIME_DATA)
@Log4j2
public class RealTimeDataServiceImpl implements IncidentService {
/**
*
*/
@Autowired
private IncidentMapper incidentMapper;
@Autowired
private RedisService redisService;
@ -38,28 +36,17 @@ public class RealTimeDataServiceImpl implements IncidentService {
*/
@Override
public void incident(CoupletMsgData coupletMsgData) {
log.info("实时数据事件开始.....");
RealTimeDataRequest cacheObject = redisService.getCacheObject("vin:" + coupletMsgData.getVin());
//判断是否有缓存数据
if (RealTimeJudge.isJudge(coupletMsgData.getVin())) {
log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
//判断数据是否一致,
if (RealTimeJudge.addRealTime(cacheObject)) {
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
CoupletMsgData query = incidentMapper.queryByIncident(coupletMsgData.getVin());
redisService.setCacheObject("vin:query:" + cacheObject.getVin(), query);
redisService.expire("vin:"+cacheObject.getVin(),10, TimeUnit.MINUTES);
} else {
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据不一致,开始传输实时数据", coupletMsgData.getVin(), cacheObject);
}
if (redisService.hasKey("实时轨迹vin:"+ coupletMsgData.getVin())){
boolean a= ("实时轨迹vin:" + coupletMsgData.getVin()).equals("实时轨迹vin:"+ coupletMsgData.getVin());
if (a){
log.info("[{}]有缓存数据,值为:[{}],且缓存数据与实时数据一致,开始传输实时数据", coupletMsgData.getVin(), coupletMsgData);
redisService.setCacheSet("vin:query:" + coupletMsgData.getVin(), coupletMsgData);
redisService.expire("vin:"+coupletMsgData.getVin(),10, TimeUnit.MINUTES);
}
}
log.info("[{}]开始传输实时数据", coupletMsgData.getVin());
log.info("实时数据事件结束.....");
}
/**
@ -69,6 +56,6 @@ public class RealTimeDataServiceImpl implements IncidentService {
*/
@Override
public String getName() {
return "real-time-data";
return AnalyzeEventContents.REAL_TIME_DATA;
}
}

View File

@ -1,5 +1,6 @@
package com.couplet.analyze.msg.service.impl;
import com.couplet.analyze.common.contents.AnalyzeEventContents;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.mapper.IncidentMapper;
import com.couplet.analyze.msg.service.IncidentService;
@ -12,7 +13,7 @@ import org.springframework.stereotype.Service;
* @Date: 2024/4/2
* @Description:
*/
@Service("stored_event")
@Service(AnalyzeEventContents.STORED_EVENT)
@Log4j2
public class StoredEventServiceImpl implements IncidentService {
@Autowired
@ -36,6 +37,6 @@ public class StoredEventServiceImpl implements IncidentService {
*/
@Override
public String getName() {
return "stored-event";
return AnalyzeEventContents.STORED_EVENT;
}
}

View File

@ -37,7 +37,7 @@ public class RealTimeJudge {
userIds = new HashSet<>();
setMap.put(realTimeDataRequest.getVin(),userIds);
}
userIds.add(realTimeDataRequest.getUserId());
// userIds.add(realTimeDataRequest.getUserId());
return true;
}

View File

@ -15,16 +15,17 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置
shared-configs:
- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
main:
allow-bean-definition-overriding: true
rabbitmq:
@ -50,3 +51,4 @@ logging:
mybatis-plus:
configuration:
map-underscore-to-camel-case: true

View File

@ -87,6 +87,11 @@
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-common-event</artifactId>
</dependency>
<!-- RabbitMQ依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
@ -105,6 +110,10 @@
<groupId>com.couplet</groupId>
<artifactId>couplet-common-event</artifactId>
</dependency>
<dependency>
<groupId>com.couplet</groupId>
<artifactId>couplet-analyze-msg</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -17,7 +17,7 @@ import org.springframework.stereotype.Component;
@EnableCustomConfig
@EnableCustomSwagger2
@EnableMyFeignClients(basePackages = ("com.couplet"))
@SpringBootApplication(scanBasePackages = {"com.couplet", "com.couplet.mq.remote"})
@SpringBootApplication(scanBasePackages = {"com.couplet"})
@EnableScheduling
public class CoupletBusinessApplication {
public static void main(String[] args) {

View File

@ -1,5 +1,6 @@
package com.couplet.business.server.controller;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.business.server.service.VehicleDetectionService;
import com.couplet.common.core.domain.Result;
import com.couplet.common.domain.CoupletVehicleData;
@ -58,21 +59,21 @@ public class VehicleDetectionController {
public void monitorinData(@PathVariable String vin){
vehicleDetectionService.monitorinData(vin);
}
/*
* @param :
* @return Result<List<CoupletVehicleData>>
* @return Result<List<CoupletVehicleData>>
* @author
* @description
* @date
*/
@PostMapping("realData")
public Result<List<CoupletVehicleData>> realData(){
List<CoupletVehicleData> list = redisService.getList();
Result<List<CoupletVehicleData>> success = Result.success(list);
@PostMapping("/monitorinDataList/{vin}")
public Result<List<CoupletMsgData>> monitorinDataList(@PathVariable String vin){
List<CoupletMsgData> monitorinDataList = vehicleDetectionService.monitorinDataList(vin);
Result<List<CoupletMsgData>> success = Result.success(monitorinDataList);
return success;
}
/*
* @param vin:
* @return void

View File

@ -1,6 +1,8 @@
package com.couplet.business.server.service;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.common.core.domain.Result;
import com.couplet.common.domain.CoupletVehicleData;
import com.couplet.common.domain.Vehicle;
import java.util.List;
@ -9,8 +11,9 @@ public interface VehicleDetectionService {
List<Vehicle> detectionList();
void monitorinData(String vin);
void stopViewingData(String vin);
List<CoupletMsgData> monitorinDataList(String vin);
void monitorinData(String vin);
}

View File

@ -44,12 +44,12 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
*/
@Autowired
private StringRedisTemplate redisTemplate;
/**
*
*/
// @Autowired
// private RemoteFenceService remoteFenceService;
@Override
public List<Fence> pageQuery(FenceConfig fenceConfig) {
List<Fence> list = fenceMapper.pageQuery(fenceConfig);
@ -70,36 +70,26 @@ public class FenceServiceImpl extends ServiceImpl<FenceMapper, Fence> implements
// remoteFenceService.fenceQueue(fenceUpdateRequest);
}
@Override
public void fenceInsert(FenceRequest fenceRequest) {
}
/**
* :
*
* @param request
* @param
* @param fenceRequest
*/
// @Override
// public void fenceInsert(HttpServletRequest request, FenceRequest fenceRequest) {
// String username = SecurityUtils.getUsername();
// fenceRequest.setCrateName(username);
// //先添加围栏
// fenceMapper.insertFence(fenceRequest);
// String[] logoIds = fenceRequest.getLogoIds();
// String[] parts = new String[0];
// for (String logoId : logoIds) {
// //把前台传入的字符串分割成数组
// parts = logoId.split(",");
// //再添加围栏和标识中间表
// fenAndLogoService.addBach(fenceRequest.getFenceId(), parts);
// }
// /**
// * 电子围栏发送改变
// */
// redisTemplate.opsForValue().set("fenceInsert", JSON.toJSONString(fenceRequest), 10, TimeUnit.MINUTES);
// }
@Override
public void fenceInsert(FenceRequest fenceRequest) {
String username = SecurityUtils.getUsername();
fenceRequest.setCrateName(username);
fenceRequest.setMaintainerName(username);
//先添加围栏
fenceMapper.insertFence(fenceRequest);
fenAndLogoService.addBach(fenceRequest.getFenceId(), fenceRequest.getLogoIds());
/**
*
*/
redisTemplate.opsForValue().set("fenceInsert", JSON.toJSONString(fenceRequest), 10, TimeUnit.MINUTES);
}
@Override
public void removeByFenceId(Long fenceId) {

View File

@ -2,11 +2,13 @@ package com.couplet.business.server.service.impl;
import afu.org.checkerframework.checker.units.qual.A;
import com.alibaba.fastjson.JSON;
import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.common.event.AnalyzeEventCache;
import com.couplet.business.server.mapper.VehicleDetectionMapper;
import com.couplet.business.server.service.VehicleDetectionService;
import com.couplet.business.server.service.VehicleManageService;
import com.couplet.common.core.domain.Result;
import com.couplet.common.domain.CoupletVehicleData;
import com.couplet.common.domain.Vehicle;
import com.couplet.common.domain.request.RealTimeDataRequest;
import com.couplet.common.redis.service.RedisService;
@ -14,11 +16,13 @@ import com.couplet.common.security.utils.SecurityUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.mysql.cj.xdevapi.JsonString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import springfox.documentation.spring.web.json.Json;
import java.util.List;
import java.lang.reflect.Array;
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
@ -28,6 +32,7 @@ import java.util.concurrent.TimeUnit;
* @date 2024/4/4 10:23
*/
@Service
@Slf4j
public class VehicleDetectionServiceImpl implements VehicleDetectionService{
@Autowired
@ -44,15 +49,30 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
return vehicles;
}
@Override
public List<CoupletMsgData> monitorinDataList(String vin) {
String key = "vin:query:" + vin;
log.info("key为:"+key);
Set<CoupletMsgData> cacheSet = redisService.getCacheSet(key);
ArrayList<CoupletMsgData> coupletMsgData = new ArrayList<>(cacheSet);
return coupletMsgData;
}
@Override
public void monitorinData(String vin) {
//创建对象
RealTimeDataRequest realTimeDataRequest = new RealTimeDataRequest();
//获取用户id
Long userId = SecurityUtils.getUserId();
//设置车辆vin
realTimeDataRequest.setVin(vin);
realTimeDataRequest.setUserId(userId);
// analyzeEventCache.queryEvent("查询实时数据"+vin,realTimeDataRequest);
// redisService.expire("查询实时数据"+vin,4,TimeUnit.MINUTES);
redisService.setVinAndUserId(realTimeDataRequest);
//创建hashSet集合
HashSet<Long> objects = new HashSet<>();
//添加车辆id
objects.add(userId);
//把对象放入hashSet集合中
//存储的对象是:key:业务+vin value: hashSet集合类型的对象
redisService.setCacheSet("实时轨迹vin:"+ vin,objects);
}
@Override
@ -60,4 +80,5 @@ public class VehicleDetectionServiceImpl implements VehicleDetectionService{
redisService.stopViewingData(vin);
}
}

View File

@ -3,6 +3,8 @@ package com.couplet.business.server.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.couplet.analyze.common.contents.AnalyzeEventContents;
import com.couplet.analyze.common.event.AnalyzeEventCache;
import com.couplet.business.server.mapper.VehicleMapper;
import com.couplet.business.server.service.FenAndLogoService;
import com.couplet.business.server.service.VehicleAndLogoService;
@ -24,6 +26,7 @@ import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.PostConstruct;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.TimeUnit;
@ -59,6 +62,9 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
@Autowired
private FenAndLogoService fenAndLogoService;
@Autowired
private AnalyzeEventCache eventCache;
/*
* @Author: LiuYunHu
* @Date: 2024/3/26 22:11
@ -254,6 +260,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
Result.error(result);
}
//获取新增的车辆id值
//执行添加电子围栏
int i = vehicleAndLogoService.vehicleBindLogo(vehicle.getVehicleId(), insertParams.getLogoIds());
@ -262,6 +269,9 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
//刷新set缓存
reCache();
//加入事件缓存
reEvent();
result = "新增成功!";
@ -395,7 +405,10 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
* @Param: []
* @Return: void
**/
@Scheduled(cron = "0/3 * * * * *")
// @Scheduled(cron = "0/3 * * * * *")
//初始化
@PostConstruct
public void reCache() {
//刷新缓存执行开始
@ -410,11 +423,12 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
bindLogoById.forEach(logoId -> {
//存标识id 的set
HashSet<Long> logos = new HashSet<>();
logos.add(logoId);
//存入redis
redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos);
redis.expire("车辆vin和标识:" + vehicle.getVin(), 2, TimeUnit.MINUTES);
// HashSet<Long> logos = new HashSet<>();
// logos.add(logoId);
// //存入redis
// redis.setCacheSet("车辆vin和标识:" + vehicle.getVin(), logos);
// redis.expire("车辆vin和标识:" + vehicle.getVin(), 5, TimeUnit.MINUTES);
//通过标识id获取标识绑定的电子围栏集合
@ -425,10 +439,29 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle> impl
fanceSet.add(fence);
//存入redis
redis.setCacheSet("车辆vin和电子围栏:" + vehicle.getVin(), fanceSet);
redis.expire("车辆vin和电子围栏:" + vehicle.getVin(), 2, TimeUnit.MINUTES);
// redis.expire("车辆vin和电子围栏:" + vehicle.getVin(), 5, TimeUnit.MINUTES);
});
});
});
}
/*
* @Author: LiuYunHu
* @Date: 2024/4/8 19:39
* @Description:
* @Param: []
* @Return: void
**/
@PostConstruct
public void reEvent() {
List<Vehicle> list = list(new VehicleListParams());
list.forEach(vehicle -> {
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.STORED_EVENT);
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.BREAKDOWN);
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.ELECTRONIC_FENCE);
eventCache.addEvent(vehicle.getVin(), AnalyzeEventContents.REAL_TIME_DATA);
});
}
}

View File

@ -16,11 +16,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -57,11 +57,10 @@
</sql>
<insert id="insertFence" parameterType="com.couplet.common.domain.request.FenceRequest" keyProperty="fenceId"
useGeneratedKeys="true">
INSERT INTO `couplet-cloud`.`couplet_fence_info`
(`fence_name`, `fence_longitude_latitude`, `fence_description`, `is_delete`, `fence_state`, `create_time`,
`update_time`, `create_name`, `maintainer_name`, `alarm_status`,`fence_condition`)
VALUES
(#{fenceName}, null, #{fenceDescription}, 0, 0, now(), null, null, #{maintainerName}, 0 ,0)
INSERT INTO `couplet-cloud`.`couplet_fence_info`
(`fence_name`,`fence_longitude_latitude`, `fence_description`, `is_delete`, `fence_state`, `create_time`,
`update_time`, `create_name`, `maintainer_name`, `alarm_status`, `fence_condition`)
VALUES (#{fenceName}, NULL, #{fenceDescription} , 0, 0, now(), NULL, #{crateName}, #{maintainerName}, 0, 1)
</insert>

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -17,11 +17,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -74,7 +74,7 @@ public class MqController {
RealTimeDataRequest realTimeDataRequest = new RealTimeDataRequest();
realTimeDataRequest.setVin(vin);
Long userId = SecurityUtils.getUserId();
realTimeDataRequest.setUserId(userId);
rabbitTemplate.convertAndSend(RabbitMQConfig.VinExchangeName, RabbitMQConfig.VinRoutingKey, realTimeDataRequest,
message -> {
message.getMessageProperties().setMessageId(IdUtils.randomUUID());

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置
@ -48,6 +48,7 @@ logging:
# RabbitMQ配置
mq:
queueName: queue
VinQueueName: vinQueueName
exchangeName: exchange
routingKey: routingKey

View File

@ -76,7 +76,7 @@ public class MqttMonitor {
//Kafka生产者配置
private static final String TOPIC_NAME = "dong";
private static final String TOPIC_NAME = "topic_lhy";
private static final String BOOTSTRAP_SERVERS = "39.103.133.136:9092";
//线程池,用于异步处理消息到来时的业务逻辑

View File

@ -15,11 +15,9 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
# 配置文件格式
file-extension: yml
# 共享配置
@ -34,11 +32,11 @@ logging:
# 订阅端配置
mqtt:
server:
# broker: tcp://115.159.47.13:1883
broker: tcp://8.130.181.16:1883
broker: tcp://115.159.47.13:1883
# broker: mqtt://115.159.47.13:1883
username:
password:
clientId: aaa
clientId: aaaaaad
qos: 0
topic: dxd
topic: xiaoYao

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

View File

@ -15,11 +15,11 @@ spring:
discovery:
# 服务注册地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
config:
# 配置中心地址
server-addr: 121.89.211.230:8848
namespace: a439ce3f-2c42-4b4c-9c4d-c8db49933c15
namespace: 172469
# 配置文件格式
file-extension: yml
# 共享配置

14
pom.xml
View File

@ -34,6 +34,8 @@
<jjwt.version>0.9.1</jjwt.version>
<minio.version>8.2.2</minio.version>
<poi.version>4.1.2</poi.version>
<Kafka.version>2.8.0</Kafka.version>
<dubbo.version>3.0.8</dubbo.version>
<transmittable-thread-local.version>2.14.3</transmittable-thread-local.version>
</properties>
@ -242,7 +244,19 @@
<artifactId>couplet-common-event</artifactId>
<version>${couplet.version}</version>
</dependency>
<!-- Kafka -->
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-clients</artifactId>
<version>${Kafka.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo</artifactId>
<version>${dubbo.version}</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>