Commit 6dc6ddac by huangjinxin

fix:时间返回优化

1 parent 3ec3f5eb
package com.dituhui.pea.order.common;
import cn.hutool.core.util.ObjectUtil;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -7,68 +9,71 @@ import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
public class TimeUtils {
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_GAP_FORMAT = "yyyy-MM-dd";
public static final String TIME_HH_MM_FORMAT = "HH:mm";
public static final String IsoTimestamp2DateTime(Timestamp timestamp) {
// Timestamp转换为日期时间字符串
LocalDateTime localDateTime = timestamp.toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
}
public static final Timestamp IsoDateTime2Timestamp(String datetime) {
// 将日期时间字符串转换为Timestamp
LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
return Timestamp.valueOf(localDateTime);
}
public static final String timestamp2DateTime(Timestamp timestamp, String pattern) {
// Timestamp转换为日期时间字符串
LocalDateTime localDateTime = timestamp.toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
public static final Timestamp dateTime2Timestamp(String datetime, String pattern) {
// 将日期时间字符串转换为Timestamp
LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(pattern));
return Timestamp.valueOf(localDateTime);
}
public static final LocalDate IsoDate2LocalDate(String s) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
}
public static final LocalDate date2LocalDate(String s, String pattern) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern(pattern));
}
public static final LocalDateTime IsoDateTime2LocalDateTime(String s) {
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
}
public static final String IsoLocalDateTime2String(LocalDateTime localDateTime) {
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
}
public static final String localDateTime2String(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
public static final String IsoLocalDate2String(LocalDate localDate) {
return localDate.format(DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
}
public static final LocalTime time2LocalTime(String s) {
return LocalTime.parse(s, DateTimeFormatter.ofPattern(TIME_HH_MM_FORMAT));
}
public static final LocalDate addDays(LocalDate date, long days) {
return date.plusDays(days);
}
public static final LocalDate subDays(LocalDate date, long days) {
return date.minusDays(days);
}
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_GAP_FORMAT = "yyyy-MM-dd";
public static final String TIME_HH_MM_FORMAT = "HH:mm";
public static final String IsoTimestamp2DateTime(Timestamp timestamp) {
// Timestamp转换为日期时间字符串
LocalDateTime localDateTime = timestamp.toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
}
public static final Timestamp IsoDateTime2Timestamp(String datetime) {
// 将日期时间字符串转换为Timestamp
LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
return Timestamp.valueOf(localDateTime);
}
public static final String timestamp2DateTime(Timestamp timestamp, String pattern) {
// Timestamp转换为日期时间字符串
LocalDateTime localDateTime = timestamp.toLocalDateTime();
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
public static final Timestamp dateTime2Timestamp(String datetime, String pattern) {
// 将日期时间字符串转换为Timestamp
LocalDateTime localDateTime = LocalDateTime.parse(datetime, DateTimeFormatter.ofPattern(pattern));
return Timestamp.valueOf(localDateTime);
}
public static final LocalDate IsoDate2LocalDate(String s) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
}
public static final LocalDate date2LocalDate(String s, String pattern) {
return LocalDate.parse(s, DateTimeFormatter.ofPattern(pattern));
}
public static final LocalDateTime IsoDateTime2LocalDateTime(String s) {
return LocalDateTime.parse(s, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
}
public static final String IsoLocalDateTime2String(LocalDateTime localDateTime) {
if (ObjectUtil.isNull(localDateTime)) {
return null;
}
return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT));
}
public static final String localDateTime2String(LocalDateTime localDateTime, String pattern) {
return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
}
public static final String IsoLocalDate2String(LocalDate localDate) {
return localDate.format(DateTimeFormatter.ofPattern(DATE_GAP_FORMAT));
}
public static final LocalTime time2LocalTime(String s) {
return LocalTime.parse(s, DateTimeFormatter.ofPattern(TIME_HH_MM_FORMAT));
}
public static final LocalDate addDays(LocalDate date, long days) {
return date.plusDays(days);
}
public static final LocalDate subDays(LocalDate date, long days) {
return date.minusDays(days);
}
}
......@@ -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
// @JsonInclude(JsonInclude.Include.NON_NULL)
......
......@@ -117,10 +117,10 @@ public class OrderServiceDetailImpl implements OrderServiceDetail {
res.setBeanTags(order.getBeanTags());
res.setTranscend(order.getTranscend());
res.setEngineerCodeSub(order.getEngineerCodeSub());
res.setPlanStartTime(order.getPlanStartTime());
res.setPlanEndTime(order.getPlanEndTime());
res.setActualStartTime(order.getActualStartTime());
res.setActualEndTime(order.getActualEndTime());
res.setPlanStartTime(TimeUtils.IsoLocalDateTime2String(order.getPlanStartTime()));
res.setPlanEndTime(TimeUtils.IsoLocalDateTime2String(order.getPlanEndTime()));
res.setActualStartTime(TimeUtils.IsoLocalDateTime2String(order.getActualStartTime()));
res.setActualEndTime(TimeUtils.IsoLocalDateTime2String(order.getActualEndTime()));
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!