若依微服务1.3.5

1、监控平台接口修改
2、tdengine服务,修改tdengine新版本last(*)显示问题。
master
xins 2 years ago
parent 4c049995a1
commit 5b2f578c9b

@ -1,6 +1,5 @@
package com.ruoyi.tdengine.api; package com.ruoyi.tdengine.api;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn;
@ -11,7 +10,6 @@ import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -47,7 +45,7 @@ public interface RemoteTdEngineService {
R<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo); R<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo);
@PostMapping("/tdengine/getHistoryData") @PostMapping("/tdengine/getHistoryData")
R<List<Map<String, Object>>> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); R<TdReturnDataVo> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto);
@PostMapping("/tdengine/getCountOfHistoryData") @PostMapping("/tdengine/getCountOfHistoryData")
R<?> getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); R<?> getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto);

@ -0,0 +1,13 @@
package com.ruoyi.tdengine.api.domain;
import lombok.Data;
import java.util.List;
import java.util.Map;
@Data
public class TdReturnDataVo {
public int count;
public List<Map<String, Object>> dataList;
}

@ -4,6 +4,7 @@ import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotEmpty;
import java.util.List;
/** /**
* @Description: TDengine * @Description: TDengine
@ -29,5 +30,6 @@ public class TdSelectDto {
//tags名称 //tags名称
private String tagsName; private String tagsName;
private List<TdField> schemaFieldValues;
} }

@ -3,6 +3,7 @@ package com.ruoyi.tdengine.api.domain;
import lombok.Data; import lombok.Data;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import java.util.List;
/** /**
* @Description: * @Description:
@ -46,4 +47,6 @@ public class TdSuperTableSelectVo {
private String deviceName; private String deviceName;
private List<TdField> schemaFieldValues;
} }

@ -1,5 +1,6 @@
package com.ruoyi.tdengine.api.factory; package com.ruoyi.tdengine.api.factory;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.*; import com.ruoyi.tdengine.api.domain.*;
@ -72,7 +73,7 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory<RemoteTdEn
} }
@Override @Override
public R<List<Map<String, Object>>> getHistoryData(TdHistorySelectDto tdHistorySelectDto) { public R<TdReturnDataVo> getHistoryData(TdHistorySelectDto tdHistorySelectDto) {
return R.fail("获取历史数据失败:" + throwable.getMessage()); return R.fail("获取历史数据失败:" + throwable.getMessage());
} }

@ -33,8 +33,12 @@ public class HwDictConstants {
public static final String FUNCTION_MODE_SERVICE = "2";//设备模型功能模式服务 public static final String FUNCTION_MODE_SERVICE = "2";//设备模型功能模式服务
public static final String FUNCTION_MODE_EVENT = "3";//设备模型功能模式事件 public static final String FUNCTION_MODE_EVENT = "3";//设备模型功能模式事件
public static final String DEVICE_STATUS_PUBLISH = "1";//设备状态:已发布 public static final String RW_FLAG_RW = "1";//读写
public static final String RW_FLAG_READ = "2";//只读
public static final String DEVICE_STATUS_PUBLISH = "1";//设备状态:已发布
public static final String DEVICE_STATUS_TEST = "0";//设备状态:已发布
public static final String DEVICE_STATUS_DELETE = "9";//设备状态:已发布
public static final String FENCE_TYPE_DEVICE = "1";//电子围栏规则类型,设备 public static final String FENCE_TYPE_DEVICE = "1";//电子围栏规则类型,设备
public static final String FENCE_TYPE_MONITOR_UNIT = "2";//电子围栏规则类型,监控单元 public static final String FENCE_TYPE_MONITOR_UNIT = "2";//电子围栏规则类型,监控单元
public static final String FENCE_TYPE_SCENE = "3";//电子围栏规则类型,场景 public static final String FENCE_TYPE_SCENE = "3";//电子围栏规则类型,场景

@ -71,6 +71,7 @@ public class TdEngineConstants {
static { static {
DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICECODE, "设备编号"); DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICECODE, "设备编号");
DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICENAME, "设备名称"); DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICENAME, "设备名称");
DEVICE_DATA_COLUMN_MAP.put(DEFAULT_FIRST_FIELD_NAME, "时间");
} }
/** /**

@ -11,6 +11,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.tdengine.api.domain.TdReturnDataVo;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -89,7 +90,7 @@ public class HwMonitorPlatformController extends BaseController {
@PutMapping("/handleAlarmInfo") @PutMapping("/handleAlarmInfo")
@RequiresPermissions("business:monitor:alarm") @RequiresPermissions("business:monitor:alarm")
public AjaxResult handleAlarmInfo(@RequestBody HwAlarmInfo hwAlarmInfo){ public AjaxResult handleAlarmInfo(@RequestBody HwAlarmInfo hwAlarmInfo) {
hwAlarmInfo.setUpdateBy(SecurityUtils.getUsername()); hwAlarmInfo.setUpdateBy(SecurityUtils.getUsername());
return toAjax(hwAlarmInfoService.updateHwAlarmInfo(hwAlarmInfo)); return toAjax(hwAlarmInfoService.updateHwAlarmInfo(hwAlarmInfo));
} }
@ -221,7 +222,7 @@ public class HwMonitorPlatformController extends BaseController {
} }
/** /**
* ID * ID
* *
* @param monitorUnitId id * @param monitorUnitId id
*/ */
@ -237,6 +238,14 @@ public class HwMonitorPlatformController extends BaseController {
} }
@RequiresPermissions("business:monitor:deviceMonitor")
@PostMapping("/publishControlCommand")
public AjaxResult publishControlCommand(@RequestBody DeviceControlVo deviceControlVo) {
hwDeviceService.publishControlCommand(deviceControlVo);
return success();
}
/** /**
* @description ID() * @description ID()
* @author xins * @author xins
@ -258,14 +267,10 @@ public class HwMonitorPlatformController extends BaseController {
@RequiresPermissions("business:monitor:deviceList") @RequiresPermissions("business:monitor:deviceList")
@PostMapping("/selectLatestDataByDeviceMode") @PostMapping("/selectLatestDataByDeviceMode")
public AjaxResult selectLatestDataByDeviceMode(@Validated @RequestBody DeviceLatestDataVo deviceLatestData) { public AjaxResult selectLatestDataByDeviceMode(@Validated @RequestBody DeviceLatestDataVo deviceLatestData) {
JSONObject returnObj = new JSONObject(); JSONObject returnObj = hwMonitorPlatformService.selectLatestDataByTags(deviceLatestData);
List<Map<String, Object>> latestDataMaps = hwMonitorPlatformService.selectLatestDataByTags(deviceLatestData);
List<DeviceDataColumnVo> deviceDataColumnVos = this.getDeviceDataColumns(latestDataMaps);
// TableDataInfo tableDataInfo = getDataTable(latestDataMaps);
returnObj.put("deviceDataColumns", deviceDataColumnVos);
returnObj.put("latestData", latestDataMaps);
return success(returnObj); return success(returnObj);
} }
@RequiresPermissions("business:monitor:deviceInfo") @RequiresPermissions("business:monitor:deviceInfo")
@GetMapping("/getDeviceInfo/{deviceId}") @GetMapping("/getDeviceInfo/{deviceId}")
public AjaxResult getDeviceInfo(@PathVariable("deviceId") Long deviceId) { public AjaxResult getDeviceInfo(@PathVariable("deviceId") Long deviceId) {
@ -289,32 +294,19 @@ public class HwMonitorPlatformController extends BaseController {
@RequiresPermissions("business:monitor:deviceInfo") @RequiresPermissions("business:monitor:deviceInfo")
@PostMapping("/getHistoryData") @PostMapping("/getHistoryData")
public AjaxResult getHistoryData(@Validated @RequestBody DeviceHistoryDataVo deviceHistoryData) { public AjaxResult getHistoryData(@Validated @RequestBody DeviceHistoryDataVo deviceHistoryData) {
// startPage();
JSONObject returnObj = new JSONObject(); JSONObject returnObj = new JSONObject();
List<Map<String, Object>> historyDataMaps = hwMonitorPlatformService.getHistoryData(deviceHistoryData); TdReturnDataVo returnDataVo = hwMonitorPlatformService.getHistoryData(deviceHistoryData);
List<DeviceDataColumnVo> deviceDataColumnVos = this.getDeviceDataColumns(historyDataMaps); if (returnDataVo != null) {
TableDataInfo tableDataInfo = getDataTable(historyDataMaps); List<DeviceDataColumnVo> deviceDataColumnVos = hwMonitorPlatformService.
getDeviceDataColumns(deviceHistoryData.getDeviceModeId(), returnDataVo.getDataList());
returnObj.put("deviceDataColumns", deviceDataColumnVos); returnObj.put("deviceDataColumns", deviceDataColumnVos);
returnObj.put("historyData", tableDataInfo); returnObj.put("historyData", returnDataVo);
}
return success(returnObj); return success(returnObj);
} }
private List<DeviceDataColumnVo> getDeviceDataColumns(List<Map<String, Object>> latestDataMaps) {
List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
if (latestDataMaps != null && latestDataMaps.size() > 0) {
Map<String, Object> latestDataMap = latestDataMaps.get(0);
for (Map.Entry<String, Object> entry : latestDataMap.entrySet()) {
DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo();
String columnKey = entry.getKey();
deviceDataColumnVo.setColumnKey(columnKey);
deviceDataColumnVo.setColumnName(TdEngineConstants.DEVICE_DATA_COLUMN_MAP.get(columnKey) == null
? columnKey : TdEngineConstants.DEVICE_DATA_COLUMN_MAP.get(columnKey));
deviceDataColumnVos.add(deviceDataColumnVo);
}
}
return deviceDataColumnVos;
}
/** /**
* *

@ -0,0 +1,20 @@
package com.ruoyi.business.domain.VO;
import lombok.Data;
/**
* @Description:
* @ClassName: DeviceControlVo
* @Author : xins
* @Date :2023-09-25 14:53
* @Version :1.0
*/
@Data
public class DeviceControlVo {
private Long deviceId;
private Long deviceModeFunctionId;
private String deviceCode;
private String type;
private Long timestamp;
private String params;//json格式
}

