parent
689c39d829
commit
eef1b021c0
@ -1,27 +1,73 @@
|
|||||||
package com.ruoyi.dataprocess.service.impl;
|
package com.ruoyi.dataprocess.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.constant.TdEngineConstants;
|
||||||
|
import com.ruoyi.dataprocess.domain.HwDevice;
|
||||||
|
import com.ruoyi.dataprocess.mapper.HwDeviceMapper;
|
||||||
import com.ruoyi.dataprocess.service.IDeviceStatusService;
|
import com.ruoyi.dataprocess.service.IDeviceStatusService;
|
||||||
import com.ruoyi.tdengine.api.RemoteTdEngineService;
|
import com.ruoyi.tdengine.api.RemoteTdEngineService;
|
||||||
|
import com.ruoyi.tdengine.api.domain.TdField;
|
||||||
|
import com.ruoyi.tdengine.api.domain.TdTableVo;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Description: 设备状态处理服务
|
* @Description: 设备状态处理服务
|
||||||
* @ClassName: DeviceStatusServiceImpl
|
* @ClassName: DeviceStatusServiceImpl
|
||||||
* @Author : xins
|
* @Author : xins
|
||||||
* @Date :2023-09-04 15:31
|
* @Date :2023-09-04 15:31
|
||||||
* @Version :1.0
|
* @Version :1.0
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class DeviceStatusServiceImpl implements IDeviceStatusService {
|
public class DeviceStatusServiceImpl implements IDeviceStatusService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private HwDeviceMapper hwDeviceMapper;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RemoteTdEngineService remoteTdEngineService;
|
private RemoteTdEngineService remoteTdEngineService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleDeviceStatus(){
|
public void handleDeviceStatus(String payloadString, String clientId) {
|
||||||
|
System.out.println("ddd:" + payloadString);
|
||||||
|
// ddd:{"msg":"设备设备连接状态信息","deviceType":"edge","connectStatus":1,
|
||||||
|
// "statusTime":1694506127199,"deviceCode":"hw-data-process-1"}
|
||||||
|
JSONObject json = JSON.parseObject(payloadString);
|
||||||
|
String deviceCode = json.getString("deviceCode");
|
||||||
|
if (clientId.equals(deviceCode)) { //校验是不是自己,如果是自己则不记录状态,返回即可。
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode);
|
||||||
|
if (hwDevice != null) {
|
||||||
|
Long deviceId = hwDevice.getDeviceId();
|
||||||
|
TdTableVo tdTableVo = new TdTableVo();
|
||||||
|
tdTableVo.setDatabaseName(TdEngineConstants.PLATFORM_DB_NAME);
|
||||||
|
tdTableVo.setTableName(TdEngineConstants.DEFAULT_DEVICE_STATUS_TABLE_NAME_PREFIX + deviceId);
|
||||||
|
|
||||||
|
List<TdField> schemaFields = new ArrayList<>();
|
||||||
|
TdField onlineStatusField = new TdField();
|
||||||
|
onlineStatusField.setFieldName("onlineStatus");
|
||||||
|
onlineStatusField.setFieldValue(json.getInteger("connectStatus"));
|
||||||
|
schemaFields.add(onlineStatusField);
|
||||||
|
|
||||||
|
TdField deviceTypeField = new TdField();
|
||||||
|
deviceTypeField.setFieldName("deviceType");
|
||||||
|
deviceTypeField.setFieldValue(json.getString("deviceType"));
|
||||||
|
schemaFields.add(deviceTypeField);
|
||||||
|
|
||||||
|
TdField tsField = new TdField();
|
||||||
|
tsField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
|
||||||
|
tsField.setFieldValue(json.getLong("statusTime"));
|
||||||
|
schemaFields.add(tsField);
|
||||||
|
|
||||||
|
tdTableVo.setSchemaFields(schemaFields);
|
||||||
|
|
||||||
System.out.println("handleDeviceStatus");
|
this.remoteTdEngineService.insertTable(tdTableVo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue