feat(ems): 为监控设备添加温度数据展示功能

- 在 EmsBaseMonitorInfo 模型中添加 temperature 字段
- 更新 TreeSelects 模型以支持温度数据
-调整温度数据查询接口
- 新增温度数据查询 SQL
- 修改sql中selectIotInstantMinitoringData以recodeTime排序
IOT
zch 3 months ago
parent 659ab3a518
commit a970b2889e

@ -6,6 +6,7 @@ import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel; import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.TreeEntity; import com.ruoyi.common.core.domain.TreeEntity;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -98,6 +99,11 @@ public class EmsBaseMonitorInfo extends BaseEntity
private List<Long> monitorTypeList; private List<Long> monitorTypeList;
private BigDecimal temperature;
public List<Long> getMonitorTypeList() { public List<Long> getMonitorTypeList() {
return monitorTypeList; return monitorTypeList;
} }
@ -300,6 +306,17 @@ public class EmsBaseMonitorInfo extends BaseEntity
return monitorHierarchy; return monitorHierarchy;
} }
public BigDecimal getTemperature() {
return temperature;
}
public void setTemperature(BigDecimal temperature) {
this.temperature = temperature;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
@ -323,6 +340,7 @@ public class EmsBaseMonitorInfo extends BaseEntity
.append("updateTime", getUpdateTime()) .append("updateTime", getUpdateTime())
.append("publicShareType", getPublicShareType()) .append("publicShareType", getPublicShareType())
.append("monitorHierarchy", getMonitorHierarchy()) .append("monitorHierarchy", getMonitorHierarchy())
.append("temperature",getTemperature())
.toString(); .toString();
} }
} }

@ -5,6 +5,7 @@ import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.core.domain.entity.SysMenu; import com.ruoyi.common.core.domain.entity.SysMenu;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -28,6 +29,10 @@ public class TreeSelects implements Serializable
private Long monitorType; private Long monitorType;
private BigDecimal tempreture;
/** 子节点 */ /** 子节点 */
@JsonInclude(JsonInclude.Include.NON_EMPTY) @JsonInclude(JsonInclude.Include.NON_EMPTY)
private List<TreeSelects> children; private List<TreeSelects> children;
@ -50,6 +55,7 @@ public class TreeSelects implements Serializable
this.code = baseMonitorInfo.getMonitorCode(); this.code = baseMonitorInfo.getMonitorCode();
this.children = baseMonitorInfo.getChildren().stream().map(TreeSelects::new).collect(Collectors.toList()); this.children = baseMonitorInfo.getChildren().stream().map(TreeSelects::new).collect(Collectors.toList());
this.monitorType = baseMonitorInfo.getMonitorType(); this.monitorType = baseMonitorInfo.getMonitorType();
this.tempreture = baseMonitorInfo.getTemperature();
} }
public TreeSelects(EmsBaseWorkUnit baseWorkUnit){ public TreeSelects(EmsBaseWorkUnit baseWorkUnit){
@ -111,4 +117,13 @@ public class TreeSelects implements Serializable
public void setMonitorType(Long monitorType) { public void setMonitorType(Long monitorType) {
this.monitorType = monitorType; this.monitorType = monitorType;
} }
public BigDecimal getTempreture() {
return tempreture;
}
public void setTempreture(BigDecimal tempreture) {
this.tempreture = tempreture;
}
} }

@ -1,13 +1,20 @@
package com.ruoyi.ems.base.service.impl; package com.ruoyi.ems.base.service.impl;
import java.util.ArrayList; import java.math.BigDecimal;
import java.util.Iterator; import java.util.*;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.ems.base.domain.TreeSelects; import com.ruoyi.ems.base.domain.TreeSelects;
import com.ruoyi.ems.record.domain.TWTempertureData;
import com.ruoyi.ems.record.mapper.TWTempertureDataMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.ems.base.mapper.EmsBaseMonitorInfoMapper; import com.ruoyi.ems.base.mapper.EmsBaseMonitorInfoMapper;
@ -26,6 +33,8 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
@Autowired @Autowired
private EmsBaseMonitorInfoMapper emsBaseMonitorInfoMapper; private EmsBaseMonitorInfoMapper emsBaseMonitorInfoMapper;
@Autowired
private TWTempertureDataMapper tWTempertureDataMapper;
/** /**
* *
* *
@ -139,9 +148,50 @@ public class EmsBaseMonitorInfoServiceImpl implements IEmsBaseMonitorInfoService
* @return * @return
*/ */
@Override @Override
public List<EmsBaseMonitorInfo> buildMonitorInfoTree(List<EmsBaseMonitorInfo> baseMonitorInfos) public List<EmsBaseMonitorInfo> buildMonitorInfoTree(List<EmsBaseMonitorInfo> baseMonitorInfos) {
{
List<EmsBaseMonitorInfo> returnList = new ArrayList<EmsBaseMonitorInfo>(); // 创建一个Map来存储温度数据键为监控ID值为TWTempertureData对象
Map<String, TWTempertureData> tempDataMap = new HashMap<>();
// 创建一个List来存储设备编号
List<String> monitorCodes = new ArrayList<>();
// 遍历设备列表
for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) {
// 如果设备不为空且监控类型为1L
if (!ObjectUtils.isEmpty(baseMonitorInfo) && baseMonitorInfo.getMonitorType() == 1L) {
// 获取设备编号并添加到设备编号列表中
String monitorCode = baseMonitorInfo.getMonitorCode();
monitorCodes.add(monitorCode);
}
}
// 如果设备编号列表不为空
if (CollectionUtils.isNotEmpty(monitorCodes)) {
// 根据设备编号列表查询最新的温度数据
List<TWTempertureData> tempDatas = tWTempertureDataMapper.selectLastTWTempertureDataByMonitorCodes(monitorCodes);
// 遍历查询到的温度数据
for (TWTempertureData tempData : tempDatas) {
// 如果温度数据和温度值不为空
if (!ObjectUtils.isEmpty(tempData) && tempData.getTempreture() != null) {
// 将温度数据存入Map中键为监控ID值为温度数据对象
tempDataMap.put(tempData.getMonitorId(), tempData);
}
}
// 再次遍历设备列表
for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) {
// 如果设备不为空且监控类型为1L
if (!ObjectUtils.isEmpty(baseMonitorInfo) && baseMonitorInfo.getMonitorType() == 1L) {
// 根据设备ID从Map中获取对应的温度数据
TWTempertureData tempData = tempDataMap.get(baseMonitorInfo.getMonitorCode());
// 如果温度数据不为空
if (!ObjectUtils.isEmpty(tempData)) {
// 设置设备的温度值
baseMonitorInfo.setTemperature(tempData.getTempreture());
}
}
}
}
List<EmsBaseMonitorInfo> returnList = new ArrayList<>();
List<Long> tempList = baseMonitorInfos.stream().map(EmsBaseMonitorInfo::getObjId).collect(Collectors.toList()); List<Long> tempList = baseMonitorInfos.stream().map(EmsBaseMonitorInfo::getObjId).collect(Collectors.toList());
for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos) for (EmsBaseMonitorInfo baseMonitorInfo : baseMonitorInfos)
{ {

@ -221,15 +221,15 @@ public class TWTempertureDataController extends BaseController
return tWTempertureDataService.selectLastTWTempertureData(tWTempertureData); return tWTempertureDataService.selectLastTWTempertureData(tWTempertureData);
} }
/** /* *//**
* *
*/ *//*
@PreAuthorize("@ss.hasPermi('ems/record:recordIOTInstant:list')") @PreAuthorize("@ss.hasPermi('ems/record:recordIOTInstant:list')")
@PostMapping("/boardTWTempertureDataList") @PostMapping("/boardTWTempertureDataList")
public AjaxResult boardTWTempertureDataList(TWTempertureData tWTempertureData) public AjaxResult boardTWTempertureDataList(TWTempertureData tWTempertureData)
{ {
List<TWTempertureData> list = tWTempertureDataService.selectTWTempertureDataList(tWTempertureData); List<TreeSelects> list = tWTempertureDataService.selectBoardTWTempertureDataList(tWTempertureData);
return success(list); return success(list);
} }*/
} }

@ -79,4 +79,8 @@ public interface TWTempertureDataMapper
* @return * @return
*/ */
public List<TWTempertureData> selectLastTWTempertureDataList(TWTempertureData tWTempertureData); public List<TWTempertureData> selectLastTWTempertureDataList(TWTempertureData tWTempertureData);
public TWTempertureData selectLastTWTempertureDataByMonitorCode(String monitorId);
public List<TWTempertureData> selectLastTWTempertureDataByMonitorCodes(List<String> monitorCodes);
} }

@ -103,7 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<where> <where>
<if test="monitorId != null and monitorId != ''"> and twtd.monitorId = #{monitorId}</if> <if test="monitorId != null and monitorId != ''"> and twtd.monitorId = #{monitorId}</if>
</where> </where>
order by twtd.recordTime desc order by twtd.recodeTime desc
</select> </select>
<insert id="insertTWTempertureData" parameterType="TWTempertureData" useGeneratedKeys="true" keyProperty="objid"> <insert id="insertTWTempertureData" parameterType="TWTempertureData" useGeneratedKeys="true" keyProperty="objid">
@ -194,4 +194,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where twtd.rownum = 1; where twtd.rownum = 1;
</select> </select>
<select id="selectLastTWTempertureDataByMonitorCode" parameterType="TWTempertureData" resultMap="TWTempertureDataResult">
SELECT twtd.tempreture
FROM T_W_TempertureData twtd
WHERE twtd.monitorId = #{monitorId}
ORDER BY twtd.objid DESC
LIMIT 1
</select>
<select id="selectLastTWTempertureDataByMonitorCodes" parameterType="list" resultMap="TWTempertureDataResult">
SELECT twtd.*
FROM (
SELECT *,
ROW_NUMBER() OVER(PARTITION BY monitorId ORDER BY recodeTime DESC) as rownum
FROM T_W_TempertureData
WHERE monitorId IN
<foreach item="monitorCode" collection="list" open="(" separator="," close=")">
#{monitorCode}
</foreach>
) twtd
LEFT JOIN ems_base_monitor_info ebmi ON twtd.monitorId = ebmi.monitor_code
WHERE twtd.rownum = 1;
</select>
</mapper> </mapper>

Loading…
Cancel
Save