Commit 5a983b74 authored by 张森's avatar 张森

30546 运行趋势页签接口开发

parent b9ae6138
...@@ -880,7 +880,9 @@ public class SupervisionConfigureController extends AbstractBaseController { ...@@ -880,7 +880,9 @@ public class SupervisionConfigureController extends AbstractBaseController {
@ApiOperation(httpMethod = "GET", value = "设备平台运行趋势 水池液位趋势API", produces = "application/json;charset=UTF-8", notes = "设备平台运行趋势 水池液位趋势API") @ApiOperation(httpMethod = "GET", value = "设备平台运行趋势 水池液位趋势API", produces = "application/json;charset=UTF-8", notes = "设备平台运行趋势 水池液位趋势API")
public ResponseModel operatingTrendWater(@RequestParam(value = "startTime", required = false) String startTime, public ResponseModel operatingTrendWater(@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime, @RequestParam(value = "endTime", required = false) String endTime,
@RequestParam(value = "bizOrgCode", required = false) String bizOrgCode) throws ParseException { @RequestParam(value = "bizOrgCode", required = false) String bizOrgCode,
@RequestParam(value = "equipCode", required = false) String equipCode,
@RequestParam(value = "indexKey", required = false) String indexKey) throws ParseException {
if (ObjectUtils.isEmpty(bizOrgCode)) { if (ObjectUtils.isEmpty(bizOrgCode)) {
ReginParams reginParams = getSelectedOrgInfo(); ReginParams reginParams = getSelectedOrgInfo();
ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity(); ReginParams.PersonIdentity personIdentity = reginParams.getPersonIdentity();
...@@ -891,7 +893,7 @@ public class SupervisionConfigureController extends AbstractBaseController { ...@@ -891,7 +893,7 @@ public class SupervisionConfigureController extends AbstractBaseController {
} }
} }
} }
EquipTrendResultVo equipTrendResultVo = equipmentSpecificService.operatingTrendWater(startTime, endTime, bizOrgCode); EquipTrendResultVo equipTrendResultVo = equipmentSpecificService.operatingTrendWater(startTime, endTime, bizOrgCode, equipCode, indexKey);
return CommonResponseUtil.success(equipTrendResultVo); return CommonResponseUtil.success(equipTrendResultVo);
} }
} }
...@@ -360,4 +360,6 @@ public interface EquipmentSpecificMapper extends BaseMapper<EquipmentSpecific> { ...@@ -360,4 +360,6 @@ public interface EquipmentSpecificMapper extends BaseMapper<EquipmentSpecific> {
List<EquipTrendInfoVo> getWaterList(@Param("bizOrgCode") String bizOrgCode); List<EquipTrendInfoVo> getWaterList(@Param("bizOrgCode") String bizOrgCode);
List<Map<String, String>> getIndexKeyByIotCode(@Param("list") Set<String> list); List<Map<String, String>> getIndexKeyByIotCode(@Param("list") Set<String> list);
List<Map<String, String>> getIndexKeyByIotCodeWaterTank(@Param("list") Set<String> list);
} }
...@@ -335,5 +335,5 @@ public interface IEquipmentSpecificSerivce extends IService<EquipmentSpecific> { ...@@ -335,5 +335,5 @@ public interface IEquipmentSpecificSerivce extends IService<EquipmentSpecific> {
EquipTrendResultVo operatingTrendPressurePump(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey) throws ParseException; EquipTrendResultVo operatingTrendPressurePump(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey) throws ParseException;
EquipTrendResultVo operatingTrendWater(String startTime, String endTime, String bizOrgCode) throws ParseException; EquipTrendResultVo operatingTrendWater(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey) throws ParseException;
} }
package com.yeejoin.equipmanage.service.impl; package com.yeejoin.equipmanage.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
...@@ -2301,9 +2302,12 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2301,9 +2302,12 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) { if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) {
String json = JSON.toJSONString(entity.getResult()); String json = JSON.toJSONString(entity.getResult());
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json); List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
// 使用Stream API进行排序
List<Map<String, String>> sortedList = listObject.stream()
.sorted(Comparator.comparing(t -> t.get("time")))
.collect(Collectors.toList());
Map<String, String> timeAndValue = new HashMap<>(); Map<String, String> timeAndValue = new HashMap<>();
for (Map<String, String> mapList : listObject) { for (Map<String, String> mapList : sortedList) {
if (mapList.containsKey(indexKey)) { if (mapList.containsKey(indexKey)) {
timeAndValue.put(mapList.get("time"), mapList.get(indexKey)); timeAndValue.put(mapList.get("time"), mapList.get(indexKey));
allTimeList.add(mapList.get("time")); allTimeList.add(mapList.get("time"));
...@@ -2419,21 +2423,35 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2419,21 +2423,35 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
} }
@Override @Override
public EquipTrendResultVo operatingTrendWater(String startTime, String endTime, String bizOrgCode) throws ParseException { public EquipTrendResultVo operatingTrendWater(String startTime, String endTime, String bizOrgCode, String equipCode, String indexKey) throws ParseException {
//横坐标数据 //横坐标数据
List<String> allTimeList = getTimePoints(startTime, endTime); List<String> allTimeList = getTimePoints(startTime, endTime);
List<EquipTrendInfoVo> equipList = equipmentSpecificMapper.getWaterList(bizOrgCode); List<EquipTrendInfoVo> equipList = new ArrayList<>();
ResponseModel entity = null;
Set<String> strings = new HashSet<>();
equipList.forEach(item -> {
String[] split = item.getIotCode().split(",");
strings.addAll(Arrays.asList(split));
});
List<Map<String, String>> indexKeyByIotCode = equipmentSpecificMapper.getIndexKeyByIotCode(strings);
Map<String, String> iotCodeIndexKeyMap = indexKeyByIotCode.stream().collect(Collectors.toMap(t -> t.get("iotCode"), t -> t.get("indexKey")));
// iot服务查到的数据,存储为map key:iotCode value: iot查询的液位数据 // iot服务查到的数据,存储为map key:iotCode value: iot查询的液位数据
HashMap<String, List<Map<String, String>>> iotDataInfoMap = new HashMap<>(); HashMap<String, List<Map<String, String>>> iotDataInfoMap = new HashMap<>();
Map<String, String> iotCodeIndexKeyMap = new HashMap<>();
Set<String> strings = new HashSet<>();
if (StrUtil.isEmpty(equipCode)) {
equipList = equipmentSpecificMapper.getWaterList(bizOrgCode);
equipList.forEach(item -> {
String[] split = item.getIotCode().split(",");
strings.addAll(Arrays.asList(split));
});
List<Map<String, String>> indexKeyByIotCode = equipmentSpecificMapper.getIndexKeyByIotCode(strings);
iotCodeIndexKeyMap = indexKeyByIotCode.stream().collect(Collectors.toMap(t -> t.get("iotCode"), t -> t.get("indexKey")));
} else {
equipList = equipmentSpecificMapper.getEquipListByCode(equipCode, indexKey, bizOrgCode);
equipList.forEach(item -> {
String[] split = item.getIotCode().split(",");
strings.addAll(Arrays.asList(split));
});
List<Map<String, String>> indexKeyByIotCode = equipmentSpecificMapper.getIndexKeyByIotCodeWaterTank(strings);
iotCodeIndexKeyMap = indexKeyByIotCode.stream().collect(Collectors.toMap(t -> t.get("iotCode"), t -> t.get("indexKey")));
}
for (String iotCode : strings) { for (String iotCode : strings) {
//iot数据查询组装 //iot数据查询组装
...@@ -2445,14 +2463,22 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2445,14 +2463,22 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
} else { } else {
throw new BadRequest("装备物联编码不存在或编码错误,请确认!"); throw new BadRequest("装备物联编码不存在或编码错误,请确认!");
} }
ResponseModel entity = null;
try { try {
if (iotCodeIndexKeyMap.containsKey(iotCode) && StringUtil.isNotEmpty(iotCodeIndexKeyMap.get(iotCode))) { if (iotCodeIndexKeyMap.containsKey(iotCode) && StringUtil.isNotEmpty(iotCodeIndexKeyMap.get(iotCode))) {
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startTime, endTime, prefix, suffix, iotCodeIndexKeyMap.get(iotCode)); String[] split = iotCodeIndexKeyMap.get(iotCode).split(",");
if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) { for (String indexKeyNew : split) {
String json = JSON.toJSONString(entity.getResult()); entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), startTime, endTime, prefix, suffix, indexKeyNew);
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json); if (200 == entity.getStatus() && !ObjectUtils.isEmpty(entity.getResult())) {
if (!CollectionUtils.isEmpty(listObject)) { String json = JSON.toJSONString(entity.getResult());
iotDataInfoMap.put(iotCode, listObject); List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
if (!CollectionUtils.isEmpty(listObject)) {
if (iotDataInfoMap.containsKey(iotCode)) {
iotDataInfoMap.get(iotCode).addAll(listObject);
} else {
iotDataInfoMap.put(iotCode, listObject);
}
}
} }
} }
} }
...@@ -2480,15 +2506,18 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2480,15 +2506,18 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
String[] split = equipInfo.getIotCode().split(","); String[] split = equipInfo.getIotCode().split(",");
for (String iotCode : split) { for (String iotCode : split) {
String indexKey = iotCodeIndexKeyMap.get(iotCode); String equipIndexKey = iotCodeIndexKeyMap.get(iotCode);
String[] equipIndexKeyNew = equipIndexKey.split(",");
if (!ObjectUtils.isEmpty(iotDataInfoMap) && iotDataInfoMap.containsKey(iotCode)) { if (!ObjectUtils.isEmpty(iotDataInfoMap) && iotDataInfoMap.containsKey(iotCode)) {
List<Map<String, String>> listObject = iotDataInfoMap.get(iotCode); List<Map<String, String>> listObject = iotDataInfoMap.get(iotCode);
for (Map<String, String> mapList : listObject) { for (Map<String, String> mapList : listObject) {
String time = change(mapList.get("time")); String time = change(mapList.get("time"));
String dateX = roundToNearestFiveMinutes(time); String dateX = roundToNextFiveMinutes(time);
if (stringIntegerHashMap.containsKey(dateX)){ if (stringIntegerHashMap.containsKey(dateX)){
if (mapList.containsKey(indexKey) && !ObjectUtils.isEmpty(mapList.get(indexKey))) { for (String key : equipIndexKeyNew) {
stringIntegerHashMap.get(dateX).add(new BigDecimal(mapList.get(indexKey))); if (mapList.containsKey(key) && !ObjectUtils.isEmpty(mapList.get(key))) {
stringIntegerHashMap.get(dateX).add(new BigDecimal(mapList.get(key)));
}
} }
} else { } else {
stringIntegerHashMap.put(dateX, new ArrayList<>()); stringIntegerHashMap.put(dateX, new ArrayList<>());
...@@ -2569,7 +2598,6 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2569,7 +2598,6 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
} }
// 格式化时间显示
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm"); private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
/** /**
...@@ -2584,11 +2612,21 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2584,11 +2612,21 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
try { try {
// 将字符串时间转换为Date对象 // 将字符串时间转换为Date对象
Date startTime = sdf.parse(startTimeStr.substring(0, 16) + ":00"); // 截取到分钟,因为我们是按五分钟计算 // 注意:这里我们直接解析startTimeStr的完整格式,但只使用年和月日时分来计算下一个五分钟节点
Date startTime = sdf.parse(startTimeStr);
Date endTime = sdf.parse(endTimeStr); Date endTime = sdf.parse(endTimeStr);
// 初始时间点为开始时间的五分钟后的时间 // 计算起始时间的下一个五分钟节点
Date currentTime = new Date(startTime.getTime() + 5 * 60 * 1000); // 加上五分钟的时间 Calendar calendar = Calendar.getInstance();
calendar.setTime(startTime);
int minute = calendar.get(Calendar.MINUTE);
int nextFiveMinute = (minute / 5 + 1) * 5; // 计算下一个五分钟节点的分钟数
calendar.set(Calendar.MINUTE, nextFiveMinute);
calendar.set(Calendar.SECOND, 0); // 重置秒为0
calendar.set(Calendar.MILLISECOND, 0); // 重置毫秒为0
// 初始时间点为起始时间的下一个五分钟节点
Date currentTime = calendar.getTime();
// 循环直到当前时间超过结束时间 // 循环直到当前时间超过结束时间
while (currentTime.before(endTime) || currentTime.equals(endTime)) { while (currentTime.before(endTime) || currentTime.equals(endTime)) {
...@@ -2596,7 +2634,8 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2596,7 +2634,8 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
timePoints.add(sdf.format(currentTime)); timePoints.add(sdf.format(currentTime));
// 计算下一个时间点(五分钟后的时间) // 计算下一个时间点(五分钟后的时间)
currentTime = new Date(currentTime.getTime() + 5 * 60 * 1000); calendar.add(Calendar.MINUTE, 5);
currentTime = calendar.getTime();
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -2606,59 +2645,36 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM ...@@ -2606,59 +2645,36 @@ public class EquipmentSpecificSerivceImpl extends ServiceImpl<EquipmentSpecificM
} }
// 定义一个DateTimeFormatter用于解析输入时间(包含秒) // 定义一个DateTimeFormatter用于解析输入时间(包含秒)
// 但实际上在这个方法中我们不会直接使用它,因为我们可以直接截取字符串 // 注意:虽然在这个方法中我们不会直接使用它,但保留它以备将来需要
private static final DateTimeFormatter parserWithSeconds = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); private static final DateTimeFormatter parserWithSeconds = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 定义一个DateTimeFormatter用于格式化输出时间(不包含秒) // 定义一个DateTimeFormatter用于格式化输出时间(不包含秒)
private static final DateTimeFormatter formatterFive = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); private static final DateTimeFormatter formatterFive = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
/** /**
* 将给定的时间转换为最接近的5分钟节点 * 将给定的时间调整为下一个5分钟节点
* *
* @param timeStr 输入的时间字符串,格式为"yyyy-MM-dd HH:mm:ss" * @param timeStr 输入的时间字符串,格式为"yyyy-MM-dd HH:mm:ss"
* @return 转换后的时间字符串,格式为"yyyy-MM-dd HH:mm" * @return 转换后的时间字符串,格式为"yyyy-MM-dd HH:mm"
*/ */
public static String roundToNearestFiveMinutes(String timeStr) { public static String roundToNextFiveMinutes(String timeStr) {
// 截取时间字符串到分钟部分(这里我们不需要真的解析秒,只是确保格式正确) // 直接解析包含秒的时间字符串(虽然在这个方法中我们不需要秒)
String timeStrToMinute = timeStr.substring(0, 16); LocalDateTime dateTime = LocalDateTime.parse(timeStr, parserWithSeconds);
// 假设timeStrToMinute已经是"yyyy-MM-dd HH:mm"格式,我们可以直接用它来构造LocalDateTime
// 但为了严谨性,我们还是使用formatter来解析(尽管在这个特定情况下不是必需的)
// LocalDateTime dateTime = LocalDateTime.parse(timeStrToMinute, formatter); // 这行其实可以省略,因为我们没有用到formatter的解析功能
// 但为了简化,我们直接构造LocalDateTime(因为我们已经知道字符串是有效的)
LocalDateTime dateTime = LocalDateTime.of(
Integer.parseInt(timeStr.substring(0, 4)), // 年
Integer.parseInt(timeStr.substring(5, 7)), // 月
Integer.parseInt(timeStr.substring(8, 10)), // 日
Integer.parseInt(timeStr.substring(11, 13)), // 时
Integer.parseInt(timeStr.substring(14, 16)) // 分
);
// 获取分钟数 // 获取分钟数
int minute = dateTime.getMinute(); int minute = dateTime.getMinute();
// 计算与最近5分钟节点的差距 // 计算到下一个5分钟节点的分钟数
// 注意:这里的计算方式需要调整,以确保正确向上或向下舍入 int nextFiveMinutes = (minute / 5 + 1) * 5; // 总是向上调整到下一个5分钟倍数
int adjustment = (minute / 5) * 5; // 向下舍入到最近的5分钟
if (minute % 5 >= 3) { // 如果分钟数距离下一个5分钟节点较近,则调整为下一个5分钟节点 // 计算需要增加的分钟数
adjustment += 5; int adjustment = nextFiveMinutes - minute;
}
// 加上差距值(可能是0,可能是5) // 加上差值以调整到下一个5分钟节点,并保留小时和日期部分,但重置秒为0
dateTime = dateTime.plusMinutes(adjustment - minute); // 使用差值来调整 LocalDateTime roundedDateTime = dateTime.plusMinutes(adjustment).withSecond(0);
// 格式化并返回结果 // 格式化并返回结果
return dateTime.format(formatterFive); return roundedDateTime.format(formatterFive);
} }
// public static void main(String[] args) {
// String time1 = "2024-09-19 03:54:10";
// String time2 = "2024-09-19 03:56:10";
//
// System.out.println(roundToNearestFiveMinutes(time1)); // 输出: 2024-09-19 03:55
// System.out.println(roundToNearestFiveMinutes(time2)); // 输出: 2024-09-19 04:00
// }
//}
} }
...@@ -3078,4 +3078,23 @@ ...@@ -3078,4 +3078,23 @@
GROUP BY GROUP BY
a.iot_code a.iot_code
</select> </select>
<select id="getIndexKeyByIotCodeWaterTank" resultType="java.util.Map">
SELECT
a.iot_code AS iotCode,
GROUP_CONCAT( b.equipment_index_key ) AS indexKey
FROM
wl_equipment_specific a
LEFT JOIN ( SELECT * FROM wl_equipment_specific_index WHERE type_code = 'LiquidLevel' ) b ON a.id = b.equipment_specific_id
WHERE
a.iot_code IN
<foreach item="item" collection="list" separator="," open="(" close=")" index="">
#{item}
</foreach>
GROUP BY
a.iot_code
HAVING
indexKey IS NOT NULL
AND indexKey != ''
</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