feat(数据中心): 新增历史记录和数据分析查询

This commit is contained in:
gx_ma
2026-03-05 16:32:10 +08:00
parent 913dd73f6e
commit 1e362f233b
36 changed files with 1254 additions and 24 deletions

View File

@@ -230,4 +230,14 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
System.out.println(s1);
}
/**
* 日期去除毫秒
* @param time 时间
* @return java.util.Date
*/
public static Date dateRemoveMs(Date time) {
String s = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, time);
return DateUtils.dateTime(DateUtils.YYYY_MM_DD_HH_MM_SS, s);
}
}

View File

@@ -229,4 +229,40 @@ public class CollectionUtils {
public static <T> Collection<T> singleton(T deptId) {
return deptId == null ? Collections.emptyList() : Collections.singleton(deptId);
}
/**
* 开始分页
*
* @param list 传入的list集合
* @param pageNum 页码
* @param pageSize 每页多少条数据
* @return
*/
public static List startPage(List list, Integer pageNum,
Integer pageSize) {
if (list == null) {
return null;
}
if (list.size() == 0) {
return null;
}
Integer count = list.size(); // 记录总数
Integer pageCount = 0; // 页数
if (count % pageSize == 0) {
pageCount = count / pageSize;
} else {
pageCount = count / pageSize + 1;
}
int fromIndex = 0; // 开始索引
int toIndex = 0; // 结束索引
if (!pageNum.equals(pageCount)) {
fromIndex = (pageNum - 1) * pageSize;
toIndex = fromIndex + pageSize;
} else {
fromIndex = (pageNum - 1) * pageSize;
toIndex = count;
}
List pageList = list.subList(fromIndex, toIndex);
return pageList;
}
}

View File

@@ -1,24 +1,35 @@
package com.fastbee.data.controller;
import com.fastbee.common.annotation.Log;
import com.fastbee.common.constant.HttpStatus;
import com.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.core.page.TableDataInfo;
import com.fastbee.common.enums.BusinessType;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.model.DeviceRelateUserInput;
import com.fastbee.iot.model.ThingsModelItem.ThingsModel;
import com.fastbee.iot.model.dto.ThingsModelDTO;
import com.fastbee.iot.service.IDeviceService;
import com.fastbee.mq.service.IMqttMessagePublish;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.quartz.SchedulerException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* 设备Controller
@@ -262,4 +273,54 @@ public class DeviceController extends BaseController
return AjaxResult.success(deviceService.getMqttConnectData(deviceId));
}
/**
* 查询变量概况
*/
@PreAuthorize("@ss.hasPermi('iot:device:query')")
@GetMapping("/listThingsModel")
@ApiOperation("查询变量概况")
public TableDataInfo listThingsModel(Integer pageNum, Integer pageSize, Long deviceId, String modelName, Integer type, Integer isMonitor, Integer isReadonly) {
Device device = deviceService.selectDeviceByDeviceId(deviceId);
if (Objects.isNull(device)) {
return new TableDataInfo();
}
TableDataInfo rspData = new TableDataInfo();
rspData.setCode(HttpStatus.SUCCESS);
rspData.setMsg("查询成功");
List<ThingsModel> thingsModelDTOList = deviceService.listThingsModel(deviceId);
if (CollectionUtils.isEmpty(thingsModelDTOList)) {
rspData.setRows(thingsModelDTOList);
rspData.setTotal(thingsModelDTOList.size());
return rspData;
}
List<Predicate<ThingsModel>> predicateList = new ArrayList<>();
if (StringUtils.isNotEmpty(modelName)) {
predicateList.add(o -> o.getName().contains(modelName));
}
if (null != type) {
predicateList.add(o -> Objects.equals(o.getType(), type));
}
if (null != isMonitor) {
predicateList.add(o -> Objects.equals(isMonitor, o.getIsMonitor()));
}
if (null != isReadonly) {
predicateList.add(o -> Objects.equals(isReadonly, o.getIsReadonly()));
predicateList.add(o -> !Objects.equals(3, o.getType()));
}
Stream<ThingsModel> stream = thingsModelDTOList.stream();
for (Predicate<ThingsModel> predicate : predicateList) {
stream = stream.filter(predicate);
}
List<ThingsModel> filterList = stream.collect(Collectors.toList());
filterList.sort(Comparator.comparing(ThingsModel::getOrder).reversed().thenComparing(ThingsModel::getId));
if (CollectionUtils.isNotEmpty(filterList)) {
List resultList = com.fastbee.common.utils.collection.CollectionUtils.startPage(filterList, pageNum, pageSize);
rspData.setRows(resultList);
} else {
rspData.setRows(new ArrayList<>());
}
rspData.setTotal(filterList.size());
return rspData;
}
}

View File

@@ -0,0 +1,69 @@
package com.fastbee.data.controller.datacenter;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.common.utils.MessageUtils;
import com.fastbee.common.utils.StringUtils;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.DeviceHistoryParam;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import com.fastbee.iot.service.DataCenterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* @author fastb
* @version 1.0
* @description: 数据中心控制器
* @date 2024-06-13 14:09
*/
@Api(tags = "数据中心管理")
@RestController
@RequestMapping("/data/center")
public class DataCenterController {
@Resource
private DataCenterService dataCenterService;
/**
* 查询设备物模型的历史数据
* @param deviceHistoryParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
@ApiOperation("查询设备的历史数据")
@PreAuthorize("@ss.hasPermi('dataCenter:history:list')")
@PostMapping("/deviceHistory")
public AjaxResult deviceHistory(@RequestBody DeviceHistoryParam deviceHistoryParam)
{
if (StringUtils.isEmpty(deviceHistoryParam.getSerialNumber())) {
return AjaxResult.error(MessageUtils.message("please.select.device"));
}
List<JSONObject> jsonObject = dataCenterService.deviceHistory(deviceHistoryParam);
return AjaxResult.success(jsonObject);
}
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
@ApiOperation("统计设备物模型指令下发数量")
@PreAuthorize("@ss.hasPermi('dataCenter:analysis:list')")
@GetMapping("/countThingsModelInvoke")
public AjaxResult countThingsModelInvoke(DataCenterParam dataCenterParam)
{
if (StringUtils.isEmpty(dataCenterParam.getSerialNumber())) {
return AjaxResult.error(MessageUtils.message("please.incoming.serialNumber"));
}
List<ThingsModelLogCountVO> list = dataCenterService.countThingsModelInvoke(dataCenterParam);
return AjaxResult.success(list);
}
}

View File

@@ -5,6 +5,8 @@ import com.fastbee.iot.model.ThingsModelItem.*;
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItemDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.fastbee.common.annotation.Excel;
@@ -21,7 +23,9 @@ import java.util.List;
* @author kerwincui
* @date 2022-01-13
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "DeviceLog", description = "设备日志对象 iot_device_log")
@Data
public class DeviceLog extends BaseEntity
{
private static final long serialVersionUID = 1L;
@@ -129,6 +133,8 @@ public class DeviceLog extends BaseEntity
/*是否历史存储*/
private Integer isHistory;
private List<String> identityList;
public Integer getIsHistory() {
return isHistory;
}

View File

@@ -2,11 +2,11 @@ package com.fastbee.iot.mapper;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DeviceStatistic;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
/**
@@ -94,4 +94,19 @@ public interface DeviceLogMapper
*/
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
/**
* 查询物模型历史数据
* @param deviceLog 设备日志
* @return java.util.List<com.fastbee.iot.model.HistoryModel>
*/
List<HistoryModel> listHistory(DeviceLog deviceLog);
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(@Param("dataCenterParam") DataCenterParam dataCenterParam, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
}

View File

@@ -1,7 +1,13 @@
package com.fastbee.iot.mapper;
import java.util.Date;
import java.util.List;
import com.fastbee.iot.domain.FunctionLog;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.FunctionLogVO;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
/**
@@ -94,4 +100,19 @@ public interface FunctionLogMapper
* @param log
*/
public void updateByMessageId(FunctionLog log);
/**
* 查询物模型历史数据
* @param functionLogVO 功能日志
* @return java.util.List<com.fastbee.iot.model.HistoryModel>
*/
List<HistoryModel> listHistory(FunctionLogVO functionLogVO);
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(@Param("dataCenterParam") DataCenterParam dataCenterParam, @Param("beginTime") Date beginTime, @Param("endTime") Date endTime);
}

