设备上电自动审核逻辑修改

This commit is contained in:
mi9688
2025-01-07 17:53:10 +08:00
parent 8ac5f1c690
commit 99e3a161a8
6 changed files with 33 additions and 20 deletions

View File

@ -58,16 +58,17 @@ public class DeviceReportSSEController extends BaseController {
* 与客户端建立http长链接
*/
@PostMapping(value = "/device/init",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter getReport() throws IOException {
public SseEmitter getReport(@RequestBody String timeStamp) throws IOException {
SseEmitter emitter= new SseEmitter(0L);
emitters.put("device-init",emitter);
String emittersKey="sse-connection-"+timeStamp;
emitters.put(emittersKey,emitter);
log.info("{}连接成功!",emittersKey);
emitter.send(JSONUtil.toJsonStr(Message.builder().event(1).content("连接成功!").build()));
return emitter;
}
@PostMapping("/device/init/new")
public AjaxResultPro sendMsg(@RequestBody DevicePowerDTO reportInfo) {
// checkDeviceReportInfo(reportInfo);
if(StringUtils.isBlank(reportInfo.getImei())){
return AjaxResultPro.success(1102,"imei不能为空",null);
}
@ -105,7 +106,7 @@ public class DeviceReportSSEController extends BaseController {
if(StringUtils.isBlank(reportInfo.getTestRecord())){
return AjaxResultPro.success(111,"testRecord不能为空!",null);
}
SseEmitter emitter = emitters.get("device-init");
// String deviceNumber = generateDeviceNumber();
//映射字段
@ -123,7 +124,7 @@ public class DeviceReportSSEController extends BaseController {
deviceReportInfo.setReplaceManufacturer(Long.valueOf(reportInfo.getFacType()));
deviceReportInfo.setTestRecord(reportInfo.getTestRecord());
//设置状态为未审核
deviceReportInfo.setStatus(1);
deviceReportInfo.setStatus(0);
//设备编码查重
List<DeviceReportInfo> list = new LambdaQueryChainWrapper<>(deviceReportInfoMapper)
.select(DeviceReportInfo::getSerialNumber,DeviceReportInfo::getImei,DeviceReportInfo::getStatus)
@ -179,6 +180,7 @@ public class DeviceReportSSEController extends BaseController {
}
}
deviceReportInfo.setSerialNumber(genDeviceNumber);
reportInfo.setSerialNumber(genDeviceNumber);
deviceReportInfo.setName(genDeviceNumber);
deviceReportInfo.setType(1);
int inserted = deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo);
@ -202,14 +204,15 @@ public class DeviceReportSSEController extends BaseController {
if(inserted1<1){
throw new ServiceException("插入设备信息失败!");
}
//当开启自动审核,也就是打开自动审核页面的时候需要推送到前端
if(emitter!=null){
emitters.forEach((k,v)->{
try {
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
} catch (IOException e) {
return AjaxResultPro.success(1104,"推送上电基本信息失败!",null);
v.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
} catch (Exception e) {
log.error("推送上电基本信息失败!",e);
}
}
});
Map<String,Object> map=new HashMap<>();
map.put("regSn",deviceReportInfo.getSerialNumber());