|
@@ -1,10 +1,8 @@
|
|
|
package cn.iocoder.yudao.module.pms.job;
|
|
package cn.iocoder.yudao.module.pms.job;
|
|
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
|
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
|
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
|
|
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
|
|
|
-import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
|
|
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
@@ -12,6 +10,8 @@ import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
|
|
import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -19,11 +19,7 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.sql.Timestamp;
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
|
@Slf4j
|
|
@Slf4j
|
|
@@ -41,26 +37,67 @@ public class TdCronJob implements JobHandler {
|
|
|
@TenantIgnore
|
|
@TenantIgnore
|
|
|
public String execute(String param) throws Exception {
|
|
public String execute(String param) throws Exception {
|
|
|
List<String> codes = new ArrayList<>();
|
|
List<String> codes = new ArrayList<>();
|
|
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice();
|
|
List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice();
|
|
|
allDevice.forEach(d -> {
|
|
allDevice.forEach(d -> {
|
|
|
codes.add(d.getSerialNumber());
|
|
codes.add(d.getSerialNumber());
|
|
|
});
|
|
});
|
|
|
List<IotDeviceDO> devices = iotDeviceMapper.selectByCodeIn(codes);
|
|
List<IotDeviceDO> devices = iotDeviceMapper.selectByCodeIn(codes);
|
|
|
|
|
+
|
|
|
List<IotDeviceDO> deviceDOS = new ArrayList<>();
|
|
List<IotDeviceDO> deviceDOS = new ArrayList<>();
|
|
|
|
|
+ List<String> allTableNames = deviceMapper.getAllTableNames();
|
|
|
for (IotDeviceDO device : devices) {
|
|
for (IotDeviceDO device : devices) {
|
|
|
String deviceCode = device.getDeviceCode();
|
|
String deviceCode = device.getDeviceCode();
|
|
|
allDevice.stream().filter(e -> e.getSerialNumber().equals(deviceCode)).findFirst().ifPresent(e -> {
|
|
allDevice.stream().filter(e -> e.getSerialNumber().equals(deviceCode)).findFirst().ifPresent(e -> {
|
|
|
device.setYfDeviceId(e.getDeviceId());
|
|
device.setYfDeviceId(e.getDeviceId());
|
|
|
- Integer i = deviceMapper.tableIfExist(e.getSerialNumber().toLowerCase());
|
|
|
|
|
- if (i==1) {
|
|
|
|
|
- List<DeviceVO> deviceVOS = deviceMapper.selectLastTime(e.getSerialNumber());
|
|
|
|
|
- if (CollUtil.isNotEmpty(deviceVOS)) {
|
|
|
|
|
- Timestamp ts = deviceVOS.get(0).getTs();
|
|
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
- String format = sdf.format(ts);
|
|
|
|
|
- device.setLastInlineTime(format);
|
|
|
|
|
|
|
+// Integer i = deviceMapper.tableIfExist(e.getSerialNumber().toLowerCase());
|
|
|
|
|
+ if (allTableNames.contains("device_"+e.getSerialNumber().toLowerCase())) {//如果存在表
|
|
|
|
|
+ Map<Object, Object> hashAll = redisTemplate.opsForHash().entries("TSLV:"+e.getProductId()+"_"+e.getSerialNumber());
|
|
|
|
|
+
|
|
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
|
|
+ String timestamp = "";
|
|
|
|
|
+ for (Map.Entry<Object, Object> entry : hashAll.entrySet()) {
|
|
|
|
|
+ String paramId = entry.getKey().toString(); // "1003"
|
|
|
|
|
+ String jsonStr = entry.getValue().toString(); // "{\"id\":\"1003\",\"ts\":\"...\"}"
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ JsonNode node = objectMapper.readTree(jsonStr);
|
|
|
|
|
+ if (node.isTextual()) {
|
|
|
|
|
+ node = objectMapper.readTree(node.asText()); // 处理双重转义
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (node.has("ts")) {
|
|
|
|
|
+ String ts = node.get("ts").asText();
|
|
|
|
|
+ timestamp = ts;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception f) {
|
|
|
|
|
+ f.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (StringUtils.isNotBlank(timestamp)) {
|
|
|
|
|
+ device.setLastInlineTime(timestamp);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// List<DeviceVO> deviceVOS = deviceMapper.selectLastTime(e.getSerialNumber());
|
|
|
|
|
+// if (CollUtil.isNotEmpty(deviceVOS)) {
|
|
|
|
|
+// Timestamp ts = deviceVOS.get(0).getTs();
|
|
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+// String format = sdf.format(ts);
|
|
|
|
|
+// device.setLastInlineTime(format);
|
|
|
|
|
+// }
|
|
|
}
|
|
}
|
|
|
|
|
+// if (i==1) {
|
|
|
|
|
+// List<DeviceVO> deviceVOS = deviceMapper.selectLastTime(e.getSerialNumber());
|
|
|
|
|
+// if (CollUtil.isNotEmpty(deviceVOS)) {
|
|
|
|
|
+// Timestamp ts = deviceVOS.get(0).getTs();
|
|
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
+// String format = sdf.format(ts);
|
|
|
|
|
+// device.setLastInlineTime(format);
|
|
|
|
|
+// }
|
|
|
|
|
+// }
|
|
|
if (e.getStatus()==1) {//未激活状态
|
|
if (e.getStatus()==1) {//未激活状态
|
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(device.getLastInlineTime())) {
|
|
if (StringUtils.isNotBlank(device.getLastInlineTime())) {
|