View File

@@ -2,7 +2,10 @@ package com.fastbee.iot.mapper;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@@ -35,4 +38,14 @@ public interface IotDbLogMapper {
List<DeviceLog> selectDeviceLogList(@Param("device") DeviceLog deviceLog);
List<DeviceLog> selectEventLogList(@Param("device") DeviceLog deviceLog);
List<HistoryModel> listHistory(@Param("device") DeviceLog deviceLog);
/**
* 统计设备物模型指令下发数量
*
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(@Param("dataCenterParam") DataCenterParam dataCenterParam);
}

View File

@@ -3,8 +3,10 @@ package com.fastbee.iot.mapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import com.fastbee.iot.tsdb.model.TdLogDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
@@ -81,4 +83,14 @@ public interface TDDeviceLogMapper {
int deleteDeviceLogByDeviceNumber(@Param("database") String dbName, @Param("serialNumber") String serialNumber);
List<HistoryModel> listHistory(@Param("database") String database, @Param("device") DeviceLog deviceLog);
/**
* 统计设备物模型指令下发数量
*
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(@Param("database") String database, @Param("dataCenterParam") DataCenterParam dataCenterParam);
}

View File

@@ -0,0 +1,29 @@
package com.fastbee.iot.model;
import lombok.Data;
/**
* @author fastb
* @version 1.0
* @description: 数据中心统一传参类
* @date 2024-06-19 17:07
*/
@Data
public class DataCenterParam {
/**
* 设备编号
*/
private String serialNumber;
/**
* 开始时间
*/
private String beginTime;
/**
* 结束时间
*/
private String endTime;
}

View File

@@ -0,0 +1,45 @@
package com.fastbee.iot.model;
import lombok.Data;
import java.util.List;
/**
* @author fastb
* @version 1.0
* @description: 设备历史数据参数
* @date 2024-06-13 15:15
*/
@Data
public class DeviceHistoryParam {
/**
* 设备id
*/
private Long deviceId;
/**
* 设备编号
*/
private String serialNumber;
private List<IdentifierVO> identifierList;
private String identifierStr;
/** 查询用的开始时间 */
private String beginTime;
/** 查询用的结束时间 */
private String endTime;
@Data
public static class IdentifierVO {
private String identifier;
private Integer type;
}
}

View File

@@ -0,0 +1,129 @@
package com.fastbee.iot.model;
import com.fastbee.common.annotation.Excel;
import com.fastbee.common.core.domain.PageEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.Date;
import java.util.List;
/**
* 设备服务下发日志对象 iot_function_log
*
* @author zhuangpeng.li
* @date 2024-11-13
*/
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "FunctionLogVO", description = "设备服务下发日志 iot_function_log")
@Data
public class FunctionLogVO extends PageEntity {
/** 设备功能日志ID */
@Excel(name = "设备功能日志ID")
@ApiModelProperty("设备功能日志ID")
private Long id;
/** 标识符 */
@Excel(name = "标识符")
@ApiModelProperty("标识符")
private String identify;
/** 1==服务下发2=属性获取3.OTA升级 */
@Excel(name = "1==服务下发2=属性获取3.OTA升级")
@ApiModelProperty("1==服务下发2=属性获取3.OTA升级")
private Integer funType;
/** 日志值 */
@Excel(name = "日志值")
@ApiModelProperty("日志值")
private String funValue;
/** 消息id */
@Excel(name = "消息id")
@ApiModelProperty("消息id")
private String messageId;
/** 设备名称 */
@Excel(name = "设备名称")
@ApiModelProperty("设备名称")
private String deviceName;
/** 设备编号 */
@Excel(name = "设备编号")
@ApiModelProperty("设备编号")
private String serialNumber;
/** 模式(1=影子模式2=在线模式3=其他) */
@Excel(name = "模式(1=影子模式2=在线模式3=其他)")
@ApiModelProperty("模式(1=影子模式2=在线模式3=其他)")
private Integer mode;
/** 用户id */
@Excel(name = "用户id")
@ApiModelProperty("用户id")
private Long userId;
/** 下发结果描述 */
@Excel(name = "下发结果描述")
@ApiModelProperty("下发结果描述")
private String resultMsg;
/** 下发结果代码 */
@Excel(name = "下发结果代码")
@ApiModelProperty("下发结果代码")
private Integer resultCode;
/** 创建者 */
@Excel(name = "创建者")
@ApiModelProperty("创建者")
private String createBy;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
@Excel(name = "创建时间")
private Date createTime;
/** 备注 */
@Excel(name = "备注")
@ApiModelProperty("备注")
private String remark;
/** 显示值 */
@Excel(name = "显示值")
@ApiModelProperty("显示值")
private String showValue;
/** 物模型名称 */
@Excel(name = "物模型名称")
@ApiModelProperty("物模型名称")
private String modelName;
/** 设备回复时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("设备回复时间")
@Excel(name = "设备回复时间")
private Date replyTime;
/** 仅用于查询时筛选条件 */
private String prefixIdentify;
private String dataType;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date beginTime;
/** 创建时间 */
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date endTime;
private List<Long> list;
private List<String> identifyList;
}

View File

@@ -0,0 +1,19 @@
package com.fastbee.iot.model;
import lombok.Data;
/**
* @author fastb
* @version 1.0
* @description: 统计物模型日志数量
* @date 2024-06-17 11:36
*/
@Data
public class ThingsModelLogCountVO {
private String identifier;
private String modelName;
private Integer counts;
}

View File

@@ -0,0 +1,99 @@
package com.fastbee.iot.model.dto;
import com.fastbee.common.core.domain.BaseEntity;
import com.fastbee.iot.model.ThingsModelItem.Datatype;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 物模型对象 iot_things_model
*
* @author kerwincui
* @date 2023-01-14
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ThingsModelDTO extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 物模型ID */
private Long modelId;
/** 物模型名称 */
private String modelName;
/** 产品ID */
private Long productId;
/** 产品名称 */
private String productName;
/** 租户ID */
private Long tenantId;
/** 租户名称 */
private String tenantName;
/** 标识符,产品下唯一 */
private String identifier;
/** 模型类别1-属性2-功能3-事件) */
private Integer type;
/** 计算公式 */
private String formula;
/** 数据定义 */
private String specs;
/** 是否图表显示0-否1-是) */
private Integer isChart;
/** 是否历史存储0-否1-是) */
private Integer isHistory;
/** 是否实时监测0-否1-是) */
private Integer isMonitor;
/** 是否分享设备权限0-否1-是) */
private Integer isSharePerm;
/** 是否分享设备权限0-否1-是) */
private Integer isApp;
private String unit;
/** 数据定义 */
private Datatype datatype;
private String limitValue;
/** 是否只读数据(0-否1-是) */
private Integer isReadonly;
private Integer modelOrder;
private String value = "";
private String ts;
private String serialNumber;
private Boolean isShadow;
/**
* 是否可下发指令 0 -不可操作 1-可
*/
private Integer canSend;
private String shadow = "";
/**
* 所属设备名称
*/
private String deviceName;
private String address;
}

View File

@@ -0,0 +1,36 @@
package com.fastbee.iot.service;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.iot.model.DeviceHistoryParam;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import java.util.List;
/**
* 数据中心服务类
* @author fastb
* @date 2024-06-13 15:29
* @version 1.0
*/
public interface DataCenterService {
/**
* 查询设备物模型的历史数据
* @param deviceHistoryParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<JSONObject> deviceHistory(DeviceHistoryParam deviceHistoryParam);
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
List<HistoryModel> queryDeviceHistory(DeviceHistoryParam deviceHistoryParam);
}

View File

@@ -1,8 +1,10 @@
package com.fastbee.iot.service;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import java.util.List;
import java.util.Map;
@@ -40,4 +42,18 @@ public interface IDeviceLogService
*/
public int insertDeviceLog(DeviceLog deviceLog);
/**
* 查询物模型历史数据
* @param deviceLog 设备日志
* @return java.util.List<com.fastbee.iot.model.HistoryModel>
*/
List<HistoryModel> listHistory(DeviceLog deviceLog);
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
}

View File

@@ -5,9 +5,11 @@ import com.fastbee.common.core.thingsModel.ThingsModelSimpleItem;
import com.fastbee.common.enums.DeviceStatus;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.model.*;
import com.fastbee.iot.model.ThingsModelItem.ThingsModel;
import com.fastbee.iot.model.ThingsModels.ThingsModelShadow;
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem;
import com.fastbee.common.core.thingsModel.ThingsModelValuesInput;
import com.fastbee.iot.model.dto.ThingsModelDTO;
import org.quartz.SchedulerException;
import java.util.List;
@@ -273,4 +275,6 @@ public interface IDeviceService
* @return
*/
public String[] getDeviceNumsByProductId(Long productId);
List<ThingsModel> listThingsModel(Long deviceId);
}

View File

@@ -2,6 +2,10 @@ package com.fastbee.iot.service;
import java.util.List;
import com.fastbee.iot.domain.FunctionLog;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.FunctionLogVO;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
/**
* 设备服务下发日志Service接口
@@ -84,4 +88,18 @@ public interface IFunctionLogService
* @param log
*/
public void updateByMessageId(FunctionLog log);
/**
* 查询物模型历史数据
* @param functionLogVO 功能日志
* @return java.util.List<com.fastbee.iot.model.HistoryModel>
*/
List<HistoryModel> listHistory(FunctionLogVO functionLogVO);
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
}

View File