@ -21,6 +21,8 @@ public class DeviceHistoryDataVo {
@NotNull(message="deviceId cannot be null") @NotNull(message="deviceId cannot be null")
private Long deviceId; private Long deviceId;
private Long deviceModeId;
private int limit; private int limit;
//指定从第几条之后输出例如limit 2,5输出第3行到第7行的数据 //指定从第几条之后输出例如limit 2,5输出第3行到第7行的数据

@ -1,37 +1,29 @@
package com.ruoyi.business.domain.VO; package com.ruoyi.business.domain.VO;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import lombok.Data;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
/**
* @Description:
* @ClassName: HwDeviceVo
* @Author : xins
* @Date :2023-09-25 15:26
* @Version :1.0
*/
@Data
public class HwDeviceVo { public class HwDeviceVo {
private Long deviceId;
private String deviceCode;
private String deviceType;//1、开关属性控制属性2、只有采集属性 private String deviceType;//1、开关属性控制属性2、只有采集属性
private String deviceName; private String deviceName;
private List<Map<String, Object>> deviceDataMaps; private Long deviceModeId;
private Map<String, Object> deviceDataMap;//监测数据
private HwDeviceModeFunction deviceModeFunction;
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public List<Map<String, Object>> getDeviceDataMaps() {
return deviceDataMaps;
}
public void setDeviceDataMaps(List<Map<String, Object>> deviceDataMaps) {
this.deviceDataMaps = deviceDataMaps;
}
} }

@ -5,6 +5,7 @@ import java.util.Map;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.VO.DeviceControlVo;
import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo; import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.domain.VO.HwMonitorUnitVo; import com.ruoyi.business.domain.VO.HwMonitorUnitVo;
@ -122,4 +123,12 @@ public interface IHwDeviceService
* @return JSONObject * @return JSONObject
*/ */
public JSONObject getOnlineDevicesCount(Long sceneId); public JSONObject getOnlineDevicesCount(Long sceneId);
/**
* @param: deviceControlVo
* @description
* @author xins
* @date 2023-09-25 14:56
*/
public void publishControlCommand(DeviceControlVo deviceControlVo);
} }

