feat:增加操作日志
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
package com.tiesheng.annotation.operation;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Documented
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface OperationLog {
|
||||||
|
|
||||||
|
String title() default "";
|
||||||
|
|
||||||
|
String subject() default "";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 如果该值存在,怎会校验参数中是否存在该值,存在则便是更新,不存在则表示添加
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
String insertKey() default "";
|
||||||
|
|
||||||
|
}
|
||||||
@@ -2,9 +2,12 @@ package com.tiesheng.migration.config;
|
|||||||
|
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
import cn.hutool.db.Db;
|
||||||
|
import cn.hutool.db.Entity;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,10 +19,32 @@ import java.util.List;
|
|||||||
@ConfigurationProperties(prefix = "tiesheng.db-migration")
|
@ConfigurationProperties(prefix = "tiesheng.db-migration")
|
||||||
public class DbMigrationConfig {
|
public class DbMigrationConfig {
|
||||||
|
|
||||||
private String table = "ts_db_migration";
|
private String table = "core_db_migration";
|
||||||
private List<String> locations = CollUtil.newArrayList("classpath:db/migration/*.sql");
|
private List<String> locations = CollUtil.newArrayList("classpath:db/migration/*.sql");
|
||||||
private String ignoreSqls = "drop,delete";
|
private String ignoreSqls = "drop,delete";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查数据库是否存在
|
||||||
|
*
|
||||||
|
* @param db
|
||||||
|
* @throws SQLException
|
||||||
|
*/
|
||||||
|
public void checkDbExists(Db db) throws SQLException {
|
||||||
|
try {
|
||||||
|
db.count(Entity.create(getTable()));
|
||||||
|
} catch (SQLException ignored) {
|
||||||
|
db.execute("CREATE TABLE `" + getTable() + "` (\n" +
|
||||||
|
" `id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,\n" +
|
||||||
|
" `create_time` datetime(0) NOT NULL,\n" +
|
||||||
|
" `update_time` datetime(0) NOT NULL,\n" +
|
||||||
|
" `is_deleted` int(6) NOT NULL DEFAULT 0,\n" +
|
||||||
|
" `file` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件名称',\n" +
|
||||||
|
" `checksum` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件checksum',\n" +
|
||||||
|
" PRIMARY KEY (`id`) USING BTREE\n" +
|
||||||
|
") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'db-合并' ROW_FORMAT = Dynamic;");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import cn.hutool.core.util.IdUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.db.Db;
|
import cn.hutool.db.Db;
|
||||||
import cn.hutool.db.Entity;
|
import cn.hutool.db.Entity;
|
||||||
import cn.hutool.log.LogFactory;
|
|
||||||
import com.tiesheng.migration.config.DbMigrationConfig;
|
import com.tiesheng.migration.config.DbMigrationConfig;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
import org.springframework.boot.web.servlet.ServletContextInitializer;
|
||||||
@@ -54,7 +53,7 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
*/
|
*/
|
||||||
private void startDeal() throws Exception {
|
private void startDeal() throws Exception {
|
||||||
Db coreDb = Db.use(dataSource);
|
Db coreDb = Db.use(dataSource);
|
||||||
checkDbMigration(coreDb);
|
dbMigrationConfig.checkDbExists(coreDb);
|
||||||
|
|
||||||
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
PathMatchingResourcePatternResolver patternResolver = new PathMatchingResourcePatternResolver();
|
||||||
for (String location : dbMigrationConfig.getLocations()) {
|
for (String location : dbMigrationConfig.getLocations()) {
|
||||||
@@ -95,7 +94,10 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
if (StrUtil.startWithAnyIgnoreCase(sql, StrUtil.splitToArray(dbMigrationConfig.getIgnoreSqls(), ","))) {
|
if (StrUtil.startWithAnyIgnoreCase(sql, StrUtil.splitToArray(dbMigrationConfig.getIgnoreSqls(), ","))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
parameter.execute(sql);
|
try {
|
||||||
|
parameter.execute(sql);
|
||||||
|
} catch (Exception ignore) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -132,26 +134,4 @@ public class DbMigrationInitializer implements ServletContextInitializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查数据库是否存在
|
|
||||||
*
|
|
||||||
* @param db
|
|
||||||
* @throws SQLException
|
|
||||||
*/
|
|
||||||
private void checkDbMigration(Db db) throws SQLException {
|
|
||||||
try {
|
|
||||||
db.count(Entity.create(dbMigrationConfig.getTable()));
|
|
||||||
} catch (SQLException ignored) {
|
|
||||||
db.execute("CREATE TABLE `" + dbMigrationConfig.getTable() + "` (\n" +
|
|
||||||
" `id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,\n" +
|
|
||||||
" `create_time` datetime(0) NOT NULL,\n" +
|
|
||||||
" `update_time` datetime(0) NOT NULL,\n" +
|
|
||||||
" `is_deleted` int(6) NOT NULL DEFAULT 0,\n" +
|
|
||||||
" `file` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件名称',\n" +
|
|
||||||
" `checksum` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '文件checksum',\n" +
|
|
||||||
" PRIMARY KEY (`id`) USING BTREE\n" +
|
|
||||||
") ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = 'db-合并' ROW_FORMAT = Dynamic;");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.tiesheng.core;
|
package com.tiesheng.core;
|
||||||
|
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -9,5 +10,6 @@ import org.springframework.context.annotation.ComponentScan;
|
|||||||
@ComponentScan({
|
@ComponentScan({
|
||||||
"com.tiesheng.core.**.*",
|
"com.tiesheng.core.**.*",
|
||||||
})
|
})
|
||||||
|
@MapperScan("com.tiesheng.core.mapper")
|
||||||
public class CoreAutoImportSelector {
|
public class CoreAutoImportSelector {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@ package com.tiesheng.core.config.exception;
|
|||||||
|
|
||||||
import cn.hutool.core.exceptions.ValidateException;
|
import cn.hutool.core.exceptions.ValidateException;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.hutool.log.LogFactory;
|
import com.tiesheng.core.config.web.TieshengWebConfigurer;
|
||||||
import com.tiesheng.util.exception.ApiException;
|
import com.tiesheng.util.exception.ApiException;
|
||||||
import com.tiesheng.util.exception.ApiRespEnum;
|
import com.tiesheng.util.exception.ApiRespEnum;
|
||||||
import com.tiesheng.util.pojos.ApiResp;
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
|
import org.springframework.boot.autoconfigure.web.servlet.MultipartProperties;
|
||||||
import org.springframework.validation.BindException;
|
import org.springframework.validation.BindException;
|
||||||
import org.springframework.validation.FieldError;
|
import org.springframework.validation.FieldError;
|
||||||
@@ -24,6 +25,9 @@ import java.io.IOException;
|
|||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
public class SpringExceptionHandler {
|
public class SpringExceptionHandler {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
TieshengWebConfigurer tieshengWebConfigurer;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 全局异常捕获
|
* 全局异常捕获
|
||||||
@@ -70,9 +74,7 @@ public class SpringExceptionHandler {
|
|||||||
return ApiResp.respCust(ApiRespEnum.ServerError.getCode(), "IO异常");
|
return ApiResp.respCust(ApiRespEnum.ServerError.getCode(), "IO异常");
|
||||||
}
|
}
|
||||||
|
|
||||||
ApiResp<String> apiResp = ApiResp.respCust(ApiRespEnum.ServerError);
|
return tieshengWebConfigurer.addExceptionHandler(e);
|
||||||
LogFactory.get().info(e);
|
|
||||||
return apiResp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.tiesheng.core.config.operation;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.tiesheng.annotation.operation.OperationLog;
|
||||||
|
import com.tiesheng.core.config.token.TokenParse;
|
||||||
|
import com.tiesheng.core.config.token.bean.TokenBean;
|
||||||
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
|
import org.aspectj.lang.annotation.Around;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.aspectj.lang.reflect.MethodSignature;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
* @ProjectName CmccSpring
|
||||||
|
* @Copyright Hangzhou ShuoChuang Technology Co.,Ltd All Right Reserved
|
||||||
|
* @Description 这里是对文件的描述
|
||||||
|
* @data 2019-07-15
|
||||||
|
* @note 这里写文件的详细功能和改动
|
||||||
|
* @note
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class OperationAspect {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CoreLogService coreLogService;
|
||||||
|
|
||||||
|
|
||||||
|
@Pointcut("@annotation(com.tiesheng.annotation.operation.OperationLog)")
|
||||||
|
public void methodArgs() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取操作日志说明
|
||||||
|
*
|
||||||
|
* @param joinPoint
|
||||||
|
*/
|
||||||
|
@Around("methodArgs()")
|
||||||
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||||
|
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
|
||||||
|
Method method = signature.getMethod();
|
||||||
|
OperationLog operationLog = method.getAnnotation(OperationLog.class);
|
||||||
|
String subject = operationLog.subject();
|
||||||
|
String insertKey = operationLog.insertKey();
|
||||||
|
|
||||||
|
Object reqObj = null;
|
||||||
|
Map<String, Object> allParams = new HashMap<>(16);
|
||||||
|
if (joinPoint.getArgs().length > 0) {
|
||||||
|
reqObj = joinPoint.getArgs()[0];
|
||||||
|
allParams.putAll(BeanUtil.beanToMap(reqObj));
|
||||||
|
}
|
||||||
|
|
||||||
|
Object response = joinPoint.proceed(joinPoint.getArgs());
|
||||||
|
allParams.putAll(BeanUtil.beanToMap(response));
|
||||||
|
|
||||||
|
if (!StrUtil.isEmpty(subject)) {
|
||||||
|
|
||||||
|
// 添加、编辑关键字处理
|
||||||
|
if (!StrUtil.isEmpty(insertKey)) {
|
||||||
|
String insertVal = MapUtil.getStr(allParams, insertKey);
|
||||||
|
subject = (StrUtil.isEmpty(insertVal) ? "添加" : "编辑") + subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 占位符处理
|
||||||
|
subject = StrUtil.format(subject, allParams);
|
||||||
|
}
|
||||||
|
|
||||||
|
coreLogService.addOperationLog(operationLog.title(), subject, reqObj);
|
||||||
|
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -16,7 +16,7 @@ import java.util.Map;
|
|||||||
@ConfigurationProperties("tiesheng.token")
|
@ConfigurationProperties("tiesheng.token")
|
||||||
public class TokenValidConfig {
|
public class TokenValidConfig {
|
||||||
|
|
||||||
private Map<String, TokenBean> list = MapUtil.newHashMap();
|
private Map<String, TokenBean> ignores = MapUtil.newHashMap();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,21 +26,21 @@ public class TokenValidConfig {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TokenBean getTokenBean(String token) {
|
public TokenBean getTokenBean(String token) {
|
||||||
if (list == null) {
|
if (ignores == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return list.get(token);
|
return ignores.get(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// setter\getter
|
// setter\getter
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
public Map<String, TokenBean> getList() {
|
public Map<String, TokenBean> getIgnores() {
|
||||||
return list;
|
return ignores;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setList(Map<String, TokenBean> list) {
|
public void setIgnores(Map<String, TokenBean> ignores) {
|
||||||
this.list = list;
|
this.ignores = ignores;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.tiesheng.core.config.web;
|
||||||
|
|
||||||
|
import cn.hutool.log.LogFactory;
|
||||||
|
import com.tiesheng.core.config.token.TokenParse;
|
||||||
|
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
||||||
|
import com.tiesheng.util.exception.ApiRespEnum;
|
||||||
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WEB配置
|
||||||
|
*
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public interface TieshengWebConfigurer {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前用户的姓名
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
default CurrentWebUser getCurrentUserName() {
|
||||||
|
CurrentWebUser webUser = new CurrentWebUser();
|
||||||
|
webUser.setId(TokenParse.getWithoutThr().getId());
|
||||||
|
return webUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加其他异常处理
|
||||||
|
*
|
||||||
|
* @param e 异常
|
||||||
|
*/
|
||||||
|
default ApiResp<String> addExceptionHandler(Exception e) {
|
||||||
|
LogFactory.get().info(e);
|
||||||
|
return ApiResp.respCust(ApiRespEnum.ServerError);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.tiesheng.core.config.web.bean;
|
||||||
|
|
||||||
|
public class CurrentWebUser {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private Object data;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// setter\getter
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(Object data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package com.tiesheng.core.controller.log;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||||
|
import com.tiesheng.core.pojos.dto.PageDTO;
|
||||||
|
import com.tiesheng.core.service.CoreLogService;
|
||||||
|
import com.tiesheng.util.pojos.ApiResp;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/manager/log")
|
||||||
|
public class ManagerLogController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
CoreLogService coreLogService;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作日志列表
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/operation/page")
|
||||||
|
public ApiResp<List<CoreLogOperation>> operationList(@Valid PageDTO dto) {
|
||||||
|
|
||||||
|
QueryWrapper<CoreLogOperation> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("is_deleted", 0);
|
||||||
|
dto.likeColumns(queryWrapper, "user_name", "title", "subject", "params");
|
||||||
|
queryWrapper.orderByDesc("create_time");
|
||||||
|
|
||||||
|
Page<CoreLogOperation> page = dto.pageObj();
|
||||||
|
coreLogService.page(page, queryWrapper);
|
||||||
|
|
||||||
|
return ApiResp.respOK(page.getRecords(), page.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.tiesheng.core.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||||
|
|
||||||
|
public interface CoreLogOperationMapper extends BaseMapper<CoreLogOperation> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,134 @@
|
|||||||
|
package com.tiesheng.core.pojos.dao;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.tiesheng.core.pojos.DaoBase;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 日志-操作
|
||||||
|
*/
|
||||||
|
@TableName(value = "core_log_operation")
|
||||||
|
public class CoreLogOperation extends DaoBase {
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_id")
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户名称
|
||||||
|
*/
|
||||||
|
@TableField(value = "user_name")
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标题
|
||||||
|
*/
|
||||||
|
@TableField(value = "title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 小标题
|
||||||
|
*/
|
||||||
|
@TableField(value = "subject")
|
||||||
|
private String subject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 其他参数
|
||||||
|
*/
|
||||||
|
@TableField(value = "params")
|
||||||
|
private String params;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户id
|
||||||
|
*
|
||||||
|
* @return user_id - 用户id
|
||||||
|
*/
|
||||||
|
public String getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置用户id
|
||||||
|
*
|
||||||
|
* @param userId 用户id
|
||||||
|
*/
|
||||||
|
public void setUserId(String userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户名称
|
||||||
|
*
|
||||||
|
* @return user_name - 用户名称
|
||||||
|
*/
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置用户名称
|
||||||
|
*
|
||||||
|
* @param userName 用户名称
|
||||||
|
*/
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取标题
|
||||||
|
*
|
||||||
|
* @return title - 标题
|
||||||
|
*/
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置标题
|
||||||
|
*
|
||||||
|
* @param title 标题
|
||||||
|
*/
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取小标题
|
||||||
|
*
|
||||||
|
* @return subject - 小标题
|
||||||
|
*/
|
||||||
|
public String getSubject() {
|
||||||
|
return subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置小标题
|
||||||
|
*
|
||||||
|
* @param subject 小标题
|
||||||
|
*/
|
||||||
|
public void setSubject(String subject) {
|
||||||
|
this.subject = subject;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取其他参数
|
||||||
|
*
|
||||||
|
* @return params - 其他参数
|
||||||
|
*/
|
||||||
|
public String getParams() {
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置其他参数
|
||||||
|
*
|
||||||
|
* @param params 其他参数
|
||||||
|
*/
|
||||||
|
public void setParams(String params) {
|
||||||
|
this.params = params;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.tiesheng.core.service;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.tiesheng.core.config.web.bean.CurrentWebUser;
|
||||||
|
import com.tiesheng.core.config.web.TieshengWebConfigurer;
|
||||||
|
import com.tiesheng.core.mapper.CoreLogOperationMapper;
|
||||||
|
import com.tiesheng.core.pojos.dao.CoreLogOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author hao
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class CoreLogService extends ServiceImpl<CoreLogOperationMapper, CoreLogOperation> {
|
||||||
|
|
||||||
|
@Autowired(required = false)
|
||||||
|
TieshengWebConfigurer tieshengWebConfigurer;
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
// 操作日志
|
||||||
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 添加操作日志
|
||||||
|
*/
|
||||||
|
public void addOperationLog(String title, String subject, Object params) {
|
||||||
|
CoreLogOperation operation = new CoreLogOperation();
|
||||||
|
CurrentWebUser currentWebUser = tieshengWebConfigurer.getCurrentUserName();
|
||||||
|
operation.setUserId(currentWebUser.getId());
|
||||||
|
operation.setUserName(currentWebUser.getName());
|
||||||
|
operation.setTitle(title);
|
||||||
|
operation.setSubject(subject);
|
||||||
|
if (params != null) {
|
||||||
|
operation.setParams(JSONUtil.toJsonStr(params));
|
||||||
|
}
|
||||||
|
save(operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
SET NAMES utf8mb4;
|
||||||
|
SET FOREIGN_KEY_CHECKS = 0;
|
||||||
|
|
||||||
|
-- ----------------------------
|
||||||
|
-- Table structure for core_log_operation
|
||||||
|
-- ----------------------------
|
||||||
|
CREATE TABLE `core_log_operation`
|
||||||
|
(
|
||||||
|
`id` varchar(50) NOT NULL,
|
||||||
|
`create_time` datetime NOT NULL,
|
||||||
|
`update_time` datetime NOT NULL,
|
||||||
|
`is_deleted` int(6) NOT NULL DEFAULT '0',
|
||||||
|
`user_id` varchar(50) DEFAULT NULL COMMENT '用户id',
|
||||||
|
`user_name` varchar(255) DEFAULT NULL COMMENT '用户名称',
|
||||||
|
`title` varchar(255) DEFAULT NULL COMMENT '标题',
|
||||||
|
`subject` varchar(500) DEFAULT NULL COMMENT '小标题',
|
||||||
|
`params` text COMMENT '其他参数',
|
||||||
|
PRIMARY KEY (`id`)
|
||||||
|
) ENGINE = InnoDB
|
||||||
|
DEFAULT CHARSET = utf8mb4 COMMENT ='日志-操作';
|
||||||
|
|
||||||
|
CREATE TABLE `core_config_system`
|
||||||
|
(
|
||||||
|
`id` varchar(50) NOT NULL,
|
||||||
|
`create_time` datetime NOT NULL,
|
||||||
|
`update_time` datetime NOT NULL,
|
||||||
|
`is_deleted` int(4) NOT NULL DEFAULT '0',
|
||||||
|
`config_key` varchar(255) NOT NULL,
|
||||||
|
`config_val` text NOT NULL,
|
||||||
|
`config_type` int(6) NOT NULL DEFAULT '0' COMMENT '类型:0-文本,1-图片,2-文件',
|
||||||
|
`remark` varchar(500) DEFAULT NULL COMMENT '说明',
|
||||||
|
`extra` varchar(255) DEFAULT NULL COMMENT '额外配置',
|
||||||
|
`read_only` int(6) NOT NULL DEFAULT '0' COMMENT '0-否,1-是',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `uni_key` (`config_key`(50)) USING BTREE
|
||||||
|
) ENGINE = InnoDB
|
||||||
|
DEFAULT CHARSET = utf8mb4 COMMENT ='配置-系统';
|
||||||
|
|
||||||
|
INSERT INTO `core_config_system`(`id`, `create_time`, `update_time`, `is_deleted`, `config_key`, `config_val`,
|
||||||
|
`config_type`, `remark`, `extra`, `read_only`)
|
||||||
|
VALUES ('manager_web_copyright', '2022-02-23 16:52:48', '2022-02-23 16:52:49', 0, 'manager_web_copyright',
|
||||||
|
'杭州铁晟提供技术支持', 0, '网站底部版权信息', '', 0);
|
||||||
|
|
||||||
|
INSERT INTO `core_config_system`(`id`, `create_time`, `update_time`, `is_deleted`, `config_key`, `config_val`,
|
||||||
|
`config_type`, `remark`, `extra`, `read_only`)
|
||||||
|
VALUES ('manager_web_title', '2022-02-24 11:56:53', '2022-02-24 11:56:53', 0, 'manager_web_title', '网站名称', 0,
|
||||||
|
'网站名称', '', 0);
|
||||||
|
|
||||||
|
INSERT INTO `core_config_system`(`id`, `create_time`, `update_time`, `is_deleted`, `config_key`, `config_val`,
|
||||||
|
`config_type`, `remark`, `extra`, `read_only`)
|
||||||
|
VALUES ('manager_web_logo', '2022-02-24 11:56:53', '2022-02-24 11:56:53', 0, 'manager_web_logo', '', 1,
|
||||||
|
'网站LOGO', '', 0);
|
||||||
|
|
||||||
|
SET FOREIGN_KEY_CHECKS = 1;
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.tiesheng.core.mapper.CoreLogOperationMapper">
|
||||||
|
<resultMap id="BaseResultMap" type="com.tiesheng.core.pojos.dao.CoreLogOperation">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
<!--@Table core_log_operation-->
|
||||||
|
<id column="id" jdbcType="VARCHAR" property="id" />
|
||||||
|
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
|
||||||
|
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
|
||||||
|
<result column="is_deleted" jdbcType="INTEGER" property="isDeleted" />
|
||||||
|
<result column="user_id" jdbcType="VARCHAR" property="userId" />
|
||||||
|
<result column="user_name" jdbcType="VARCHAR" property="userName" />
|
||||||
|
<result column="title" jdbcType="VARCHAR" property="title" />
|
||||||
|
<result column="subject" jdbcType="VARCHAR" property="subject" />
|
||||||
|
<result column="params" jdbcType="LONGVARCHAR" property="params" />
|
||||||
|
</resultMap>
|
||||||
|
<sql id="Base_Column_List">
|
||||||
|
<!--@mbg.generated-->
|
||||||
|
id, create_time, update_time, is_deleted, user_id, user_name, title, subject, params
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user