|
@@ -46,6 +46,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
|
+import java.lang.reflect.Field;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
@@ -248,35 +249,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
}
|
|
}
|
|
|
|
|
|
//4.通过MQTT把信息参数发送到设备
|
|
//4.通过MQTT把信息参数发送到设备
|
|
- String topic = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, devInfo.getClientId());
|
|
|
|
-
|
|
|
|
- //构建检测区域
|
|
|
|
- Map<String, BigDecimal> base = new HashMap<>();
|
|
|
|
- base.put("x_cm_start", request.getXxStart());
|
|
|
|
- base.put("x_cm_stop", request.getXxEnd());
|
|
|
|
- base.put("y_cm_start", request.getYyStart());
|
|
|
|
- base.put("y_cm_stop", request.getYyEnd());
|
|
|
|
- base.put("z_cm_start", request.getZzStart());
|
|
|
|
- base.put("z_cm_stop", request.getZzEnd());
|
|
|
|
- Map<String, Map<String, BigDecimal>> baseParent = new HashMap<>();
|
|
|
|
- baseParent.put("base", base);
|
|
|
|
-
|
|
|
|
- //构建安装高度
|
|
|
|
- Map<String, BigDecimal> z_cm = new HashMap<>();
|
|
|
|
- z_cm.put("z_cm", request.getHeight());
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- //发送最终消息
|
|
|
|
- JSONObject jsonObject = new JSONObject();
|
|
|
|
- jsonObject.put("ext_region", baseParent);
|
|
|
|
- jsonObject.put("sensor_location", z_cm);
|
|
|
|
-
|
|
|
|
- try {
|
|
|
|
- mqttClient.sendMessage(topic, jsonObject.toJSONString());
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- log.error("发送设备参数到MQTT失败", e);
|
|
|
|
- throw new BizException(ErrorEnum.MQTT_SEND_ERROR.getErrorCode(), ErrorEnum.MQTT_SEND_ERROR.getErrorMessage());
|
|
|
|
- }
|
|
|
|
|
|
+ sendDeviceParamsToMqtt(devInfo.getClientId(), request);
|
|
|
|
|
|
return updateResult;
|
|
return updateResult;
|
|
}
|
|
}
|
|
@@ -341,8 +314,13 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
throw new BizException(ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorCode(), ErrorEnum.DEVICE_IS_NOT_EXIST.getErrorMessage());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //2.校验是否为主绑人
|
|
|
|
+ if (!devInfo.getUserId().equals(params.getUserId())){
|
|
|
|
+ throw new BizException(ErrorEnum.USER_NO_PERMISSION.getErrorCode(), ErrorEnum.USER_NO_PERMISSION.getErrorMessage());
|
|
|
|
+ }
|
|
|
|
|
|
- //2..更新数据
|
|
|
|
|
|
+
|
|
|
|
+ //3.更新数据
|
|
devInfo.setTenantId(params.getTenantId());
|
|
devInfo.setTenantId(params.getTenantId());
|
|
devInfo.setDevName(params.getDevName());
|
|
devInfo.setDevName(params.getDevName());
|
|
devInfo.setHeight(params.getHeight());
|
|
devInfo.setHeight(params.getHeight());
|
|
@@ -359,9 +337,14 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
devInfo.setZzEnd(params.getZzEnd());
|
|
devInfo.setZzEnd(params.getZzEnd());
|
|
devInfo.setLength(params.getXxEnd().subtract(params.getXxStart()));
|
|
devInfo.setLength(params.getXxEnd().subtract(params.getXxStart()));
|
|
devInfo.setWidth(params.getYyEnd().subtract(params.getYyStart()));
|
|
devInfo.setWidth(params.getYyEnd().subtract(params.getYyStart()));
|
|
|
|
+ devInfo.setFallingConfirm(params.getFallingConfirm());
|
|
|
|
|
|
boolean updated = devInfoService.updateById(devInfo);
|
|
boolean updated = devInfoService.updateById(devInfo);
|
|
- return updated;
|
|
|
|
|
|
+
|
|
|
|
+ //4.通过MQTT把信息参数发送到设备
|
|
|
|
+ sendDeviceParamsToMqtt(devInfo.getClientId(), params);
|
|
|
|
+
|
|
|
|
+ return updated;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -374,6 +357,80 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 发送设备参数到MQTT的通用方法
|
|
|
|
+ * @param clientId 设备客户端ID
|
|
|
|
+ * @param params 设备参数(DeviceBandingParams或UpdateDeviceParams)
|
|
|
|
+ */
|
|
|
|
+ private void sendDeviceParamsToMqtt(String clientId, Object params) {
|
|
|
|
+ String topic = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, clientId);
|
|
|
|
+
|
|
|
|
+ //构建检测区域
|
|
|
|
+ Map<String, BigDecimal> base = new HashMap<>();
|
|
|
|
+ base.put("x_cm_start", getFieldValue(params, "xxStart"));
|
|
|
|
+ base.put("x_cm_stop", getFieldValue(params, "xxEnd"));
|
|
|
|
+ base.put("y_cm_start", getFieldValue(params, "yyStart"));
|
|
|
|
+ base.put("y_cm_stop", getFieldValue(params, "yyEnd"));
|
|
|
|
+ base.put("z_cm_start", getFieldValue(params, "zzStart"));
|
|
|
|
+ base.put("z_cm_stop", getFieldValue(params, "zzEnd"));
|
|
|
|
+ Map<String, Map<String, BigDecimal>> baseParent = new HashMap<>();
|
|
|
|
+ baseParent.put("base", base);
|
|
|
|
+
|
|
|
|
+ //构建安装高度
|
|
|
|
+ Map<String, BigDecimal> z_cm = new HashMap<>();
|
|
|
|
+ z_cm.put("z_cm", getFieldValue(params, "height"));
|
|
|
|
+
|
|
|
|
+ //构建跌倒确认时间
|
|
|
|
+ Map<String, Integer> fallingStateMachineDurations = new HashMap<>();
|
|
|
|
+ // 从参数中获取跌倒确认时间
|
|
|
|
+ BigDecimal fallingConfirm = getFieldValue(params, "fallingConfirm");
|
|
|
|
+ if (fallingConfirm != null && fallingConfirm.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
+ int confirmTime = fallingConfirm.intValue();
|
|
|
|
+ fallingStateMachineDurations.put("durationUntilConfirm_sec", confirmTime);
|
|
|
|
+ // minTimeOfTarInFallLoc_sec 是 durationUntilConfirm_sec的90%
|
|
|
|
+ fallingStateMachineDurations.put("minTimeOfTarInFallLoc_sec", (int)(confirmTime * 0.9));
|
|
|
|
+ // 固定默认值
|
|
|
|
+ fallingStateMachineDurations.put("durationUntilCalling_sec", 13);
|
|
|
|
+ fallingStateMachineDurations.put("durationUntilReset_sec", 3);
|
|
|
|
+ } else {
|
|
|
|
+ // 使用默认值
|
|
|
|
+ fallingStateMachineDurations.put("durationUntilConfirm_sec", 53);
|
|
|
|
+ fallingStateMachineDurations.put("minTimeOfTarInFallLoc_sec", 33);
|
|
|
|
+ fallingStateMachineDurations.put("durationUntilCalling_sec", 13);
|
|
|
|
+ fallingStateMachineDurations.put("durationUntilReset_sec", 3);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //发送最终消息
|
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
|
+ jsonObject.put("ext_region", baseParent);
|
|
|
|
+ jsonObject.put("sensor_location", z_cm);
|
|
|
|
+ jsonObject.put("fallingStateMachineDurations", fallingStateMachineDurations);
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ mqttClient.sendMessage(topic, jsonObject.toJSONString());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("发送设备参数到MQTT失败", e);
|
|
|
|
+ throw new BizException(ErrorEnum.MQTT_SEND_ERROR.getErrorCode(), ErrorEnum.MQTT_SEND_ERROR.getErrorMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 通过反射获取对象字段值
|
|
|
|
+ * @param obj 对象
|
|
|
|
+ * @param fieldName 字段名
|
|
|
|
+ * @return 字段值
|
|
|
|
+ */
|
|
|
|
+ private BigDecimal getFieldValue(Object obj, String fieldName) {
|
|
|
|
+ try {
|
|
|
|
+ Field field = obj.getClass().getDeclaredField(fieldName);
|
|
|
|
+ field.setAccessible(true);
|
|
|
|
+ return (BigDecimal) field.get(obj);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("获取字段值失败: {}", fieldName, e);
|
|
|
|
+ return BigDecimal.ZERO;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public Boolean updateDeviceLocation(DeviceLocationParams params) {
|
|
public Boolean updateDeviceLocation(DeviceLocationParams params) {
|
|
@@ -557,7 +614,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
extSubRegions.add(regionJson);
|
|
extSubRegions.add(regionJson);
|
|
}
|
|
}
|
|
JSONObject infoMsg = new JSONObject();
|
|
JSONObject infoMsg = new JSONObject();
|
|
- subRegionMsg.put("ext_sub_regions", extSubRegions);
|
|
|
|
|
|
+ infoMsg.put("ext_sub_regions", extSubRegions);
|
|
|
|
|
|
String topicDev = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, devInfo.getClientId());
|
|
String topicDev = String.format(TopicConstants.TOPIC_SET_DEVICE_PARAM, devInfo.getClientId());
|
|
try {
|
|
try {
|
|
@@ -873,11 +930,11 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public WcTimesQueryRes getWcTimes(Long clientId, String time) {
|
|
|
|
|
|
+ public WcTimesQueryRes getWcTimes(Long devId, String time) {
|
|
|
|
|
|
LocalDate inputDate = LocalDate.parse(time);
|
|
LocalDate inputDate = LocalDate.parse(time);
|
|
LocalDate tomorrow = inputDate.plusDays(1);
|
|
LocalDate tomorrow = inputDate.plusDays(1);
|
|
- List<AlarmEvent> list = alarmEventService.list(new LambdaQueryWrapper<AlarmEvent>().eq(AlarmEvent::getClientId, clientId).ge(AlarmEvent::getCreateTime, inputDate).lt(AlarmEvent::getCreateTime, tomorrow));
|
|
|
|
|
|
+ List<AlarmEvent> list = alarmEventService.list(new LambdaQueryWrapper<AlarmEvent>().eq(AlarmEvent::getDevId, devId).ge(AlarmEvent::getCreateTime, inputDate).lt(AlarmEvent::getCreateTime, tomorrow));
|
|
WcTimesQueryRes res = new WcTimesQueryRes();
|
|
WcTimesQueryRes res = new WcTimesQueryRes();
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|