diff --git a/src/main/java/com/sztzjy/forex/trading_trading/config/SpringContextEventListener.java b/src/main/java/com/sztzjy/forex/trading_trading/config/SpringContextEventListener.java new file mode 100644 index 0000000..770f14d --- /dev/null +++ b/src/main/java/com/sztzjy/forex/trading_trading/config/SpringContextEventListener.java @@ -0,0 +1,32 @@ +package com.sztzjy.forex.trading_trading.config; + +import com.sztzjy.forex.trading_trading.entity.Log; +import com.sztzjy.forex.trading_trading.service.LogService; +import lombok.RequiredArgsConstructor; +import org.springframework.context.event.EventListener; +import org.springframework.core.annotation.Order; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Component; + + +/** + * 事件监听器 + */ +@Component +@RequiredArgsConstructor +public class SpringContextEventListener { + private final LogService logService; + + /** + * 异步保存操作日志 + * + * @param event 发布日志事件 详见{@link com.sztzjy.forex.trading_trading.annotation.aspect.OperateLogAspect},{@link LogRecordEvent} + */ + @Order + @Async + @EventListener(LogRecordEvent.class) + public void logListener(LogRecordEvent event) { + Log log = (Log) event.getSource(); + logService.add(log); + } +} diff --git a/src/main/resources/mappers/LogMapper.xml b/src/main/resources/mappers/LogMapper.xml new file mode 100644 index 0000000..161d11d --- /dev/null +++ b/src/main/resources/mappers/LogMapper.xml @@ -0,0 +1,366 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + + + + + + + + and ${criterion.condition} + + + and ${criterion.condition} #{criterion.value} + + + and ${criterion.condition} #{criterion.value} and #{criterion.secondValue} + + + and ${criterion.condition} + + #{listItem} + + + + + + + + + + + + id, create_time, update_time, action, description, ip_address, operator_id, operator_name, + params, user_agent + + + + + + delete from system_log + where id = #{id,jdbcType=VARCHAR} + + + + delete from system_log + + + + + + + insert into system_log (id, create_time, update_time, + action, description, ip_address, + operator_id, operator_name, params, + user_agent) + values (#{id,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, + #{action,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{ipAddress,jdbcType=VARCHAR}, + #{operatorId,jdbcType=VARCHAR}, #{operatorName,jdbcType=VARCHAR}, #{params,jdbcType=VARCHAR}, + #{userAgent,jdbcType=VARCHAR}) + + + + insert into system_log + + + id, + + + create_time, + + + update_time, + + + action, + + + description, + + + ip_address, + + + operator_id, + + + operator_name, + + + params, + + + user_agent, + + + + + #{id,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=TIMESTAMP}, + + + #{updateTime,jdbcType=TIMESTAMP}, + + + #{action,jdbcType=VARCHAR}, + + + #{description,jdbcType=VARCHAR}, + + + #{ipAddress,jdbcType=VARCHAR}, + + + #{operatorId,jdbcType=VARCHAR}, + + + #{operatorName,jdbcType=VARCHAR}, + + + #{params,jdbcType=VARCHAR}, + + + #{userAgent,jdbcType=VARCHAR}, + + + + + + + update system_log + + + id = #{record.id,jdbcType=VARCHAR}, + + + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + + + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + + + action = #{record.action,jdbcType=VARCHAR}, + + + description = #{record.description,jdbcType=VARCHAR}, + + + ip_address = #{record.ipAddress,jdbcType=VARCHAR}, + + + operator_id = #{record.operatorId,jdbcType=VARCHAR}, + + + operator_name = #{record.operatorName,jdbcType=VARCHAR}, + + + params = #{record.params,jdbcType=VARCHAR}, + + + user_agent = #{record.userAgent,jdbcType=VARCHAR}, + + + + + + + + + update system_log + set id = #{record.id,jdbcType=VARCHAR}, + create_time = #{record.createTime,jdbcType=TIMESTAMP}, + update_time = #{record.updateTime,jdbcType=TIMESTAMP}, + action = #{record.action,jdbcType=VARCHAR}, + description = #{record.description,jdbcType=VARCHAR}, + ip_address = #{record.ipAddress,jdbcType=VARCHAR}, + operator_id = #{record.operatorId,jdbcType=VARCHAR}, + operator_name = #{record.operatorName,jdbcType=VARCHAR}, + params = #{record.params,jdbcType=VARCHAR}, + user_agent = #{record.userAgent,jdbcType=VARCHAR} + + + + + + + update system_log + + + create_time = #{createTime,jdbcType=TIMESTAMP}, + + + update_time = #{updateTime,jdbcType=TIMESTAMP}, + + + action = #{action,jdbcType=VARCHAR}, + + + description = #{description,jdbcType=VARCHAR}, + + + ip_address = #{ipAddress,jdbcType=VARCHAR}, + + + operator_id = #{operatorId,jdbcType=VARCHAR}, + + + operator_name = #{operatorName,jdbcType=VARCHAR}, + + + params = #{params,jdbcType=VARCHAR}, + + + user_agent = #{userAgent,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + + update system_log + set create_time = #{createTime,jdbcType=TIMESTAMP}, + update_time = #{updateTime,jdbcType=TIMESTAMP}, + action = #{action,jdbcType=VARCHAR}, + description = #{description,jdbcType=VARCHAR}, + ip_address = #{ipAddress,jdbcType=VARCHAR}, + operator_id = #{operatorId,jdbcType=VARCHAR}, + operator_name = #{operatorName,jdbcType=VARCHAR}, + params = #{params,jdbcType=VARCHAR}, + user_agent = #{userAgent,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file