系统日志
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package org.xyzh.system.controller;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.xyzh.api.system.dto.TbSysLogDTO;
|
||||
import org.xyzh.api.system.service.LogService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageRequest;
|
||||
|
||||
/**
|
||||
* @description 系统日志控制器
|
||||
* @filename LogController.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2026-01-01
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/system/log")
|
||||
public class LogController {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LogController.class);
|
||||
|
||||
@Autowired
|
||||
private LogService logService;
|
||||
|
||||
// ================= 系统日志相关接口 =================
|
||||
|
||||
/**
|
||||
* 添加系统日志
|
||||
*/
|
||||
@PostMapping
|
||||
@PreAuthorize("hasAuthority('log:log:add')")
|
||||
public ResultDomain<TbSysLogDTO> addSysLog(@RequestBody TbSysLogDTO sysLog) {
|
||||
return logService.addSysLog(sysLog);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计日志数量
|
||||
*/
|
||||
@PostMapping("/count")
|
||||
@PreAuthorize("hasAuthority('log:log:view')")
|
||||
public ResultDomain<Integer> countSysLog(@RequestBody TbSysLogDTO filter) {
|
||||
return logService.countSysLog(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取日志列表
|
||||
*/
|
||||
@PostMapping("/list")
|
||||
@PreAuthorize("hasAuthority('log:log:view')")
|
||||
public ResultDomain<TbSysLogDTO> getSysLogList(@RequestBody TbSysLogDTO filter) {
|
||||
return logService.getSysLogList(filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询日志
|
||||
*/
|
||||
@PostMapping("/page")
|
||||
@PreAuthorize("hasAuthority('log:log:view')")
|
||||
public ResultDomain<TbSysLogDTO> getSysLogPage(@RequestBody PageRequest<TbSysLogDTO> pageRequest) {
|
||||
return logService.getSysLogPage(pageRequest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.xyzh.system.mapper.log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.api.system.dto.TbSysLogDTO;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @description 系统日志Mapper接口
|
||||
* @filename TbSysLogMapper.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
@Mapper
|
||||
public interface TbSysLogMapper extends BaseMapper<TbSysLogDTO> {
|
||||
|
||||
/**
|
||||
* @description 插入系统日志
|
||||
* @param logDTO 系统日志DTO
|
||||
* @return int 插入结果
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int insertLog(TbSysLogDTO logDTO);
|
||||
|
||||
/**
|
||||
* @description 更新系统日志
|
||||
* @param logDTO 系统日志DTO
|
||||
* @return int 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int updateLog(TbSysLogDTO logDTO);
|
||||
|
||||
/**
|
||||
* @description 删除系统日志
|
||||
* @param logDTO 系统日志DTO
|
||||
* @return int 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int deleteLog(TbSysLogDTO logDTO);
|
||||
|
||||
/**
|
||||
* @description 根据日志ID查询系统日志
|
||||
* @param logId 日志ID
|
||||
* @return TbSysLogDTO 系统日志DTO
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
TbSysLogDTO getLogById(String logId);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统日志列表
|
||||
* @param filter 系统日志DTO
|
||||
* @return List<TbSysLogDTO> 系统日志列表
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
List<TbSysLogDTO> getLogByFilter(@Param("filter") TbSysLogDTO filter);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统日志分页列表
|
||||
* @param filter 系统日志DTO
|
||||
* @param pageParam 分页参数
|
||||
* @return List<TbSysLogDTO> 系统日志列表
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
List<TbSysLogDTO> getLogPageByFilter(@Param("filter") TbSysLogDTO filter, @Param("pageParam") PageParam pageParam);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统日志数量
|
||||
* @param filter 系统日志DTO
|
||||
* @return int 系统日志数量
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int getLogCount(TbSysLogDTO filter);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
package org.xyzh.system.mapper.log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.xyzh.api.system.dto.TbSysLoginLogDTO;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @description 系统登录日志Mapper接口
|
||||
* @filename TbSysLoginLogMapper.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
@Mapper
|
||||
public interface TbSysLoginLogMapper extends BaseMapper<TbSysLoginLogDTO> {
|
||||
|
||||
/**
|
||||
* @description 插入系统登录日志
|
||||
* @param loginLogDTO 系统登录日志DTO
|
||||
* @return int 插入结果
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int insertLoginLog(TbSysLoginLogDTO loginLogDTO);
|
||||
|
||||
/**
|
||||
* @description 更新系统登录日志
|
||||
* @param loginLogDTO 系统登录日志DTO
|
||||
* @return int 更新结果
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int updateLoginLog(TbSysLoginLogDTO loginLogDTO);
|
||||
|
||||
/**
|
||||
* @description 删除系统登录日志
|
||||
* @param loginLogDTO 系统登录日志DTO
|
||||
* @return int 删除结果
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int deleteLoginLog(TbSysLoginLogDTO loginLogDTO);
|
||||
|
||||
/**
|
||||
* @description 根据登录日志ID查询系统登录日志
|
||||
* @param loginLogId 登录日志ID
|
||||
* @return TbSysLoginLogDTO 系统登录日志DTO
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
TbSysLoginLogDTO getLoginLogById(String loginLogId);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统登录日志列表
|
||||
* @param filter 系统登录日志DTO
|
||||
* @return List<TbSysLoginLogDTO> 系统登录日志列表
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
List<TbSysLoginLogDTO> getLoginLogByFilter(@Param("filter") TbSysLoginLogDTO filter);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统登录日志分页列表
|
||||
* @param filter 系统登录日志DTO
|
||||
* @param pageParam 分页参数
|
||||
* @return List<TbSysLoginLogDTO> 系统登录日志列表
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
List<TbSysLoginLogDTO> getLoginLogPageByFilter(@Param("filter") TbSysLoginLogDTO filter, @Param("pageParam") PageParam pageParam);
|
||||
|
||||
/**
|
||||
* @description 根据条件查询系统登录日志数量
|
||||
* @param filter 系统登录日志DTO
|
||||
* @return int 系统登录日志数量
|
||||
* @author yslg
|
||||
* @since 2025-11-07
|
||||
*/
|
||||
int getLoginLogCount(TbSysLoginLogDTO filter);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,137 @@
|
||||
package org.xyzh.system.service.impl;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.xyzh.api.system.dto.TbSysLogDTO;
|
||||
import org.xyzh.api.system.service.LogService;
|
||||
import org.xyzh.common.core.domain.ResultDomain;
|
||||
import org.xyzh.common.core.page.PageDomain;
|
||||
import org.xyzh.common.core.page.PageParam;
|
||||
import org.xyzh.common.core.page.PageRequest;
|
||||
import org.xyzh.common.utils.StringUtils;
|
||||
import org.xyzh.common.utils.id.IdUtil;
|
||||
import org.xyzh.system.mapper.log.TbSysLogMapper;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @description 系统日志服务实现类
|
||||
* @filename LogServiceImpl.java
|
||||
* @author yslg
|
||||
* @copyright yslg
|
||||
* @since 2026-01-01
|
||||
*/
|
||||
@DubboService(
|
||||
version = "1.0.0",
|
||||
group = "system",
|
||||
timeout = 3000,
|
||||
retries = 0
|
||||
)
|
||||
public class LogServiceImpl implements LogService {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(LogServiceImpl.class);
|
||||
|
||||
private static final String MSG_LOG_PARAM_REQUIRED = "日志参数不能为空";
|
||||
private static final String MSG_FILTER_PARAM_REQUIRED = "查询条件不能为空";
|
||||
private static final String MSG_PAGE_PARAM_REQUIRED = "分页参数不能为空";
|
||||
|
||||
@Resource
|
||||
private TbSysLogMapper sysLogMapper;
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysLogDTO> addSysLog(TbSysLogDTO sysLog) {
|
||||
if (sysLog == null) {
|
||||
return ResultDomain.failure(MSG_LOG_PARAM_REQUIRED);
|
||||
}
|
||||
|
||||
try {
|
||||
// 设置默认值
|
||||
if (StringUtils.isBlank(sysLog.getLogId())) {
|
||||
sysLog.setLogId(IdUtil.generateID());
|
||||
}
|
||||
if (StringUtils.isBlank(sysLog.getOptsn())) {
|
||||
sysLog.setOptsn(IdUtil.generateID());
|
||||
}
|
||||
if (sysLog.getCreateTime() == null) {
|
||||
sysLog.setCreateTime(new Date());
|
||||
}
|
||||
if (sysLog.getDeleted() == null) {
|
||||
sysLog.setDeleted(false);
|
||||
}
|
||||
|
||||
int rows = sysLogMapper.insertLog(sysLog);
|
||||
if (rows > 0) {
|
||||
logger.info("添加系统日志成功, logId={}", sysLog.getLogId());
|
||||
return ResultDomain.success("添加系统日志成功", sysLog);
|
||||
}
|
||||
logger.warn("添加系统日志失败, logId={}", sysLog.getLogId());
|
||||
return ResultDomain.failure("添加系统日志失败");
|
||||
} catch (Exception e) {
|
||||
logger.error("添加系统日志异常", e);
|
||||
return ResultDomain.failure("添加系统日志异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<Integer> countSysLog(TbSysLogDTO filter) {
|
||||
if (filter == null) {
|
||||
return ResultDomain.failure(MSG_FILTER_PARAM_REQUIRED);
|
||||
}
|
||||
|
||||
try {
|
||||
int count = sysLogMapper.getLogCount(filter);
|
||||
return ResultDomain.success("统计日志数量成功", count);
|
||||
} catch (Exception e) {
|
||||
logger.error("统计日志数量异常", e);
|
||||
return ResultDomain.failure("统计日志数量异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysLogDTO> getSysLogList(TbSysLogDTO filter) {
|
||||
try {
|
||||
List<TbSysLogDTO> list = sysLogMapper.getLogByFilter(filter);
|
||||
if (list == null) {
|
||||
list = Collections.emptyList();
|
||||
}
|
||||
return ResultDomain.success("获取日志列表成功", list);
|
||||
} catch (Exception e) {
|
||||
logger.error("获取日志列表异常", e);
|
||||
return ResultDomain.failure("获取日志列表异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResultDomain<TbSysLogDTO> getSysLogPage(PageRequest<TbSysLogDTO> pageRequest) {
|
||||
if (pageRequest == null) {
|
||||
return ResultDomain.failure(MSG_PAGE_PARAM_REQUIRED);
|
||||
}
|
||||
|
||||
try {
|
||||
PageParam pageParam = pageRequest.getPageParam();
|
||||
TbSysLogDTO filter = pageRequest.getFilter();
|
||||
|
||||
// 查询总数
|
||||
int total = sysLogMapper.getLogCount(filter);
|
||||
pageParam.setTotal(total);
|
||||
pageParam.setTotalPages(pageParam.getPageSize() == 0 ? 0 :
|
||||
(int) Math.ceil((double) total / pageParam.getPageSize()));
|
||||
|
||||
// 查询分页数据
|
||||
List<TbSysLogDTO> data = sysLogMapper.getLogPageByFilter(filter, pageParam);
|
||||
if (data == null) {
|
||||
data = Collections.emptyList();
|
||||
}
|
||||
|
||||
PageDomain<TbSysLogDTO> pageDomain = new PageDomain<>(pageParam, data);
|
||||
return ResultDomain.success("分页查询日志成功", pageDomain);
|
||||
} catch (Exception e) {
|
||||
logger.error("分页查询日志异常", e);
|
||||
return ResultDomain.failure("分页查询日志异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
<?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="org.xyzh.system.mapper.log.TbSysLogMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.system.dto.TbSysLogDTO">
|
||||
<id column="log_id" property="logId" jdbcType="VARCHAR"/>
|
||||
<result column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="type" property="type" jdbcType="INTEGER"/>
|
||||
<result column="level" property="level" jdbcType="VARCHAR"/>
|
||||
<result column="module" property="module" jdbcType="VARCHAR"/>
|
||||
<result column="ip_address" property="ipAddress" jdbcType="VARCHAR"/>
|
||||
<result column="ip_source" property="ip_source" jdbcType="VARCHAR"/>
|
||||
<result column="browser" property="browser" jdbcType="VARCHAR"/>
|
||||
<result column="os" property="os" jdbcType="VARCHAR"/>
|
||||
<result column="message" property="message" jdbcType="VARCHAR"/>
|
||||
<result column="data" property="data" typeHandler="org.xyzh.common.jdbc.handler.FastJson2TypeHandler"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="creator_name" property="creatorName" jdbcType="VARCHAR"/>
|
||||
<result column="service" property="servce" jdbcType="VARCHAR"/>
|
||||
<result column="dept_path" property="deptPath" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础列 -->
|
||||
<sql id="Base_Column_List">
|
||||
log_id, optsn, type, level, module, ip_address, ip_source, browser, os, message,
|
||||
data, creator, creator_name, service, dept_path, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 插入系统日志 -->
|
||||
<insert id="insertLog" parameterType="org.xyzh.api.system.dto.TbSysLogDTO">
|
||||
INSERT INTO sys.tb_sys_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
log_id,
|
||||
optsn,
|
||||
type,
|
||||
level,
|
||||
module,
|
||||
message,
|
||||
service,
|
||||
<if test="ipAddress != null and ipAddress != ''">ip_address,</if>
|
||||
<if test="ip_source != null and ip_source != ''">ip_source,</if>
|
||||
<if test="browser != null and browser != ''">browser,</if>
|
||||
<if test="os != null and os != ''">os,</if>
|
||||
<if test="data != null">data,</if>
|
||||
<if test="creator != null and creator != ''">creator,</if>
|
||||
<if test="creatorName != null and creatorName != ''">creator_name,</if>
|
||||
<if test="deptPath != null and deptPath != ''">dept_path,</if>
|
||||
<if test="updater != null and updater != ''">updater,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="deleteTime != null">delete_time,</if>
|
||||
<if test="deleted != null">deleted,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
#{logId},
|
||||
#{optsn},
|
||||
#{type},
|
||||
#{level},
|
||||
#{module},
|
||||
#{message},
|
||||
#{servce},
|
||||
<if test="ipAddress != null and ipAddress != ''">#{ipAddress},</if>
|
||||
<if test="ip_source != null and ip_source != ''">#{ip_source},</if>
|
||||
<if test="browser != null and browser != ''">#{browser},</if>
|
||||
<if test="os != null and os != ''">#{os},</if>
|
||||
<if test="data != null">#{data, typeHandler=org.xyzh.common.jdbc.handler.FastJson2TypeHandler},</if>
|
||||
<if test="creator != null and creator != ''">#{creator},</if>
|
||||
<if test="creatorName != null and creatorName != ''">#{creatorName},</if>
|
||||
<if test="deptPath != null and deptPath != ''">#{deptPath},</if>
|
||||
<if test="updater != null and updater != ''">#{updater},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="deleteTime != null">#{deleteTime},</if>
|
||||
<if test="deleted != null">#{deleted},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新系统日志 -->
|
||||
<update id="updateLog" parameterType="org.xyzh.api.system.dto.TbSysLogDTO">
|
||||
UPDATE sys.tb_sys_log
|
||||
<set>
|
||||
<if test="type != null">type = #{type},</if>
|
||||
<if test="level != null and level != ''">level = #{level},</if>
|
||||
<if test="module != null and module != ''">module = #{module},</if>
|
||||
<if test="ipAddress != null and ipAddress != ''">ip_address = #{ipAddress},</if>
|
||||
<if test="ip_source != null and ip_source != ''">ip_source = #{ip_source},</if>
|
||||
<if test="browser != null and browser != ''">browser = #{browser},</if>
|
||||
<if test="os != null and os != ''">os = #{os},</if>
|
||||
<if test="message != null and message != ''">message = #{message},</if>
|
||||
<if test="data != null">data = #{data, typeHandler=org.xyzh.common.jdbc.handler.FastJson2TypeHandler},</if>
|
||||
<if test="servce != null and servce != ''">service = #{servce},</if>
|
||||
<if test="updater != null and updater != ''">updater = #{updater},</if>
|
||||
<if test="deptPath != null and deptPath != ''">dept_path = #{deptPath},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="deleteTime != null">delete_time = #{deleteTime},</if>
|
||||
<if test="deleted != null">deleted = #{deleted},</if>
|
||||
</set>
|
||||
WHERE log_id = #{logId}
|
||||
</update>
|
||||
|
||||
<!-- 删除系统日志 -->
|
||||
<update id="deleteLog" parameterType="org.xyzh.api.system.dto.TbSysLogDTO">
|
||||
UPDATE sys.tb_sys_log
|
||||
SET deleted = true,
|
||||
delete_time = NOW()
|
||||
WHERE log_id = #{logId}
|
||||
</update>
|
||||
|
||||
<!-- 根据日志ID查询系统日志 -->
|
||||
<select id="getLogById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM sys.tb_sys_log
|
||||
WHERE log_id = #{logId}
|
||||
AND (deleted IS NULL OR deleted = false)
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询系统日志列表 -->
|
||||
<select id="getLogByFilter" resultMap="BaseResultMap" parameterType="org.xyzh.api.system.dto.TbSysLogDTO">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM sys.tb_sys_log
|
||||
<where>
|
||||
<if test="filter.logId != null and filter.logId != ''">
|
||||
AND log_id = #{filter.logId}
|
||||
</if>
|
||||
<if test="filter.type != null">
|
||||
AND type = #{filter.type}
|
||||
</if>
|
||||
<if test="filter.level != null and filter.level != ''">
|
||||
AND level = #{filter.level}
|
||||
</if>
|
||||
<if test="filter.module != null and filter.module != ''">
|
||||
AND module = #{filter.module}
|
||||
</if>
|
||||
<if test="filter.ipAddress != null and filter.ipAddress != ''">
|
||||
AND ip_address = #{filter.ipAddress}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
<if test="filter.servce != null and filter.servce != ''">
|
||||
AND service = #{filter.servce}
|
||||
</if>
|
||||
<if test="filter.deptPath != null and filter.deptPath != ''">
|
||||
AND dept_path LIKE CONCAT(#{filter.deptPath}, '%')
|
||||
</if>
|
||||
<if test="filter.message != null and filter.message != ''">
|
||||
AND message LIKE CONCAT('%', #{filter.message}, '%')
|
||||
</if>
|
||||
<if test="filter.startTime != null">
|
||||
AND create_time >= #{filter.startTime}
|
||||
</if>
|
||||
<if test="filter.endTime != null">
|
||||
AND create_time <= #{filter.endTime}
|
||||
</if>
|
||||
AND (deleted IS NULL OR deleted = false)
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询系统日志分页列表 -->
|
||||
<select id="getLogPageByFilter" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM sys.tb_sys_log
|
||||
<where>
|
||||
<if test="filter.logId != null and filter.logId != ''">
|
||||
AND log_id = #{filter.logId}
|
||||
</if>
|
||||
<if test="filter.type != null">
|
||||
AND type = #{filter.type}
|
||||
</if>
|
||||
<if test="filter.level != null and filter.level != ''">
|
||||
AND level = #{filter.level}
|
||||
</if>
|
||||
<if test="filter.module != null and filter.module != ''">
|
||||
AND module = #{filter.module}
|
||||
</if>
|
||||
<if test="filter.ipAddress != null and filter.ipAddress != ''">
|
||||
AND ip_address = #{filter.ipAddress}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
<if test="filter.servce != null and filter.servce != ''">
|
||||
AND service = #{filter.servce}
|
||||
</if>
|
||||
<if test="filter.deptPath != null and filter.deptPath != ''">
|
||||
AND dept_path LIKE CONCAT(#{filter.deptPath}, '%')
|
||||
</if>
|
||||
<if test="filter.message != null and filter.message != ''">
|
||||
AND message LIKE CONCAT('%', #{filter.message}, '%')
|
||||
</if>
|
||||
<if test="filter.startTime != null">
|
||||
AND create_time >= #{filter.startTime}
|
||||
</if>
|
||||
<if test="filter.endTime != null">
|
||||
AND create_time <= #{filter.endTime}
|
||||
</if>
|
||||
AND (deleted IS NULL OR deleted = false)
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询系统日志数量 -->
|
||||
<select id="getLogCount" resultType="java.lang.Integer" parameterType="org.xyzh.api.system.dto.TbSysLogDTO">
|
||||
SELECT COUNT(1)
|
||||
FROM sys.tb_sys_log
|
||||
<where>
|
||||
<if test="logId != null and logId != ''">
|
||||
AND log_id = #{logId}
|
||||
</if>
|
||||
<if test="type != null">
|
||||
AND type = #{type}
|
||||
</if>
|
||||
<if test="level != null and level != ''">
|
||||
AND level = #{level}
|
||||
</if>
|
||||
<if test="module != null and module != ''">
|
||||
AND module = #{module}
|
||||
</if>
|
||||
<if test="ipAddress != null and ipAddress != ''">
|
||||
AND ip_address = #{ipAddress}
|
||||
</if>
|
||||
<if test="creator != null and creator != ''">
|
||||
AND creator = #{creator}
|
||||
</if>
|
||||
<if test="servce != null and servce != ''">
|
||||
AND service = #{servce}
|
||||
</if>
|
||||
<if test="deptPath != null and deptPath != ''">
|
||||
AND dept_path LIKE CONCAT(#{deptPath}, '%')
|
||||
</if>
|
||||
<if test="message != null and message != ''">
|
||||
AND message LIKE CONCAT('%', #{message}, '%')
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND create_time <= #{endTime}
|
||||
</if>
|
||||
AND (deleted IS NULL OR deleted = false)
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
@@ -0,0 +1,186 @@
|
||||
<?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="org.xyzh.system.mapper.log.TbSysLoginLogMapper">
|
||||
|
||||
<!-- 结果映射 -->
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.system.dto.TbSysLoginLogDTO">
|
||||
<id column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userId" jdbcType="VARCHAR"/>
|
||||
<result column="username" property="username" jdbcType="VARCHAR"/>
|
||||
<result column="ip_address" property="ipAddress" jdbcType="VARCHAR"/>
|
||||
<result column="ip_source" property="ipSource" jdbcType="VARCHAR"/>
|
||||
<result column="browser" property="browser" jdbcType="VARCHAR"/>
|
||||
<result column="os" property="os" jdbcType="VARCHAR"/>
|
||||
<result column="password" property="password" jdbcType="VARCHAR"/>
|
||||
<result column="login_time" property="loginTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="error_count" property="errorCount" jdbcType="INTEGER"/>
|
||||
<result column="message" property="message" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础列 -->
|
||||
<sql id="Base_Column_List">
|
||||
optsn, user_id, username, ip_address, ip_source, browser, os, password,
|
||||
login_time, status, error_count, message, create_time
|
||||
</sql>
|
||||
|
||||
<!-- 插入系统登录日志 -->
|
||||
<insert id="insertLoginLog" parameterType="org.xyzh.api.system.dto.TbSysLoginLogDTO">
|
||||
INSERT INTO sys.tb_sys_login_log
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
optsn,
|
||||
user_id,
|
||||
username,
|
||||
<if test="ipAddress != null and ipAddress != ''">ip_address,</if>
|
||||
<if test="ipSource != null and ipSource != ''">ip_source,</if>
|
||||
<if test="browser != null and browser != ''">browser,</if>
|
||||
<if test="os != null and os != ''">os,</if>
|
||||
<if test="password != null and password != ''">password,</if>
|
||||
<if test="loginTime != null">login_time,</if>
|
||||
<if test="status != null">status,</if>
|
||||
<if test="errorCount != null">error_count,</if>
|
||||
<if test="message != null and message != ''">message,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
</trim>
|
||||
VALUES
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
#{optsn},
|
||||
#{userId},
|
||||
#{username},
|
||||
<if test="ipAddress != null and ipAddress != ''">#{ipAddress},</if>
|
||||
<if test="ipSource != null and ipSource != ''">#{ipSource},</if>
|
||||
<if test="browser != null and browser != ''">#{browser},</if>
|
||||
<if test="os != null and os != ''">#{os},</if>
|
||||
<if test="password != null and password != ''">#{password},</if>
|
||||
<if test="loginTime != null">#{loginTime},</if>
|
||||
<if test="status != null">#{status},</if>
|
||||
<if test="errorCount != null">#{errorCount},</if>
|
||||
<if test="message != null and message != ''">#{message},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<!-- 更新系统登录日志 -->
|
||||
<update id="updateLoginLog" parameterType="org.xyzh.api.system.dto.TbSysLoginLogDTO">
|
||||
UPDATE sys.tb_sys_login_log
|
||||
<set>
|
||||
<if test="userId != null and userId != ''">user_id = #{userId},</if>
|
||||
<if test="username != null and username != ''">username = #{username},</if>
|
||||
<if test="ipAddress != null and ipAddress != ''">ip_address = #{ipAddress},</if>
|
||||
<if test="ipSource != null and ipSource != ''">ip_source = #{ipSource},</if>
|
||||
<if test="browser != null and browser != ''">browser = #{browser},</if>
|
||||
<if test="os != null and os != ''">os = #{os},</if>
|
||||
<if test="password != null and password != ''">password = #{password},</if>
|
||||
<if test="loginTime != null">login_time = #{loginTime},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="errorCount != null">error_count = #{errorCount},</if>
|
||||
<if test="message != null and message != ''">message = #{message},</if>
|
||||
</set>
|
||||
WHERE optsn = #{optsn}
|
||||
</update>
|
||||
|
||||
<!-- 删除系统登录日志 -->
|
||||
<delete id="deleteLoginLog" parameterType="org.xyzh.api.system.dto.TbSysLoginLogDTO">
|
||||
DELETE FROM sys.tb_sys_login_log
|
||||
WHERE optsn = #{optsn}
|
||||
</delete>
|
||||
|
||||
<!-- 根据登录日志ID查询系统登录日志 -->
|
||||
<select id="getLoginLogById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM sys.tb_sys_login_log
|
||||
WHERE optsn = #{loginLogId}
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询系统登录日志列表 -->
|
||||
<select id="getLoginLogByFilter" resultMap="BaseResultMap" parameterType="org.xyzh.api.system.dto.TbSysLoginLogDTO">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM sys.tb_sys_login_log
|
||||
<where>
|
||||
<if test="filter.optsn != null and filter.optsn != ''">
|
||||
AND optsn = #{filter.optsn}
|
||||
</if>
|
||||
<if test="filter.userId != null and filter.userId != ''">
|
||||
AND user_id = #{filter.userId}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND username LIKE CONCAT('%', #{filter.username}, '%')
|
||||
</if>
|
||||
<if test="filter.ipAddress != null and filter.ipAddress != ''">
|
||||
AND ip_address = #{filter.ipAddress}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.startTime != null">
|
||||
AND login_time >= #{filter.startTime}
|
||||
</if>
|
||||
<if test="filter.endTime != null">
|
||||
AND login_time <= #{filter.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY login_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询系统登录日志分页列表 -->
|
||||
<select id="getLoginLogPageByFilter" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List" />
|
||||
FROM sys.tb_sys_login_log
|
||||
<where>
|
||||
<if test="filter.optsn != null and filter.optsn != ''">
|
||||
AND optsn = #{filter.optsn}
|
||||
</if>
|
||||
<if test="filter.userId != null and filter.userId != ''">
|
||||
AND user_id = #{filter.userId}
|
||||
</if>
|
||||
<if test="filter.username != null and filter.username != ''">
|
||||
AND username LIKE CONCAT('%', #{filter.username}, '%')
|
||||
</if>
|
||||
<if test="filter.ipAddress != null and filter.ipAddress != ''">
|
||||
AND ip_address = #{filter.ipAddress}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.startTime != null">
|
||||
AND login_time >= #{filter.startTime}
|
||||
</if>
|
||||
<if test="filter.endTime != null">
|
||||
AND login_time <= #{filter.endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY login_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<!-- 根据条件查询系统登录日志数量 -->
|
||||
<select id="getLoginLogCount" resultType="java.lang.Integer" parameterType="org.xyzh.api.system.dto.TbSysLoginLogDTO">
|
||||
SELECT COUNT(1)
|
||||
FROM sys.tb_sys_login_log
|
||||
<where>
|
||||
<if test="optsn != null and optsn != ''">
|
||||
AND optsn = #{optsn}
|
||||
</if>
|
||||
<if test="userId != null and userId != ''">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="username != null and username != ''">
|
||||
AND username LIKE CONCAT('%', #{username}, '%')
|
||||
</if>
|
||||
<if test="ipAddress != null and ipAddress != ''">
|
||||
AND ip_address = #{ipAddress}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND login_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND login_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user