@ -1,7 +1,10 @@
package com.ruoyi.business.service; package com.ruoyi.business.service;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.business.domain.VO.DeviceDataColumnVo;
import com.ruoyi.business.domain.VO.DeviceHistoryDataVo; import com.ruoyi.business.domain.VO.DeviceHistoryDataVo;
import com.ruoyi.business.domain.VO.DeviceLatestDataVo; import com.ruoyi.business.domain.VO.DeviceLatestDataVo;
import com.ruoyi.tdengine.api.domain.TdReturnDataVo;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,16 +23,26 @@ public interface IHwMonitorPlatformService {
* @description * @description
* @author xins * @author xins
* @date 2023-09-16 14:49 * @date 2023-09-16 14:49
* @return List<Map<Object>> * @return JSONObject
*/ */
public List<Map<String, Object>> selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo); public JSONObject selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo);
/** /**
* @param: deviceHistoryDataVo * @param: deviceHistoryDataVo
* @description * @description
* @author xins * @author xins
* @date 2023-09-16 15:14 * @date 2023-09-16 15:14
* @return List<Map<Object>> * @return TdReturnDataVo
*/ */
public List<Map<String, Object>> getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo); public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo);
/**
* @return List<DeviceDataColumnVo>
* @param: deviceModeId
* @param: latestDataMaps
* @description
* @author xins
* @date 2023-09-25 15:40
*/
public List<DeviceDataColumnVo> getDeviceDataColumns(Long deviceModeId, List<Map<String, Object>> latestDataMaps);
} }

@ -111,19 +111,26 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService {
*/ */
@Override @Override
public List<AlarmTypeVo> selectAlarmsByAlarmType(Long sceneId) { public List<AlarmTypeVo> selectAlarmsByAlarmType(Long sceneId) {
//根据报警类型id group获取报警信息
List<AlarmTypeVo> list = hwAlarmInfoMapper.selectAlarmsByAlarmType(sceneId); List<AlarmTypeVo> list = hwAlarmInfoMapper.selectAlarmsByAlarmType(sceneId);
//获取报警类型并转成map
HwAlarmType queryAlarmType = new HwAlarmType(); HwAlarmType queryAlarmType = new HwAlarmType();
queryAlarmType.setSceneId(sceneId); queryAlarmType.setSceneId(sceneId);
List<HwAlarmType> alarmTypes = hwAlarmTypeMapper.selectHwAlarmTypeList(queryAlarmType); List<HwAlarmType> alarmTypes = hwAlarmTypeMapper.selectHwAlarmTypeList(queryAlarmType);
Map<Long, HwAlarmType> alarmTypeMap = alarmTypes.stream() Map<Long, HwAlarmType> alarmTypeMap = alarmTypes.stream()
.collect(Collectors.toMap(HwAlarmType::getAlarmTypeId, alarmType -> alarmType)); .collect(Collectors.toMap(HwAlarmType::getAlarmTypeId, alarmType -> alarmType));
//从数据库根据alarmtype group获取的报警信息循环去设置报警类型名称
list.stream().forEach(alarmType -> { list.stream().forEach(alarmType -> {
if (alarmType.getAlarmTypeId() != null) {
alarmType.setAlarmTypeName(alarmTypeMap.get(alarmType.getAlarmTypeId()) == null ? "" alarmType.setAlarmTypeName(alarmTypeMap.get(alarmType.getAlarmTypeId()) == null ? ""
: alarmTypeMap.get(alarmType.getAlarmTypeId()).getAlarmTypeName()); : alarmTypeMap.get(alarmType.getAlarmTypeId()).getAlarmTypeName());
alarmTypeMap.remove(alarmType.getAlarmTypeId()); alarmTypeMap.remove(alarmType.getAlarmTypeId());
}
}); });
//以下是补齐其他报警类型没有报警的数据报警数量为0.
Set<Long> alarmTypeIds = alarmTypeMap.keySet(); Set<Long> alarmTypeIds = alarmTypeMap.keySet();
for (Long alarmTypeId : alarmTypeIds) { for (Long alarmTypeId : alarmTypeIds) {
HwAlarmType alarmType = alarmTypeMap.get(alarmTypeId); HwAlarmType alarmType = alarmTypeMap.get(alarmTypeId);
@ -133,8 +140,6 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService {
alarmTypeVo.setAlarmCount(0); alarmTypeVo.setAlarmCount(0);
list.add(alarmTypeVo); list.add(alarmTypeVo);
} }
return list; return list;
} }
} }