@@ -0,0 +1,145 @@
package com.fastbee.iot.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.*;
import com.fastbee.iot.model.ThingsModelItem.ThingsModel;
import com.fastbee.iot.service.*;
import com.fastbee.iot.tsdb.service.ILogService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @author fastb
* @version 1.0
* @description: 数据中心服务类
* @date 2024-06-13 15:29
*/
@Service
public class DataCenterServiceImpl implements DataCenterService {
@Resource
private IDeviceLogService deviceLogService;
@Resource
private IFunctionLogService functionLogService;
@Resource
private ILogService logService;
@Resource
private IDeviceService deviceService;
@Override
public List<JSONObject> deviceHistory(DeviceHistoryParam deviceHistoryParam) {
List<JSONObject> resultList = new ArrayList<>();
List<DeviceHistoryParam.IdentifierVO> identifierVOList = new ArrayList<>();
if (CollectionUtils.isEmpty(deviceHistoryParam.getIdentifierList())) {
List<ThingsModel> list = deviceService.listThingsModel(deviceHistoryParam.getDeviceId());
for (ThingsModel thingsModel : list) {
DeviceHistoryParam.IdentifierVO identifierVO = new DeviceHistoryParam.IdentifierVO();
identifierVO.setIdentifier(thingsModel.getId());
identifierVO.setType(thingsModel.getType());
identifierVOList.add(identifierVO);
}
} else {
identifierVOList = deviceHistoryParam.getIdentifierList();
}
if (CollectionUtils.isEmpty(identifierVOList)) {
return resultList;
}
List<String> identifierList = identifierVOList.stream().map(DeviceHistoryParam.IdentifierVO::getIdentifier).collect(Collectors.toList());
deviceHistoryParam.setIdentifierList(identifierVOList);
List<HistoryModel> historyModelList = this.queryDeviceHistory(deviceHistoryParam);
historyModelList.sort(Comparator.comparing(HistoryModel::getTime));
return this.handleData(identifierList, historyModelList);
}
@Override
public List<HistoryModel> queryDeviceHistory(DeviceHistoryParam deviceHistoryParam) {
List<HistoryModel> historyModelList = new ArrayList<>();
List<DeviceHistoryParam.IdentifierVO> identifierVOList = deviceHistoryParam.getIdentifierList();
List<String> propertyIdentifierList = identifierVOList.stream().filter(t -> 1 == t.getType()).map(DeviceHistoryParam.IdentifierVO::getIdentifier).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(propertyIdentifierList)) {
DeviceLog deviceLog = new DeviceLog();
deviceLog.setIdentityList(propertyIdentifierList);
deviceLog.setSerialNumber(deviceHistoryParam.getSerialNumber());
deviceLog.setBeginTime(deviceHistoryParam.getBeginTime());
deviceLog.setEndTime(deviceHistoryParam.getEndTime());
List<HistoryModel> historyModelList1 = deviceLogService.listHistory(deviceLog);
historyModelList.addAll(historyModelList1);
}
List<String> functionIdentifierList = identifierVOList.stream().filter(t -> 2 == t.getType()).map(DeviceHistoryParam.IdentifierVO::getIdentifier).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(functionIdentifierList)) {
FunctionLogVO functionLogVO = new FunctionLogVO();
functionLogVO.setIdentifyList(functionIdentifierList);
functionLogVO.setSerialNumber(deviceHistoryParam.getSerialNumber());
functionLogVO.setBeginTime(DateUtils.dateTime(DateUtils.YY_MM_DD_HH_MM_SS, deviceHistoryParam.getBeginTime()));
functionLogVO.setEndTime(DateUtils.dateTime(DateUtils.YY_MM_DD_HH_MM_SS, deviceHistoryParam.getEndTime()));
historyModelList.addAll(functionLogService.listHistory(functionLogVO));
}
List<String> eventIdentifierList = identifierVOList.stream().filter(t -> 3 == t.getType()).map(DeviceHistoryParam.IdentifierVO::getIdentifier).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(eventIdentifierList)) {
DeviceLog eventLog = new DeviceLog();
eventLog.setIdentityList(eventIdentifierList);
eventLog.setSerialNumber(deviceHistoryParam.getSerialNumber());
eventLog.setBeginTime(deviceHistoryParam.getBeginTime());
eventLog.setEndTime(deviceHistoryParam.getEndTime());
historyModelList.addAll(logService.listHistory(eventLog));
}
return historyModelList;
}
private List<JSONObject> handleData(List<String> identifierList, List<HistoryModel> historyModelList) {
List<JSONObject> resultList = new ArrayList<>();
if (CollectionUtils.isEmpty(historyModelList)) {
return resultList;
}
LinkedHashMap<Date, List<HistoryModel>> map = historyModelList.stream()
.collect(Collectors.groupingBy(HistoryModel::getTime, LinkedHashMap::new, Collectors.toList()));
// Map<String, HistoryModel> oldHistoryModelMap = new HashMap<>(2);
for (Map.Entry<Date, List<HistoryModel>> entry : map.entrySet()) {
JSONObject jsonObject = new JSONObject();
List<HistoryModel> value = entry.getValue();
Map<String, HistoryModel> historyModelMap = value.stream().collect(Collectors.toMap(HistoryModel::getIdentify, Function.identity(), (o, n) -> n));
List<JSONObject> jsonObjectList = new ArrayList<>();
for (String identifier : identifierList) {
JSONObject jsonObject1 = new JSONObject();
HistoryModel historyModel = historyModelMap.get(identifier);
if (null != historyModel) {
// oldHistoryModelMap.put(identifier, historyModel);
jsonObject1.put(historyModel.getIdentify(), historyModel.getValue());
} else {
// HistoryModel oldHistoryModel = oldHistoryModelMap.get(identifier);
// if (null != oldHistoryModel) {
// jsonObject1.put(identifier, oldHistoryModel.getValue());
// } else {
// jsonObject1.put(identifier, null);
// }
jsonObject1.put(identifier, null);
}
jsonObjectList.add(jsonObject1);
}
jsonObject.put(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, entry.getKey()), jsonObjectList);
resultList.add(jsonObject);
}
return resultList;
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
List<ThingsModelLogCountVO> resultList = new ArrayList<>();
resultList.addAll(deviceLogService.countThingsModelInvoke(dataCenterParam));
resultList.addAll(functionLogService.countThingsModelInvoke(dataCenterParam));
return resultList;
}
}

View File

@@ -4,6 +4,9 @@ import com.fastbee.common.core.domain.model.LoginUser;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.common.utils.SecurityUtils;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import com.fastbee.iot.tsdb.service.ILogService;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.service.IDeviceLogService;
@@ -67,4 +70,14 @@ public class DeviceLogServiceImpl implements IDeviceLogService
deviceLog.setCreateBy(loginUser.getUsername());
return logService.saveDeviceLog(deviceLog);
}
@Override
public List<HistoryModel> listHistory(DeviceLog deviceLog) {
return logService.listHistory(deviceLog);
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
return logService.countThingsModelInvoke(dataCenterParam);
}
}

View File

@@ -34,6 +34,7 @@ import com.fastbee.iot.model.ThingsModels.PropertyDto;
import com.fastbee.iot.model.ThingsModels.ThingsModelShadow;
import com.fastbee.iot.model.ThingsModels.ThingsModelValueItem;
import com.fastbee.iot.model.ThingsModels.ValueItem;
import com.fastbee.iot.model.dto.ThingsModelDTO;
import com.fastbee.iot.service.*;
import com.fastbee.iot.service.cache.IDeviceCache;
import com.fastbee.iot.tsdb.service.ILogService;
@@ -52,6 +53,7 @@ import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.fastbee.common.utils.SecurityUtils.getLoginUser;
@@ -1413,4 +1415,22 @@ public class DeviceServiceImpl implements IDeviceService {
return deviceMapper.getDeviceNumsByProductId(productId);
}
@Override
public List<ThingsModel> listThingsModel(Long deviceId) {
Device device = deviceMapper.selectDeviceByDeviceId(deviceId);
JSONObject thingsModelObject = JSONObject.parseObject(thingsModelService.getCacheThingsModelByProductId(device.getProductId()));
JSONArray properties = thingsModelObject.getJSONArray("properties");
JSONArray functions = thingsModelObject.getJSONArray("functions");
List<ThingsModelValueItem> thingsModelValueItems = getCacheDeviceStatus(device.getProductId(), device.getSerialNumber());
// 物模型转换赋值
List<ThingsModel> thingsList = new ArrayList<>();
if (!CollectionUtils.isEmpty(properties)) {
thingsList.addAll(convertJsonToThingsList(properties, thingsModelValueItems, 1));
}
if (!CollectionUtils.isEmpty(functions)) {
thingsList.addAll(convertJsonToThingsList(functions, thingsModelValueItems, 2));
}
return thingsList;
}
}

View File

@@ -1,7 +1,14 @@
package com.fastbee.iot.service.impl;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.iot.model.DataCenterParam;
import com.fastbee.iot.model.FunctionLogVO;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.ThingsModelLogCountVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.fastbee.iot.mapper.FunctionLogMapper;
@@ -131,4 +138,29 @@ public class FunctionLogServiceImpl implements IFunctionLogService
public void updateByMessageId(FunctionLog log){
functionLogMapper.updateByMessageId(log);
}
@Override
public List<HistoryModel> listHistory(FunctionLogVO functionLogVO) {
return functionLogMapper.listHistory(functionLogVO);
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
Date beginTime = null;
Date endTime = null;
if (dataCenterParam.getBeginTime() != null && dataCenterParam.getBeginTime() != "" && dataCenterParam.getEndTime() != null && dataCenterParam.getEndTime() != "") {
beginTime = parseTime(dataCenterParam.getBeginTime());
endTime = parseTime(dataCenterParam.getEndTime());
}
return functionLogMapper.countThingsModelInvoke(dataCenterParam, beginTime, endTime);
}
private Date parseTime(String time) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.parse(time);
} catch (ParseException e) {
throw new IllegalArgumentException("时间格式错误: " + time, e);
}
}
}

View File

@@ -3,8 +3,7 @@ package com.fastbee.iot.tsdb.service;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DeviceStatistic;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.*;
import com.fastbee.iot.tsdb.model.TdLogDto;
import java.util.List;
@@ -40,5 +39,17 @@ public interface ILogService {
/** 查询物模型日志列表 **/
List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog);
/**
* 查询物模型历史数据
* @param deviceLog 设备日志
* @return java.util.List<com.fastbee.iot.model.HistoryModel>
*/
List<HistoryModel> listHistory(DeviceLog deviceLog);
/**
* 统计设备物模型指令下发数量
* @param dataCenterParam 传参
* @return com.fastbee.common.core.domain.AjaxResult
*/
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
}

View File

@@ -4,9 +4,7 @@ import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DeviceStatistic;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.*;
import com.fastbee.iot.tsdb.config.InfluxConfig;
import com.fastbee.iot.tsdb.service.ILogService;
import com.fastbee.iot.tsdb.model.TdLogDto;
@@ -511,4 +509,169 @@ public class InfluxLogService implements ILogService {
return monitorList;
}
@Override
public List<HistoryModel> listHistory(DeviceLog deviceLog) {
QueryApi queryApi = influxDBClient.getQueryApi();
StringBuilder fluxQuery = new StringBuilder();
fluxQuery.append("from(bucket: \"").append(influxConfig.getBucket()).append("\") ");
// 处理时间范围
if (deviceLog.getBeginTime() != null && !deviceLog.getBeginTime().isEmpty()
&& deviceLog.getEndTime() != null && !deviceLog.getEndTime().isEmpty()) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date beginDate = sdf.parse(deviceLog.getBeginTime());
Date endDate = sdf.parse(deviceLog.getEndTime());
// 转换为RFC3339格式时间字符串
String startRFC3339 = beginDate.toInstant().toString();
String stopRFC3339 = endDate.toInstant().toString();
fluxQuery.append("|> range(start: ")
.append(startRFC3339)
.append(", stop: ")
.append(stopRFC3339)
.append(") ");
} catch (ParseException e) {
e.printStackTrace();
// 若解析失败,可使用默认时间范围
fluxQuery.append("|> range(start: 0) ");
}
} else {
fluxQuery.append("|> range(start: 0) ");
}
fluxQuery.append("|> filter(fn: (r) => r._measurement == \"").append(influxConfig.getMeasurement()).append("\") ");
fluxQuery.append("|> pivot(\n" +
" rowKey:[\"_time\"], \n" +
" columnKey: [\"_field\"], \n" +
" valueColumn: \"_value\"\n" +
" )");
List<String> filterConditions = new ArrayList<>();
if (deviceLog.getSerialNumber() != null && !deviceLog.getSerialNumber().isEmpty()) {
filterConditions.add("r.serialNumber == \"" + deviceLog.getSerialNumber() + "\"");
}
if (deviceLog.getIdentityList() != null && !deviceLog.getIdentityList().isEmpty()) {
StringBuilder identityFilter = new StringBuilder("r.identify =~ /^(");
for (int i = 0; i < deviceLog.getIdentityList().size(); i++) {
if (i > 0) {
identityFilter.append("|");
}
identityFilter.append(deviceLog.getIdentityList().get(i));
}
identityFilter.append(")$/");
filterConditions.add(identityFilter.toString());
}
if (deviceLog.getLogType() != null) {
filterConditions.add("r.logType == " + deviceLog.getLogType());
}
if (!filterConditions.isEmpty()) {
fluxQuery.append("|> filter(fn: (r) => ");
for (int i = 0; i < filterConditions.size(); i++) {
if (i > 0) {
fluxQuery.append(" and ");
}
fluxQuery.append(filterConditions.get(i));
}
fluxQuery.append(") ");
}
fluxQuery.append("|> sort(columns: [\"_time\"], desc: true) ");
// 分页处理
int offset = (deviceLog.getPageNum() - 1) * deviceLog.getPageSize();
fluxQuery.append("|> limit(n: ").append(deviceLog.getPageSize()).append(", offset: ").append(offset).append(") ");
fluxQuery.append("|> keep(columns: [\"logValue\", \"_time\", \"identify\"]) ");
List<FluxTable> tables = queryApi.query(fluxQuery.toString());
List<HistoryModel> historyList = new ArrayList<>();
for (FluxTable table : tables) {
for (FluxRecord record : table.getRecords()) {
HistoryModel historyModel = new HistoryModel();
historyModel.setValue((String) record.getValueByKey("logValue"));
historyModel.setTime(new Date(record.getTime().getEpochSecond() * 1000));
historyModel.setIdentify((String) record.getValueByKey("identify"));
historyList.add(historyModel);
}
}
return historyList;
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
QueryApi queryApi = influxDBClient.getQueryApi();
StringBuilder fluxQuery = new StringBuilder();
fluxQuery.append("from(bucket: \"").append(influxConfig.getBucket()).append("\") ");
// 处理时间范围
if (dataCenterParam.getBeginTime() != null && !dataCenterParam.getBeginTime().isEmpty()
&& dataCenterParam.getEndTime() != null && !dataCenterParam.getEndTime().isEmpty()) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
Date beginDate = sdf.parse(dataCenterParam.getBeginTime());
Date endDate = sdf.parse(dataCenterParam.getEndTime());
// 转换为RFC3339格式时间字符串
String startRFC3339 = beginDate.toInstant().toString();
String stopRFC3339 = endDate.toInstant().toString();
fluxQuery.append("|> range(start: ")
.append(startRFC3339)
.append(", stop: ")
.append(stopRFC3339)
.append(") ");
} catch (ParseException e) {
e.printStackTrace();
// 若解析失败,可使用默认时间范围
fluxQuery.append("|> range(start: 0) ");
}
} else {
fluxQuery.append("|> range(start: 0) ");
}
fluxQuery.append("|> filter(fn: (r) => r._measurement == \"").append(influxConfig.getMeasurement()).append("\") ");
fluxQuery.append("|> pivot(\n" +
" rowKey:[\"_time\"], \n" +
" columnKey: [\"_field\"], \n" +
" valueColumn: \"_value\"\n" +
" )");
fluxQuery.append("|> filter(fn: (r) => r.log_type == 2) ");
List<String> filterConditions = new ArrayList<>();
if (dataCenterParam.getSerialNumber() != null && !dataCenterParam.getSerialNumber().isEmpty()) {
filterConditions.add("r.serial_number == \"" + dataCenterParam.getSerialNumber() + "\"");
}
if (!filterConditions.isEmpty()) {
fluxQuery.append("|> filter(fn: (r) => ");
for (int i = 0; i < filterConditions.size(); i++) {
if (i > 0) {
fluxQuery.append(" and ");
}
fluxQuery.append(filterConditions.get(i));
}
fluxQuery.append(") ");
}
fluxQuery.append("|> group() ");
int counts = 0;
List<FluxTable> tables = queryApi.query(fluxQuery.toString());
if (!tables.isEmpty() && !tables.get(0).getRecords().isEmpty()) {
counts = tables.get(0).getRecords().size();
}
List<ThingsModelLogCountVO> resultList = new ArrayList<>();
for (FluxTable table : tables) {
for (FluxRecord record : table.getRecords()) {
ThingsModelLogCountVO vo = new ThingsModelLogCountVO();
vo.setIdentifier((String) record.getValueByKey("identify"));
vo.setCounts(counts);
resultList.add(vo);
}
}
return resultList;
}
}

