Commit 39fe65bd authored by chenfm's avatar chenfm

增加设备实例详情接口, 查询设备最新数据接口

parent d098668d
...@@ -60,4 +60,11 @@ public class CommonConstants { ...@@ -60,4 +60,11 @@ public class CommonConstants {
public static final String HTTP_HEADER_X_FORWARDED_FOR = "x-forwarded-for"; public static final String HTTP_HEADER_X_FORWARDED_FOR = "x-forwarded-for";
public static final String HTTP_HEADER_PROXY_CLIENT_IP = "Proxy-Client-IP"; public static final String HTTP_HEADER_PROXY_CLIENT_IP = "Proxy-Client-IP";
public static final String HTTP_HEADER_WL_PROXY_CLIENT_IP = "WL-Proxy-Client-IP"; public static final String HTTP_HEADER_WL_PROXY_CLIENT_IP = "WL-Proxy-Client-IP";
/**
* 模型数据表前缀
**/
public static final String MODEL_DATA_TABLE_PREFIX = "iot_data_model_";
} }
...@@ -18,10 +18,13 @@ public class ECode { ...@@ -18,10 +18,13 @@ public class ECode {
public static final ECode PARAM_ERROR = new ECode(600, "参数不合法"); public static final ECode PARAM_ERROR = new ECode(600, "参数不合法");
public static final ECode TOKEN_INVALID = new ECode(601, "无效的Token"); public static final ECode TOKEN_INVALID = new ECode(601, "无效的Token");
public static final ECode TOKEN_EXPIRED = new ECode(602, "Token已过期"); public static final ECode TOKEN_EXPIRED = new ECode(602, "Token已过期");
public static final ECode NO_DATA = new ECode(603, "没有数据");
public static final ECode BIZ_PARAM_ERROR = new ECode(1000, "业务参数错误"); public static final ECode BIZ_PARAM_ERROR = new ECode(1000, "业务参数错误");
public static final ECode BATCHID_FORMATTOR_ERROR = new ECode(11001, "时间格式错误"); public static final ECode BATCHID_FORMATTOR_ERROR = new ECode(11001, "时间格式错误");
public static final ECode BATCHID_LENTGH_ERROR = new ECode(11001, "长度错误"); public static final ECode BATCHID_LENTGH_ERROR = new ECode(11002, "长度错误");
public static final ECode DEVICE_NOT_FOUND = new ECode(20001, "设备不存在");
public ECode(int code, String message) { public ECode(int code, String message) {
this.code = code; this.code = code;
......
package com.esv.datacenter.iot.common.util;
import java.util.List;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.common.util.SqlUtils
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:26
* @version: 1.0
*/
public class SqlUtils {
public static String makeSqlParams(List<String> collection) {
StringBuilder builder = new StringBuilder();
for (Object key : collection) {
builder.append(",");
builder.append(key.toString());
}
return builder.toString();
}
}
package com.esv.datacenter.iot.module.dashboard.service.impl; package com.esv.datacenter.iot.module.dashboard.service.impl;
import com.esv.datacenter.iot.common.component.TimescaleComponent; import com.esv.datacenter.iot.common.component.TimescaleComponent;
import com.esv.datacenter.iot.common.constants.CommonConstants;
import com.esv.datacenter.iot.common.util.SqlUtils;
import com.esv.datacenter.iot.module.dashboard.req.DashboardReq; import com.esv.datacenter.iot.module.dashboard.req.DashboardReq;
import com.esv.datacenter.iot.module.dashboard.req.HistoryDashboardReq; import com.esv.datacenter.iot.module.dashboard.req.HistoryDashboardReq;
import com.esv.datacenter.iot.module.dashboard.service.DashboardService; import com.esv.datacenter.iot.module.dashboard.service.DashboardService;
...@@ -42,9 +44,9 @@ public class DashboardServiceImpl implements DashboardService { ...@@ -42,9 +44,9 @@ public class DashboardServiceImpl implements DashboardService {
List<ModelDataVO> modelDataVOList = new ArrayList<>(); List<ModelDataVO> modelDataVOList = new ArrayList<>();
for (DashboardReq dashboardReq : dashboardReqList) { for (DashboardReq dashboardReq : dashboardReqList) {
Long modelId = dashboardReq.getModelId(); Long modelId = dashboardReq.getModelId();
String tableName = "iot_data_model_" + modelId; String tableName = CommonConstants.MODEL_DATA_TABLE_PREFIX + modelId;
String sql = "select time" String sql = "select time"
+ getSqlParams(dashboardReq.getPropertyCodeList()) + SqlUtils.makeSqlParams(dashboardReq.getPropertyCodeList())
+ " from " + " from "
+ tableName + tableName
+ " where device_id = ?" + " where device_id = ?"
...@@ -64,31 +66,22 @@ public class DashboardServiceImpl implements DashboardService { ...@@ -64,31 +66,22 @@ public class DashboardServiceImpl implements DashboardService {
List<ModelDataVO> modelDataVOList = new ArrayList<>(); List<ModelDataVO> modelDataVOList = new ArrayList<>();
for (DashboardReq dashboardReq : dashboardReqList) { for (DashboardReq dashboardReq : dashboardReqList) {
Long modelId = dashboardReq.getModelId(); Long modelId = dashboardReq.getModelId();
String tableName = "iot_data_model_" + modelId; String tableName = CommonConstants.MODEL_DATA_TABLE_PREFIX + modelId;
String sql = "select time" String sql = "select time"
+ getSqlParams(dashboardReq.getPropertyCodeList()) + SqlUtils.makeSqlParams(dashboardReq.getPropertyCodeList())
+ " from " + " from "
+ tableName + tableName
+ " where device_id = ?" + " where device_id = ?"
+ " and (time > ?)" + " and (time > ? and time < ?)"
+ " order by time"; + " order by time";
log.info("select modelData sql: {}", sql); log.info("select modelData sql: {}", sql);
List<Map<String, Object>> dataList = List<Map<String, Object>> dataList =
jdbcTemplate.queryForList(sql, dashboardReq.getDeviceId(), jdbcTemplate.queryForList(sql, dashboardReq.getDeviceId(),
beginTime); beginTime, endTime);
ModelDataVO modelDataVO = new ModelDataVO(modelId, dataList); ModelDataVO modelDataVO = new ModelDataVO(modelId, dataList);
modelDataVOList.add(modelDataVO); modelDataVOList.add(modelDataVO);
} }
return modelDataVOList; return modelDataVOList;
} }
private String getSqlParams(List<String> collection) {
StringBuilder builder = new StringBuilder();
for (Object key : collection) {
builder.append(",");
builder.append(key.toString());
}
return builder.toString();
}
} }
...@@ -12,7 +12,7 @@ import lombok.Data; ...@@ -12,7 +12,7 @@ import lombok.Data;
public class DataModelPropertyVO { public class DataModelPropertyVO {
/** /**
* * 主键
*/ */
private Long id; private Long id;
/** /**
......
package com.esv.datacenter.iot.module.devicemodel.controller;
import com.esv.datacenter.iot.common.response.ECode;
import com.esv.datacenter.iot.common.response.EResponse;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceDataForm;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceDataService;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.controller.DeviceDataController
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 16:47
* @version: 1.0
*/
@Slf4j
@RestController
@RequestMapping("/deviceModel/data")
@Validated
public class DeviceDataController {
private DeviceDataService deviceDataService;
@Autowired
public DeviceDataController(DeviceDataService deviceDataService) {
this.deviceDataService = deviceDataService;
}
@PostMapping("getDataByModel")
public EResponse<DeviceDataVO> currentData(@RequestBody @Validated DeviceDataForm deviceDataForm) {
DeviceDataVO deviceDataVO = deviceDataService.currentData(deviceDataForm.getDeviceId(), deviceDataForm.getDataModelId());
if (deviceDataVO == null) {
return EResponse.error(ECode.NO_DATA);
}
return EResponse.ok(deviceDataVO);
}
}
...@@ -9,6 +9,9 @@ import com.esv.datacenter.iot.common.vo.PageResultVO; ...@@ -9,6 +9,9 @@ import com.esv.datacenter.iot.common.vo.PageResultVO;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceInstanceForm;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceInstanceService; import com.esv.datacenter.iot.module.devicemodel.service.DeviceInstanceService;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceTypeService; import com.esv.datacenter.iot.module.devicemodel.service.DeviceTypeService;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceDetailVO;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
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;
...@@ -105,6 +108,21 @@ public class DeviceInstanceController { ...@@ -105,6 +108,21 @@ public class DeviceInstanceController {
return EResponse.ok(pageResultVO); return EResponse.ok(pageResultVO);
} }
@PostMapping("detail")
public EResponse<DeviceDetailVO> detail(@RequestBody @Validated(ValidatorDetail.class) DeviceInstanceForm form) {
DeviceInstanceVO deviceInstance = deviceInstanceService.deviceInstanceDetail(form.getId());
if (deviceInstance == null) {
return EResponse.error(ECode.DEVICE_NOT_FOUND);
}
Long deviceTypeId = deviceInstance.getDeviceTypeId();
DeviceTypeVO deviceTypeVO = deviceTypeService.deviceTypeDetail(deviceTypeId);
DeviceDetailVO deviceDetailVO = new DeviceDetailVO();
deviceDetailVO.setDeviceInstance(deviceInstance);
deviceDetailVO.setDeviceType(deviceTypeVO);
return EResponse.ok(deviceDetailVO);
}
/** /**
* @description 通过设备类型ID获取设备列表 * @description 通过设备类型ID获取设备列表
* @param form: * @param form:
......
package com.esv.datacenter.iot.module.devicemodel.dao; package com.esv.datacenter.iot.module.devicemodel.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.esv.datacenter.iot.module.datamodel.form.DataModelForm; import com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto;
import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity; import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
...@@ -26,4 +26,15 @@ public interface DeviceTypeDao extends BaseMapper<DeviceTypeEntity> { ...@@ -26,4 +26,15 @@ public interface DeviceTypeDao extends BaseMapper<DeviceTypeEntity> {
* @createTime 2020/08/07 9:34 * @createTime 2020/08/07 9:34
**/ **/
IPage select4Page(IPage page, DeviceTypeForm queryObj); IPage select4Page(IPage page, DeviceTypeForm queryObj);
/**
* description 查询设备类型详情
* param [id]
* return com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto
* author chenfm
* createTime 2020/8/13 16:16
**/
DeviceTypeDto deviceTypeDetail(Long id);
} }
package com.esv.datacenter.iot.module.devicemodel.dto;
import lombok.Data;
import java.util.Date;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDTO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 16:13
* @version: 1.0
*/
@Data
public class DeviceTypeDto {
/**
* 主键
*/
private Long id;
/**
* 名称
*/
private String name;
/**
* 描述
*/
private String description;
/**
* 设备实例数量
*/
private Long instanceCount;
/**
* 创建者
*/
private String createUser;
/**
* 修改者
*/
private String updateUser;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
}
package com.esv.datacenter.iot.module.devicemodel.form;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.form.DeviceDataForm
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:34
* @version: 1.0
*/
@Data
public class DeviceDataForm {
/**
* 数据模型ID
*/
@NotNull
private Long dataModelId;
/**
* 设备实例id
**/
@NotNull
private Long deviceId;
}
...@@ -22,7 +22,7 @@ public class DeviceInstanceForm { ...@@ -22,7 +22,7 @@ public class DeviceInstanceForm {
/** /**
* *
*/ */
@NotNull(message = "[设备ID]不能为空", groups = {ValidatorDelete.class, ValidatorUpdate.class}) @NotNull(message = "[设备ID]不能为空", groups = {ValidatorDelete.class, ValidatorUpdate.class, ValidatorDetail.class})
private Long id; private Long id;
/** /**
* 设备类型ID * 设备类型ID
......
package com.esv.datacenter.iot.module.devicemodel.service;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.service.DeviceDataService
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 16:49
* @version: 1.0
*/
public interface DeviceDataService {
DeviceDataVO currentData(Long deviceId, Long dataModelId);
}
...@@ -126,5 +126,14 @@ public interface DeviceInstanceService extends IService<DeviceInstanceEntity> { ...@@ -126,5 +126,14 @@ public interface DeviceInstanceService extends IService<DeviceInstanceEntity> {
**/ **/
void changeDeviceOnlineState(List<String> communicationIdList); void changeDeviceOnlineState(List<String> communicationIdList);
/**
* description 设备实例详情
* param [deviceInstanceId]
* return com.esv.datacenter.iot.module.devicemodel.vo.DeviceInstanceVO
* author chenfm
* createTime 2020/8/13 16:24
**/
DeviceInstanceVO deviceInstanceDetail(Long deviceInstanceId);
} }
...@@ -2,13 +2,12 @@ package com.esv.datacenter.iot.module.devicemodel.service; ...@@ -2,13 +2,12 @@ package com.esv.datacenter.iot.module.devicemodel.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.datacenter.iot.common.vo.PageResultVO; import com.esv.datacenter.iot.common.vo.PageResultVO;
import com.esv.datacenter.iot.module.datamodel.vo.DataModelBriefVO;
import com.esv.datacenter.iot.module.datamodel.vo.DataModelDetailVO; import com.esv.datacenter.iot.module.datamodel.vo.DataModelDetailVO;
import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity; import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeBriefVO; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeBriefVO;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeStatisticsVO; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeStatisticsVO;
import lombok.Data; import com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO;
import java.util.List; import java.util.List;
...@@ -100,5 +99,14 @@ public interface DeviceTypeService extends IService<DeviceTypeEntity> { ...@@ -100,5 +99,14 @@ public interface DeviceTypeService extends IService<DeviceTypeEntity> {
**/ **/
List<DeviceTypeStatisticsVO> getDeviceTypeStatistics(); List<DeviceTypeStatisticsVO> getDeviceTypeStatistics();
/**
* description 设备类型详细
* param [deviceTypeId]
* return com.esv.datacenter.iot.module.devicemodel.vo.DeviceTypeVO
* author chenfm
* createTime 2020/8/13 16:11
**/
DeviceTypeVO deviceTypeDetail(Long deviceTypeId);
} }
package com.esv.datacenter.iot.module.devicemodel.service.impl;
import com.esv.datacenter.iot.common.component.TimescaleComponent;
import com.esv.datacenter.iot.common.constants.CommonConstants;
import com.esv.datacenter.iot.module.datamodel.entity.DataModelEntity;
import com.esv.datacenter.iot.module.datamodel.service.DataModelPropertyService;
import com.esv.datacenter.iot.module.datamodel.service.DataModelService;
import com.esv.datacenter.iot.module.datamodel.vo.DataModelPropertyVO;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceDataService;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataPropertyVO;
import com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO;
import com.zaxxer.hikari.HikariDataSource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.service.impl.DeviceDataServiceImpl
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:12
* @version: 1.0
*/
@Slf4j
@Service("deviceDataService")
public class DeviceDataServiceImpl implements DeviceDataService {
private DataModelService dataModelService;
private DataModelPropertyService dataModelPropertyService;
private JdbcTemplate jdbcTemplate;
@Autowired
public DeviceDataServiceImpl(DataModelService dataModelService,
DataModelPropertyService dataModelPropertyService,
TimescaleComponent timescaleComponent) {
this.dataModelService = dataModelService;
this.dataModelPropertyService = dataModelPropertyService;
HikariDataSource dataSource = timescaleComponent.getHikariDataSource();
jdbcTemplate = new JdbcTemplate(dataSource);
}
@Override
public DeviceDataVO currentData(Long deviceId, Long dataModelId) {
DataModelEntity dataModelEntity = dataModelService.getModelInfo(dataModelId);
if (dataModelEntity == null) {
return null;
}
DeviceDataVO deviceDataVO = new DeviceDataVO();
BeanUtils.copyProperties(dataModelEntity, deviceDataVO);
Map<String, Object> dataMap = selectCurrentData(deviceId, dataModelId);
deviceDataVO.setReportTime((Date) dataMap.get("time"));
List<DataModelPropertyVO> propertyList = dataModelPropertyService.getModelPropertyList(dataModelId);
if (propertyList != null && !propertyList.isEmpty()) {
List<DeviceDataPropertyVO> list = new ArrayList<>(propertyList.size());
// List<String> columnNames = new ArrayList<>();
// propertyList.forEach(v -> columnNames.add(v.getPropertyCode()));
for (DataModelPropertyVO dataModelPropertyVO : propertyList) {
DeviceDataPropertyVO deviceDataPropertyVO = new DeviceDataPropertyVO();
BeanUtils.copyProperties(dataModelPropertyVO, deviceDataPropertyVO);
String propertyValue = String.valueOf(dataMap.get(deviceDataPropertyVO.getPropertyCode()));
deviceDataPropertyVO.setPropertyValue(propertyValue);
list.add(deviceDataPropertyVO);
}
deviceDataVO.setPropertyList(list);
}
return deviceDataVO;
}
private Map<String, Object> selectCurrentData(Long deviceId, Long dataModelId) {
String tableName = CommonConstants.MODEL_DATA_TABLE_PREFIX + dataModelId;
String sql = "select * from "
+ tableName
+ " where device_id = ?"
+ " order by time desc limit 1";
return jdbcTemplate.queryForMap(sql, deviceId);
}
}
...@@ -169,4 +169,17 @@ public class DeviceInstanceServiceImpl extends ServiceImpl<DeviceInstanceDao, De ...@@ -169,4 +169,17 @@ public class DeviceInstanceServiceImpl extends ServiceImpl<DeviceInstanceDao, De
baseMapper.update(entity, updateWrapper); baseMapper.update(entity, updateWrapper);
} }
@Override
public DeviceInstanceVO deviceInstanceDetail(Long deviceInstanceId) {
DeviceInstanceEntity deviceInstanceEntity = baseMapper.selectById(deviceInstanceId);
if (deviceInstanceEntity == null) {
return null;
}
DeviceInstanceVO deviceInstanceVO = new DeviceInstanceVO();
BeanUtils.copyProperties(deviceInstanceEntity, deviceInstanceVO);
deviceInstanceVO.setCreateTime(deviceInstanceEntity.getCreateTime().getTime());
deviceInstanceVO.setUpdateTime(deviceInstanceEntity.getUpdateTime().getTime());
return deviceInstanceVO;
}
} }
\ No newline at end of file
...@@ -9,11 +9,10 @@ import com.esv.datacenter.iot.common.response.ECode; ...@@ -9,11 +9,10 @@ import com.esv.datacenter.iot.common.response.ECode;
import com.esv.datacenter.iot.common.vo.PageResultVO; import com.esv.datacenter.iot.common.vo.PageResultVO;
import com.esv.datacenter.iot.module.datamodel.entity.DataModelEntity; import com.esv.datacenter.iot.module.datamodel.entity.DataModelEntity;
import com.esv.datacenter.iot.module.datamodel.service.DataModelPropertyService; import com.esv.datacenter.iot.module.datamodel.service.DataModelPropertyService;
import com.esv.datacenter.iot.module.datamodel.vo.DataModelBriefVO;
import com.esv.datacenter.iot.module.datamodel.vo.DataModelDetailVO; import com.esv.datacenter.iot.module.datamodel.vo.DataModelDetailVO;
import com.esv.datacenter.iot.module.datamodel.vo.DataModelPropertyVO;
import com.esv.datacenter.iot.module.devicemodel.dao.DeviceTypeDao; import com.esv.datacenter.iot.module.devicemodel.dao.DeviceTypeDao;
import com.esv.datacenter.iot.module.devicemodel.dto.DeviceInstanceDto; import com.esv.datacenter.iot.module.devicemodel.dto.DeviceInstanceDto;
import com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto;
import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity; import com.esv.datacenter.iot.module.devicemodel.entity.DeviceTypeEntity;
import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm; import com.esv.datacenter.iot.module.devicemodel.form.DeviceTypeForm;
import com.esv.datacenter.iot.module.devicemodel.service.DeviceDataMapService; import com.esv.datacenter.iot.module.devicemodel.service.DeviceDataMapService;
...@@ -201,4 +200,15 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType ...@@ -201,4 +200,15 @@ public class DeviceTypeServiceImpl extends ServiceImpl<DeviceTypeDao, DeviceType
return voList; return voList;
} }
@Override
public DeviceTypeVO deviceTypeDetail(Long deviceTypeId) {
DeviceTypeDto deviceTypeDto = baseMapper.deviceTypeDetail(deviceTypeId);
DeviceTypeVO deviceTypeVO = new DeviceTypeVO();
BeanUtils.copyProperties(deviceTypeDto, deviceTypeVO);
deviceTypeVO.setCreateTime(deviceTypeDto.getCreateTime().getTime());
deviceTypeVO.setUpdateTime(deviceTypeDto.getUpdateTime().getTime());
return deviceTypeVO;
}
} }
\ No newline at end of file
package com.esv.datacenter.iot.module.devicemodel.vo;
import lombok.Data;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataPropertyVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:07
* @version: 1.0
*/
@Data
public class DeviceDataPropertyVO {
/**
* 主键
*/
private Long id;
/**
* 模型ID
*/
private Long modelId;
/**
* 属性代码
*/
private String propertyCode;
/**
* 属性名称
*/
private String propertyName;
/**
* 属性类型(字典表)
*/
private Integer propertyType;
/**
* 属性默认值
*/
private String propertyDefaultValue;
/**
* 属性单位
*/
private String propertyUnit;
/**
* 排列序号
*/
private Long sortNum;
private String propertyValue;
}
package com.esv.datacenter.iot.module.devicemodel.vo;
import lombok.Data;
import java.util.Date;
import java.util.List;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.vo.DeviceDataVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 17:09
* @version: 1.0
*/
@Data
public class DeviceDataVO {
/**
* 主键
*/
private Long id;
/**
* 模型名称
*/
private String name;
/**
* 模型描述
*/
private String description;
private Date reportTime;
private List<DeviceDataPropertyVO> propertyList;
}
package com.esv.datacenter.iot.module.devicemodel.vo;
import lombok.Data;
/**
* @description:
* @project: datacenter-iot-service
* @name: com.esv.datacenter.iot.module.devicemodel.vo.DeviceDetailVO
* @author: chenfm
* @email: chenfengman@esvtek.com
* @createTime: 2020/8/13 15:42
* @version: 1.0
*/
@Data
public class DeviceDetailVO {
/**
* description 设备实例信息
* author chenfm
* createTime 2020/8/13 15:43
**/
private DeviceInstanceVO deviceInstance;
/**
* description 设备类型信息
* author chenfm
* createTime 2020/8/13 15:43
**/
private DeviceTypeVO deviceType;
}
...@@ -29,4 +29,12 @@ ...@@ -29,4 +29,12 @@
ORDER BY name ASC ORDER BY name ASC
</select> </select>
<select id="deviceTypeDetail" resultType="com.esv.datacenter.iot.module.devicemodel.dto.DeviceTypeDto">
select type.*, count(instance.id) instance_count
from device_type type
left join device_instance instance on instance.device_type_id = type.id and instance.deleted = 0
where type.id = #{id}
group by type.id
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment