|
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.zy.bms.common.Constant;
|
|
|
import com.zy.bms.entity.lp.LpInfoState;
|
|
|
import com.zy.bms.pojo.dto.MqttDTO;
|
|
|
+import com.zy.bms.pojo.dto.WakeAndThreshLpDTO;
|
|
|
import com.zy.bms.service.IPostMqttMsgService;
|
|
|
import com.zy.bms.service.lp.ILpInfoStateService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -30,28 +31,59 @@ public class LpHandlers {
|
|
|
/**
|
|
|
* 基本信息上传
|
|
|
*/
|
|
|
- public void deviceInfoHandler(String topic, MqttDTO mqttDTO) {
|
|
|
+ public void deviceInfoHandler(String openNum, MqttDTO mqttDTO) {
|
|
|
try {
|
|
|
- String openNum = Constant.splitOpenNum(topic);
|
|
|
LpInfoState dbDevice = lpInfoStateService.getByOpenNum(openNum);
|
|
|
LpInfoState device = TransformEntity.tsf2LpInfoState(openNum, mqttDTO);
|
|
|
- //若数据库中不存在设备信息直接插入
|
|
|
- if (dbDevice == null) {
|
|
|
+ if (dbDevice == null) {//若数据库中不存在设备信息直接插入
|
|
|
lpInfoStateService.save(device);
|
|
|
return;
|
|
|
}
|
|
|
- BigDecimal wakeInt = BigDecimal.valueOf(mqttDTO.getDouble("sleept")).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- Integer thresh = mqttDTO.getInt("thresh");
|
|
|
- BigDecimal dbWakeInt = dbDevice.getWakeInt().setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
- //如果远程设备的(唤醒时间,阈值)与数据库的数据不一致,则发送消息更新设备的设置数据与数据库保持一致
|
|
|
- if ((dbWakeInt != null && !dbWakeInt.equals(wakeInt)) ||
|
|
|
- (dbDevice.getThresh() != null && !dbDevice.getThresh().equals(thresh))) {
|
|
|
- postMqttMsgService.setWakeAndThreshLp(openNum, wakeInt, thresh);
|
|
|
- }
|
|
|
+ setWakeAndThreshLp(openNum, dbDevice, device);
|
|
|
//更新数据库设备状态信息
|
|
|
lpInfoStateService.update(device, new QueryWrapper<LpInfoState>().eq("open_num", openNum));
|
|
|
} catch (Exception e) {
|
|
|
log.error("路牌上传基本信息异常", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 定位信息上传
|
|
|
+ */
|
|
|
+ public void deviceLocationHandler(String openNum, MqttDTO mqttDTO) {
|
|
|
+ try {
|
|
|
+ LpInfoState device = TransformEntity.tsf2LpInfoState(openNum, mqttDTO);
|
|
|
+ // 更新数据库设备状态信息
|
|
|
+ lpInfoStateService.update(device, new QueryWrapper<LpInfoState>().eq("open_num", openNum));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("路牌上传位置信息异常", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置 唤醒时间和阈值
|
|
|
+ *
|
|
|
+ * @param openNum 设备码
|
|
|
+ * @param local 本地设置参数
|
|
|
+ * @param remote 远程设置参数
|
|
|
+ */
|
|
|
+ private void setWakeAndThreshLp(String openNum, LpInfoState local, LpInfoState remote) {
|
|
|
+ WakeAndThreshLpDTO dto = new WakeAndThreshLpDTO();
|
|
|
+ dto.setOpenNum(openNum);
|
|
|
+ //如果远程设备的(唤醒时间,阈值)与数据库的数据不一致,则发送消息更新设备的设置数据与数据库保持一致
|
|
|
+ if (!local.getWakeInt().equals(remote.getWakeInt()) || !local.getThresh().equals(remote.getThresh())) {
|
|
|
+ dto.setWakeInt(local.getWakeInt());
|
|
|
+ dto.setThresh(local.getThresh());
|
|
|
+ //以数据库为主,不需要更新这两个字段,故设置为null
|
|
|
+ remote.setWakeInt(null);
|
|
|
+ remote.setThresh(null);
|
|
|
+ }
|
|
|
+ //是否需要定位
|
|
|
+ dto.setGetLocation(local.getUpdateLocationFlag() == 1 ? Constant.STATUS.TRUE : Constant.STATUS.FALSE);
|
|
|
+ //是否需要更新数据
|
|
|
+ dto.setSetf((dto.getWakeInt() != null || dto.getThresh() != null) ? Constant.STATUS.TRUE : Constant.STATUS.FALSE);
|
|
|
+ postMqttMsgService.setWakeAndThreshLp(dto);
|
|
|
+ //不管有没有更新,都设置为不需要在更新位置信息了
|
|
|
+ remote.setUpdateLocationFlag(0);
|
|
|
+ }
|
|
|
}
|