@ -7,6 +7,7 @@ import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.HwDeviceModeFunction; import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.HwScene; import com.ruoyi.business.domain.HwScene;
import com.ruoyi.business.domain.VO.DeviceControlVo;
import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo; import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.mapper.HwDeviceMapper; import com.ruoyi.business.mapper.HwDeviceMapper;
@ -97,7 +98,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
*/ */
@Override @Override
public List<HwDevice> selectLinkDeviceList(Long deviceId) { public List<HwDevice> selectLinkDeviceList(Long deviceId) {
return hwDeviceMapper.selectLinkedDevices(deviceId); List<HwDevice> devices = hwDeviceMapper.selectLinkedDevices(deviceId);
for (HwDevice device : devices) {
device.setDevicePic("http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg");
}
return devices;
} }
/** /**
@ -404,45 +409,95 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
Long sceneId = queryHwDevice.getSceneId(); Long sceneId = queryHwDevice.getSceneId();
String databaseName = TdEngineConstants.getDatabaseName(sceneId); String databaseName = TdEngineConstants.getDatabaseName(sceneId);
queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT);
List<HwDevice> hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice); List<HwDevice> hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice);
hwDevices.forEach(hwDevice -> { hwDevices.forEach(hwDevice -> {
Long deviceId = hwDevice.getDeviceId(); Long deviceId = hwDevice.getDeviceId();
HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction();
queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId());
List<HwDeviceModeFunction> deviceModeFunctions = hwDevieModeFunctionMapper.selectHwDeviceModeFunctionList(queryDeviceModeFunction);
String tableName = TdEngineConstants.getDeviceDataTableName(deviceId); String tableName = TdEngineConstants.getDeviceDataTableName(deviceId);
TdSelectDto tdSelectDto = new TdSelectDto(); TdSelectDto tdSelectDto = new TdSelectDto();
tdSelectDto.setDatabaseName(databaseName); tdSelectDto.setDatabaseName(databaseName);
tdSelectDto.setTableName(tableName); tdSelectDto.setTableName(tableName);
List<Map<String, Object>> deviceLatestDataMapList = (List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData(); List<TdField> schemaFieldValues = new ArrayList<TdField>();
List<HwDeviceModeFunction> modeFunctions = new ArrayList<>();
HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction(); deviceModeFunctions.forEach(mf -> {
queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId()); if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
List<HwDeviceModeFunction> deviceModeFunctions = hwDevieModeFunctionMapper.selectHwDeviceModeFunctionList(queryDeviceModeFunction); TdField field = new TdField();
List<HwDeviceModeFunction> dds = deviceModeFunctions.stream() field.setFieldName(mf.getFunctionIdentifier());
.filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE) schemaFieldValues.add(field);
&& dmf.getDataType() != null && String.valueOf(dmf.getDataType()).equals(String.valueOf(DataTypeEnums.TINYINT.getDataCode()))).collect(Collectors.toList()); } else if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)) {
modeFunctions.add(mf);
HwDeviceVo hwDeviceVo = new HwDeviceVo();
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
if (dds != null && dds.size() > 0) {
hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE);
HwDeviceModeFunction dd = dds.get(0);
List<Map<String, Object>> ddValueMapList = new ArrayList<Map<String, Object>>();
Map<String, Object> ddValueMap = new HashMap<String, Object>();
deviceLatestDataMapList.forEach(deviceLatestDataMap -> {
ddValueMap.put(dd.getFunctionIdentifier(), deviceLatestDataMap.get(dd.getFunctionIdentifier()) == null
? 0 : deviceLatestDataMap.get(dd.getFunctionIdentifier()));
});
ddValueMapList.add(ddValueMap);
hwDeviceVo.setDeviceDataMaps(ddValueMapList);
controlDeviceVos.add(hwDeviceVo);
} else {
hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE);
hwDeviceVo.setDeviceDataMaps(deviceLatestDataMapList);
acquisitionDeviceVos.add(hwDeviceVo);
} }
});
tdSelectDto.setSchemaFieldValues(schemaFieldValues);
//从tdengine获取此设备的最新数据
List<Map<String, Object>> deviceLatestDataMapList =
(List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData();
//获取此设备模型的功能列表
//获取可控制设备根据功能是属性的并且属性的数据类型是tinyint类型的bool类型开关就是用tinyint并且是读写的
// List<HwDeviceModeFunction> dds = deviceModeFunctions.stream()
// .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)
// && dmf.getDataType() != null
// && String.valueOf(dmf.getDataType())
// .equals(String.valueOf(DataTypeEnums.TINYINT.getDataCode()))
// && dmf.getRwFlag()!=null
// && dmf.getRwFlag().equals(HwDictConstants.RW_FLAG_RW)
// ).collect(Collectors.toList());
//转换成mapkey为标识符value为功能名称主要tdengine存的是标识符用来下面转换成功能名称
Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect(
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName));
//获取可控制设备,根据是否有服务判断
// List<HwDeviceModeFunction> modeFunctions = deviceModeFunctions.stream()
// .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)
// ).collect(Collectors.toList());
if (modeFunctions != null && modeFunctions.size() > 0) {
modeFunctions.forEach(modeFunction -> {
HwDeviceVo hwDeviceVo = new HwDeviceVo();
hwDeviceVo.setDeviceId(deviceId);
hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE);
hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode());
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
hwDeviceVo.setDeviceModeFunction(modeFunction);
controlDeviceVos.add(hwDeviceVo);
});
}
//将functionIdetifier转换成功能名称
Map<String, Object> ddValueMap = new HashMap<String, Object>();
if (deviceLatestDataMapList != null) {
deviceLatestDataMapList.forEach(deviceLatestDataMap -> {
Set<String> functionIdentifiers = deviceLatestDataMap.keySet();
for (String dataFunctionIdentifier : functionIdentifiers) {
if (functionIndentifierName.get(dataFunctionIdentifier) != null) {
ddValueMap.put(functionIndentifierName.get(dataFunctionIdentifier),
deviceLatestDataMap.get(dataFunctionIdentifier));
}
}
});
}
//不论是否是控制型设备都显示最新数据
HwDeviceVo hwDeviceVo = new HwDeviceVo();
hwDeviceVo.setDeviceId(deviceId);
hwDeviceVo.setDeviceModeId(hwDevice.getDeviceModeId());
hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode());
hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE);
hwDeviceVo.setDeviceDataMap(ddValueMap);
//TODO:去掉下边一行
ddValueMap.put("ii", "http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg");
acquisitionDeviceVos.add(hwDeviceVo);
}); });
devicesMap.put(HwDictConstants.CONTROL_DEVICE_NAME, controlDeviceVos); devicesMap.put(HwDictConstants.CONTROL_DEVICE_NAME, controlDeviceVos);
@ -494,7 +549,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
jsonObject.put(String.valueOf(key), onlineDeviceCountPerDay.get(key)); jsonObject.put(String.valueOf(key), onlineDeviceCountPerDay.get(key));
} }
} }
redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO,jsonObject.toString()); redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO, jsonObject.toString());
} }
private Map<Long, Integer> computeDeviceCountPerDay(Long startTime, Long endTime) { private Map<Long, Integer> computeDeviceCountPerDay(Long startTime, Long endTime) {
@ -562,32 +617,45 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
/** /**
* @return String
* @param: sceneId * @param: sceneId
* @description 线 * @description 线
* @author xins * @author xins
* @date 2023-09-21 9:09 * @date 2023-09-21 9:09
* @return String
*/ */
@Override @Override
public JSONObject getOnlineDevicesCount(Long sceneId){ public JSONObject getOnlineDevicesCount(Long sceneId) {
JSONObject returnObj = new JSONObject(); JSONObject returnObj = new JSONObject();
int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId); int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId);
JSONObject sortedJsonObject = new JSONObject();
String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO); String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO);
if (onlineDeviceCountJsonStr != null) {
JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr); JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr);
JSONObject sortedJsonObject = new JSONObject(); jsonObject.forEach((key, value) -> {
jsonObject.forEach((key,value) ->{ String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD, new Date(Long.parseLong(key)));
String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD,new Date(Long.parseLong(key))); sortedJsonObject.put(dateStrKey, value);
sortedJsonObject.put(dateStrKey,value);
}); });
returnObj.put("onlineDevicesTrend",sortedJsonObject); }
returnObj.put("onlineDevicesCount",onlineDevicesCount);
returnObj.put("onlineDevicesTrend", sortedJsonObject);
returnObj.put("onlineDevicesCount", onlineDevicesCount);
return returnObj; return returnObj;
} }
public void publishContrlCommand(String channel,String message){ /**
redisTemplate.convertAndSend(channel,message); * @param: deviceControlVo
* @description
* @author xins
* @date 2023-09-25 14:56
*/
@Override
public void publishControlCommand(DeviceControlVo deviceControlVo) {
String channel = "";
String message = "";
redisTemplate.convertAndSend(channel, message);
} }
} }

@ -1,20 +1,27 @@
package com.ruoyi.business.service.impl; package com.ruoyi.business.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.VO.DeviceDataColumnVo; import com.ruoyi.business.domain.VO.DeviceDataColumnVo;
import com.ruoyi.business.domain.VO.DeviceHistoryDataVo; import com.ruoyi.business.domain.VO.DeviceHistoryDataVo;
import com.ruoyi.business.domain.VO.DeviceLatestDataVo; import com.ruoyi.business.domain.VO.DeviceLatestDataVo;
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
import com.ruoyi.business.service.IHwMonitorPlatformService; import com.ruoyi.business.service.IHwMonitorPlatformService;
import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.common.core.constant.TdEngineConstants;
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.TdHistorySelectDto; import com.ruoyi.tdengine.api.domain.TdHistorySelectDto;
import com.ruoyi.tdengine.api.domain.TdReturnDataVo;
import com.ruoyi.tdengine.api.domain.TdSuperTableSelectVo; import com.ruoyi.tdengine.api.domain.TdSuperTableSelectVo;
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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @Description: * @Description:
@ -28,18 +35,31 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
@Resource @Resource
private RemoteTdEngineService remoteTdEngineService; private RemoteTdEngineService remoteTdEngineService;
@Autowired
private HwDeviceModeFunctionMapper deviceModeFunctionMapper;
/** /**
* @return List<Map < Object>> * @return JSONObject
* @param: deviceLatestDataVo * @param: deviceLatestDataVo
* @description * @description
* @author xins * @author xins
* @date 2023-09-16 14:49 * @date 2023-09-16 14:49
*/ */
@Override @Override
public List<Map<String, Object>> selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo) { public JSONObject selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo) {
JSONObject returnObj = new JSONObject();
Long deviceModeId = deviceLatestDataVo.getDeviceModeId();
HwDeviceModeFunction queryModeFunction = new HwDeviceModeFunction();
queryModeFunction.setDeviceModeId(deviceModeId);
queryModeFunction.setFunctionMode(HwDictConstants.FUNCTION_MODE_ATTRIBUTE);
List<HwDeviceModeFunction> deviceModeFunctions = deviceModeFunctionMapper.selectHwDeviceModeFunctionList(queryModeFunction);
Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect(
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName));
functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP);
TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo(); TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo();
String databaseName = TdEngineConstants.getDatabaseName(deviceLatestDataVo.getSceneId()); String databaseName = TdEngineConstants.getDatabaseName(deviceLatestDataVo.getSceneId());
String superTableName = TdEngineConstants.getSuperTableName(deviceLatestDataVo.getDeviceModeId()); String superTableName = TdEngineConstants.getSuperTableName(deviceModeId);
tdSuperTableSelectVo.setDatabaseName(databaseName); tdSuperTableSelectVo.setDatabaseName(databaseName);
tdSuperTableSelectVo.setSuperTableName(superTableName); tdSuperTableSelectVo.setSuperTableName(superTableName);
tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICECODE);//todo,换成deviceid tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICECODE);//todo,换成deviceid
@ -52,20 +72,53 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
tdSuperTableSelectVo.setEndTime(deviceLatestDataVo.getEndTime()); tdSuperTableSelectVo.setEndTime(deviceLatestDataVo.getEndTime());
tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset()); tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset());
tdSuperTableSelectVo.setLimit(deviceLatestDataVo.getLimit()); tdSuperTableSelectVo.setLimit(deviceLatestDataVo.getLimit());
return this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData();
List<TdField> schemaFieldValues = new ArrayList<TdField>();
List<HwDeviceModeFunction> modeFunctions = new ArrayList<>();
deviceModeFunctions.forEach(mf -> {
TdField field = new TdField();
field.setFieldName(mf.getFunctionIdentifier());
schemaFieldValues.add(field);
});
tdSuperTableSelectVo.setSchemaFieldValues(schemaFieldValues);
List<Map<String, Object>> latestDataMaps =
this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData();
List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
if (latestDataMaps != null && latestDataMaps.size() > 0) {
Map<String, Object> latestDataMap = latestDataMaps.get(0);
for (Map.Entry<String, Object> entry : latestDataMap.entrySet()) {
DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo();
String columnKey = entry.getKey();
if(!columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEID)
&& !columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEMODEID)){
deviceDataColumnVo.setColumnKey(columnKey);
deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null
? columnKey : functionIndentifierName.get(columnKey));
deviceDataColumnVos.add(deviceDataColumnVo);
}
}
}
returnObj.put("deviceDataColumns", deviceDataColumnVos);
returnObj.put("latestData", latestDataMaps);
return returnObj;
} }
/** /**
* @return TdReturnDataVo
* @param: deviceHistoryDataVo * @param: deviceHistoryDataVo
* @description * @description
* @author xins * @author xins
* @date 2023-09-16 15:14 * @date 2023-09-16 15:14
* @return List<Map<Object>>
*/ */
@Override @Override
public List<Map<String, Object>> getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) { public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) {
TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto(); TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto();
tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName(deviceHistoryDataVo.getSceneId())); tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName(deviceHistoryDataVo.getSceneId()));
tdHistorySelectDto.setTableName(TdEngineConstants.getDeviceDataTableName(deviceHistoryDataVo.getDeviceId())); tdHistorySelectDto.setTableName(TdEngineConstants.getDeviceDataTableName(deviceHistoryDataVo.getDeviceId()));
@ -80,7 +133,40 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
tdHistorySelectDto.setLimit(deviceHistoryDataVo.getLimit()); tdHistorySelectDto.setLimit(deviceHistoryDataVo.getLimit());
return this.remoteTdEngineService.getHistoryData(tdHistorySelectDto).getData(); return this.remoteTdEngineService.getHistoryData(tdHistorySelectDto).getData();
}
/**
* @return List<DeviceDataColumnVo>
* @param: deviceModeId
* @param: latestDataMaps
* @description
* @author xins
* @date 2023-09-25 15:40
*/
@Override
public List<DeviceDataColumnVo> getDeviceDataColumns(Long deviceModeId, List<Map<String, Object>> latestDataMaps) {
HwDeviceModeFunction queryModeFunction = new HwDeviceModeFunction();
queryModeFunction.setDeviceModeId(deviceModeId);
queryModeFunction.setFunctionMode(HwDictConstants.FUNCTION_MODE_ATTRIBUTE);
List<HwDeviceModeFunction> deviceModeFunctions = deviceModeFunctionMapper.selectHwDeviceModeFunctionList(queryModeFunction);
Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect(
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName));
functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP);
List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
if (latestDataMaps != null && latestDataMaps.size() > 0) {
Map<String, Object> latestDataMap = latestDataMaps.get(0);
for (Map.Entry<String, Object> entry : latestDataMap.entrySet()) {
DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo();
String columnKey = entry.getKey();
deviceDataColumnVo.setColumnKey(columnKey);
deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null
? columnKey : functionIndentifierName.get(columnKey));
deviceDataColumnVos.add(deviceDataColumnVo);
}
}
return deviceDataColumnVos;
} }
} }

