ah_jjzhgd_service/securitycontrol-model/securitycontrol-system/src/main/resources/mapper/SysLogMapper.xml

178 lines
8.0 KiB
XML
Raw Normal View History

2024-02-28 14:04:50 +08:00
<?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" >
2024-04-18 14:04:25 +08:00
<mapper namespace="com.securitycontrol.system.mapper.ISysLogMapper">
2024-02-28 14:04:50 +08:00
2024-02-28 16:45:59 +08:00
<!--保存系统日志-->
<insert id="saveLogs">
2024-02-29 10:31:31 +08:00
INSERT INTO sys_logs
2024-02-28 16:45:59 +08:00
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="logId != null and logId != ''">log_id,</if>
<if test="ip != null and ip!=''">ip,</if>
<if test="userId != null ">user_id,</if>
<if test="model != null and model!=''">model,</if>
<if test="operaUserName != null and operaUserName!=''">opera_user_name,</if>
<if test="operTime != null and operTime!=''">oper_time,</if>
<if test="method != null and method!=''">method,</if>
<if test="params != null and params!=''">params,</if>
<if test="operateDetail != null and operateDetail!=''">operate_detail,</if>
<if test="operType != null and operType!=''">oper_type,</if>
<if test="operUri != null and operUri!=''">oper_uri,</if>
<if test="logType != null">log_type,</if>
2024-04-16 10:05:22 +08:00
<if test="fruit != null">result,</if>
2024-02-28 16:45:59 +08:00
<if test="times != null and times!=''">times,</if>
<if test="failureReason != null and failureReason!=''">failure_reason,</if>
<if test="grade != null and grade!=''">grade,</if>
<if test="errType != null and errType!=''">err_type,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="logId != null and logId != ''">#{logId},</if>
<if test="ip != null and ip!=''">#{ip},</if>
<if test="userId != null">#{userId},</if>
<if test="model != null and model!=''">#{model},</if>
2024-02-29 10:31:31 +08:00
<if test="operaUserName != null and operaUserName!=''">#{operaUserName},</if>
2024-02-28 16:45:59 +08:00
<if test="operTime != null and operTime!=''">#{operTime},</if>
<if test="method != null and method!=''">#{method},</if>
<if test="params != null and params!=''">#{params},</if>
<if test="operateDetail != null and operateDetail!=''">#{operateDetail},</if>
<if test="operType != null and operType!=''">#{operType},</if>
<if test="operUri != null and operUri!=''">#{operUri},</if>
<if test="logType != null">#{logType},</if>
2024-04-16 10:05:22 +08:00
<if test="fruit != null">#{fruit},</if>
2024-02-28 16:45:59 +08:00
<if test="times != null and times!=''">#{times},</if>
<if test="failureReason != null and failureReason!=''">#{failureReason},</if>
<if test="grade != null and grade!=''">#{grade},</if>
<if test="errType != null and errType!=''">#{errType},</if>
</trim>
</insert>
2024-04-16 10:05:22 +08:00
<insert id="setLogsSet">
insert into sys_logs_set(capacity) value(#{capacity})
</insert>
<update id="updateLogsSet">
update sys_logs_set set capacity=#{capacity}
</update>
<select id="getSystemLogs" resultType="com.securitycontrol.system.api.domain.SysLog">
SELECT log_id,opera_user_name operaUserName,ip,user_id userId,model,
oper_time operTime,method,params,result fruit,
operate_detail operateDetail,oper_type operType,oper_uri operUri,
log_type logType,failure_reason failureReason,grade,
2024-04-17 10:14:42 +08:00
err_type errType,method_type methodType,times
2024-04-16 10:05:22 +08:00
from sys_logs
where log_type=#{logType}
<if test="operaUserName!=null and operaUserName!=''">
2024-04-17 10:14:42 +08:00
and opera_user_name LIKE concat('%',#{operaUserName},'%')
2024-04-16 10:05:22 +08:00
</if>
<if test="model!=null and model!=''">
2024-04-17 10:14:42 +08:00
and model LIKE concat('%',#{model},'%')
</if>
<if test="operType!=null and operType!=''">
and oper_type LIKE concat('%',#{operType},'%')
2024-04-16 10:05:22 +08:00
</if>
<if test="params!=null and params!=''">
2024-04-17 10:14:42 +08:00
and params LIKE concat('%',#{params},'%')
</if>
<if test="fruit!=null and fruit!=''">
and result =#{fruit}
2024-04-16 10:05:22 +08:00
</if>
2024-04-17 10:14:42 +08:00
<if test="errType!=null and errType!=''">
and err_type=#{errType}
</if>
<if test="grade!=null and grade!=''">
and grade=#{grade}
2024-04-16 10:05:22 +08:00
</if>
<if test="endTime!=null and endTime!=''">
2024-04-17 10:14:42 +08:00
and oper_time BETWEEN concat(#{startTime}, ' 00:00:00') AND concat(#{endTime},' 23:59:59')
2024-04-16 10:05:22 +08:00
</if>
<if test="ip!=null and ip!=''">
and ip=#{ip}
</if>
<if test="logSort!=null and logDesc !=null and logSort!='' and logDesc!='' ">
order by
<if test='logSort=="1"'>
oper_time
</if>
<if test='logSort=="2"'>
opera_user_name
</if>
<if test='logSort=="3"'>
model
</if>
<if test='logSort=="4"'>
ip
</if>
<if test='logSort=="5"'>
grade
</if>
<if test='logDesc=="1"'>
DESC
</if>
<if test='logDesc=="2"'>
ASC
</if>
</if>
</select>
<select id="getLogsSet" resultType="java.lang.String">
select capacity
from sys_logs_set
</select>
<select id="getLogStatistics" resultType="java.lang.Integer">
select COUNT(1) num
FROM sys_logs
where log_type=#{logType}
<if test="endTime!=null and endTime!=''">
2024-04-17 10:14:42 +08:00
and oper_time BETWEEN concat(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime},' 23:59:59')
2024-04-16 10:05:22 +08:00
</if>
</select>
<select id="getLogsList" resultType="com.securitycontrol.system.api.domain.SysLog">
select COUNT(1) num,oper_type operType
FROM sys_logs
WHERE oper_type IS NOT NULL
<if test="endTime!=null and endTime!=''">
and oper_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime},' 23:59:59')
</if>
GROUP by oper_type
</select>
<!--查询模块-->
<select id="getModule" resultType="com.securitycontrol.system.api.domain.SysLog">
select CONCAT(IFNULL(sm.menu_name,''),'->',IFNULL(sm2.menu_name,'')) module ,sm3.menu_name operateDetail
from sys_menu sm
left join sys_menu sm2 on sm2.p_id=sm.menu_id and sm2.menu_type=1
left join sys_menu sm3 on sm3.p_id=sm2.menu_id and sm3.menu_type=2
where sm3.menu_auth=#{module}
limit 1
</select>
2024-04-16 15:26:55 +08:00
<select id="getErrorLogs" resultType="java.lang.Integer">
select count(1)
from sys_logs
where log_type=2
and DATE_FORMAT(oper_time,'%Y-%m-%d')=CURRENT_DATE
</select>
<select id="getLogsRl" resultType="java.lang.String">
SELECT
round(((data_length + index_length) / 1024 / 1024), 2) AS 'Size in MB'
FROM information_schema.TABLES
WHERE table_schema = 'jj_zhgd' AND table_name = 'sys_logs'
</select>
<select id="getAllLogs" resultType="com.securitycontrol.system.api.domain.SysLog">
2024-04-17 10:14:42 +08:00
select count(1) num,result fruit
2024-04-16 15:26:55 +08:00
from sys_logs
where oper_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime},' 23:59:59')
GROUP BY result
</select>
<select id="getModuleName" resultType="java.lang.String">
select CONCAT(IFNULL(sm.menu_name,''),'->',IFNULL(sm2.menu_name,'')) module
from sys_menu sm
left join sys_menu sm2 on sm2.p_id=sm.menu_id and sm2.menu_type=1
where sm2.menu_url=#{operUri}
limit 1
</select>
2024-04-17 10:14:42 +08:00
<select id="getModuleIsc" resultType="java.lang.String">
select menu_name
from sys_menu sm
where sm.menu_url=#{operUri}
limit 1
</select>
2024-02-28 14:04:50 +08:00
</mapper>