| | |
| | | import org.springframework.beans.BeanUtils; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.time.Instant; |
| | | import java.time.LocalDate; |
| | | import java.time.OffsetDateTime; |
| | | import java.time.ZoneId; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.format.DateTimeParseException; |
| | | |
| | | @Data |
| | | public class SiteExcelDTO { |
| | |
| | | if (site.getEstablishmentTime() != null) { |
| | | dto.setEstablishmentTime(site.getEstablishmentTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | } |
| | | dto.setOfficialRunTime(formatDateOnly(site.getOfficialRunTime())); |
| | | return dto; |
| | | } |
| | | |
| | | static String formatDateOnly(String value) { |
| | | if (value == null || value.trim().isEmpty()) { |
| | | return value; |
| | | } |
| | | String text = value.trim(); |
| | | try { |
| | | return LocalDate.parse(text, DateTimeFormatter.ISO_LOCAL_DATE).toString(); |
| | | } catch (DateTimeParseException ignored) { |
| | | // Continue with timestamp formats used by historical site data. |
| | | } |
| | | try { |
| | | return OffsetDateTime.parse(text, DateTimeFormatter.ISO_OFFSET_DATE_TIME) |
| | | .atZoneSameInstant(ZoneId.of("Asia/Shanghai")).toLocalDate().toString(); |
| | | } catch (DateTimeParseException ignored) { |
| | | // Some records use an instant with millisecond precision and a trailing Z. |
| | | } |
| | | try { |
| | | return Instant.parse(text).atZone(ZoneId.of("Asia/Shanghai")).toLocalDate().toString(); |
| | | } catch (DateTimeParseException ignored) { |
| | | return text; |
| | | } |
| | | } |
| | | } |