liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?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.jeeplus.modules.sys.dao.LogDao">
    
    <select id="findList" resultType="Log">
        SELECT 
            a.*,
            u.id AS "createBy.id",
            u.name AS "createBy.name",
            c.name AS "createBy.company.name",
            o.name AS "createBy.office.name"
        FROM sys_log a
        JOIN sys_user u ON u.id = a.create_by
        JOIN sys_office c ON c.id = u.company_id
        JOIN sys_office o ON o.id = u.office_id
        WHERE a.create_date BETWEEN #{beginDate} AND #{endDate}
        <if test="title != null and title != ''">
            AND a.title LIKE 
                    <if test="dbName == 'oracle'">'%'||#{title}||'%'</if>
                    <if test="dbName == 'mysql'">CONCAT('%', #{title}, '%')</if>
        </if>
        <if test="createBy != null and createBy.id != null and createBy.id != ''">
            AND a.create_by = #{createBy.id}
        </if>
        <if test="requestUri != null and requestUri != ''">
            AND a.request_uri LIKE 
                    <if test="dbName == 'oracle'">'%'||#{requestUri}||'%'</if>
                    <if test="dbName == 'mysql'">CONCAT('%', #{requestUri}, '%')</if>
        </if>
        <if test="exception != null and exception != ''">
            AND a.type = #{TYPE_EXCEPTION}
        </if>
        ORDER BY a.create_date DESC
    </select>
    
    <select id="get" resultType="Log">
        SELECT 
            * 
        FROM sys_log 
        WHERE id = #{id}
    </select>
    
    <update id="delete">
        DELETE FROM sys_log 
        WHERE id = #{id}
    </update>
    
    <update id="empty">
        DELETE FROM sys_log 
    </update>
    
    <insert id="insert">
        INSERT INTO sys_log(
            id, 
            type, 
            title,
            create_by, 
            create_date, 
            remote_addr, 
            user_agent, 
            request_uri, 
            method, 
            params, 
            exception
        ) VALUES (
            #{id}, 
            #{type}, 
            #{title}, 
            #{createBy.id}, 
            #{createDate}, 
            #{remoteAddr}, 
            #{userAgent}, 
            #{requestUri}, 
            #{method}, 
            #{params}, 
            #{exception}
        )
    </insert>
    
</mapper>