Bladeren bron

feat:实体基类默认值

韩帛霖 1 jaar geleden
bovenliggende
commit
4537f0feb3
1 gewijzigde bestanden met toevoegingen van 84 en 64 verwijderingen
  1. 84 64
      ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java

+ 84 - 64
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/BaseEntity.java

@@ -1,140 +1,160 @@
 package com.ruoyi.common.core.domain;
 
 import java.io.Serializable;
+import java.text.SimpleDateFormat;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
+
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.fasterxml.jackson.annotation.JsonInclude;
+import com.ruoyi.common.utils.DateUtils;
+import com.ruoyi.common.utils.SecurityUtils;
 
 /**
  * Entity基类
- * 
+ *
  * @author ruoyi
  */
-public class BaseEntity implements Serializable
-{
+public class BaseEntity implements Serializable {
+
+
     private static final long serialVersionUID = 1L;
 
-    /** 搜索值 */
+    /**
+     * 搜索值
+     */
     @JsonIgnore
     private String searchValue;
 
-    /** 创建者Id*/
+    /**
+     * 创建者Id
+     */
     private Long createById;
 
-    /** 修改者Id*/
-    private Long updateById;
-
-    public Long getUpdateById() {
-        return updateById;
-    }
-
-    public void setUpdateById(Long updateById) {
-        this.updateById = updateById;
-    }
-
-    /** 创建者 */
+    /**
+     * 创建者
+     */
     private String createBy;
 
-    public Long getCreateById() {
-        return createById;
-    }
-
-    public void setCreateById(Long createById) {
-        this.createById = createById;
-    }
-
-    /** 创建时间 */
+    /**
+     * 创建时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
-    /** 更新者 */
+    /**
+     * 修改者Id
+     */
+    private Long updateById;
+
+    /**
+     * 更新者
+     */
     private String updateBy;
 
-    /** 更新时间 */
+    /**
+     * 更新时间
+     */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date updateTime;
 
-    /** 备注 */
+    /**
+     * 备注
+     */
     private String remark;
 
-    /** 请求参数 */
+    /**
+     * 请求参数
+     */
     @JsonInclude(JsonInclude.Include.NON_EMPTY)
     private Map<String, Object> params;
 
-    public String getSearchValue()
-    {
+    public String getSearchValue() {
         return searchValue;
     }
 
-    public void setSearchValue(String searchValue)
-    {
+    public void setSearchValue(String searchValue) {
         this.searchValue = searchValue;
     }
 
-    public String getCreateBy()
-    {
-        return createBy;
+    public Long getCreateById() {
+        return createById == null ? SecurityUtils.getUserId() : createById;
+    }
+
+    public void setCreateById(Long createById) {
+        this.createById = createById;
     }
 
-    public void setCreateBy(String createBy)
-    {
+    public String getCreateBy() {
+        return createBy == null ? SecurityUtils.getUsername() : createBy;
+    }
+
+    public void setCreateBy(String createBy) {
         this.createBy = createBy;
     }
 
-    public Date getCreateTime()
-    {
-        return createTime;
+    public Date getCreateTime() {
+        return createTime == null || createTime.toString().isEmpty() ? getNowData() : createTime;
     }
 
-    public void setCreateTime(Date createTime)
-    {
+    public void setCreateTime(Date createTime) {
         this.createTime = createTime;
     }
 
-    public String getUpdateBy()
-    {
-        return updateBy;
+    public Long getUpdateById() {
+        return updateById == null ? SecurityUtils.getUserId() : updateById;
     }
 
-    public void setUpdateBy(String updateBy)
-    {
+    public void setUpdateById(Long updateById) {
+        this.updateById = updateById;
+    }
+
+    public String getUpdateBy() {
+        return updateBy == null ? SecurityUtils.getUsername() : updateBy;
+    }
+
+    public void setUpdateBy(String updateBy) {
         this.updateBy = updateBy;
     }
 
-    public Date getUpdateTime()
-    {
-        return updateTime;
+    public Date getUpdateTime() {
+        return updateTime == null || updateTime.toString().isEmpty() ? getNowData() : updateTime;
     }
 
-    public void setUpdateTime(Date updateTime)
-    {
+    public void setUpdateTime(Date updateTime) {
         this.updateTime = updateTime;
     }
 
-    public String getRemark()
-    {
+    public String getRemark() {
         return remark;
     }
 
-    public void setRemark(String remark)
-    {
+    public void setRemark(String remark) {
         this.remark = remark;
     }
 
-    public Map<String, Object> getParams()
-    {
-        if (params == null)
-        {
+    public Map<String, Object> getParams() {
+        if (params == null) {
             params = new HashMap<>();
         }
         return params;
     }
 
-    public void setParams(Map<String, Object> params)
-    {
+    public void setParams(Map<String, Object> params) {
         this.params = params;
     }
+
+    Date getNowData() {
+        String dateString = DateUtils.getTime();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            Date date = sdf.parse(dateString);
+            return date;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return new Date();
+    }
 }