mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-07 17:55:59 +08:00
管理员日志-增加管理员名称
This commit is contained in:
parent
5c1346e22c
commit
db4c92e23e
@ -27,16 +27,10 @@ CREATE TABLE `admin_logs` (
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`admin_id` int(11) NOT NULL DEFAULT '0' COMMENT '管理员ID',
|
||||
`module` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '模块',
|
||||
`title` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法标题',
|
||||
`opt` int(2) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0 COMMENT '操作指令(0其它 1新增 2修改 3删除 4查询 5登录 6退出登录)',
|
||||
`method` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法',
|
||||
`request_method` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方式POST,GET,PUT,DELETE',
|
||||
`url` varchar(266) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求URL',
|
||||
`param` text COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '请求参数',
|
||||
`result` text COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '返回参数',
|
||||
`opt` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '操作指令',
|
||||
`remark` mediumtext COLLATE utf8mb4_unicode_ci COMMENT '备注',
|
||||
`ip` varchar(45) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT 'ip',
|
||||
`ip_area` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '地址',
|
||||
`error_msg` varchar(2000) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '错误消息',
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `a_m_o` (`admin_id`,`module`,`opt`)
|
||||
|
@ -4,6 +4,7 @@ CREATE TABLE `admin_logs`
|
||||
(
|
||||
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
|
||||
`admin_id` int(11) NOT NULL DEFAULT '0' COMMENT '管理员ID',
|
||||
`admin_name` varchar(16) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '管理员姓名',
|
||||
`module` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '模块',
|
||||
`title` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '请求方法标题',
|
||||
`opt` int(2) NOT NULL DEFAULT '0' COMMENT '操作指令(0其它 1新增 2修改 3删除 4登录 5退出登录)',
|
||||
|
@ -30,7 +30,9 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import xyz.playedu.api.annotation.Log;
|
||||
import xyz.playedu.api.domain.AdminLog;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.service.AdminLogService;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.service.BackendAuthService;
|
||||
import xyz.playedu.api.util.IpUtil;
|
||||
import xyz.playedu.api.util.RequestUtil;
|
||||
@ -47,6 +49,8 @@ public class AdminLogAspect {
|
||||
|
||||
@Autowired private BackendAuthService authService;
|
||||
|
||||
@Autowired private AdminUserService adminUserService;
|
||||
|
||||
@Autowired private AdminLogService adminLogService;
|
||||
|
||||
/** 排除敏感属性字段 */
|
||||
@ -87,9 +91,15 @@ public class AdminLogAspect {
|
||||
return;
|
||||
}
|
||||
|
||||
AdminUser adminUser = adminUserService.findById(authService.userId());
|
||||
if (null == adminUser) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 日志
|
||||
AdminLog adminLog = new AdminLog();
|
||||
adminLog.setAdminId(authService.userId());
|
||||
adminLog.setAdminId(adminUser.getId());
|
||||
adminLog.setAdminName(adminUser.getName());
|
||||
adminLog.setModule("BACKEND");
|
||||
adminLog.setTitle(controllerLog.title());
|
||||
adminLog.setOpt(controllerLog.businessType().ordinal());
|
||||
@ -167,6 +177,8 @@ public class AdminLogAspect {
|
||||
for (String i : EXCLUDE_PROPERTIES) {
|
||||
if (key.equals(i)) {
|
||||
jsonObjectResult.put(key, "******");
|
||||
}else {
|
||||
jsonObjectResult.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ public class AdminLogController {
|
||||
String sortAlgo = MapUtils.getString(params, "sort_algo");
|
||||
|
||||
Integer adminId = MapUtils.getInteger(params, "admin_id");
|
||||
String adminName = MapUtils.getString(params, "admin_name");
|
||||
String module = MapUtils.getString(params, "module");
|
||||
String title = MapUtils.getString(params, "title");
|
||||
Integer opt = MapUtils.getInteger(params, "opt");
|
||||
@ -75,6 +76,7 @@ public class AdminLogController {
|
||||
} else {
|
||||
filter.setAdminId(BCtx.getId());
|
||||
}
|
||||
filter.setAdminName(adminName);
|
||||
filter.setModule(module);
|
||||
filter.setTitle(title);
|
||||
filter.setOpt(opt);
|
||||
@ -84,17 +86,6 @@ public class AdminLogController {
|
||||
filter.setSortAlgo(sortAlgo);
|
||||
|
||||
PaginationResult<AdminLog> result = adminLogService.paginate(page, size, filter);
|
||||
if(result.getTotal() > 0){
|
||||
List<AdminUser> adminUsers = adminUserService.chunks(result.getData().stream().map(AdminLog::getAdminId).toList());
|
||||
if(null != adminUsers && adminUsers.size() > 0){
|
||||
Map<Integer, String> adminUserMap = adminUsers.stream().collect(Collectors.toMap(AdminUser::getId, AdminUser::getName));
|
||||
result.getData()
|
||||
.forEach(
|
||||
adminLog -> {
|
||||
adminLog.setAdminName(adminUserMap.get(adminLog.getAdminId()));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("data", result.getData());
|
||||
|
@ -40,7 +40,7 @@ public class AdminLog implements Serializable {
|
||||
@JsonProperty("admin_id")
|
||||
private Integer adminId;
|
||||
|
||||
@TableField(exist = false)
|
||||
/** 管理员姓名 */
|
||||
@JsonProperty("admin_name")
|
||||
private String adminName;
|
||||
|
||||
@ -102,6 +102,9 @@ public class AdminLog implements Serializable {
|
||||
&& (this.getAdminId() == null
|
||||
? other.getAdminId() == null
|
||||
: this.getAdminId().equals(other.getAdminId()))
|
||||
&& (this.getAdminName() == null
|
||||
? other.getAdminName() == null
|
||||
: this.getAdminName().equals(other.getAdminName()))
|
||||
&& (this.getModule() == null
|
||||
? other.getModule() == null
|
||||
: this.getModule().equals(other.getModule()))
|
||||
@ -146,6 +149,7 @@ public class AdminLog implements Serializable {
|
||||
int result = 1;
|
||||
result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
|
||||
result = prime * result + ((getAdminId() == null) ? 0 : getAdminId().hashCode());
|
||||
result = prime * result + ((getAdminName() == null) ? 0 : getAdminName().hashCode());
|
||||
result = prime * result + ((getModule() == null) ? 0 : getModule().hashCode());
|
||||
result = prime * result + ((getTitle() == null) ? 0 : getTitle().hashCode());
|
||||
result = prime * result + ((getOpt() == null) ? 0 : getOpt().hashCode());
|
||||
@ -170,6 +174,7 @@ public class AdminLog implements Serializable {
|
||||
sb.append("Hash = ").append(hashCode());
|
||||
sb.append(", id=").append(id);
|
||||
sb.append(", adminId=").append(adminId);
|
||||
sb.append(", adminName=").append(adminName);
|
||||
sb.append(", module=").append(module);
|
||||
sb.append(", title=").append(title);
|
||||
sb.append(", opt=").append(opt);
|
||||
|
@ -22,6 +22,8 @@ public class AdminLogPaginateFiler {
|
||||
|
||||
private Integer adminId;
|
||||
|
||||
private String adminName;
|
||||
|
||||
private String module;
|
||||
|
||||
private String title;
|
||||
|
@ -7,6 +7,7 @@
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.AdminLog">
|
||||
<id property="id" column="id" jdbcType="BIGINT"/>
|
||||
<result property="adminId" column="admin_id" jdbcType="INTEGER"/>
|
||||
<result property="adminName" column="admin_name" jdbcType="VARCHAR"/>
|
||||
<result property="module" column="module" jdbcType="VARCHAR"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="opt" column="opt" jdbcType="INTEGER"/>
|
||||
@ -22,7 +23,7 @@
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,admin_id,module,title,
|
||||
id,admin_id,admin_name,module,title,
|
||||
opt,method,request_method,url,param,result,
|
||||
ip,ip_area,error_msg,created_at
|
||||
</sql>
|
||||
@ -34,6 +35,9 @@
|
||||
<if test="adminId != null">
|
||||
AND `admin_logs`.`admin_id` = #{adminId}
|
||||
</if>
|
||||
<if test="adminName != null and adminName != ''">
|
||||
AND `admin_logs`.`admin_name` LIKE concat('%',#{adminName},'%')
|
||||
</if>
|
||||
<if test="module != null and module != ''">
|
||||
AND `admin_logs`.`module` LIKE concat('%',#{module},'%')
|
||||
</if>
|
||||
@ -43,12 +47,12 @@
|
||||
<if test="opt != null">
|
||||
AND `admin_logs`.`opt` = #{opt}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND `admin_logs`.`created_at` >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND `admin_logs`.`created_at` <= #{endTime}
|
||||
<if test="startTime != null and startTime != '' ">
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND `admin_logs`.`created_at` BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
</if>
|
||||
|
||||
</where>
|
||||
|
||||
<if test="sortAlgo == 'asc'">
|
||||
@ -81,6 +85,9 @@
|
||||
<if test="adminId != null">
|
||||
AND `admin_logs`.`admin_id` = #{adminId}
|
||||
</if>
|
||||
<if test="adminName != null and adminName != ''">
|
||||
AND `admin_logs`.`admin_name` LIKE concat('%',#{adminName},'%')
|
||||
</if>
|
||||
<if test="module != null and module != ''">
|
||||
AND `admin_logs`.`module` LIKE concat('%',#{module},'%')
|
||||
</if>
|
||||
@ -90,11 +97,10 @@
|
||||
<if test="opt != null">
|
||||
AND `admin_logs`.`opt` = #{opt}
|
||||
</if>
|
||||
<if test="startTime != null and startTime != ''">
|
||||
AND `admin_logs`.`created_at` >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND `admin_logs`.`created_at` <= #{endTime}
|
||||
<if test="startTime != null and startTime != '' ">
|
||||
<if test="endTime != null and endTime != ''">
|
||||
AND `admin_logs`.`created_at` BETWEEN #{startTime} AND #{endTime}
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
Loading…
x
Reference in New Issue
Block a user