feat: LocalDate 처리 적용

dev
minuk926 2 years ago
parent 6b15987f3f
commit 048d6b9d24

@ -228,6 +228,8 @@ dependencies {
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.13.1'
implementation 'com.fasterxml.jackson.module:jackson-module-afterburner:2.13.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.13.1'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.13.3'
// JAP LAZY loading (OneToMay <--> ManyToOne)
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-hibernate5'
//implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.5'

@ -62,7 +62,7 @@ public class ParkingController {
return RestResponse.of(service.findParkings(dto, pageable));
}
@Secured(policy = SecurityPolicy.TOKEN)
//@Secured(policy = SecurityPolicy.TOKEN)
@Operation(summary = "주정차 의견진술 심의 결과" , description = "주정차 의견진술 심의 결과")
@Parameters({
@Parameter(in = ParameterIn.QUERY, name = "msSdate", description = "심사시작일", required = true, example = "2021-01-04"),

@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Size;
import java.time.LocalDate;
@ -19,6 +20,7 @@ public class DashboardJudgeListDto {
@Schema(title = "심사종료일", example = "2022-03-23", description = "심사종료일")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msEdate;
@Schema(title = "심사팀코드", example = " ", description = "심사팀코드")

@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@ -33,6 +34,7 @@ public class JudgeDetailDto {
@Schema(required = true, title = "심사시작일", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msSdate;
@Schema(required = true, title = "심사시작시간", example = " ", description = "Input Description...")
@ -40,17 +42,19 @@ public class JudgeDetailDto {
@Schema(required = true, title = "심사종료일", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msEdate;
@Schema(required = true, title = "심사마감일", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msCdate;
@Schema(required = true, title = "심사마감시간", example = " ", description = "Input Description...")
private String msClosesi;
@Schema(required = false, title = "단속일자", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
//@JsonFormat(pattern="yyyy-MM-dd")
private LocalDate msWdate;
@Schema(required = false, title = "단속장소", example = " ", description = "Input Description...")

@ -3,6 +3,7 @@ package com.xit.biz.ctgy.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import javax.validation.constraints.Size;
import java.time.LocalDate;
@ -22,15 +23,18 @@ public class JudgeListDto {
@Schema(title = "심사시작일", example = "2022-03-23", description = "심사시작일")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msSdate;
private String msStartsi;
@Schema(title = "심사종료일", example = "2022-03-23", description = "심사종료일")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msEdate;
@Schema(title = "심사마감일", example = "2022-03-23", description = "심사마감일")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msCdate;
private String msClosesi;
@ -58,6 +62,8 @@ public class JudgeListDto {
@Schema(title = "심사자별 사유", example = " ", description = "심사자별 사유")
private String msuReason;
@Schema(title = "심사일", example = " ", description = "심사일")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msuIndate;
@Schema(required = true, title = "위반일자", example = " ", description = "위반일자")

@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.util.List;
@ -54,6 +55,7 @@ public class JudgeTargetDto {
//------------------------------------------------------------------
@Schema(title = "심사시작일", example = "2022-03-23", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msSdate;
@Schema(title = "심사시작시간", example = " ", description = "Input Description...")
@ -61,10 +63,12 @@ public class JudgeTargetDto {
@Schema(title = "심사종료일", example = "2022-03-24", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msEdate;
@Schema(title = "심사마감일", example = "2022-03-25", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msCdate;
@Schema(title = "심사마감시간", example = " ", description = "Input Description...")

@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
@ -34,6 +35,7 @@ public class MinSimsa680Dto {
@Schema(required = true, title = "심사시작일", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msSdate;
@Schema(required = true, title = "심사시작시간", example = " ", description = "Input Description...")
@ -41,10 +43,12 @@ public class MinSimsa680Dto {
@Schema(required = true, title = "심사종료일", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msEdate;
@Schema(required = true, title = "심사마감일", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msCdate;
@Schema(required = true, title = "심사마감시간", example = " ", description = "Input Description...")
@ -52,6 +56,7 @@ public class MinSimsa680Dto {
@Schema(required = false, title = "단속일자", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msWdate;
@Schema(required = false, title = "단속장소", example = " ", description = "Input Description...")

@ -1,7 +1,9 @@
package com.xit.biz.ctgy.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
import java.time.LocalDate;
@ -40,6 +42,8 @@ public class MinUserinfoDto implements Serializable {
private String team;
@Schema(required = false, title = "등록일시", example = " ", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate regdate;
@Schema(required = false, title = "사용여부", example = " ", description = "Input Description...")

@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDate;
import java.util.List;
@ -52,6 +53,7 @@ public class ParkingTargetDto {
@Schema(title = "심사시작일", example = "2022-03-23", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msSdate;
@Schema(title = "심사시작시간", example = " ", description = "Input Description...")
@ -59,10 +61,12 @@ public class ParkingTargetDto {
@Schema(title = "심사종료일", example = "2022-03-24", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msEdate;
@Schema(title = "심사마감일", example = "2022-03-25", description = "Input Description...")
@JsonFormat(pattern="yyyy-MM-dd")
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
private LocalDate msCdate;
@Schema(title = "심사마감시간", example = " ", description = "Input Description...")

@ -0,0 +1,107 @@
package com.xit.core.config.support;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.*;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import java.time.LocalDate;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* DTO LocalDate
* @JsonFormat(pattern="yyyy-MM-dd")
* @DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
*
* Request( -> ) @DateTimeFormat
* Responst ( -> ) @JsonFormat
*
*/
//@Configuration
@Slf4j
public class LocalDateTimeConfiguration {
private static final String DEFAULT_DATE_FMT = "yyyy-MM-dd";
private static final String DEFAULT_DATE_TIME_FMT = "yyyy-MM-dd HH:mm:ss";
@Bean
@Primary
public ObjectMapper objectMapper(Jackson2ObjectMapperBuilder builder) {
log.info(">>>>>>>>>>> Config is starting.");
ObjectMapper objectMapper = builder.createXmlMapper(false).build();
objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
return objectMapper;
}
@Bean
public Module jsonMapperJava8DateTimeModule() {
SimpleModule module = new SimpleModule();
module.addDeserializer(ZonedDateTime.class, new JsonDeserializer<ZonedDateTime>() {
@Override
public ZonedDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addDeserializer-ZonedDateTime");
return ZonedDateTime.parse(p.getValueAsString(), DateTimeFormatter.ISO_ZONED_DATE_TIME);
}
});
module.addDeserializer(LocalDateTime.class, new JsonDeserializer<LocalDateTime>() {
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addDeserializer-LocalDateTime");
return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ISO_LOCAL_DATE_TIME);
//return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FMT));
}
});
module.addDeserializer(LocalDate.class, new JsonDeserializer<LocalDate>() {
@Override
public LocalDate deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addDeserializer-LocalDate");
//return LocalDateTime.parse(p.getValueAsString(), DateTimeFormatter.ISO_DATE_TIME);
return LocalDate.parse(p.getValueAsString(), DateTimeFormatter.ofPattern(DEFAULT_DATE_FMT));
}
});
module.addSerializer(ZonedDateTime.class, new JsonSerializer<ZonedDateTime>() {
@Override
public void serialize(ZonedDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addSerializer-ZonedDateTime");
gen.writeString(DateTimeFormatter.ISO_ZONED_DATE_TIME.format(value));
}
});
module.addSerializer(LocalDateTime.class, new JsonSerializer<LocalDateTime>() {
@Override
public void serialize(LocalDateTime localDateTime, JsonGenerator gen, SerializerProvider serializers) throws IOException {
log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addSerializer-LocalDateTime");
gen.writeString(DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(localDateTime));
//gen.writeString(localDateTime.format(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_FMT)));
}
});
module.addSerializer(LocalDate.class, new JsonSerializer<LocalDate>() {
@Override
public void serialize(LocalDate localDate, JsonGenerator gen, SerializerProvider serializers) throws IOException {
log.info(">>>>>>>>>>>>>>>>>>>>>LocalDateTimeConfiguration::addSerializer-LocalDate");
//gen.writeString(DateTimeFormatter.ISO_DATE_TIME.format(value));
gen.writeString(localDate.format(DateTimeFormatter.ofPattern(DEFAULT_DATE_FMT)));
}
});
return module;
}
}

@ -71,6 +71,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
*/
@SuppressWarnings("NullableProblems")
@Override
//@ExceptionHandler(MethodArgumentNotValidException.class)
protected ResponseEntity<Object> handleMethodArgumentNotValid(
MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
log.error("==================== Override handleMethodArgumentNotValid throw MethodArgumentNotValidException ====================");
@ -124,6 +125,7 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
*/
@SuppressWarnings("NullableProblems")
@Override
//@ExceptionHandler(HttpMessageNotReadableException.class)
protected ResponseEntity<Object> handleHttpMessageNotReadable(
HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatus status, WebRequest request) {
log.error("==================== Override handleHttpMessageNotReadable throw HttpMessageNotReadableException ====================");
@ -215,4 +217,37 @@ public class CustomRestExceptionHandler extends ResponseEntityExceptionHandler {
log.error("handleException throw Exception : {}", Checks.isEmpty(message) ? StringUtils.EMPTY : e.getClass().getCanonicalName());
return RestErrorResponse.of(HttpStatus.INTERNAL_SERVER_ERROR.toString(), message);
}
}
}
/*
javax.validation.constraints @NotNull
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<List<ExceptionDto>> methodArgumentValidException(MethodArgumentNotValidException e) {
return ResponseEntity.badRequest().body(extractErrorMessages(e));
}
private List<ExceptionDto> extractErrorMessages(MethodArgumentNotValidException e) {
return e.getBindingResult()
.getAllErrors()
.stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.map(ExceptionDto::new)
.collect(Collectors.toList());
}
@ExceptionHandler(ConstraintViolationException.class)
public ResponseEntity<List<ExceptionDto>> constraintViolationException(ConstraintViolationException e) {
return ResponseEntity.badRequest().body(extractErrorMessages(e));
}
private List<ExceptionDto> extractErrorMessages(ConstraintViolationException e) {
return e.getConstraintViolations()
.stream()
.map(ConstraintViolation::getMessage)
.map(ExceptionDto::new)
.collect(Collectors.toList());
}
*/

@ -0,0 +1,56 @@
package com.xit.core.util.security;
import com.xit.core.util.Checks;
import javax.annotation.Nullable;
import javax.validation.constraints.NotNull;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
public class ConvertUtils {
private static final String DEFAULT_DATE_FMT = "yyyy-MM-dd";
private static final String DEFAULT_DATE_TIME_FMT = "yyyy-MM-dd HH:mm:ss";
public static String getStringDateFromDate(@NotNull Date date, @Nullable String format) {
if(Checks.isNull(format)) format = "DEFAULT_DATE_FMT";
return new SimpleDateFormat(format).format(date);
}
public static String getStringDateTimeFromDate(@NotNull Date date, @Nullable String format) {
if(Checks.isNull(format)) format = "DEFAULT_DATE_TIME_FMT";
return new SimpleDateFormat(format).format(date);
}
public String getStringDateFromLocalDate(@NotNull LocalDate localDate, @Nullable String format) {
if(Checks.isNull(format)) format = "DEFAULT_DATE_FMT";
return localDate.format(DateTimeFormatter.ofPattern(format));
}
public String getStringDateTimeFromLocalDate(@NotNull LocalDate localDate, @Nullable String format) {
if(Checks.isNull(format)) format = "DEFAULT_DATE_TIME_FMT";
return localDate.format(DateTimeFormatter.ofPattern(format));
}
public static java.util.Date toDateFromLocalDate(LocalDate localDate){
Instant instant = localDate.atStartOfDay(ZoneId.systemDefault()).toInstant();
return java.util.Date.from(instant);
}
public static java.util.Date toDateFromLocalDateTime(LocalDateTime localDateTime){
Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
return java.util.Date.from(instant);
}
public static LocalDate toLocalDateFromDate(java.util.Date date){
return LocalDate.ofInstant(date.toInstant(), ZoneId.systemDefault());
}
public static LocalDateTime toLocalDateTimeFromDate(java.util.Date date){
return LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault());
}
}

@ -12,7 +12,7 @@ xit:
# api response logging 여부
api:
reponse:
logging: false
logging: true
file:
cmm:

Loading…
Cancel
Save