设备审核接口1

This commit is contained in:
mi9688 2024-12-19 16:06:17 +08:00
parent 42011de122
commit 12a6f75767
4 changed files with 93 additions and 43 deletions

View File

@ -51,21 +51,21 @@ public class DeviceOtherMsgConsumer {
System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber); System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber);
//设备上报数据消息 //设备上报数据消息
if(topic.endsWith("/info/up")){ if(topic.endsWith("hzlink/info/up")){
deviceDataReportHandler(new String(data)); deviceDataReportHandler(new String(data));
//构建回复消息 //构建回复消息
Map<String,Object> reportMsg=new HashMap<>(); Map<String,Object> reportMsg=new HashMap<>();
reportMsg.put("code",0); reportMsg.put("code",0);
reportMsg.put("msg","ok"); reportMsg.put("msg","ok");
issueInstructionsProducer.receiveDataReportResponse(productId.toString(),serialNumber,JSONUtil.toJsonStr(reportMsg)); issueInstructionsProducer.receiveDataReportResponse(productId.toString(),serialNumber,JSONUtil.toJsonStr(reportMsg));
} else if ( topic.endsWith("/info/reply")) { } else if ( topic.endsWith("hzlink/info/reply")) {
platformDataReportAckHandler(new String(data)); platformDataReportAckHandler(new String(data));
} else if (topic.endsWith("cmd/down")) { } else if (topic.endsWith("hzlink/cmd/down")) {
platformCmdHandler(new String(data)); platformCmdHandler(new String(data));
//回应 //回应
} else if (topic.endsWith("cmd/reply")) { } else if (topic.endsWith("hzlink/cmd/reply")) {
deviceCmdAckHandler(new String(data)); deviceCmdAckHandler(new String(data));
} }
otherMsgHandler.messageHandler(bo); otherMsgHandler.messageHandler(bo);

View File

