综合查询页面
This commit is contained in:
@ -1,5 +1,8 @@
|
||||
package com.xzzn.common.enums;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* device-设备类别
|
||||
*
|
||||
@ -13,7 +16,10 @@ public enum DeviceCategory
|
||||
CLUSTER("CLUSTER", "电池簇"),
|
||||
BATTERY("BATTERY", "单体电池"),
|
||||
AMMETER("AMMETER", "电表"),
|
||||
COOLING("COOLING", "冷液体");
|
||||
COOLING("COOLING", "冷却"),
|
||||
DH("DH", "动环"),
|
||||
XF("XF", "消防"),
|
||||
BATTERY_GROUP("BATTERY_GROUP", "电池组");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
@ -33,4 +39,19 @@ public enum DeviceCategory
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
// 缓存info与code的映射(优化查询效率)
|
||||
private static final Map<String, String> INFO_CODE_MAP = new HashMap<>();
|
||||
|
||||
// 静态块初始化缓存
|
||||
static {
|
||||
for (DeviceCategory category : DeviceCategory.values()) {
|
||||
INFO_CODE_MAP.put(category.info, category.code);
|
||||
}
|
||||
}
|
||||
|
||||
// 通过info获取code的方法
|
||||
public static String getCodeByInfo(String info) {
|
||||
return INFO_CODE_MAP.get(info); // 从缓存中直接获取,效率高
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,6 +32,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
|
||||
public static String YYYYMMDD = "yyyyMMdd";
|
||||
|
||||
public static String YYYY_MM_DD_HH_MM_00 = "yyyy-MM-dd HH:mm:00";
|
||||
|
||||
private static String[] parsePatterns = {
|
||||
"yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM",
|
||||
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
|
||||
@ -252,4 +254,39 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
return time.format(DateTimeFormatter.ofPattern("yyyy-MM"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加 LocalDateTime ==> String
|
||||
*/
|
||||
public static String convertToString(LocalDateTime time) {
|
||||
return time.format(DateTimeFormatter.ofPattern(YYYY_MM_DD_HH_MM_SS));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将输入时间调整到下一分钟的整点(秒数强制为00)
|
||||
* 例如:2026-09-03 18:34:49 -> 2026-09-03 18:35:00
|
||||
* @param timeStr 输入时间字符串(支持yyyy-MM-dd HH:mm:ss格式)
|
||||
* @return 调整后的时间字符串(yyyy-MM-dd HH:mm:00)
|
||||
* @throws ParseException 时间格式错误时抛出
|
||||
*/
|
||||
public static String adjustToNextMinute(String timeStr) throws ParseException {
|
||||
// 1. 解析原始时间(使用包含秒数的格式)
|
||||
SimpleDateFormat fullFormat = new SimpleDateFormat(YYYY_MM_DD_HH_MM_SS);
|
||||
Date originalDate = fullFormat.parse(timeStr);
|
||||
|
||||
// 2. 使用Calendar调整时间
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(originalDate);
|
||||
|
||||
// 3. 如果当前秒数大于0,自动进1分钟(否则保持当前分钟)
|
||||
if (cal.get(Calendar.SECOND) > 0) {
|
||||
cal.add(Calendar.MINUTE, 1); // 分钟+1
|
||||
}
|
||||
|
||||
// 4. 强制设置秒数和毫秒为0
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
|
||||
// 5. 格式化为目标字符串
|
||||
return new SimpleDateFormat(YYYY_MM_DD_HH_MM_00).format(cal.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user