@ -170,7 +170,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectAlarmsByAlarmType" parameterType="Long" resultMap="AlarmTypeVoResult"> <select id="selectAlarmsByAlarmType" parameterType="Long" resultMap="AlarmTypeVoResult">
SELECT count(*) as alarm_count,alarm_type_id from hw_alarm_info SELECT count(*) as alarm_count,alarm_type_id from hw_alarm_info
where scene_id = #{sceneId} group by alarm_type_id; where scene_id = #{sceneId} and alarm_type_id is not null group by alarm_type_id;
</select> </select>
<select id="selectAlarmCountByFenceArea" parameterType="Long" resultMap="AlarmInfoVoResult"> <select id="selectAlarmCountByFenceArea" parameterType="Long" resultMap="AlarmInfoVoResult">

@ -84,6 +84,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectHwDeviceList" parameterType="HwDevice" resultMap="HwDeviceResult"> <select id="selectHwDeviceList" parameterType="HwDevice" resultMap="HwDeviceResult">
<include refid="selectHwDeviceVo"/> <include refid="selectHwDeviceVo"/>
<where> <where>
and device_status !='9'
<if test="deviceCode != null and deviceCode != ''"> and device_code like concat('%', #{deviceCode}, '%')</if> <if test="deviceCode != null and deviceCode != ''"> and device_code like concat('%', #{deviceCode}, '%')</if>
<if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if> <if test="deviceName != null and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
<if test="sceneId != null "> and scene_id = #{sceneId}</if> <if test="sceneId != null "> and scene_id = #{sceneId}</if>
@ -96,7 +97,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceModeId != null "> and device_mode_id = #{deviceModeId}</if> <if test="deviceModeId != null "> and device_mode_id = #{deviceModeId}</if>
<if test="accessGwProtocol != null "> and access_gw_protocol = #{accessGwProtocol}</if> <if test="accessGwProtocol != null "> and access_gw_protocol = #{accessGwProtocol}</if>
<if test="activeStatus != null and activeStatus != ''"> and active_status = #{activeStatus}</if> <if test="activeStatus != null and activeStatus != ''"> and active_status = #{activeStatus}</if>
<if test="deviceStatus != null and deviceStatus != ''"> and device_status = #{deviceStatus}</if>
<if test="activeTime != null "> and active_time = #{activeTime}</if> <if test="activeTime != null "> and active_time = #{activeTime}</if>
<if test="devicePic != null and devicePic != ''"> and device_pic = #{devicePic}</if> <if test="devicePic != null and devicePic != ''"> and device_pic = #{devicePic}</if>
<if test="ipAddress != null and ipAddress != ''"> and ip_address = #{ipAddress}</if> <if test="ipAddress != null and ipAddress != ''"> and ip_address = #{ipAddress}</if>

@ -167,4 +167,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from hw_device hd where hd.device_status=1 and (hd.device_type=2 or hd.device_type=3) and hd.scene_id = #{sceneId} from hw_device hd where hd.device_status=1 and (hd.device_type=2 or hd.device_type=3) and hd.scene_id = #{sceneId}
</select> </select>
<delete id="deleteHwFenceTargetByElectronicFenceId" parameterType="Long">
delete from hw_fence_target where electronic_fence_id = #{electronicFenceId}
</delete>
<insert id="batchHwFenceTarget">
insert into hw_fence_target( electronic_fence_id, target_type, target_id) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.electronicFenceId}, #{item.targetType}, #{item.targetId})
</foreach>
</insert>
<select id="selectHwElectronicFenceJoinList" parameterType="HwElectronicFence" resultMap="HwElectronicFenceResult">
select hef.electronic_fence_id,hef.electronic_fence_name,hef.fence_type,hef.trigger_status,
hs.scene_name
from hw_electronic_fence hef
left join hw_scene hs on hef.scene_id = hs.scene_id
<where>
<if test="electronicFenceName != null and electronicFenceName != ''"> and hef.electronic_fence_name like concat('%', #{electronicFenceName}, '%')</if>
<if test="tenantId != null "> and hef.tenant_id = #{tenantId}</if>
<if test="sceneId != null "> and hef.scene_id = #{sceneId}</if>
<if test="fenceType != null and fenceType != ''"> and hef.fence_type = #{fenceType}</if>
<if test="effectiveTimeFlag != null and effectiveTimeFlag != ''"> and hef.effective_time_flag = #{effectiveTimeFlag}</if>
<if test="timeZone != null and timeZone != ''"> and hef.time_zone = #{timeZone}</if>
<if test="effectiveTime != null and effectiveTime != ''"> and hef.effective_time = #{effectiveTime}</if>
<if test="triggerStatus != null and triggerStatus != ''"> and hef.trigger_status = #{triggerStatus}</if>
<if test="fencePushFlag != null and fencePushFlag != ''"> and hef.fence_push_flag = #{fencePushFlag}</if>
<if test="fencePushContent != null and fencePushContent != ''"> and hef.fence_push_content = #{fencePushContent}</if>
<if test="fenceRecoverContent != null and fenceRecoverContent != ''"> and hef.fence_recover_content = #{fenceRecoverContent}</if>
<if test="fenceField != null and fenceField != ''"> and hef.fence_field = #{fenceField}</if>
<!-- 租户数据范围过滤 -->
${params.tenantDataScope}
</where>
</select>
</mapper> </mapper>

@ -1,5 +1,6 @@
package com.ruoyi.tdengine.controller; package com.ruoyi.tdengine.controller;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn;
import com.ruoyi.common.core.hw.validated.tdengine.InsertTdTable; import com.ruoyi.common.core.hw.validated.tdengine.InsertTdTable;
@ -332,7 +333,11 @@ public class TdEngineController {
// }else {//查询聚合 // }else {//查询聚合
// return R.ok(this.tdEngineService.getAggregateData(selectVisualDto)); // return R.ok(this.tdEngineService.getAggregateData(selectVisualDto));
// } // }
return R.ok(this.tdEngineService.getHistoryData(tdHistorySelectDto)); int count = this.tdEngineService.getCountOfHistoryData(tdHistorySelectDto);
TdReturnDataVo returnDataVo = new TdReturnDataVo();
returnDataVo.setCount(count);
returnDataVo.setDataList(this.tdEngineService.getHistoryData(tdHistorySelectDto));
return R.ok(returnDataVo);
} catch (UncategorizedSQLException e) { } catch (UncategorizedSQLException e) {
String message = e.getCause().getMessage(); String message = e.getCause().getMessage();
try { try {
@ -347,32 +352,6 @@ public class TdEngineController {
} }
} }
/**
* @return R<?>
* @param: tdHistorySelectDto
* @description
* @author xins
* @date 2023-08-29 17:29
*/
@PostMapping("/getCountOfHistoryData")
public R<?> getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto) {
try {
return R.ok(this.tdEngineService.getCountOfHistoryData(tdHistorySelectDto));
} catch (UncategorizedSQLException e) {
String message = e.getCause().getMessage();
try {
message = message.substring(message.lastIndexOf("invalid operation"));
} catch (Exception ex) {
}
log.error(message);
return R.fail(message);
} catch (Exception e) {
log.error(e.getMessage());
return R.fail(e.getMessage());
}
}
/** /**
* @return R<?> * @return R<?>
* @param: tdSelectDto * @param: tdSelectDto

@ -138,8 +138,7 @@ public interface TdEngineMapper {
*/ */
List<Map<String, Object>> getHistoryData(TdHistorySelectDto tdHistorySelectDto); List<Map<String, Object>> getHistoryData(TdHistorySelectDto tdHistorySelectDto);
Map<String, Long> getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto); int getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto);
// /** // /**
// * 检查表是否存在 // * 检查表是否存在

