Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
<module>ruoyi-modules</module>
<module>ruoyi-api</module>
<module>ruoyi-common</module>
<module>ruoyi-dependencies</module>
</modules>
<packaging>pom</packaging>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.ruoyi.common.core.utils;

import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.web.domain.BaseEntity;

import java.lang.reflect.Method;
import java.util.Date;

/**
* 实体填充工具类
*
* @author 李佳琦
* @date 2026/2/27 16:44
*/
public class EntityFillUtils {

/**
* 填充实体*
*
* @param entity 实体对象
* @return 填充后的实体对象
*/
public static <T extends BaseEntity> T fillEntity(T entity) {
return EntityFillUtils.fillEntity(entity, null, null);
}

/**
* 填充实体*
*
* @param entity 实体对象
* @param username 用户名
* @return 填充后的实体对象
*/
public static <T extends BaseEntity> T fillEntity(T entity, String username) {
return EntityFillUtils.fillEntity(entity, null, username);
}

/**
* 填充实体
*
* @param entity 实体对象
* @param idField id字段名
* @param username 用户名
* @return 填充后的实体对象
*/
public static <T extends BaseEntity> T fillEntity(T entity, String idField, String username) {
Class<? extends BaseEntity> clazz = entity.getClass();
// 如果idField为空,则默认为Id
if (idField == null || idField.isEmpty()) {
idField = "id";
}
// idField首字母大写
idField = StringUtils.capitalize(idField);

Method getId = null;
try {
getId = clazz.getMethod("get" + idField);
} catch (Exception e) {
throw new ServiceException("缺失基础字段: " + idField);
}
try {
Date now = DateUtils.getNowDate();
// 新增
if (getId.invoke(entity) == null) {
clazz.getMethod("setCreateBy", String.class).invoke(entity, username);
clazz.getMethod("setCreateTime", Date.class).invoke(entity, now);
}
clazz.getMethod("setUpdateBy", String.class).invoke(entity, username);
clazz.getMethod("setUpdateTime", Date.class).invoke(entity, now);
clazz.getMethod("setDelFlag", String.class).invoke(entity, "0");
} catch (Exception e) {
throw new ServiceException("调起函数异常");
}
return entity;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.ruoyi.common.core.web.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;
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;

/**
* Entity基类
Expand All @@ -19,7 +20,7 @@ public class BaseEntity implements Serializable

/** 搜索值 */
@JsonIgnore
private String searchValue;
private transient String searchValue;

/** 创建者 */
private String createBy;
Expand All @@ -40,7 +41,7 @@ public class BaseEntity implements Serializable

/** 请求参数 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> params;
private transient Map<String, Object> params;

public String getSearchValue()
{
Expand Down
19 changes: 19 additions & 0 deletions ruoyi-dependencies/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.ruoyi</groupId>
<artifactId>ruoyi</artifactId>
<version>3.6.7</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>ruoyi-dependencies</artifactId>
<packaging>pom</packaging>

<description>
ruoyi-dependencies依赖管理模块
</description>

</project>