@ -16,8 +16,8 @@ public class IssueInstructionsProducer {
@Autowired @Autowired
private PubMqttCallBack pubMqttCallBack; private PubMqttCallBack pubMqttCallBack;
private final String issueInstructionsTopicTemplate = "/{0}/{1}/cmd/down";//平台给设备下发指令主题模板 private final String issueInstructionsTopicTemplate = "hzlink/{0}/{1}/cmd/down";//平台给设备下发指令主题模板
private final String receiveDataReportResponseTopicTemplate = "/{0}/{1}/info/reply";//平台回应收到设备上报数据主题模板 private final String receiveDataReportResponseTopicTemplate = "hzlink/{0}/{1}/info/reply";//平台回应收到设备上报数据主题模板
/** /**
* 平台给设备下发的指令 * 平台给设备下发的指令

View File

@ -35,7 +35,7 @@ public class DeviceOperationController {
public AjaxResult control(@RequestBody DeviceOperationDTO deviceOperationDTO){ public AjaxResult control(@RequestBody DeviceOperationDTO deviceOperationDTO){
//构建主题 //构建主题
String topic ="/"+deviceOperationDTO.getProductId()+"/"+deviceOperationDTO.getDeviceNumber()+"/cmd/down"; String topic ="hzlink/"+deviceOperationDTO.getProductId()+"/"+deviceOperationDTO.getDeviceNumber()+"/cmd/down";
//构建消息 //构建消息
Map<String,Object> param = new HashMap<>(); Map<String,Object> param = new HashMap<>();
//远程阀控 //远程阀控

View File

@ -7,8 +7,11 @@ import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult; import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.domain.AjaxResultPro; import com.fastbee.common.core.domain.AjaxResultPro;
import com.fastbee.common.exception.ServiceException; import com.fastbee.common.exception.ServiceException;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceReportInfo; import com.fastbee.iot.domain.DeviceReportInfo;
import com.fastbee.iot.domain.UtilDeviceNumberAdd; import com.fastbee.iot.domain.UtilDeviceNumberAdd;
import com.fastbee.iot.mapper.DeviceMapper;
import com.fastbee.iot.mapper.DeviceReportInfoMapper; import com.fastbee.iot.mapper.DeviceReportInfoMapper;
import com.fastbee.iot.mapper.UtilDeviceNumberAddMapper; import com.fastbee.iot.mapper.UtilDeviceNumberAddMapper;
import com.fastbee.iot.model.dto.DevicePowerDTO; import com.fastbee.iot.model.dto.DevicePowerDTO;
@ -20,6 +23,7 @@ import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException; import java.io.IOException;
import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -46,6 +50,10 @@ public class DeviceReportSSEController extends BaseController {
@Autowired @Autowired
private UtilDeviceNumberAddMapper numberAddMapper ; private UtilDeviceNumberAddMapper numberAddMapper ;
@Autowired
private DeviceMapper deviceMapper;
/** /**
* 与客户端建立http长链接 * 与客户端建立http长链接
*/ */
@ -61,34 +69,34 @@ public class DeviceReportSSEController extends BaseController {
public AjaxResultPro sendMsg(@RequestBody DevicePowerDTO reportInfo) { public AjaxResultPro sendMsg(@RequestBody DevicePowerDTO reportInfo) {
// checkDeviceReportInfo(reportInfo); // checkDeviceReportInfo(reportInfo);
if(StringUtils.isBlank(reportInfo.getImei())){ if(StringUtils.isBlank(reportInfo.getImei())){
return AjaxResultPro.success(111,"imei不能为空",null); return AjaxResultPro.success(1102,"imei不能为空",null);
} }
if(StringUtils.isBlank(reportInfo.getIccid())){ if(StringUtils.isBlank(reportInfo.getIccid())){
return AjaxResultPro.success(111,"iccid不能为空!",null); return AjaxResultPro.success(1102,"iccid不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getMcuId())){ if(StringUtils.isBlank(reportInfo.getMcuId())){
return AjaxResultPro.success(111,"mcuId不能为空!",null); return AjaxResultPro.success(1102,"mcuId不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getBspType())){ if(StringUtils.isBlank(reportInfo.getBspType())){
return AjaxResultPro.success(111,"bspType不能为空!",null); return AjaxResultPro.success(1102,"bspType不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getLteType())){ if(StringUtils.isBlank(reportInfo.getLteType())){
return AjaxResultPro.success(111,"lteType不能为空!",null); return AjaxResultPro.success(1102,"lteType不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getMcuType())){ if(StringUtils.isBlank(reportInfo.getMcuType())){
return AjaxResultPro.success(111,"mcuType不能为空!",null); return AjaxResultPro.success(1102,"mcuType不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getMcuFw())){ if(StringUtils.isBlank(reportInfo.getMcuFw())){
return AjaxResultPro.success(111,"mcuFw不能为空!",null); return AjaxResultPro.success(1102,"mcuFw不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getLteFw())){ if(StringUtils.isBlank(reportInfo.getLteFw())){
return AjaxResultPro.success(111,"lteFw不能为空!",null); return AjaxResultPro.success(1102,"lteFw不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getLcdType())){ if(StringUtils.isBlank(reportInfo.getLcdType())){
return AjaxResultPro.success(111,"lcdType不能为空!",null); return AjaxResultPro.success(1102,"lcdType不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getVoiceType())){ if(StringUtils.isBlank(reportInfo.getVoiceType())){
return AjaxResultPro.success(111,"voiceType不能为空!",null); return AjaxResultPro.success(1102,"voiceType不能为空!",null);
} }
if(StringUtils.isBlank(reportInfo.getFacType())){ if(StringUtils.isBlank(reportInfo.getFacType())){
return AjaxResultPro.success(111,"facType不能为空!",null); return AjaxResultPro.success(111,"facType不能为空!",null);
@ -115,53 +123,95 @@ public class DeviceReportSSEController extends BaseController {
deviceReportInfo.setReplaceManufacturer(Long.valueOf(reportInfo.getFacType())); deviceReportInfo.setReplaceManufacturer(Long.valueOf(reportInfo.getFacType()));
deviceReportInfo.setTestRecord(reportInfo.getTestRecord()); deviceReportInfo.setTestRecord(reportInfo.getTestRecord());
//设置状态为未审核 //设置状态为未审核
if (emitter==null) { deviceReportInfo.setStatus(1);
deviceReportInfo.setStatus(0);
}
//设备编码查重 //设备编码查重
List<DeviceReportInfo> list = new LambdaQueryChainWrapper<>(deviceReportInfoMapper) List<DeviceReportInfo> list = new LambdaQueryChainWrapper<>(deviceReportInfoMapper)
.select(DeviceReportInfo::getSerialNumber,DeviceReportInfo::getImei) .select(DeviceReportInfo::getSerialNumber,DeviceReportInfo::getImei,DeviceReportInfo::getStatus)
.eq(DeviceReportInfo::getSerialNumber, deviceReportInfo.getSerialNumber()) .eq(DeviceReportInfo::getSerialNumber, deviceReportInfo.getSerialNumber())
.or() .or()
.eq(DeviceReportInfo::getImei, deviceReportInfo.getImei()) .eq(DeviceReportInfo::getImei, deviceReportInfo.getImei())
.list(); .list();
if (!list.isEmpty()) { if (!list.isEmpty()) {
if (list.get(0).getImei().equals(deviceReportInfo.getImei())) { if (list.get(0).getImei().equals(deviceReportInfo.getImei())) {
return AjaxResultPro.success(112, "IMEI号重复!", null); //如果已经审核通过了就更新信息进行覆盖如果未审核就提示信息已提交待审核
if(list.get(0).getStatus()==0){
return AjaxResultPro.success(1100,"设备注册信息已提交待审核,请勿重复提交!",null);
}
if (list.get(0).getStatus()==1) {
boolean update = new LambdaUpdateChainWrapper<>(deviceReportInfoMapper)
.set(DeviceReportInfo::getImei, reportInfo.getImei())
.set(DeviceReportInfo::getIccid, reportInfo.getIccid())
.set(DeviceReportInfo::getMcuId, reportInfo.getMcuId())
.set(DeviceReportInfo::getBspType,reportInfo.getBspType())
.set(DeviceReportInfo::getLteType, reportInfo.getLteType())
.set(DeviceReportInfo::getMcuType, reportInfo.getMcuType())
.set(DeviceReportInfo::getMcuFw, reportInfo.getMcuFw())
.set(DeviceReportInfo::getLteFw, reportInfo.getLteFw())
.set(DeviceReportInfo::getLcdManufacturer, Long.valueOf(reportInfo.getLcdType()))
.set(DeviceReportInfo::getVoiceManufacturer, Long.valueOf(reportInfo.getVoiceType()))
.set(DeviceReportInfo::getReplaceManufacturer, Long.valueOf(reportInfo.getFacType()))
.set(DeviceReportInfo::getTestRecord,reportInfo.getTestRecord())
.eq(DeviceReportInfo::getImei, deviceReportInfo.getImei())
.update();
if (update) {
Map<String,Object> map=new HashMap<>();
map.put("regSn",list.get(0).getSerialNumber());
return AjaxResultPro.success(1210, "设备注册信息更新!", map);
}
}
return AjaxResultPro.success(1105, "IMEI号重复!", null);
} }
} }
//自动生成设备编码 //自动生成设备编码
List<UtilDeviceNumberAdd> numberAdds = new LambdaQueryChainWrapper<>(numberAddMapper).list(); List<UtilDeviceNumberAdd> numberAdds = new LambdaQueryChainWrapper<>(numberAddMapper).list();
System.err.println("累加列表:"+numberAdds); System.err.println("累加列表:"+numberAdds);
if (numberAdds.isEmpty()) { if (numberAdds.isEmpty()) {
return AjaxResultPro.success(112,"未查询到设备编码排序信息!",null); return AjaxResultPro.success(1103,"未查询到设备编码排序信息!",null);
} }
new LambdaUpdateChainWrapper<>(numberAddMapper).set(UtilDeviceNumberAdd::getSuffix, numberAdds.get(0).getSuffix() + 1).update(); new LambdaUpdateChainWrapper<>(numberAddMapper).set(UtilDeviceNumberAdd::getSuffix, numberAdds.get(0).getSuffix() + 1).update();
String genDeviceNumber= numberAdds.get(0).getPrefix()+padZero(numberAdds.get(0).getSuffix()+1); String genDeviceNumber= numberAdds.get(0).getPrefix()+padZero(numberAdds.get(0).getSuffix()+1);
if(!list.isEmpty()){ if(!list.isEmpty()){
if (list.get(0).getSerialNumber().equals(deviceReportInfo.getSerialNumber())) { if (list.get(0).getSerialNumber().equals(deviceReportInfo.getSerialNumber())) {
return AjaxResultPro.success(112,"设备编号重复!",null);
} return AjaxResultPro.success(1103,"设备编号重复!",null);
}
deviceReportInfo.setSerialNumber(genDeviceNumber);
int inserted = deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo);
if(inserted==0){
return AjaxResultPro.success(113,"设备上电审核信息插入失败!",null);
} }
}
deviceReportInfo.setSerialNumber(genDeviceNumber);
deviceReportInfo.setName(genDeviceNumber);
int inserted = deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo);
if(inserted==0){
return AjaxResultPro.success(1104,"设备上电审核信息插入失败!",null);
}
//插入成功后插入设备信息
Device device= new Device();
device.setDeviceName(genDeviceNumber);
device.setProductName("内乡县水电双计设备02");
device.setFirmwareVersion(BigDecimal.valueOf(1));
device.setSerialNumber(deviceReportInfo.getSerialNumber());
device.setCreateTime(DateUtils.getNowDate());
device.setProductId(147L);
device.setStatus(1);//未激活
device.setCreateTime(deviceReportInfo.getPowersTime());
device.setTenantId(1L);//默认总管理员
int inserted1 = deviceMapper.insert(device);
if(inserted1<1){
throw new ServiceException("插入设备信息失败!");
}
//当开启自动审核也就是打开自动审核页面的时候需要推送到前端 //当开启自动审核也就是打开自动审核页面的时候需要推送到前端
if(emitter!=null){ if(emitter!=null){
try { try {
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build())); emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
} catch (IOException e) { } catch (IOException e) {
return AjaxResultPro.success(114,"推送上电基本信息失败!",null); return AjaxResultPro.success(1104,"推送上电基本信息失败!",null);
} }
} }
Map<String,Object> map=new HashMap<>(); Map<String,Object> map=new HashMap<>();
map.put("regSn",deviceReportInfo.getSerialNumber()); map.put("regSn",deviceReportInfo.getSerialNumber());
return AjaxResultPro.success(110,"设备审核通过!",map); return AjaxResultPro.success(1200,"设备审核通过!",map);
} }
@PostMapping("/device/init/new/remove") @PostMapping("/device/init/new/remove")