@ -116,12 +116,12 @@ public interface ITdEngineService {
/** /**
* @param: tdHistorySelectDto * @param: tdHistorySelectDto
* @description * @description
* @author xins * @author xins
* @date 2023-08-29 16:54 * @date 2023-09-25 16:20
* @return Long * @return int
*/ */
public Long getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto) throws Exception; public int getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto);
// void initSTableFrame(String msg) throws Exception; // void initSTableFrame(String msg) throws Exception;

@ -210,26 +210,22 @@ public class TdEngineServiceImpl implements ITdEngineService {
// } // }
List<Map<String, Object>> historyDataMaps = this.tdEngineMapper.getHistoryData(tdHistorySelectDto); List<Map<String, Object>> historyDataMaps = this.tdEngineMapper.getHistoryData(tdHistorySelectDto);
return historyDataMaps; return historyDataMaps;
} }
/** /**
* @return Long
* @param: tdHistorySelectDto * @param: tdHistorySelectDto
* @description * @description
* @author xins * @author xins
* @date 2023-08-29 16:54 * @date 2023-09-25 16:20
* @return int
*/ */
@Override @Override
public Long getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto) throws Exception { public int getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto){
Map<String, Long> countMap = this.tdEngineMapper.getCountOfHistoryData(tdHistorySelectDto); int count = this.tdEngineMapper.getCountOfHistoryData(tdHistorySelectDto);
if (countMap == null) { return count;
return 0L;
} }
return countMap.get("dataCount");
}
// //
// /** // /**
// * 检查数据库表是否存在 // * 检查数据库表是否存在
@ -303,5 +299,4 @@ public class TdEngineServiceImpl implements ITdEngineService {
// return maps; // return maps;
// } // }
} }

