【feat】 优化调整time类型字段

This commit is contained in:
Kris 2025-06-09 10:37:50 +08:00
parent d087e1b8c5
commit 2ef79ab159

View File

@ -85,10 +85,12 @@ public class DataUtil {
break; break;
case "date": case "date":
case "datetime": case "datetime":
case "time":
case "boolean": case "boolean":
result = type; result = type;
break; break;
case "time":
result = "time(3)";
break;
case "long": case "long":
case "int": case "int":
result = "int(" + length + ")"; result = "int(" + length + ")";
@ -420,11 +422,30 @@ public class DataUtil {
} }
calendar.setTime(date); calendar.setTime(date);
return calendar; return calendar;
case "time":
return adjustHour(data);
default: default:
return data; return data;
} }
} }
public static String adjustHour(String timeStr) {
// 提取小时部分并转换为整数
int hour = Integer.parseInt(timeStr.substring(0, 2));
// 减去8小时并处理跨天逻辑
int adjustedHour = hour - 8;
if (adjustedHour < 0) {
adjustedHour += 24; // 处理负数情况跨天
}
// 格式化为两位字符串自动补零
String newHour = String.format("%02d", adjustedHour);
// 拼接原始字符串的剩余部分分钟++毫秒
return newHour + timeStr.substring(2);
}
public static boolean isUpdate(String field){ public static boolean isUpdate(String field){
switch (field) { switch (field) {
case "LastModifiedDate": case "LastModifiedDate":