设备审核接口1
This commit is contained in:
parent
42011de122
commit
12a6f75767
@ -51,21 +51,21 @@ public class DeviceOtherMsgConsumer {
|
||||
|
||||
System.err.println("主题:"+topic+"--产品id:"+productId+"--设备序列号:"+serialNumber);
|
||||
//设备上报数据消息
|
||||
if(topic.endsWith("/info/up")){
|
||||
if(topic.endsWith("hzlink/info/up")){
|
||||
deviceDataReportHandler(new String(data));
|
||||
//构建回复消息
|
||||
Map<String,Object> reportMsg=new HashMap<>();
|
||||
reportMsg.put("code",0);
|
||||
reportMsg.put("msg","ok");
|
||||
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));
|
||||
|
||||
} else if (topic.endsWith("cmd/down")) {
|
||||
} else if (topic.endsWith("hzlink/cmd/down")) {
|
||||
platformCmdHandler(new String(data));
|
||||
//回应
|
||||
|
||||
} else if (topic.endsWith("cmd/reply")) {
|
||||
} else if (topic.endsWith("hzlink/cmd/reply")) {
|
||||
deviceCmdAckHandler(new String(data));
|
||||
}
|
||||
otherMsgHandler.messageHandler(bo);
|
||||
|
@ -16,8 +16,8 @@ public class IssueInstructionsProducer {
|
||||
@Autowired
|
||||
private PubMqttCallBack pubMqttCallBack;
|
||||
|
||||
private final String issueInstructionsTopicTemplate = "/{0}/{1}/cmd/down";//平台给设备下发指令主题模板
|
||||
private final String receiveDataReportResponseTopicTemplate = "/{0}/{1}/info/reply";//平台回应收到设备上报数据主题模板
|
||||
private final String issueInstructionsTopicTemplate = "hzlink/{0}/{1}/cmd/down";//平台给设备下发指令主题模板
|
||||
private final String receiveDataReportResponseTopicTemplate = "hzlink/{0}/{1}/info/reply";//平台回应收到设备上报数据主题模板
|
||||
|
||||
/**
|
||||
* 平台给设备下发的指令
|
||||
|
@ -35,7 +35,7 @@ public class DeviceOperationController {
|
||||
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<>();
|
||||
//远程阀控
|
||||
|
@ -7,8 +7,11 @@ import com.fastbee.common.core.controller.BaseController;
|
||||
import com.fastbee.common.core.domain.AjaxResult;
|
||||
import com.fastbee.common.core.domain.AjaxResultPro;
|
||||
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.UtilDeviceNumberAdd;
|
||||
import com.fastbee.iot.mapper.DeviceMapper;
|
||||
import com.fastbee.iot.mapper.DeviceReportInfoMapper;
|
||||
import com.fastbee.iot.mapper.UtilDeviceNumberAddMapper;
|
||||
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.servlet.mvc.method.annotation.SseEmitter;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -46,6 +50,10 @@ public class DeviceReportSSEController extends BaseController {
|
||||
@Autowired
|
||||
private UtilDeviceNumberAddMapper numberAddMapper ;
|
||||
|
||||
|
||||
@Autowired
|
||||
private DeviceMapper deviceMapper;
|
||||
|
||||
/**
|
||||
* 与客户端建立http长链接
|
||||
*/
|
||||
@ -61,34 +69,34 @@ public class DeviceReportSSEController extends BaseController {
|
||||
public AjaxResultPro sendMsg(@RequestBody DevicePowerDTO reportInfo) {
|
||||
// checkDeviceReportInfo(reportInfo);
|
||||
if(StringUtils.isBlank(reportInfo.getImei())){
|
||||
return AjaxResultPro.success(111,"imei不能为空",null);
|
||||
return AjaxResultPro.success(1102,"imei不能为空",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getIccid())){
|
||||
return AjaxResultPro.success(111,"iccid不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"iccid不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getMcuId())){
|
||||
return AjaxResultPro.success(111,"mcuId不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"mcuId不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getBspType())){
|
||||
return AjaxResultPro.success(111,"bspType不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"bspType不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getLteType())){
|
||||
return AjaxResultPro.success(111,"lteType不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"lteType不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getMcuType())){
|
||||
return AjaxResultPro.success(111,"mcuType不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"mcuType不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getMcuFw())){
|
||||
return AjaxResultPro.success(111,"mcuFw不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"mcuFw不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getLteFw())){
|
||||
return AjaxResultPro.success(111,"lteFw不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"lteFw不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getLcdType())){
|
||||
return AjaxResultPro.success(111,"lcdType不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"lcdType不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getVoiceType())){
|
||||
return AjaxResultPro.success(111,"voiceType不能为空!",null);
|
||||
return AjaxResultPro.success(1102,"voiceType不能为空!",null);
|
||||
}
|
||||
if(StringUtils.isBlank(reportInfo.getFacType())){
|
||||
return AjaxResultPro.success(111,"facType不能为空!",null);
|
||||
@ -115,53 +123,95 @@ public class DeviceReportSSEController extends BaseController {
|
||||
deviceReportInfo.setReplaceManufacturer(Long.valueOf(reportInfo.getFacType()));
|
||||
deviceReportInfo.setTestRecord(reportInfo.getTestRecord());
|
||||
//设置状态为未审核
|
||||
if (emitter==null) {
|
||||
deviceReportInfo.setStatus(0);
|
||||
}
|
||||
deviceReportInfo.setStatus(1);
|
||||
//设备编码查重
|
||||
List<DeviceReportInfo> list = new LambdaQueryChainWrapper<>(deviceReportInfoMapper)
|
||||
.select(DeviceReportInfo::getSerialNumber,DeviceReportInfo::getImei)
|
||||
.select(DeviceReportInfo::getSerialNumber,DeviceReportInfo::getImei,DeviceReportInfo::getStatus)
|
||||
.eq(DeviceReportInfo::getSerialNumber, deviceReportInfo.getSerialNumber())
|
||||
.or()
|
||||
.eq(DeviceReportInfo::getImei, deviceReportInfo.getImei())
|
||||
.list();
|
||||
if (!list.isEmpty()) {
|
||||
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();
|
||||
System.err.println("累加列表:"+numberAdds);
|
||||
if (numberAdds.isEmpty()) {
|
||||
return AjaxResultPro.success(112,"未查询到设备编码排序信息!",null);
|
||||
}
|
||||
new LambdaUpdateChainWrapper<>(numberAddMapper).set(UtilDeviceNumberAdd::getSuffix, numberAdds.get(0).getSuffix() + 1).update();
|
||||
//自动生成设备编码
|
||||
List<UtilDeviceNumberAdd> numberAdds = new LambdaQueryChainWrapper<>(numberAddMapper).list();
|
||||
System.err.println("累加列表:"+numberAdds);
|
||||
if (numberAdds.isEmpty()) {
|
||||
return AjaxResultPro.success(1103,"未查询到设备编码排序信息!",null);
|
||||
}
|
||||
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.get(0).getSerialNumber().equals(deviceReportInfo.getSerialNumber())) {
|
||||
return AjaxResultPro.success(112,"设备编号重复!",null);
|
||||
}
|
||||
}
|
||||
deviceReportInfo.setSerialNumber(genDeviceNumber);
|
||||
int inserted = deviceReportInfoMapper.insertDeviceReportInfo(deviceReportInfo);
|
||||
if(inserted==0){
|
||||
return AjaxResultPro.success(113,"设备上电审核信息插入失败!",null);
|
||||
if(!list.isEmpty()){
|
||||
if (list.get(0).getSerialNumber().equals(deviceReportInfo.getSerialNumber())) {
|
||||
|
||||
return AjaxResultPro.success(1103,"设备编号重复!",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){
|
||||
try {
|
||||
emitter.send(JSONUtil.toJsonStr(Message.builder().event(2).content("新的消息").data(reportInfo).build()));
|
||||
} catch (IOException e) {
|
||||
return AjaxResultPro.success(114,"推送上电基本信息失败!",null);
|
||||
return AjaxResultPro.success(1104,"推送上电基本信息失败!",null);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("regSn",deviceReportInfo.getSerialNumber());
|
||||
return AjaxResultPro.success(110,"设备审核通过!",map);
|
||||
Map<String,Object> map=new HashMap<>();
|
||||
map.put("regSn",deviceReportInfo.getSerialNumber());
|
||||
return AjaxResultPro.success(1200,"设备审核通过!",map);
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("/device/init/new/remove")
|
||||
|
Loading…
x
Reference in New Issue
Block a user