Merge branch 'master' of https://codeup.aliyun.com/6428039c708c83a3fd907211/hzwmiot/hzwmiot24_java
This commit is contained in:
@ -136,6 +136,12 @@ public class Device extends BaseEntity
|
||||
@ApiModelProperty("设备摘要")
|
||||
private String summary;
|
||||
|
||||
/**
|
||||
* 设备名称编号搜索
|
||||
*/
|
||||
@ApiModelProperty("设备名称编号搜索")
|
||||
private String deviceNameOrSerialNumber;
|
||||
|
||||
/** 分组ID,用于分组查询 **/
|
||||
@ApiModelProperty("分组ID,用于分组查询")
|
||||
private Long groupId;
|
||||
|
@ -136,5 +136,11 @@ public class ThingsModel extends BaseEntity
|
||||
private String language;
|
||||
|
||||
private List<String> modelIdList;
|
||||
public ThingsModel() {
|
||||
|
||||
}
|
||||
public ThingsModel(Long productId) {
|
||||
this.productId = productId;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,9 @@ import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 设备日志Mapper接口
|
||||
@ -134,4 +136,17 @@ public interface DeviceLogMapper
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
|
||||
|
||||
/**
|
||||
* 创建数据库表
|
||||
*
|
||||
// * @param tableName 表名称
|
||||
*/
|
||||
// int createTable(@Param("tableName") String tableName, @Param("id") Long id);
|
||||
|
||||
List<HashMap<String, Object>> selectDayData(Map<String, Object> kvHashMap);
|
||||
|
||||
void createTableByDate(String ymTableName);
|
||||
|
||||
List<DeviceLog> selectDataList(HashMap<String, Object> kvHashMap);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ public interface DeviceMapper
|
||||
*/
|
||||
public int updateDeviceThingsModelValue(ThingsModelValuesInput input);
|
||||
|
||||
|
||||
public List<Device> selectDeviceListNotUser(Device deviceEntity);
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.fastbee.iot.mapper;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -8,6 +8,8 @@ import com.fastbee.iot.model.MonitorModel;
|
||||
import java.util.Date;
|
||||
import com.fastbee.iot.model.ThingsModelLogCountVO;
|
||||
import com.fastbee.iot.model.param.DataCenterParam;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -106,4 +108,6 @@ public interface IDeviceLogService
|
||||
* @return com.fastbee.common.core.domain.AjaxResult
|
||||
*/
|
||||
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
|
||||
|
||||
List<HashMap<String, Object>> selectDayData(HashMap<String, Object> kvHashMap);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.fastbee.common.core.thingsModel.ThingsModelValuesInput;
|
||||
import com.fastbee.iot.model.dto.ThingsModelDTO;
|
||||
import org.quartz.SchedulerException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -329,4 +330,9 @@ public interface IDeviceService
|
||||
*/
|
||||
List<DeviceGroup> listDeviceGroupByGroupIds(List<Long> groupIds);
|
||||
|
||||
List<Map<String,Object>> devicePointInfo(Device device);
|
||||
|
||||
|
||||
ArrayList<Object> getDeviceLogAllCurves(Long deviceId, String beginTime, String endTime);
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.fastbee.iot.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.common.utils.StringUtils;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.domain.DeviceLog;
|
||||
import com.fastbee.iot.domain.ThingsModel;
|
||||
import com.fastbee.iot.mapper.TableMapper;
|
||||
import com.fastbee.iot.model.DeviceReport;
|
||||
import com.fastbee.iot.model.HistoryModel;
|
||||
import com.fastbee.iot.service.IDeviceService;
|
||||
@ -44,6 +46,10 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
@Autowired
|
||||
private IDeviceService deviceService;
|
||||
|
||||
@Autowired
|
||||
private TableMapper tableMapper;
|
||||
|
||||
private String tableName = "iot_device_log_";
|
||||
/**
|
||||
* 查询设备日志
|
||||
*
|
||||
@ -216,4 +222,26 @@ public class DeviceLogServiceImpl implements IDeviceLogService {
|
||||
public List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam) {
|
||||
return logService.countThingsModelInvoke(dataCenterParam);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<HashMap<String, Object>> selectDayData(HashMap<String, Object> kvHashMap) {
|
||||
String serialNumber = (String) kvHashMap.get("serialNumber");
|
||||
if (kvHashMap.get("tableName") == null) {
|
||||
Date date = new Date();
|
||||
String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, date);
|
||||
kvHashMap.put("tableName", tableName + ym);
|
||||
}
|
||||
if (kvHashMap.get("tableName2") == null) {
|
||||
String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, DateUtil.offsetMonth(new Date(), -1));
|
||||
kvHashMap.put("tableName2", tableName + ym);
|
||||
}
|
||||
if (tableMapper.getTableByName(kvHashMap.get("tableName").toString()) == null) {
|
||||
deviceLogMapper.createTable(kvHashMap.get("tableName").toString(),1L);
|
||||
}
|
||||
if (tableMapper.getTableByName(kvHashMap.get("tableName2").toString()) == null) {
|
||||
deviceLogMapper.createTable(kvHashMap.get("tableName2").toString(),1L);
|
||||
}
|
||||
return deviceLogMapper.selectDayData(kvHashMap);
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.fastbee.iot.mapper.*;
|
||||
import com.fastbee.iot.model.*;
|
||||
import com.fastbee.iot.model.ThingsModelItem.Datatype;
|
||||
import com.fastbee.iot.model.ThingsModelItem.EnumItem;
|
||||
import com.fastbee.iot.model.ThingsModelItem.ThingsModel;
|
||||
import com.fastbee.iot.domain.ThingsModel;
|
||||
import com.fastbee.iot.model.ThingsModels.*;
|
||||
import com.fastbee.iot.model.dto.ThingsModelDTO;
|
||||
import com.fastbee.iot.model.gateWay.SubDeviceListVO;
|
||||
@ -623,11 +623,11 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
// 排序
|
||||
thingsList = thingsList.stream().sorted(Comparator.comparing(ThingsModelValueItem::getOrder).reversed()).collect(Collectors.toList());
|
||||
// 数组类型物模型里面对象赋值
|
||||
List<ThingsModel>[] arrayParams = new List[dataType.getArrayCount()];
|
||||
List<com.fastbee.iot.model.ThingsModelItem.ThingsModel>[] arrayParams = new List[dataType.getArrayCount()];
|
||||
for (int i = 0; i < dataType.getArrayCount(); i++) {
|
||||
List<ThingsModel> thingsModels = new ArrayList<>();
|
||||
List<com.fastbee.iot.model.ThingsModelItem.ThingsModel> thingsModels = new ArrayList<>();
|
||||
for (int j = 0; j < thingsList.size(); j++) {
|
||||
ThingsModel thingsModel = new ThingsModel();
|
||||
com.fastbee.iot.model.ThingsModelItem.ThingsModel thingsModel = new com.fastbee.iot.model.ThingsModelItem.ThingsModel();
|
||||
BeanUtils.copyProperties(thingsList.get(j), thingsModel);
|
||||
String shadow = thingsList.get(j).getShadow();
|
||||
if (StringUtils.isNotEmpty(shadow) && !shadow.equals("")) {
|
||||
@ -1592,5 +1592,75 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
return deviceMapper.listDeviceGroupByGroupIds(groupIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* 所有设备点数据
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<Map<String, Object>> devicePointInfo(Device devices) {
|
||||
ArrayList<Map<String, Object>> resultList = new ArrayList<>();
|
||||
List<Device> deviceList = selectDeviceList(devices);
|
||||
|
||||
for (Device device : deviceList) {
|
||||
HashMap<String, Object> itemMap = new HashMap<>();
|
||||
resultList.add(itemMap);
|
||||
Integer integer = 0;
|
||||
|
||||
itemMap.put("device",device);
|
||||
if (device.getStatus() != null) {
|
||||
if (device.getStatus().equals(4)) {
|
||||
integer = 1;
|
||||
}
|
||||
}
|
||||
itemMap.put("online",integer);
|
||||
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<Object> getDeviceLogAllCurves(Long deviceId, String beginTime, String endTime) {
|
||||
if (deviceId == null) {
|
||||
throw new RuntimeException("请上传devicerId");
|
||||
}
|
||||
|
||||
Device device = selectDeviceByDeviceId(deviceId);
|
||||
if (device == null) {
|
||||
throw new RuntimeException("未查到该设备");
|
||||
}
|
||||
|
||||
ArrayList<Object> list = new ArrayList<>();
|
||||
HashMap<String, Object> kvHashMap = new HashMap<>();
|
||||
kvHashMap.put("serialNumber", device.getSerialNumber());
|
||||
kvHashMap.put("beginTime", beginTime);
|
||||
kvHashMap.put("endTime", endTime);
|
||||
List<ThingsModel> thingsModels = thingsModelService.selectThingsModelList(new ThingsModel(device.getProductId()));
|
||||
List<DeviceLog> deviceLogs= logService.selectDataList(kvHashMap);
|
||||
Map<String, List<DeviceLog>> collect = deviceLogs != null ? deviceLogs.stream().collect(Collectors.groupingBy(t -> t.getIdentity())): new HashMap();
|
||||
for (ThingsModel modelDevice : thingsModels) {
|
||||
HashMap<String, Object> dataListMap = new HashMap<>();
|
||||
|
||||
List<DeviceLog> deviceLogs1 = collect.get(modelDevice.getIdentifier());
|
||||
dataListMap.put("name", modelDevice.getModelName());
|
||||
if (StringUtils.isNotEmpty(modelDevice.getSpecs())) {
|
||||
cn.hutool.json.JSONObject object = new cn.hutool.json.JSONObject(modelDevice.getSpecs());
|
||||
dataListMap.put("unit",object.get("unit"));
|
||||
}else{
|
||||
dataListMap.put("unit","");
|
||||
}
|
||||
if (deviceLogs1 != null) {
|
||||
System.out.println(deviceLogs1);
|
||||
dataListMap.put("time",deviceLogs1.stream().map(t->t.getCreateTime()).collect(Collectors.toList()));
|
||||
dataListMap.put("data",deviceLogs1.stream().map(t->t.getLogValue()).collect(Collectors.toList()));
|
||||
}else{
|
||||
dataListMap.put("time",new ArrayList<>());
|
||||
dataListMap.put("data",new ArrayList<>());
|
||||
}
|
||||
list.add(dataListMap);
|
||||
}
|
||||
return list ;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import com.fastbee.iot.tdengine.service.model.TdLogDto;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -73,4 +74,6 @@ public interface ILogService {
|
||||
List<ThingsModelLogCountVO> countThingsModelInvoke(DataCenterParam dataCenterParam);
|
||||
|
||||
DeviceLog selectLastReport(DeviceLog deviceLog);
|
||||
|
||||
List<DeviceLog> selectDataList(HashMap<String, Object> kvHashMap);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.fastbee.iot.tdengine.service.impl;
|
||||
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.fastbee.common.utils.DateUtils;
|
||||
import com.fastbee.iot.domain.Device;
|
||||
import com.fastbee.iot.domain.DeviceLog;
|
||||
@ -15,9 +17,7 @@ import com.fastbee.iot.tdengine.service.model.TdLogDto;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@ -28,9 +28,9 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class MySqlLogServiceImpl implements ILogService {
|
||||
|
||||
private String tableName = "iot_device_log_";
|
||||
|
||||
private DeviceLogMapper deviceLogMapper;
|
||||
private String tableName = "iot_device_log_";
|
||||
|
||||
@Resource
|
||||
private TableMapper tableMapper;
|
||||
@ -148,4 +148,35 @@ public class MySqlLogServiceImpl implements ILogService {
|
||||
public DeviceLog selectLastReport(DeviceLog deviceLog) {
|
||||
return deviceLogMapper.selectLastReport(deviceLog);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceLog> selectDataList(HashMap<String, Object> kvHashMap) {
|
||||
if (kvHashMap.get("endTime") != null) {
|
||||
DateTime endTime = DateUtil.parse(kvHashMap.get("endTime").toString());
|
||||
String yyyyMM = endTime.toString("yyyyMM");
|
||||
String yyyyMM2 = DateUtil.offsetMonth(endTime, -1).toString("yyyyMM");
|
||||
if (tableMapper.getTableByName(tableName + yyyyMM) == null) {
|
||||
deviceLogMapper.createTableByDate(tableName + yyyyMM);
|
||||
}
|
||||
if (tableMapper.getTableByName(tableName + yyyyMM2) == null) {
|
||||
deviceLogMapper.createTableByDate(tableName + yyyyMM2);
|
||||
}
|
||||
kvHashMap.put("tableName", tableName + yyyyMM);
|
||||
kvHashMap.put("tableName2", tableName + yyyyMM2);
|
||||
}
|
||||
if (kvHashMap.get("tableName") == null) {
|
||||
Date date = new Date();
|
||||
String ym = DateUtils.parseDateToStr(DateUtils.YYYYMM, date);
|
||||
String ym2 = DateUtils.parseDateToStr(DateUtils.YYYYMM, DateUtil.offsetMonth(new Date(), -1));
|
||||
if (tableMapper.getTableByName(tableName + ym) == null) {
|
||||
deviceLogMapper.createTableByDate(tableName + ym);
|
||||
}
|
||||
if (tableMapper.getTableByName(tableName + ym2) == null) {
|
||||
deviceLogMapper.createTableByDate(tableName + ym2);
|
||||
}
|
||||
kvHashMap.put("tableName", tableName + ym);
|
||||
kvHashMap.put("tableName2", tableName + ym2);
|
||||
}
|
||||
return deviceLogMapper.selectDataList(kvHashMap);
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@ import com.fastbee.iot.tdengine.service.model.TdLogDto;
|
||||
import com.fastbee.iot.util.SnowflakeIdWorker;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -162,4 +164,9 @@ public class TdengineLogServiceImpl implements ILogService {
|
||||
public DeviceLog selectLastReport(DeviceLog deviceLog) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DeviceLog> selectDataList(HashMap<String, Object> kvHashMap) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user