View File

@@ -5,9 +5,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.mapper.IotDbLogMapper;
import com.fastbee.iot.model.DeviceStatistic;
import com.fastbee.iot.model.HistoryModel;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.model.*;
import com.fastbee.iot.tsdb.service.ILogService;
import com.fastbee.iot.tsdb.model.TdLogDto;
import lombok.extern.slf4j.Slf4j;
@@ -117,4 +115,16 @@ public class IotDbLogService implements ILogService {
return iotDbLogMapper.selectMonitorList(deviceLog);
}
@Override
public List<HistoryModel> listHistory(DeviceLog deviceLog) {
return iotDbLogMapper.listHistory(deviceLog);
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
List<ThingsModelLogCountVO> thingsModelLogCountVOS = iotDbLogMapper.countThingsModelInvoke(dataCenterParam);
thingsModelLogCountVOS.forEach(vo -> {vo.setCounts(thingsModelLogCountVOS.size());});
return thingsModelLogCountVOS;
}
}

View File

@@ -5,14 +5,16 @@ import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.domain.EventLog;
import com.fastbee.iot.mapper.EventLogMapper;
import com.fastbee.iot.model.DeviceStatistic;
import com.fastbee.iot.model.*;
import com.fastbee.iot.tsdb.model.TdLogDto;
import com.fastbee.iot.tsdb.service.ILogService;
import com.fastbee.iot.mapper.DeviceLogMapper;
import com.fastbee.iot.model.MonitorModel;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
@@ -106,4 +108,29 @@ public class MySqlLogServiceImpl implements ILogService {
public List<DeviceLog> selectDeviceLogList(DeviceLog deviceLog) {
return deviceLogMapper.selectDeviceLogList(deviceLog);
}
@Override
public List<HistoryModel> listHistory(DeviceLog deviceLog) {
return deviceLogMapper.listHistory(deviceLog);
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
Date beginTime = null;
Date endTime = null;
if (dataCenterParam.getBeginTime() != null && dataCenterParam.getEndTime() != null) {
beginTime = parseTime(dataCenterParam.getBeginTime());
endTime = parseTime(dataCenterParam.getEndTime());
}
return deviceLogMapper.countThingsModelInvoke(dataCenterParam, beginTime, endTime);
}
private Date parseTime(String time) {
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
return format.parse(time);
} catch (ParseException e) {
throw new IllegalArgumentException("时间格式错误: " + time, e);
}
}
}

View File

@@ -1,11 +1,11 @@
package com.fastbee.iot.tsdb.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.fastbee.common.utils.DateUtils;
import com.fastbee.iot.domain.Device;
import com.fastbee.iot.domain.DeviceLog;
import com.fastbee.iot.model.DeviceStatistic;
import com.fastbee.iot.model.*;
import com.fastbee.iot.tsdb.service.ILogService;
import com.fastbee.iot.model.MonitorModel;
import com.fastbee.iot.mapper.TDDeviceLogMapper;
import com.fastbee.iot.tsdb.model.TdLogDto;
import com.fastbee.iot.util.SnowflakeIdWorker;
@@ -123,4 +123,18 @@ public class TdengineLogServiceImpl implements ILogService {
return tDDeviceLogMapper.deleteDeviceLogByDeviceNumber(dbName, deviceNumber);
}
@Override
public List<HistoryModel> listHistory(DeviceLog deviceLog) {
List<HistoryModel> historyModelList = tDDeviceLogMapper.listHistory(dbName, deviceLog);
for (HistoryModel historyModel : historyModelList) {
historyModel.setTime(DateUtils.dateRemoveMs(historyModel.getTime()));
}
return historyModelList;
}
@Override
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
return tDDeviceLogMapper.countThingsModelInvoke(dbName, dataCenterParam);
}
}

View File

@@ -194,4 +194,42 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by create_time desc
</select>
<select id="listHistory" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="HistoryResult">
select log_value,
create_time,
identify
from iot_device_log
<where>
<if test="serialNumber != null and serialNumber != ''">
and serial_number = #{serialNumber}
</if>
<if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
and create_time between #{beginTime} and #{endTime}
</if>
<if test="identityList != null and identityList != ''">
and identify in
<foreach collection="identityList" item="identify" open="(" separator="," close=")">
#{identify}
</foreach>
</if>
<if test="logType != null">
and log_type = #{logType}
</if>
</where>
order by create_time desc
</select>
<select id="countThingsModelInvoke" resultType="com.fastbee.iot.model.ThingsModelLogCountVO">
select identify identifier, min(model_name) modelName, count(identify) counts
from iot_device_log
where log_type = 2
<if test="dataCenterParam.serialNumber != null and dataCenterParam.serialNumber != ''">
and serial_number = #{dataCenterParam.serialNumber}
</if>
<if test="beginTime != null and endTime != null ">
and create_time between #{beginTime} and #{endTime}
</if>
group by identify
</select>
</mapper>

View File

@@ -182,4 +182,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</trim>
where message_id = #{messageId}
</update>
<select id="listHistory" parameterType="com.fastbee.iot.domain.FunctionLog" resultType="com.fastbee.iot.model.HistoryModel">
select create_time as time,
fun_value as value,
identify as identify,
model_name as moderName
from iot_function_log
<where>
<if test="serialNumber != null and serialNumber != ''">
and serial_number = #{serialNumber}
</if>
<if test="beginTime != null and endTime != null">
and create_time between #{beginTime} and #{endTime}
</if>
<if test="identifyList != null and identifyList != ''">
and identify in
<foreach collection="identifyList" item="identify" open="(" separator="," close=")">
#{identify}
</foreach>
</if>
</where>
order by create_time desc
</select>
<select id="countThingsModelInvoke" resultType="com.fastbee.iot.model.ThingsModelLogCountVO">
select identify identifier, min(model_name) modelName, count(identify) counts
from iot_function_log
where fun_type = 1
<if test="dataCenterParam.serialNumber != null and dataCenterParam.serialNumber != ''">
and serial_number = #{dataCenterParam.serialNumber}
</if>
<if test="beginTime != null and endTime != null ">
and create_time between #{beginTime} and #{endTime}
</if>
group by identify
</select>
</mapper>

View File

@@ -35,9 +35,9 @@
<!-- <result property="identify" column="root.ln.device_log.identify" />-->
<!-- </resultMap>-->
<!-- <resultMap type="com.fastbee.iot.model.vo.ThingsModelLogCountVO" id="ThingsModelLogCountVO">-->
<!-- <result property="identifier" column="root.ln.device_log.identify" />-->
<!-- </resultMap>-->
<resultMap type="com.fastbee.iot.model.ThingsModelLogCountVO" id="ThingsModelLogCountVO">
<result property="identifier" column="root.ln.device_log.identify" />
</resultMap>
<update id="createDB">
create database ${database}
@@ -177,6 +177,40 @@
order by time desc
</select>
<select id="listHistory" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="HistoryResult">
select log_value,
identify
FROM root.ln.device_log
<where>
<if test="device.serialNumber != null and device.serialNumber != ''">
and serial_number = '${device.serialNumber}'
</if>
<if test="device.beginTime != null and device.beginTime != '' and device.endTime != null and device.endTime != ''">
and time <![CDATA[ >= ]]> ${device.beginTime} and time <![CDATA[ <= ]]> ${device.endTime}
</if>
<if test="device.identityList != null and device.identityList.size > 0">
and identify in
<foreach collection="device.identityList" item="identify" open="(" separator="," close=")">
'${identify}'
</foreach>
</if>
<if test="device.logType != null">
and log_type = #{device.logType}
</if>
</where>
order by time desc
</select>
<select id="countThingsModelInvoke" resultMap="ThingsModelLogCountVO">
select identify
FROM root.ln.device_log
where log_type = 2
<if test="dataCenterParam.serialNumber != null and dataCenterParam.serialNumber != ''">
and serial_number = '${dataCenterParam.serialNumber}'
</if>
<if test="dataCenterParam.beginTime != null and dataCenterParam.beginTime != '' and dataCenterParam.endTime != null and dataCenterParam.endTime != ''">
and time <![CDATA[ >= ]]> ${dataCenterParam.beginTime} and time <![CDATA[ <= ]]> ${dataCenterParam.endTime}
</if>
</select>
</mapper>

View File

@@ -27,12 +27,11 @@
<result property="remark" column="remark" />
</resultMap>
<!-- <resultMap type="com.fastbee.iot.model.HistoryModel" id="HistoryResult">-->
<!-- <result property="time" column="ts" />-->
<!-- <result property="value" column="log_value" />-->
<!-- <result property="identify" column="identify" />-->
<!-- <result property="moderName" column="mode" />-->
<!-- </resultMap>-->
<resultMap type="com.fastbee.iot.model.HistoryModel" id="HistoryResult">
<result property="time" column="ts" />
<result property="value" column="log_value" />
<result property="identify" column="identify" />
</resultMap>
<!-- <resultMap type="com.fastbee.iot.model.HistoryBo" id="HistoryResultBo">-->
<!-- <result property="value" column="log_value" />-->
@@ -173,4 +172,42 @@
order by ts desc
</select>
<select id="listHistory" parameterType="com.fastbee.iot.domain.DeviceLog" resultMap="HistoryResult">
select ts,
log_value,
identify
from ${database}.device_log
<where>
<if test="device.beginTime != null and device.beginTime != '' and device.endTime != null and device.endTime != ''">
and ts between #{device.beginTime} and #{device.endTime}
</if>
<if test="device.serialNumber != null and device.serialNumber !=''">
and serial_number = #{device.serialNumber}
</if>
<if test="device.identityList != null and device.identityList.size > 0">
and identify in
<foreach collection="device.identityList" item="identify" open="(" separator="," close=")">
#{identify}
</foreach>
</if>
<if test="device.logType != null">
and log_type = #{device.logType}
</if>
</where>
order by ts desc
</select>
<select id="countThingsModelInvoke" resultType="com.fastbee.iot.model.ThingsModelLogCountVO">
select identify identifier, count(identify) counts
from ${database}.device_log
where log_type = 2
<if test="dataCenterParam.serialNumber != null and dataCenterParam.serialNumber != ''">
and serial_number = #{dataCenterParam.serialNumber}
</if>
<if test="dataCenterParam.beginTime != null and dataCenterParam.beginTime != '' and dataCenterParam.endTime != null and dataCenterParam.endTime != ''">
and ts between #{dataCenterParam.beginTime} and #{dataCenterParam.endTime}
</if>
group by identify
</select>
</mapper>

View File