@ -212,7 +212,10 @@
<!--适用于设备监测页面可以getLatestDataByTags通过tag监控单元ID来获取最新信息先根据监控单元获取设备信息再根据设备来获取最新的数据--> <!--适用于设备监测页面可以getLatestDataByTags通过tag监控单元ID来获取最新信息先根据监控单元获取设备信息再根据设备来获取最新的数据-->
<select id="getLatestData" parameterType="com.ruoyi.tdengine.api.domain.TdSelectDto" <select id="getLatestData" parameterType="com.ruoyi.tdengine.api.domain.TdSelectDto"
resultType="java.util.Map"> resultType="java.util.Map">
select last(*) from #{databaseName}.#{tableName} select
<foreach item="item" collection="schemaFieldValues" separator=","
index="">last(${item.fieldName})</foreach>
from #{databaseName}.#{tableName}
</select> </select>
@ -220,7 +223,9 @@
也可以用select last_row()--> 也可以用select last_row()-->
<select id="getLatestDataByTags" parameterType="com.ruoyi.tdengine.api.domain.TdSelectDto" <select id="getLatestDataByTags" parameterType="com.ruoyi.tdengine.api.domain.TdSelectDto"
resultType="java.util.Map"> resultType="java.util.Map">
select * from (select last(*), last(devicename),last(devicecode) from #{databaseName}.#{superTableName} select * from (select
<foreach item="item" collection="schemaFieldValues" separator=","
index="">last(${item.fieldName})</foreach>, last(devicecode),last(devicename), last(deviceid),last(devicemodeid),last(ts) from #{databaseName}.#{superTableName}
<where> <where>
<if test="firstFieldName != null and firstFieldName != '' and <if test="firstFieldName != null and firstFieldName != '' and
startTime!= null "> startTime!= null ">
@ -267,14 +272,16 @@
</if> </if>
</select> </select>
<select id="getCountOfHistoryData" parameterType="com.ruoyi.tdengine.api.domain.TdSelectDto" resultType="int" >
<select id="getCountOfHistoryData" parameterType="com.ruoyi.tdengine.api.domain.TdSelectDto" resultType="java.util.Map" > SELECT count(*) FROM #{databaseName}.#{tableName}
<!--as后不要用常用单词例如count会报错-->
SELECT count(0) as dataCount FROM #{databaseName}.#{tableName}
<where> <where>
<if test="#{firstFieldName} != null and #{firstFieldName} != '' and <if test="#{firstFieldName} != null and #{firstFieldName} != '' and
startTime!= 0 and endTime != 0"> startTime!= 0 ">
${firstFieldName} BETWEEN #{startTime} AND #{endTime} and ${firstFieldName} &gt;= #{startTime}
</if>
<if test="#{firstFieldName} != null and #{firstFieldName} != '' and
endTime != 0">
and ${firstFieldName} &lt;= #{endTime}
</if> </if>
</where> </where>
</select> </select>

@ -79,7 +79,7 @@
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="在线状态" prop="onlineStatus"> <!--el-form-item label="在线状态" prop="onlineStatus">
<el-select v-model="queryParams.onlineStatus" placeholder="请选择" clearable> <el-select v-model="queryParams.onlineStatus" placeholder="请选择" clearable>
<el-option <el-option
v-for="dict in dict.type.hw_device_online_status" v-for="dict in dict.type.hw_device_online_status"
@ -88,7 +88,7 @@
:value="dict.value" :value="dict.value"
></el-option> ></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item-->
@ -159,11 +159,11 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column label="在线状态" align="center" prop="onlineStatus"> <!--el-table-column label="在线状态" align="center" prop="onlineStatus">
<template slot-scope="scope"> <template slot-scope="scope">
<dict-tag :options="dict.type.hw_device_online_status" :value="scope.row.onlineStatus"/> <dict-tag :options="dict.type.hw_device_online_status" :value="scope.row.onlineStatus"/>
</template> </template>
</el-table-column> </el-table-column-->
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button <el-button

Loading…
Cancel
Save