feat: 推送人脸和车辆信息
This commit is contained in:
parent
724a4d70fe
commit
d0d5951de5
|
@ -2,7 +2,6 @@ package com.bootdo.datasend.dianxin.task;
|
|||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.parser.Feature;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.bootdo.datasend.dianxin.cache.DeviceCache;
|
||||
import com.bootdo.datasend.dianxin.domain.BaseUserRecord;
|
||||
|
@ -16,6 +15,7 @@ import com.bootdo.util.StringKit;
|
|||
import lombok.RequiredArgsConstructor;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
|
@ -29,7 +29,9 @@ public class StandardTask {
|
|||
private final BaseVehicleRecordService vehicleRecordService;
|
||||
private final RestTemplate restTemplate;
|
||||
private final BaseUserRecordService userRecordService;
|
||||
// @Scheduled(cron = "0/5 * * * * ? ")
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
// @Scheduled(cron = "0/5 * * * * ? ")
|
||||
public void sendVehicleRecord() {
|
||||
|
||||
List<BaseVehicleRecord> lists = vehicleRecordService.list(new QueryWrapper<BaseVehicleRecord>()
|
||||
|
@ -77,29 +79,11 @@ public class StandardTask {
|
|||
list.add(requestDataListDTO);
|
||||
dataDTO.setRequestDataList(list);
|
||||
dto.setRequestData(dataDTO);
|
||||
// String requestBody = JSON.toJSONString(dto);
|
||||
String requestBody = JSON.toJSONString(dto, SerializerFeature.BrowserCompatible);
|
||||
logger.info("json格式字符串:{}", requestBody);
|
||||
// 比如队列名称是 instruction||{gatewaySN} ,需替换成实际的 gatewaySN 值
|
||||
String gatewaySN = deviceInfo != null ? deviceInfo.getGeminiSn() : "";
|
||||
String queueName = "instruction||" + gatewaySN;
|
||||
// String url = "https://cyy.csxdtx.com:10010/api/zdyq-equipment/dwBoxRecord/acceptDwCarRecord";
|
||||
String url = "";
|
||||
|
||||
try {
|
||||
// 发送 POST 请求,这里假设接口返回类型为 String ,可根据实际调整
|
||||
// 消息队列发送
|
||||
// rabbitTemplate.convertAndSend(queueName, JSON.toJSONString(dto));
|
||||
// 调接口
|
||||
String result = restTemplate.postForObject(url, requestBody, String.class);
|
||||
logger.info("调用接口返回结果:{}", result);
|
||||
|
||||
// 若返回码符合成功逻辑(需看接口文档定义),更新发送状态
|
||||
boolean b = sendVehicleMq(dto);
|
||||
if (b) {
|
||||
h.setIsSend(1);
|
||||
vehicleRecordService.saveOrUpdate(h);
|
||||
logger.info("车辆记录发送成功:" + h.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("调用接口发送数据失败,记录 ID:{},异常:{}", h.getId(), e.getMessage());
|
||||
logger.info("车辆数据发送成功:" + h.getId());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -145,30 +129,32 @@ public class StandardTask {
|
|||
list.add(requestDataListDTO);
|
||||
dataDTO.setRequestDataList(list);
|
||||
dto.setRequestData(dataDTO);
|
||||
String requestBody = JSON.toJSONString(dto);
|
||||
System.out.println("JOSN格式字符串"+requestBody);
|
||||
logger.info("json格式字符串:{}", requestBody);
|
||||
// 比如队列名称是 instruction||{gatewaySN} ,需替换成实际的 gatewaySN 值
|
||||
String gatewaySN = deviceInfo != null ? deviceInfo.getGeminiSn() : "";
|
||||
String queueName = "instruction||" + gatewaySN;
|
||||
// String url = "http://cyy.csxdtx.com:10010/api/zdyq-equipment/dwBoxRecord/accept";
|
||||
String url = "";
|
||||
|
||||
try {
|
||||
// 发送 POST 请求,这里假设接口返回类型为 String ,可根据实际调整
|
||||
// 消息队列发送
|
||||
// rabbitTemplate.convertAndSend(queueName, JSON.toJSONString(dto));
|
||||
// 调接口
|
||||
String result = restTemplate.postForObject(url, requestBody, String.class);
|
||||
logger.info("调用接口返回结果:{}", result);
|
||||
|
||||
// 若返回码符合成功逻辑(需看接口文档定义),更新发送状态
|
||||
boolean result = sendUserMq(dto);
|
||||
if (result) {
|
||||
h.setIsSend(1);
|
||||
userRecordService.saveOrUpdate(h);
|
||||
logger.info("人脸抓拍记录发送成功:" + h.getId());
|
||||
} catch (Exception e) {
|
||||
logger.error("调用接口发送数据失败,记录 ID:{},异常:{}", h.getId(), e.getMessage());
|
||||
logger.info("人脸数据发送成功:" + h.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean sendVehicleMq(VehicleRecordDto bean) {
|
||||
try {
|
||||
rabbitTemplate.convertAndSend("warnrecord", "routing.key.vehiclerecord", JSON.toJSONString(bean));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public boolean sendUserMq(UserRecordDto bean) {
|
||||
try {
|
||||
rabbitTemplate.convertAndSend("warnrecord", "routing.key.userrecord", JSON.toJSONString(bean));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue