|
|
@@ -70,7 +70,6 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
@Autowired
|
|
|
private IotDeviceAddressService iotDeviceAddressService;
|
|
|
|
|
|
- String connectionId = TestConst.connectionId;
|
|
|
@Override
|
|
|
public Object sendCmd(CmdModel cmdModel) throws Exception {
|
|
|
log.info("【测报灯】发送指令 任务 cmdModel={}", cmdModel);
|
|
|
@@ -121,11 +120,10 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
}
|
|
|
}
|
|
|
String topic = IotMqttConstant.YFCbdTopic.TOPIC_CBD_CMD_PREFIX + cmdModel.getIotDevice().getDevCode();
|
|
|
- log.info("!!!!!!!!!!【看这里:临时测试】这里的connectionId写死了,对接业务时候换掉,取出来真实的");
|
|
|
- //String connectionId = cmdModel.getIotDevice().getDevconnBid();
|
|
|
- mqttManager.publishMsg(connectionId, topic, mqttMsgContent);
|
|
|
+ IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(cmdModel.getIotDevice().getDevBid());
|
|
|
+ mqttManager.publishMsg(iotDevice.getDevconnBid(), topic, mqttMsgContent);
|
|
|
|
|
|
- log.info("【CBD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}",connectionId,topic, mqttMsgContent);
|
|
|
+ log.info("【CBD】发送指令完毕!connectionId:{},topic :{} mqttMsgContent: {}",iotDevice.getDevconnBid(),topic, mqttMsgContent);
|
|
|
|
|
|
cmdModel.setClogSendresult(clogSendresult);
|
|
|
cmdModel.setClogDesc(mqttMsgContent);
|
|
|
@@ -201,26 +199,34 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
return JSONUtils.toJSONString(extConf);
|
|
|
}
|
|
|
|
|
|
- public void cmdData(JSONObject ext, String devUpdateddate) throws Exception {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param ext
|
|
|
+ * @param devUpdateddate
|
|
|
+ * @param topic
|
|
|
+ * @param connectionId
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public void cmdData(JSONObject ext, String devUpdateddate,String topic,String connectionId) throws Exception {
|
|
|
log.info("【测报灯】数据解析 {}", ext.toString());
|
|
|
- TestConst.printError("!!!!!!!!!!【看这里:临时测试】这里的connectionId写死了,对接业务时候换掉,取出来");
|
|
|
- String devtypeBid = mqttManager.getDeviceTypeBizId(connectionId);
|
|
|
- String firmBid = mqttManager.getFirmBizId(connectionId);
|
|
|
+ String devId=mqttManager.getDevIdByTopic(connectionId,topic);
|
|
|
+ IotDevice iotDeviceFromDb= iIotDeviceService.selectIotDeviceByDevBid(devId);
|
|
|
+ if (iotDeviceFromDb == null) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
boolean isCbd = true;
|
|
|
String vtype = ext.getString("vtype");
|
|
|
if (ext.containsKey("dat_f")) {
|
|
|
ext.put("datt", ext.getString("dat_f"));
|
|
|
}
|
|
|
if (StringUtils.isNotEmpty(vtype) && vtype.equals("6")) {
|
|
|
- devtypeBid = "xct";
|
|
|
isCbd = false;
|
|
|
}
|
|
|
-
|
|
|
- IotDevice iotDevice = new IotDevice();
|
|
|
- iotDevice.setDevtypeBid(devtypeBid);
|
|
|
- iotDevice.setFirmBid(firmBid);
|
|
|
- iotDevice.setDevUpdateddate(devUpdateddate);
|
|
|
- iotDevice.setDevStatus("1");
|
|
|
+ if(!isCbd){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ iotDeviceFromDb.setDevUpdateddate(devUpdateddate);
|
|
|
+ iotDeviceFromDb.setDevStatus("1");
|
|
|
|
|
|
HashMap<String, String> keyMaps = new HashMap<>();
|
|
|
keyMaps.put("dver", "devVersion");
|
|
|
@@ -231,76 +237,76 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
String k = entry.getValue();
|
|
|
String v = ext.getString(entry.getKey());
|
|
|
if (StringUtils.isNotEmpty(v)) {
|
|
|
- ReflectUtils.invokeSetter(iotDevice, k, v);
|
|
|
+ ReflectUtils.invokeSetter(iotDeviceFromDb, k, v);
|
|
|
}
|
|
|
}
|
|
|
- // 设备不存在 就不在处理
|
|
|
- IotDevice iotDeviceOld = iIotDeviceService.selectIotDeviceByTypeFirmCode(iotDevice.getDevtypeBid(), iotDevice.getFirmBid(), iotDevice.getDevCode());
|
|
|
- if (iotDeviceOld == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- iotDevice.setDevBid(iotDeviceOld.getDevBid());
|
|
|
+
|
|
|
String lat = ext.getString("lat");
|
|
|
String lng = ext.getString("lng");
|
|
|
|
|
|
- if (!Objects.equals(iotDeviceOld.getDevPositionstatus(), "0")) {
|
|
|
- iotDeviceAddressService.setDeviceAddress(iotDevice, lng, lat);
|
|
|
+ if (!Objects.equals(iotDeviceFromDb.getDevPositionstatus(), "0")) {
|
|
|
+ iotDeviceAddressService.setDeviceAddress(iotDeviceFromDb, lng, lat);
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
// 单独处理是否识别是否开启识别:0禁用(不带识别)1识别 2 计数
|
|
|
String disable = ext.getString("disable");
|
|
|
log.info("【测报灯-解析识别状态】disable:{}", disable);
|
|
|
- /*String extInfoOld = iotDeviceOld.getExtInfo();
|
|
|
- String extInfo = extInfoOld == null ? "{}" : extInfoOld;
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(extInfo);
|
|
|
- jsonObject.put("disable", disable);
|
|
|
- iotDevice.setExtInfo(jsonObject.toString());*/
|
|
|
} catch (Exception e) {
|
|
|
log.error("【测报灯-解析识别状态 异常】disable:{}", e.getMessage());
|
|
|
}
|
|
|
// 更新设备基础信息数据库 mysql
|
|
|
- iIotDeviceService.updateIotDevice(iotDevice);
|
|
|
+ iIotDeviceService.updateIotDevice(iotDeviceFromDb);
|
|
|
|
|
|
// 更新设备数据信息到数据库 mongodb
|
|
|
- String cId = iotDeviceOld.getTid();
|
|
|
+ String cId = iotDeviceFromDb.getTid();
|
|
|
String devConfig = "";
|
|
|
if (isCbd) {
|
|
|
- devConfig = this.cbdData(ext, cId, iotDevice);
|
|
|
+ devConfig = this.cbdData(ext, cId, iotDeviceFromDb);
|
|
|
} else {
|
|
|
- devConfig = this.xctData(ext, cId, iotDevice);
|
|
|
+ devConfig = this.xctData(ext, cId, iotDeviceFromDb);
|
|
|
}
|
|
|
|
|
|
// 创建或更新设备配置信息
|
|
|
if (StringUtils.isNotEmpty(devConfig)) {
|
|
|
- iIotDeviceconfigService.createOrUpdateDevConfig(iotDeviceOld, devConfig, iotDevice.getDevUpdateddate());
|
|
|
+ iIotDeviceconfigService.createOrUpdateDevConfig(iotDeviceFromDb, devConfig, iotDeviceFromDb.getDevUpdateddate());
|
|
|
}
|
|
|
|
|
|
// 保存 设备最新数据 到redis
|
|
|
iIotDevicelasteddataService.createOrUpdateDeviceLastedData(
|
|
|
- ext, iotDeviceOld, iotDevice.getDevUpdateddate(), 60 * 60 * 24L);
|
|
|
+ ext, iotDeviceFromDb, iotDeviceFromDb.getDevUpdateddate(), 60 * 60 * 24L);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void cmdOffline(JSONObject ext) {
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param ext
|
|
|
+ * @param topic
|
|
|
+ * @param connectionId
|
|
|
+ */
|
|
|
+ public void cmdOffline(JSONObject ext,String topic,String connectionId) {
|
|
|
log.debug("测报灯离线数据 {}", ext.toString());
|
|
|
- String devtypeBid = mqttManager.getDeviceTypeBizId(SERVICE_NAME);
|
|
|
- String firmBid = mqttManager.getFirmBizId(SERVICE_NAME);
|
|
|
- String devCode = ext.getString("imei");
|
|
|
- // 设备不存在 就不在处理
|
|
|
- IotDevice iotDeviceOld = iIotDeviceService.selectIotDeviceByTypeFirmCode(devtypeBid, firmBid, devCode);
|
|
|
- if (iotDeviceOld == null) {
|
|
|
- return;
|
|
|
+ String devId=mqttManager.getDevIdByTopic(connectionId,topic);
|
|
|
+ IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(devId);
|
|
|
+ if (iotDevice == null) {
|
|
|
+ return ;
|
|
|
}
|
|
|
IotDevice newIotDevice = new IotDevice();
|
|
|
- newIotDevice.setDevBid(iotDeviceOld.getDevBid());
|
|
|
+ newIotDevice.setDevBid(devId);
|
|
|
newIotDevice.setDevStatus("0");
|
|
|
newIotDevice.setDevOfflinedate(DateUtils.dateTimeNow());
|
|
|
iIotDeviceService.updateIotDevice(newIotDevice);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param topic
|
|
|
+ * @param dataJson
|
|
|
+ * @param connectionId
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
@Override
|
|
|
- public Object receiveData(String topic, JSONObject dataJson) throws Exception {
|
|
|
+ public Object receiveData(String topic, JSONObject dataJson,String connectionId) throws Exception {
|
|
|
log.info("【测报灯】收到的 设备上报数据 {}", dataJson.toString());
|
|
|
// 接收设备上报数据后的处理逻辑
|
|
|
String devUpdateddate = dataJson.getString("devUpdateddate");
|
|
|
@@ -308,7 +314,7 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
devUpdateddate = DateUtils.dateTimeNow();
|
|
|
}
|
|
|
if (dataJson.containsKey("Image")) {
|
|
|
- Object result = this.receivePicData(dataJson, devUpdateddate);
|
|
|
+ Object result = this.receivePicData(dataJson, devUpdateddate, topic,connectionId);
|
|
|
log.info("测报灯实现类 接收数据:" + result);
|
|
|
} else {
|
|
|
String cmd = dataJson.getString("cmd");
|
|
|
@@ -323,21 +329,33 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
}
|
|
|
|
|
|
if (cmd.equals("data")) {
|
|
|
- this.cmdData(ext, devUpdateddate);
|
|
|
+ this.cmdData(ext, devUpdateddate,topic,connectionId);
|
|
|
} else if (cmd.equals("offline")) {
|
|
|
- this.cmdOffline(ext);
|
|
|
+ this.cmdOffline(ext,topic,connectionId);
|
|
|
}
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param jsonObject
|
|
|
+ * @param devUpdateddate
|
|
|
+ * @param topic
|
|
|
+ * @param connectionId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public Object receivePicData(JSONObject jsonObject, String devUpdateddate) {
|
|
|
- String devtypeBid = mqttManager.getDeviceTypeBizId(SERVICE_NAME);
|
|
|
- String firmBid = mqttManager.getFirmBizId(SERVICE_NAME);
|
|
|
+ public Object receivePicData(JSONObject jsonObject, String devUpdateddate ,String topic,String connectionId) {
|
|
|
+ String devId=mqttManager.getDevIdByTopic(connectionId,topic);
|
|
|
+ IotDevice iotDevice= iIotDeviceService.selectIotDeviceByDevBid(devId);
|
|
|
+ if (iotDevice == null) {
|
|
|
+ return "设备不存在 就不在处理";
|
|
|
+ }
|
|
|
+ String devtypeBid = iotDevice.getDevtypeBid();
|
|
|
String deviceTypeId = jsonObject.getString("device_type_id");
|
|
|
String devCode = jsonObject.getString("imei");
|
|
|
- log.info("【解析测报灯数据】:devtypeBid:{},firmBid:{},deviceTypeId,{},devCode:{}", devtypeBid, firmBid, deviceTypeId, devCode);
|
|
|
+ log.info("【解析测报灯数据】:devtypeBid:{},deviceTypeId,{},devCode:{}", devtypeBid, deviceTypeId, devCode);
|
|
|
boolean isCbd = true;
|
|
|
if (StringUtils.isNotEmpty(deviceTypeId) && !deviceTypeId.equals("3")) {
|
|
|
devtypeBid = "xct";
|
|
|
@@ -348,13 +366,6 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
return "暂不处理吸虫塔设备";
|
|
|
}
|
|
|
|
|
|
- // 设备不存在 就不在处理
|
|
|
- IotDevice iotDevice = iIotDeviceService.selectIotDeviceByTypeFirmCode(devtypeBid, firmBid, devCode);
|
|
|
-
|
|
|
- if (iotDevice == null) {
|
|
|
- return "设备不存在 就不在处理";
|
|
|
- }
|
|
|
-
|
|
|
String cbdimgAddr = jsonObject.getString("Image");
|
|
|
if (StringUtils.isEmpty(cbdimgAddr)) {
|
|
|
return "图片地址不存在,则不处理";
|
|
|
@@ -365,23 +376,30 @@ public class CqCbdDeviceImpl implements ICbdDevice {
|
|
|
return "测报灯指令上报的图片结果";
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param jobjMsg
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
public boolean isDeviceProps(JSONObject jobjMsg) {
|
|
|
-
|
|
|
if ("data".equals(jobjMsg.getString("cmd"))) {
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param topic
|
|
|
+ * @param jobjMsg
|
|
|
+ * @param connectionId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@Override
|
|
|
- public IotDevice findIotDevice(String topic, JSONObject jobjMsg) {
|
|
|
- String devCode = topic.substring(topic.lastIndexOf("/") + 1);
|
|
|
- String devtypeBid = mqttManager.getDeviceTypeBizId(connectionId);
|
|
|
- String firmBid = mqttManager.getFirmBizId(connectionId);
|
|
|
- //查询
|
|
|
- IotDevice ret = iIotDeviceService.selectIotDeviceByTypeFirmCode(devtypeBid, firmBid, devCode);
|
|
|
+ public IotDevice findIotDevice(String topic, JSONObject jobjMsg,String connectionId) {
|
|
|
+ String devId = mqttManager.getDevIdByTopic(connectionId,topic);
|
|
|
+ IotDevice ret = iIotDeviceService.selectIotDeviceByDevBid(devId);
|
|
|
log.debug("查到了一个iotdevice {}", ret);
|
|
|
return ret;
|
|
|
}
|