diff --git a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/permission/entity/PermissionPersistence.java b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/permission/entity/PermissionPersistence.java
index 3ab67bf2..1fe83847 100644
--- a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/permission/entity/PermissionPersistence.java
+++ b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/permission/entity/PermissionPersistence.java
@@ -5,7 +5,7 @@
import lombok.Data;
import java.io.Serializable;
-import java.util.Date;
+import java.time.LocalDateTime;
/**
* Permission.(Permission) Persistence object class
@@ -79,13 +79,13 @@ public class PermissionPersistence implements Serializable {
* Created time
*/
@TableField(value = "created_time", fill = FieldFill.INSERT)
- private Date createdTime;
+ private LocalDateTime createdTime;
/**
* Modified time
*/
@TableField(value = "modified_time", fill = FieldFill.INSERT_UPDATE)
- private Date modifiedTime;
+ private LocalDateTime modifiedTime;
public static final String COL_ID = "id";
diff --git a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/role/entity/RolePersistence.java b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/role/entity/RolePersistence.java
index 95d47400..f994a441 100644
--- a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/role/entity/RolePersistence.java
+++ b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/role/entity/RolePersistence.java
@@ -5,7 +5,7 @@
import lombok.Data;
import java.io.Serializable;
-import java.util.Date;
+import java.time.LocalDateTime;
/**
* Role.(Role) Persistence object class
@@ -48,13 +48,13 @@ public class RolePersistence implements Serializable {
* Created time
*/
@TableField(value = "created_time", fill = FieldFill.INSERT)
- private Date createdTime;
+ private LocalDateTime createdTime;
/**
* Modified time
*/
@TableField(value = "modified_time", fill = FieldFill.INSERT_UPDATE)
- private Date modifiedTime;
+ private LocalDateTime modifiedTime;
public static final String COL_ID = "id";
diff --git a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/entity/UserPersistence.java b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/entity/UserPersistence.java
index 3df6256f..3dadf8db 100644
--- a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/entity/UserPersistence.java
+++ b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/entity/UserPersistence.java
@@ -5,7 +5,8 @@
import lombok.Data;
import java.io.Serializable;
-import java.util.Date;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
/**
*
UserPersistence
@@ -60,7 +61,7 @@ public class UserPersistence implements Serializable {
* Birthday
*/
@TableField(value = "birthday")
- private Date birthday;
+ private LocalDate birthday;
/**
* 26 gender options
@@ -93,13 +94,13 @@ public class UserPersistence implements Serializable {
* Created time
*/
@TableField(value = "created_time", fill = FieldFill.INSERT)
- private Date createdTime;
+ private LocalDateTime createdTime;
/**
* Modified time
*/
@TableField(value = "modified_time", fill = FieldFill.INSERT_UPDATE)
- private Date modifiedTime;
+ private LocalDateTime modifiedTime;
public static final String COL_ID = "id";
diff --git a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserServiceImpl.java b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserServiceImpl.java
index 31ebbc97..0208df0d 100644
--- a/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserServiceImpl.java
+++ b/auth-center/src/main/java/com/jmsoftware/maf/authcenter/user/service/impl/UserServiceImpl.java
@@ -25,7 +25,6 @@
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
-import java.util.Date;
/**
* UserServiceImpl
@@ -69,9 +68,6 @@ public SignupResponse saveUserForSignup(@Valid SignupPayload payload) {
userPersistence.setEmail(payload.getEmail());
userPersistence.setPassword(bCryptPasswordEncoder.encode(payload.getPassword()));
userPersistence.setStatus(UserStatus.ENABLED.getStatus());
- val currentTime = new Date();
- userPersistence.setCreatedTime(currentTime);
- userPersistence.setModifiedTime(currentTime);
this.save(userPersistence);
log.warn("Saved user for signup. {}", userPersistence);
val response = new SignupResponse();
diff --git a/common/src/main/java/com/jmsoftware/maf/common/bean/ResponseBodyBean.java b/common/src/main/java/com/jmsoftware/maf/common/bean/ResponseBodyBean.java
index e3bb9725..6be4a751 100644
--- a/common/src/main/java/com/jmsoftware/maf/common/bean/ResponseBodyBean.java
+++ b/common/src/main/java/com/jmsoftware/maf/common/bean/ResponseBodyBean.java
@@ -11,7 +11,7 @@
import org.springframework.lang.Nullable;
import java.io.Serializable;
-import java.util.Date;
+import java.time.LocalDateTime;
/**
* ResponseBodyBean
@@ -35,7 +35,7 @@ public class ResponseBodyBean implements Serializable {
*/
@Setter(AccessLevel.NONE)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
- Date timestamp = new Date();
+ LocalDateTime timestamp = LocalDateTime.now();
/**
* Default status is 200 OK.
*/
diff --git a/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/security/UserPrincipal.java b/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/security/UserPrincipal.java
index 999dbe1a..ca8bddde 100644
--- a/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/security/UserPrincipal.java
+++ b/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/security/UserPrincipal.java
@@ -13,6 +13,8 @@
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -57,7 +59,7 @@ public class UserPrincipal implements UserDetails {
/**
* Birthday
*/
- private Date birthday;
+ private LocalDate birthday;
/**
* Gender
*/
@@ -69,11 +71,11 @@ public class UserPrincipal implements UserDetails {
/**
* Create time
*/
- private Date gmtCreated;
+ private LocalDateTime gmtCreated;
/**
* Modify time
*/
- private Date gmtModified;
+ private LocalDateTime gmtModified;
/**
* Roles that user has
*/
diff --git a/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/GetUserByLoginTokenResponse.java b/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/GetUserByLoginTokenResponse.java
index 5621a389..e02f9d71 100644
--- a/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/GetUserByLoginTokenResponse.java
+++ b/common/src/main/java/com/jmsoftware/maf/common/domain/authcenter/user/GetUserByLoginTokenResponse.java
@@ -2,7 +2,8 @@
import lombok.Data;
-import java.util.Date;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
/**
* GetUserByLoginTokenResponse
@@ -41,7 +42,7 @@ public class GetUserByLoginTokenResponse {
/**
* Birthday (yyyy-MM-dd)
*/
- private Date birthday;
+ private LocalDate birthday;
/**
* 58 gender options
*/
@@ -57,9 +58,9 @@ public class GetUserByLoginTokenResponse {
/**
* Create time
*/
- private Date createdTime;
+ private LocalDateTime createdTime;
/**
* Modify time
*/
- private Date modifiedTime;
+ private LocalDateTime modifiedTime;
}
diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/controller/AbstractExcelImportController.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/controller/AbstractExcelImportController.java
index f242e5fb..45a05f5d 100644
--- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/controller/AbstractExcelImportController.java
+++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/controller/AbstractExcelImportController.java
@@ -14,7 +14,6 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
-import org.apache.http.client.utils.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
@@ -37,8 +36,10 @@
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.math.BigDecimal;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.time.format.DateTimeParseException;
import java.util.*;
/**
@@ -553,13 +554,17 @@ private File uploadTempFile(byte[] itemBytes, String fileName) {
* @see
* Upload large files : Spring Boot
*/
+ @SuppressWarnings("AlibabaRemoveCommentedCode")
private File uploadFile(MultipartHttpServletRequest request) throws IOException {
val multipartFile = request.getFileMap().get(FILE_KEY);
// Don't do this.
// it loads all of the bytes in java heap memory that leads to OutOfMemoryError. We'll use stream instead.
// byte[] fileBytes = multipartFile.getBytes();
@Cleanup val fileStream = new BufferedInputStream(multipartFile.getInputStream());
- val fileName = DateUtils.formatDate(new Date(), "yyyyMMddHHmmssSSS") + multipartFile.getOriginalFilename();
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
+ val fileName = String.format("%s%s",
+ LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS")),
+ multipartFile.getOriginalFilename());
val targetFile = new File(TEMP_FILE_PATH + fileName);
FileUtils.copyInputStreamToFile(fileStream, targetFile);
uploadFileToSftp(targetFile);
@@ -872,8 +877,8 @@ private void registerBindHandlerMethods() {
String.class,
Field.class,
Object.class);
- val bindDateField = ReflectionUtils.findMethod(this.getClass(),
- "bindDateField",
+ val bindLocalDateTimeField = ReflectionUtils.findMethod(this.getClass(),
+ "bindLocalDateTimeField",
String.class,
Field.class,
Object.class);
@@ -882,7 +887,7 @@ private void registerBindHandlerMethods() {
this.bindMethodMap.put(Long.class, bindLongField);
this.bindMethodMap.put(Float.class, bindFloatField);
this.bindMethodMap.put(Double.class, bindDoubleField);
- this.bindMethodMap.put(Date.class, bindDateField);
+ this.bindMethodMap.put(LocalDateTime.class, bindLocalDateTimeField);
} catch (Exception e) {
log.error("The bindMethod required was not found in this class!", e);
}
@@ -1091,7 +1096,7 @@ private Boolean bindStringField(String value, Field field, Object bean) throws I
}
/**
- * Bind date field boolean.
+ * Bind LocalDateTime field boolean.
*
* @param value the value
* @param field the field
@@ -1099,15 +1104,14 @@ private Boolean bindStringField(String value, Field field, Object bean) throws I
* @return the boolean
* @throws IllegalAccessException the illegal access exception
*/
- private Boolean bindDateField(String value, Field field, Object bean) throws IllegalAccessException {
+ private Boolean bindLocalDateTimeField(String value, Field field, Object bean) throws IllegalAccessException {
try {
- val simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- val date = value == null ? null : simpleDateFormat.parse(value);
+ val date = value == null ? null : LocalDateTime.parse(value, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
field.setAccessible(true);
field.set(bean, date);
field.setAccessible(false);
- } catch (ParseException e) {
- log.error("Exception occurred when binding Date field! Exception message: {}, value: {}, field: {}",
+ } catch (DateTimeParseException e) {
+ log.error("Exception occurred when binding LocalDateTime field! Exception message: {}, value: {}, field: {}",
e.getMessage(), value, field.getName());
val formattedMessage = String.format("Invalid data of the row %d, col %d, must be date",
rowLocation.get(), columnLocation.get());
diff --git a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/database/MyBatisPlusMetaObjectHandler.java b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/database/MyBatisPlusMetaObjectHandler.java
index a16ed994..c73eb4bc 100644
--- a/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/database/MyBatisPlusMetaObjectHandler.java
+++ b/spring-cloud-starter/src/main/java/com/jmsoftware/maf/springcloudstarter/database/MyBatisPlusMetaObjectHandler.java
@@ -3,11 +3,10 @@
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.jmsoftware.maf.common.domain.DeletedField;
import lombok.extern.slf4j.Slf4j;
-import lombok.val;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
-import java.util.Date;
+import java.time.LocalDateTime;
/**
* MyBatisPlusConfiguration
@@ -28,17 +27,17 @@ public class MyBatisPlusMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
log.info("Starting to insert fill metaObject: {}", metaObject.getOriginalObject());
- val now = new Date();
+ LocalDateTime now = LocalDateTime.now();
this.strictInsertFill(metaObject, DELETED_FIELD_NAME, Byte.class, DeletedField.NOT_DELETED.getValue())
- .strictInsertFill(metaObject, CREATED_TIME_FIELD_NAME, Date.class, now)
- .strictInsertFill(metaObject, MODIFIED_TIME_FIELD_NAME, Date.class, now);
+ .strictInsertFill(metaObject, CREATED_TIME_FIELD_NAME, LocalDateTime.class, now)
+ .strictInsertFill(metaObject, MODIFIED_TIME_FIELD_NAME, LocalDateTime.class, now);
log.info("Finished to insert fill metaObject: {}", metaObject.getOriginalObject());
}
@Override
public void updateFill(MetaObject metaObject) {
log.info("Starting to update fill metaObject: {}", metaObject.getOriginalObject());
- this.strictUpdateFill(metaObject, MODIFIED_TIME_FIELD_NAME, Date.class, new Date());
+ this.strictUpdateFill(metaObject, MODIFIED_TIME_FIELD_NAME, LocalDateTime.class, LocalDateTime.now());
log.info("Finished to update fill metaObject: {}", metaObject.getOriginalObject());
}
}