@@ -408,6 +408,9 @@ INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COM
INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COMPONENT","QUERY","IS_FRAME","IS_CACHE","MENU_TYPE","VISIBLE","STATUS","PERMS","ICON","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(3059,'通道管理',3058,1,'sip','iot/sip/index',null,1,0,'C','0','0','iot:video:list','swagger','admin',TO_DATE('2024-07-15 14:43:22.000000000','SYYYY-MM-DD HH24:MI:SS.FF9'),'',null,'');
INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COMPONENT","QUERY","IS_FRAME","IS_CACHE","MENU_TYPE","VISIBLE","STATUS","PERMS","ICON","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(3060,'视频配置',3058,2,'mediaServer','iot/sip/mediaServer',null,1,0,'C','0','0',null,'edit','admin',TO_DATE('2024-07-15 14:48:52.000000000','SYYYY-MM-DD HH24:MI:SS.FF9'),'',null,'');
INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COMPONENT","QUERY","IS_FRAME","IS_CACHE","MENU_TYPE","VISIBLE","STATUS","PERMS","ICON","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(3062,'大屏展示',2000,6,'http://localhost/bigScreen',null,null,0,0,'M','0','0','','monitor-a','admin',TO_DATE('2025-03-19 15:07:39.000000000','SYYYY-MM-DD HH24:MI:SS.FF9'),'admin',TO_DATE('2025-03-20 22:18:42.000000000','SYYYY-MM-DD HH24:MI:SS.FF9'),'');
INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COMPONENT","QUERY","IS_FRAME","IS_CACHE","MENU_TYPE","VISIBLE","STATUS","PERMS","ICON","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(3343, '数据中心', 0, 5, 'dataCenter', NULL, NULL, 1, 0, 'M', '0', 0, '', 'bar_chart', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), '');
INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COMPONENT","QUERY","IS_FRAME","IS_CACHE","MENU_TYPE","VISIBLE","STATUS","PERMS","ICON","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(3344, '数据分析', 3343, 2, 'analysis', 'dataCenter/analysis', NULL, 1, 0, 'C', '0', 0, 'dataCenter:analysis:list', 'custom', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), '', NULL, '');
INSERT INTO "SYS_MENU"("MENU_ID","MENU_NAME","PARENT_ID","ORDER_NUM","PATH","COMPONENT","QUERY","IS_FRAME","IS_CACHE","MENU_TYPE","VISIBLE","STATUS","PERMS","ICON","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(3345, '历史记录', 3343, 1, 'history', 'dataCenter/history', NULL, 1, 0, 'C', '0', 0, 'dataCenter:history:list', 'excel', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), '');
SET IDENTITY_INSERT "SYS_MENU" OFF;
SET IDENTITY_INSERT "SYS_NOTICE" ON;
INSERT INTO "SYS_NOTICE"("NOTICE_ID","NOTICE_TITLE","NOTICE_TYPE","NOTICE_CONTENT","STATUS","CREATE_BY","CREATE_TIME","UPDATE_BY","UPDATE_TIME","REMARK") VALUES(1,'FastBeeV1.2版本发布','2',0x3C703EE8BF99E698AFE6B58BE8AF95E58685E5AEB9EFBC8CE696B0E78988E69CACE58A9FE883BDEFBC9A3C2F703E3C6F6C3E3C6C693EE694AFE68C81E5A49AE7A79FE688B73C2F6C693E3C6C693EE694AFE68C81E8AEBEE5A487E58886E4BAAB3C2F6C693E3C6C693EE694AFE68C81E697B6E5BA8FE695B0E68DAEE5BA933C2F6C693E3C6C693EE7AE80E58D95E8AEA4E8AF81E5928CE58AA0E5AF86E8AEA4E8AF81E7BB9FE4B8803C2F6C693E3C2F6F6C3E,'0','admin',TO_DATE('2021-12-15 21:36:18.000000000','SYYYY-MM-DD HH24:MI:SS.FF9'),'admin',TO_DATE('2023-09-26 21:21:30.000000000','SYYYY-MM-DD HH24:MI:SS.FF9'),'管理员');

View File

@@ -2391,6 +2391,9 @@ INSERT INTO `sys_menu` VALUES (3058, '视频中心', 0, 1, 'video', NULL, NULL,
INSERT INTO `sys_menu` VALUES (3059, '通道管理', 3058, 1, 'sip', 'iot/sip/index', NULL, 1, 0, 'C', '0', '0', 'iot:video:list', 'swagger', 'admin', '2024-07-15 14:43:22', '', NULL, '');
INSERT INTO `sys_menu` VALUES (3060, '视频配置', 3058, 2, 'mediaServer', 'iot/sip/mediaServer', NULL, 1, 0, 'C', '0', '0', NULL, 'edit', 'admin', '2024-07-15 14:48:52', '', NULL, '');
INSERT INTO `sys_menu` VALUES (3062, '大屏展示', 2000, 6, 'http://localhost/bigScreen', NULL, NULL, 0, 0, 'M', '0', '0', '', 'monitor-a', 'admin', '2025-03-19 15:07:39', 'admin', '2025-03-20 22:18:42', '');
INSERT INTO `sys_menu` VALUES (3343, '数据中心', 0, 5, 'dataCenter', NULL, NULL, 1, 0, 'M', '0', 0, '', 'bar_chart', 'admin', '2024-05-24 14:42:04', 'admin', '2025-01-11 09:33:52', '');
INSERT INTO `sys_menu` VALUES (3344, '数据分析', 3343, 2, 'analysis', 'dataCenter/analysis', NULL, 1, 0, 'C', '0', 0, 'dataCenter:analysis:list', 'custom', 'admin', '2024-06-11 15:46:19', '', NULL, '');
INSERT INTO `sys_menu` VALUES (3345, '历史记录', 3343, 1, 'history', 'dataCenter/history', NULL, 1, 0, 'C', '0', 0, 'dataCenter:history:list', 'excel', 'admin', '2024-05-24 14:44:58', 'admin', '2024-05-24 14:46:07', '');
-- ----------------------------
-- Table structure for sys_notice

View File

@@ -3308,6 +3308,9 @@ INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path"
INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES ('3059', '通道管理', '3058', '1', 'sip', 'iot/sip/index', NULL, '1', '0', 'C', '0', '0', 'iot:video:list', 'swagger', 'admin', TO_DATE('2024-07-15 14:43:22', 'SYYYY-MM-DD HH24:MI:SS'), '', NULL, '');
INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES ('3060', '视频配置', '3058', '2', 'mediaServer', 'iot/sip/mediaServer', NULL, '1', '0', 'C', '0', '0', NULL, 'edit', 'admin', TO_DATE('2024-07-15 14:48:52', 'SYYYY-MM-DD HH24:MI:SS'), '', NULL, '');
INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES ('3062', '大屏展示', '2000', '6', 'http://localhost/bigScreen', NULL, NULL, '0', '0', 'M', '0', '0', '', 'monitor-a', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), 'admin', TO_DATE('2025-03-20 22:18:42', 'SYYYY-MM-DD HH24:MI:SS'), '');
INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES ('3343', '数据中心', '0', '5', 'dataCenter', NULL, NULL, '1', '0', 'M', '0', '0', '', 'bar_chart', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), '');
INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES ('3344', '数据分析', '3343', '2', 'analysis', 'dataCenter/analysis', NULL, '1', '0', 'C', '0', '0', 'dataCenter:analysis:list', 'custom', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), '', NULL, '');
INSERT INTO "sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES ('3345', '历史记录', '3343', '1', 'history', 'dataCenter/history', NULL, '1', '0', 'C', '0', '0', 'dataCenter:history:list', 'excel', 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), 'admin', TO_DATE('2025-03-19 15:07:39', 'SYYYY-MM-DD HH24:MI:SS'), '');
COMMIT;
COMMIT;

View File

@@ -3309,6 +3309,9 @@ INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num
INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES (3059, '通道管理', 3058, 1, 'sip', 'iot/sip/index', NULL, 1, 0, 'C', '0', '0', 'iot:video:list', 'swagger', 'admin', '2024-07-15 14:43:22', '', NULL, '');
INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES (3060, '视频配置', 3058, 2, 'mediaServer', 'iot/sip/mediaServer', NULL, 1, 0, 'C', '0', '0', NULL, 'edit', 'admin', '2024-07-15 14:48:52', '', NULL, '');
INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES (3062, '大屏展示', 2000, 6, 'http://localhost/bigScreen', NULL, NULL, 0, 0, 'M', '0', '0', '', 'monitor-a', 'admin', '2025-03-19 15:07:39', 'admin', '2025-03-20 22:18:42', '');
INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES (3343, '数据中心', 0, 5, 'dataCenter', NULL, NULL, 1, 0, 'M', '0', 0, '', 'bar_chart', 'admin', '2024-05-24 14:42:04', 'admin', '2025-01-11 09:33:52', '');
INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES (3344, '数据分析', 3343, 2, 'analysis', 'dataCenter/analysis', NULL, 1, 0, 'C', '0', 0, 'dataCenter:analysis:list', 'custom', 'admin', '2024-06-11 15:46:19', '', NULL, '');
INSERT INTO "public"."sys_menu" ("menu_id", "menu_name", "parent_id", "order_num", "path", "component", "query", "is_frame", "is_cache", "menu_type", "visible", "status", "perms", "icon", "create_by", "create_time", "update_by", "update_time", "remark") VALUES (3345, '历史记录', 3343, 1, 'history', 'dataCenter/history', NULL, 1, 0, 'C', '0', 0, 'dataCenter:history:list', 'excel', 'admin', '2024-05-24 14:44:58', 'admin', '2024-05-24 14:46:07', '');
COMMIT;
-- ----------------------------

File diff suppressed because one or more lines are too long