perf: 优化

server_five_liuyunhu
lijiayao 2024-04-06 21:56:29 +08:00
parent 8803a91628
commit e5c4c0b9a4
13 changed files with 105 additions and 35 deletions

View File

@ -83,6 +83,7 @@ public class Fence extends BaseEntity{
*/ */
private Integer alarmStatus; private Integer alarmStatus;
private Integer fenceCondition;
/** /**
@ -93,24 +94,6 @@ public class Fence extends BaseEntity{
@TableField(exist = false) @TableField(exist = false)
private String logoName; private String logoName;
public static Fence updateFenceStatus(FenceUpdateRequest fenceUpdateRequest) {
return Fence.builder()
.fenceName(fenceUpdateRequest.getFenceName())
.fenceDescription(fenceUpdateRequest.getFenceDescription())
.fenceState(fenceUpdateRequest.getFenceState())
.fenceLongitudeLatitude(fenceUpdateRequest.getFenceLongitudeLatitude())
.createName(fenceUpdateRequest.getCrateName())
.createTime(fenceUpdateRequest.getCreateTime())
.isDelete(fenceUpdateRequest.getIsDelete())
.maintainerName(fenceUpdateRequest.getMaintainerName())
.alarmStatus(fenceUpdateRequest.getAlarmStatus())
.updateTime(fenceUpdateRequest.getUpdateTime())
.fenceId(fenceUpdateRequest.getFenceId())
.build();
}
// public static Fence fenceInsert(FenceRequest fenceRequest) { // public static Fence fenceInsert(FenceRequest fenceRequest) {
// //

View File

@ -65,6 +65,7 @@ public class FenceRequest {
* *
*/ */
private Integer alarmStatus; private Integer alarmStatus;
private Integer fenceCondition;
/** /**
* *
*/ */

View File

@ -68,6 +68,7 @@ public class FenceUpdateRequest {
* *
*/ */
private Integer alarmStatus; private Integer alarmStatus;
private Integer fenceCondition;
public Integer getIsDelete() { public Integer getIsDelete() {
return isDelete; return isDelete;

View File

@ -52,7 +52,9 @@ public class FenceConsumer {
hashSet.add(fenceUpdateRequest); hashSet.add(fenceUpdateRequest);
hashMap.put(fenceUpdateRequest.getFenceId()+"",fenceUpdateRequest); hashMap.put(fenceUpdateRequest.getFenceId()+"",fenceUpdateRequest);
// redisTemplate.opsForH("fence", JSON.toJSONString(hashMap),10,TimeUnit.MINUTES); // redisTemplate.opsForH("fence", JSON.toJSONString(hashMap),10,TimeUnit.MINUTES);
redisTemplate.opsForHash().put("fence", fenceUpdateRequest.getFenceId()+"", JSON.toJSONString(hashMap)); // redisTemplate.opsForHash().put("fence", fenceUpdateRequest.getFenceId()+"", JSON.toJSONString(hashMap));
redisTemplate.opsForList().rightPush("fence",JSON.toJSONString(hashMap));
redisTemplate.expire("fence", 10, TimeUnit.MINUTES);
//判断车辆是否有实时数据,如果没有则删除数据 //判断车辆是否有实时数据,如果没有则删除数据
channel.basicAck(deliveryTag, false); channel.basicAck(deliveryTag, false);
} else { } else {

View File

@ -47,7 +47,6 @@ public class MsgConsumer {
redisTemplate.expire("消息不重复:" + messageId, 5, TimeUnit.MINUTES); redisTemplate.expire("消息不重复:" + messageId, 5, TimeUnit.MINUTES);
try { try {
if (0 < add) { if (0 < add) {
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(realTimeDataRequest)); JSONObject jsonObject = JSONObject.parseObject(String.valueOf(realTimeDataRequest));
Long userId = jsonObject.getLong("userId"); Long userId = jsonObject.getLong("userId");
String vin = jsonObject.getString("vin"); String vin = jsonObject.getString("vin");

View File

@ -0,0 +1,40 @@
package com.couplet.analyze.msg.service.impl.ElectronicFence;
import com.alibaba.fastjson.JSON;
import com.couplet.common.domain.Fence;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
/**
* @Author: LiJiaYao
* @Date: 2024/4/6
* @Description:
*/
@Component
@Log4j2
public class ElectronicFenceJuge {
@Autowired
public static StringRedisTemplate redisTemplate;
public static boolean isJudge() {
String fenceKey="fence";
if (redisTemplate.hasKey(fenceKey)) {
ArrayList<Fence> fences = new ArrayList<>();
List<String> fence = redisTemplate.opsForList().range(fenceKey, 0, -1);
for (String s : fence) {
Fence parseObject = JSON.parseObject(s, Fence.class);
fences.add(parseObject);
}
log.info("更改的电子围栏内容是:"+fence);
}
return true;
}
}

View File

@ -1,12 +1,18 @@
package com.couplet.analyze.msg.service.impl; package com.couplet.analyze.msg.service.impl;
import com.alibaba.fastjson.JSON;
import com.couplet.analyze.msg.domain.CoupletMsgData; import com.couplet.analyze.msg.domain.CoupletMsgData;
import com.couplet.analyze.msg.service.IncidentService; import com.couplet.analyze.msg.service.IncidentService;
import com.couplet.common.domain.Fence;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/** /**
* @Author: LiJiaYao * @Author: LiJiaYao
* @Date: 2024/4/2 * @Date: 2024/4/2
@ -28,12 +34,51 @@ public class ElectronicFenceServiceImpl implements IncidentService {
public void incident(CoupletMsgData coupletMsgData) { public void incident(CoupletMsgData coupletMsgData) {
log.info("电子围栏事件开始......."); log.info("电子围栏事件开始.......");
String fenceKey="fence";
if (redisTemplate.hasKey("fence")) { ArrayList<Fence> fences = new ArrayList<>();
if (redisTemplate.hasKey(fenceKey)) {
log.info("电子围栏事件redis存在......."); log.info("电子围栏事件redis存在.......");
String s = redisTemplate.opsForValue().get("fence"); List<String> fence = redisTemplate.opsForList().range(fenceKey, 0, -1);
for (String s : fence) {
Fence parseObject = JSON.parseObject(s, Fence.class);
fences.add(parseObject);
}
// jingdu;
// longitude;
// weidu;
// latitude;
for (Fence data : fences) {
log.info("更改的电子围栏内容是:"+s); String fenceLongitudeLatitude = data.getFenceLongitudeLatitude();
/**
*
*/
String[] split = fenceLongitudeLatitude.split(";");
for (String s : split) {
String[] strings = s.split(",");
if (strings.length == 2){
Double trim = Double.valueOf(strings[0].trim());
Double trim1 = Double.valueOf(strings[1].trim());
boolean a = trim<= Double.valueOf(coupletMsgData.getLongitude());
boolean b = trim1 < Double.valueOf(coupletMsgData.getLatitude());
if (a && b){
log.info("电子围栏报警啦!!!!您的车驶出范围啦!!!");
}else {
log.info("电子围栏报警啦!!!!正常啦!!!");
}
log.info("经度是:"+trim);
log.info("纬度是:"+trim1);
}else {
throw new RuntimeException("电子围栏经纬度格式错误"+strings);
}
}
}
log.info("更改的电子围栏内容是:"+fence);
log.info("电子围栏事件结束......."); log.info("电子围栏事件结束.......");
} }

View File

@ -38,7 +38,7 @@ public class RealTimeDataServiceImpl implements IncidentService {
log.info("实时数据事件开始....."); log.info("实时数据事件开始.....");
if (RealTimeJudge.isJudge(coupletMsgData.getVin())){ if (RealTimeJudge.isJudge(coupletMsgData.getVin())){
log.info("[{}]开始传输实时数据", coupletMsgData.getVin()); log.info("有实时数据,值为:[{}]开始传输实时数据", coupletMsgData.getVin());
} }
log.info("[{}]开始传输实时数据", coupletMsgData.getVin()); log.info("[{}]开始传输实时数据", coupletMsgData.getVin());

View File

@ -30,8 +30,4 @@ public class OnLineVehicleController {
return success; return success;
} }
} }

View File

@ -184,11 +184,10 @@ public class VehicleController extends BaseController {
@GetMapping("onOrOutLineByVIN") @GetMapping("onOrOutLineByVIN")
public Integer onOrOutLineByVIN(@RequestParam("params") String params) { public Integer onOrOutLineByVIN(@RequestParam("params") String params) {
String[] split = params.split(","); String[] split = params.split(",");
return vehicleService.onOrOutLineByVIN(split[0], Integer.parseInt(split[1])); return vehicleService.onOrOutLineByVIN(split[0], Integer.parseInt(split[1]));
} }
} }

View File

@ -28,23 +28,26 @@ public class RabbitMQConfig implements RabbitTemplate.ConfirmCallback, RabbitTem
public String queueName; public String queueName;
//队列名 //队列名
public static final String finByVinQueueName="finByVinQueueName"; public static final String finByVinQueueName="finByVinQueueName";
public static final String FENCE_QUEUE ="fenceQueue";
//交换机 //交换机
public static final String VinExchangeName="vinExchangeName"; public static final String VinExchangeName="vinExchangeName";
public static final String FENCE_EXCHANGE="fenceExchange";
//路由键 //路由键
public static final String VinRoutingKey="vinRoutingKey"; public static final String VinRoutingKey="vinRoutingKey";
public static final String FENCE_ROUTINGKEY="fenceRoutingKey";
//队列名 //队列名
public static final String FENCE_QUEUE ="fenceQueue";
//交换机 //交换机
@Value("exchangeName") @Value("exchangeName")
public String exchangeName; public String exchangeName;
public static final String FENCE_EXCHANGE="fenceExchange";
//路由键 //路由键
@Value("routingKey") @Value("routingKey")
public String routingKey; public String routingKey;
//路由键 //路由键
public static final String FENCE_ROUTINGKEY="fenceRoutingKey";
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;

View File

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

View File

@ -14,6 +14,6 @@ import org.springframework.web.bind.annotation.RequestBody;
public interface RemoteFenceService { public interface RemoteFenceService {
@PostMapping("/mq/fenceQueue") @PostMapping("/mq/fenceQueue")
public void fenceQueue(@RequestBody FenceUpdateRequest fenceUpdateRequest); public void fenceQueue(@RequestBody FenceUpdateRequest teRequest);
} }