Commit 6dc6ddac by huangjinxin

fix:时间返回优化

1 parent 3ec3f5eb
package com.dituhui.pea.order.common; package com.dituhui.pea.order.common;
import cn.hutool.core.util.ObjectUtil;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -7,68 +9,71 @@ import java.time.LocalTime; ...@@ -7,68 +9,71 @@ import java.time.LocalTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
public class TimeUtils { public class TimeUtils {
public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
public static final String DATE_NO_GAP_FORMAT = "yyyyMMdd"; public static final String DATE_NO_GAP_FORMAT = "yyyyMMdd";
public static final String DATE_GAP_FORMAT = "yyyy-MM-dd"; public static final String DATE_GAP_FORMAT = "yyyy-MM-dd";
public static final String TIME_HH_MM_FORMAT = "HH:mm"; public static final String TIME_HH_MM_FORMAT = "HH:mm";
public static final String IsoTimestamp2DateTime(Timestamp timestamp) { public static final String IsoTimestamp2DateTime(Timestamp timestamp) {
// Timestamp转换为日期时间字符串 // Timestamp转换为日期时间字符串
LocalDateTime localDateTime = timestamp.toLocalDateTime(); LocalDateTime localDateTime = timestamp.toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
} }
public static final Timestamp IsoDateTime2Timestamp(String datetime) { public static final Timestamp IsoDateTime2Timestamp(String datetime) {
// 将日期时间字符串转换为Timestamp // 将日期时间字符串转换为Timestamp
LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
return Timestamp.valueOf(localDateTime); return Timestamp.valueOf(localDateTime);
} }
public static final String timestamp2DateTime(Timestamp timestamp, String pattern) { public static final String timestamp2DateTime(Timestamp timestamp, String pattern) {
// Timestamp转换为日期时间字符串 // Timestamp转换为日期时间字符串
LocalDateTime localDateTime = timestamp.toLocalDateTime(); LocalDateTime localDateTime = timestamp.toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern(pattern)); return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
} }
public static final Timestamp dateTime2Timestamp(String datetime, String pattern) { public static final Timestamp dateTime2Timestamp(String datetime, String pattern) {
// 将日期时间字符串转换为Timestamp // 将日期时间字符串转换为Timestamp
LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(pattern)); LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(pattern));
return Timestamp.valueOf(localDateTime); return Timestamp.valueOf(localDateTime);
} }
public static final LocalDate IsoDate2LocalDate(String s) { public static final LocalDate IsoDate2LocalDate(String s) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern(DATE_GAP_FORMAT)); return LocalDate.parse(s, DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
} }
public static final LocalDate date2LocalDate(String s, String pattern) { public static final LocalDate date2LocalDate(String s, String pattern) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern(pattern)); return LocalDate.parse(s, DateTimeFormatter.ofPattern(pattern));
} }
public static final LocalDateTime IsoDateTime2LocalDateTime(String s) { public static final LocalDateTime IsoDateTime2LocalDateTime(String s) {
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); return LocalDateTime.parse(s, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
} }
public static final String IsoLocalDateTime2String(LocalDateTime localDateTime) { public static final String IsoLocalDateTime2String(LocalDateTime localDateTime) {
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); if (ObjectUtil.isNull(localDateTime)) {
} return null;
}
public static final String localDateTime2String(LocalDateTime localDateTime, String pattern) { return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
return localDateTime.format(DateTimeFormatter.ofPattern(pattern)); }
}
public static final String localDateTime2String(LocalDateTime localDateTime, String pattern) {
public static final String IsoLocalDate2String(LocalDate localDate) { return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
return localDate.format(DateTimeFormatter.ofPattern(DATE_GAP_FORMAT)); }
}
public static final String IsoLocalDate2String(LocalDate localDate) {
public static final LocalTime time2LocalTime(String s) { return localDate.format(DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
return LocalTime.parse(s, DateTimeFormatter.ofPattern(TIME_HH_MM_FORMAT)); }
}
public static final LocalTime time2LocalTime(String s) {
public static final LocalDate addDays(LocalDate date, long days) { return LocalTime.parse(s, DateTimeFormatter.ofPattern(TIME_HH_MM_FORMAT));
return date.plusDays(days); }
}
public static final LocalDate addDays(LocalDate date, long days) {
public static final LocalDate subDays(LocalDate date, long days) { return date.plusDays(days);
return date.minusDays(days); }
}
public static final LocalDate subDays(LocalDate date, long days) {
return date.minusDays(days);
}
} }
...@@ -113,22 +113,22 @@ public class OrderServiceDetailResp { ...@@ -113,22 +113,22 @@ public class OrderServiceDetailResp {
/** /**
* 计划开始时间 * 计划开始时间
*/ */
private LocalDateTime planStartTime; private String planStartTime;
/** /**
* 计划结束时间 * 计划结束时间
*/ */
private LocalDateTime planEndTime; private String planEndTime;
/** /**
* 开始服务时间 * 开始服务时间
*/ */
private LocalDateTime actualStartTime; private String actualStartTime;
/** /**
* 结束服务时间 * 结束服务时间
*/ */
private LocalDateTime actualEndTime; private String actualEndTime;
// //
// @Data // @Data
// @JsonInclude(JsonInclude.Include.NON_NULL) // @JsonInclude(JsonInclude.Include.NON_NULL)
......
...@@ -117,10 +117,10 @@ public class OrderServiceDetailImpl implements OrderServiceDetail { ...@@ -117,10 +117,10 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
res.setBeanTags(order.getBeanTags()); res.setBeanTags(order.getBeanTags());
res.setTranscend(order.getTranscend()); res.setTranscend(order.getTranscend());
res.setEngineerCodeSub(order.getEngineerCodeSub()); res.setEngineerCodeSub(order.getEngineerCodeSub());
res.setPlanStartTime(order.getPlanStartTime()); res.setPlanStartTime(TimeUtils.IsoLocalDateTime2String(order.getPlanStartTime()));
res.setPlanEndTime(order.getPlanEndTime()); res.setPlanEndTime(TimeUtils.IsoLocalDateTime2String(order.getPlanEndTime()));
res.setActualStartTime(order.getActualStartTime()); res.setActualStartTime(TimeUtils.IsoLocalDateTime2String(order.getActualStartTime()));
res.setActualEndTime(order.getActualEndTime()); res.setActualEndTime(TimeUtils.IsoLocalDateTime2String(order.getActualEndTime()));
return Result.success(res); return Result.success(res);
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!