陈昶聿
9 天以前 8a73ac17d717c32aa8fd97f4c682094d7b1c0654
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
<?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.smartor.mapper.MchFollowupPlanItemMapper">
 
    <resultMap id="MchFollowupPlanItemResult" type="com.smartor.domain.MchFollowupPlanItem">
        <id property="id" column="id"/>
        <result property="planId" column="plan_id"/>
        <result property="seq" column="seq"/>
        <result property="sendType" column="send_type"/>
        <result property="sendTime" column="send_time"/>
        <result property="titleName" column="title_name"/>
        <result property="content" column="content"/>
        <result property="templateId" column="template_id"/>
        <result property="url" column="url"/>
        <result property="sendStatus" column="send_status"/>
        <result property="retryCount" column="retry_count"/>
        <result property="nextRetryTime" column="next_retry_time"/>
        <result property="sendTimeActual" column="send_time_actual"/>
        <result property="resultMsg" column="result_msg"/>
        <result property="providerMsgId" column="provider_msg_id"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
 
    <sql id="selectItemVo">
        select id, plan_id, seq, send_type, send_time, title_name, content, template_id, url,
               send_status, retry_count, next_retry_time, send_time_actual,
               result_msg, provider_msg_id, create_time, update_time
        from mch_followup_plan_item
    </sql>
 
    <insert id="insertMchFollowupPlanItem" parameterType="com.smartor.domain.MchFollowupPlanItem"
            useGeneratedKeys="true" keyProperty="id">
        insert into mch_followup_plan_item
        (plan_id, seq, send_type, send_time, title_name, content, template_id, url,
         send_status, retry_count, next_retry_time, send_time_actual,
         result_msg, provider_msg_id, create_time, update_time)
        values
        (#{planId}, #{seq}, #{sendType}, #{sendTime}, #{titleName}, #{content}, #{templateId}, #{url},
         #{sendStatus}, #{retryCount}, #{nextRetryTime}, #{sendTimeActual},
         #{resultMsg}, #{providerMsgId}, #{createTime}, #{updateTime})
    </insert>
 
    <update id="updateMchFollowupPlanItem" parameterType="com.smartor.domain.MchFollowupPlanItem">
        update mch_followup_plan_item
        <set>
            <if test="sendType != null">send_type = #{sendType},</if>
            <if test="sendTime != null">send_time = #{sendTime},</if>
            <if test="titleName != null">title_name = #{titleName},</if>
            <if test="content != null">content = #{content},</if>
            <if test="templateId != null">template_id = #{templateId},</if>
            <if test="url != null">url = #{url},</if>
            <if test="sendStatus != null">send_status = #{sendStatus},</if>
            <if test="retryCount != null">retry_count = #{retryCount},</if>
            <if test="nextRetryTime != null">next_retry_time = #{nextRetryTime},</if>
            <if test="sendTimeActual != null">send_time_actual = #{sendTimeActual},</if>
            <if test="resultMsg != null">result_msg = #{resultMsg},</if>
            <if test="providerMsgId != null">provider_msg_id = #{providerMsgId},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </set>
        where id = #{id}
    </update>
 
    <update id="updateSendResult" parameterType="com.smartor.domain.MchFollowupPlanItem">
        update mch_followup_plan_item
        set send_status = #{sendStatus,jdbcType=CHAR},
            retry_count = #{retryCount,jdbcType=INTEGER},
            next_retry_time = #{nextRetryTime,jdbcType=TIMESTAMP},
            send_time_actual = #{sendTimeActual,jdbcType=TIMESTAMP},
            result_msg = #{resultMsg,jdbcType=VARCHAR},
            provider_msg_id = #{providerMsgId,jdbcType=VARCHAR},
            update_time = #{updateTime,jdbcType=TIMESTAMP}
        where id = #{id}
    </update>
 
    <select id="selectMchFollowupPlanItemById" resultMap="MchFollowupPlanItemResult">
        <include refid="selectItemVo"/>
        where id = #{id}
    </select>
 
    <select id="selectByPlanId" resultMap="MchFollowupPlanItemResult">
        <include refid="selectItemVo"/>
        where plan_id = #{planId}
        order by seq asc, id asc
    </select>
 
    <select id="selectDueItems" resultMap="MchFollowupPlanItemResult">
        select i.id, i.plan_id, i.seq, i.send_type, i.send_time, i.title_name, i.content,
               i.template_id, i.url, i.send_status, i.retry_count, i.next_retry_time,
               i.send_time_actual, i.result_msg, i.provider_msg_id, i.create_time, i.update_time
        from mch_followup_plan_item i
        inner join mch_followup_plan p on p.id = i.plan_id
        where p.orgid = #{orgid}
          and p.plan_status = '0'
          and i.send_status = '0'
          and i.send_time &lt;= #{now}
          and (i.next_retry_time is null or i.next_retry_time &lt;= #{now})
        order by i.send_time asc, i.seq asc, i.id asc
        limit #{limit}
    </select>
 
    <update id="claimItem">
        update mch_followup_plan_item
        set send_status = '1',
            update_time = #{now}
        where id = #{id}
          and send_status = '0'
    </update>
 
    <update id="cancelPendingByPlanId">
        update mch_followup_plan_item
        set send_status = '5',
            result_msg = '计划重建,取消未发送节点',
            update_time = #{now}
        where plan_id = #{planId}
          and send_status = '0'
    </update>
 
    <select id="countPendingByPlanId" resultType="int">
        select count(1)
        from mch_followup_plan_item
        where plan_id = #{planId}
          and send_status in ('0', '1')
    </select>
 
</mapper>