|
@@ -12,7 +12,10 @@ import com.xy.dto.CommandMqtt;
|
|
|
import com.xy.dto.DeviceEventMsgDto;
|
|
|
import com.xy.dto.DeviceStatusDto;
|
|
|
import com.xy.dto.DeviceTempRecordsDto;
|
|
|
-import com.xy.entity.*;
|
|
|
+import com.xy.entity.DeviceConfig;
|
|
|
+import com.xy.entity.DeviceStatus;
|
|
|
+import com.xy.entity.DeviceSysinfo;
|
|
|
+import com.xy.entity.SysDictRedis;
|
|
|
import com.xy.mapper.DeviceStatusMapper;
|
|
|
import com.xy.mapper.entity.DeviceStatusCount;
|
|
|
import com.xy.utils.*;
|
|
@@ -58,8 +61,6 @@ public class DeviceStatusServiceImpl extends ServiceImpl<DeviceStatusMapper, Dev
|
|
|
|
|
|
private DeviceSysinfoServiceImpl deviceSysinfoService;
|
|
|
|
|
|
- private DeviceVersionUpServiceImpl deviceVersionUpService;
|
|
|
-
|
|
|
private RedisService<DeviceVersionUpServiceImpl.UpInfo> upInfoRedisService;
|
|
|
|
|
|
private MqttServiceImpl mqttService;
|
|
@@ -78,8 +79,8 @@ public class DeviceStatusServiceImpl extends ServiceImpl<DeviceStatusMapper, Dev
|
|
|
if (!Emptys.check(up.getTempValue())) {
|
|
|
return;
|
|
|
}
|
|
|
- DeviceSysinfo deviceSysinfo = deviceSysinfoService.getById(up.getDeviceId());
|
|
|
//添加设备温度日志
|
|
|
+ DeviceSysinfo deviceSysinfo = deviceSysinfoService.getById(up.getDeviceId());
|
|
|
if (!deviceSysinfo.getIsHaveTemp()) {
|
|
|
return;
|
|
|
}
|
|
@@ -123,37 +124,32 @@ public class DeviceStatusServiceImpl extends ServiceImpl<DeviceStatusMapper, Dev
|
|
|
})
|
|
|
.execute(() -> {
|
|
|
//检查是否可升级
|
|
|
- if (!Emptys.check(up.getIsUpVersion()) || !up.getIsUpVersion()) {
|
|
|
+ String appKey = up.getAppKey();
|
|
|
+ String version = up.getVersion();
|
|
|
+ if (!Emptys.check(appKey) || !Emptys.check(version)) {
|
|
|
return;
|
|
|
}
|
|
|
- DeviceVersionUpServiceImpl.UpInfo upInfo = upInfoRedisService.get(DeviceVersionUpServiceImpl.upInfoKey);
|
|
|
+ String key = String.format(DeviceVersionUpServiceImpl.upInfoKey, appKey);
|
|
|
+ DeviceVersionUpServiceImpl.UpInfo upInfo = upInfoRedisService.get(key);
|
|
|
if (upInfo == null || !upInfo.getEnable()) {
|
|
|
return;
|
|
|
}
|
|
|
- LambdaQueryWrapper<DeviceVersionUp> lambdaQueryWrapper = new LambdaQueryWrapper<DeviceVersionUp>()
|
|
|
- .eq(DeviceVersionUp::getDeviceId, up.getDeviceId())
|
|
|
- .ge(DeviceVersionUp::getDeviceVersion, upInfo.getVersion())
|
|
|
- .and(deviceVersionUpLambdaQueryWrapper -> deviceVersionUpLambdaQueryWrapper
|
|
|
- .in(DeviceVersionUp::getStatus, Arrays.asList(2, 4, 5))
|
|
|
- .or()
|
|
|
- .eq(DeviceVersionUp::getProgress, 100)
|
|
|
- );
|
|
|
- long count = deviceVersionUpService.count(lambdaQueryWrapper);
|
|
|
- if (count > 0) {
|
|
|
+ //下发升级指令
|
|
|
+ int a1 = Integer.parseInt(version.substring(0, version.lastIndexOf(".")).replaceAll("\\.", ""));
|
|
|
+ int a2 = Integer.parseInt(version.substring(version.lastIndexOf(".") + 1));
|
|
|
+ int b1 = Integer.parseInt(upInfo.getVersion().substring(0, upInfo.getVersion().lastIndexOf(".")).replaceAll("\\.", ""));
|
|
|
+ int b2 = Integer.parseInt(upInfo.getVersion().substring(upInfo.getVersion().lastIndexOf(".") + 1));
|
|
|
+ boolean isUp = (a1 < b1) || (a1 == b1 && a2 < b2);
|
|
|
+ if (!isUp) {
|
|
|
return;
|
|
|
}
|
|
|
- //下发升级指令
|
|
|
String templetStr = SysDictUtils.getValue(EnumMqttCmdTempletTask.Code.CODE.getCode(), EnumMqttCmdTempletTask.APPUPDATE.getCode(), String.class);
|
|
|
- String appId = LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getAppId);
|
|
|
- String appKey = LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getAppKey);
|
|
|
- String version = LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getVersion);
|
|
|
- String src = LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getSrc);
|
|
|
JSONObject templet = JSONUtil.parseObj(templetStr);
|
|
|
JSONObject data = templet.getJSONObject("data")
|
|
|
- .set(appId, upInfo.getAppId())
|
|
|
- .set(appKey, upInfo.getAppKey())
|
|
|
- .set(version, upInfo.getVersion())
|
|
|
- .set(src, upInfo.getSrc());
|
|
|
+ .set(LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getAppId), upInfo.getAppId())
|
|
|
+ .set(LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getAppKey), upInfo.getAppKey())
|
|
|
+ .set(LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getVersion), upInfo.getVersion())
|
|
|
+ .set(LambdaUtils.getProperty(DeviceVersionUpServiceImpl.UpInfo::getSrc), upInfo.getSrc());
|
|
|
templet.set("data", data);
|
|
|
CommandMqtt commandMqtt = new CommandMqtt()
|
|
|
.setDeviceId(up.getDeviceId())
|