wlzboy
5 天以前 7de1396e315896dbc72a9d54e44f77434ea90f18
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?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.ruoyi.system.mapper.NotifyTaskMapper">
    
    <resultMap type="NotifyTask" id="NotifyTaskResult">
        <id     property="id"           column="id"/>
        <result property="taskId"       column="task_id"/>
        <result property="taskCode"     column="task_code"/>
        <result property="notifyType"   column="notify_type"/>
        <result property="userId"       column="user_id"/>
        <result property="userName"     column="user_name"/>
        <result property="userPhone"    column="user_phone"/>
        <result property="title"        column="title"/>
        <result property="content"      column="content"/>
        <result property="extraData"    column="extra_data"/>
        <result property="status"       column="status"/>
        <result property="retryCount"   column="retry_count"/>
        <result property="maxRetry"     column="max_retry"/>
        <result property="errorMsg"     column="error_msg"/>
        <result property="createBy"     column="create_by"/>
        <result property="createTime"   column="create_time"/>
        <result property="updateBy"     column="update_by"/>
        <result property="updateTime"   column="update_time"/>
        <result property="remark"       column="remark"/>
    </resultMap>
 
    <sql id="selectNotifyTaskVo">
        select id, task_id, task_code, notify_type, user_id, user_name, user_phone, 
               title, content, extra_data, status, retry_count, max_retry, error_msg,
               create_by, create_time, update_by, update_time, remark
        from sys_notify_task
    </sql>
 
    <select id="selectNotifyTaskById" parameterType="Long" resultMap="NotifyTaskResult">
        <include refid="selectNotifyTaskVo"/>
        where id = #{id}
    </select>
 
    <select id="selectNotifyTaskList" parameterType="NotifyTask" resultMap="NotifyTaskResult">
        <include refid="selectNotifyTaskVo"/>
        <where>
            <if test="taskId != null">
                AND task_id = #{taskId}
            </if>
            <if test="taskCode != null and taskCode != ''">
                AND task_code = #{taskCode}
            </if>
            <if test="notifyType != null and notifyType != ''">
                AND notify_type = #{notifyType}
            </if>
            <if test="userId != null">
                AND user_id = #{userId}
            </if>
            <if test="userName != null and userName != ''">
                AND user_name like concat('%', #{userName}, '%')
            </if>
            <if test="status != null and status != ''">
                AND status = #{status}
            </if>
        </where>
        order by create_time desc
    </select>
 
    <select id="selectPendingNotifyTasks" parameterType="int" resultMap="NotifyTaskResult">
        <include refid="selectNotifyTaskVo"/>
        where status = '0' and retry_count &lt; max_retry
        order by create_time asc
        limit #{limit}
    </select>
 
    <select id="countByTaskUserType" resultType="int">
        select count(1) from sys_notify_task 
        where task_id = #{taskId} and user_id = #{userId} and notify_type = #{notifyType}
    </select>
 
    <insert id="insertNotifyTask" parameterType="NotifyTask" useGeneratedKeys="true" keyProperty="id">
        insert into sys_notify_task (
            task_id, task_code, notify_type, user_id, user_name, user_phone,
            title, content, extra_data, status, retry_count, max_retry, error_msg,
            create_by, create_time, update_by, update_time, remark
        ) values (
            #{taskId}, #{taskCode}, #{notifyType}, #{userId}, #{userName}, #{userPhone},
            #{title}, #{content}, #{extraData}, #{status}, #{retryCount}, #{maxRetry}, #{errorMsg},
            #{createBy}, sysdate(), #{updateBy}, sysdate(), #{remark}
        )
    </insert>
 
    <update id="updateNotifyTask" parameterType="NotifyTask">
        update sys_notify_task
        <set>
            <if test="taskId != null">task_id = #{taskId},</if>
            <if test="taskCode != null">task_code = #{taskCode},</if>
            <if test="notifyType != null">notify_type = #{notifyType},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="title != null">title = #{title},</if>
            <if test="content != null">content = #{content},</if>
            <if test="extraData != null">extra_data = #{extraData},</if>
            <if test="status != null">status = #{status},</if>
            <if test="retryCount != null">retry_count = #{retryCount},</if>
            <if test="maxRetry != null">max_retry = #{maxRetry},</if>
            <if test="errorMsg != null">error_msg = #{errorMsg},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            update_time = sysdate()
        </set>
        where id = #{id}
    </update>
 
    <update id="updateNotifyTaskStatus">
        update sys_notify_task 
        set status = #{status}, error_msg = #{errorMsg}, update_time = sysdate()
        where id = #{id}
    </update>
 
    <update id="incrementRetryCount" parameterType="Long">
        update sys_notify_task 
        set retry_count = retry_count + 1, update_time = sysdate()
        where id = #{id}
    </update>
 
    <delete id="deleteNotifyTaskById" parameterType="Long">
        delete from sys_notify_task where id = #{id}
    </delete>
 
    <delete id="deleteNotifyTaskByIds" parameterType="String">
        delete from sys_notify_task where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>