陈昶聿
3 天以前 3acf9415fce2dd21c0fd5d67805b72a8bde24a81
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<?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="followupDate" column="followup_date"/>
        <result property="followupUserId" column="followup_user_id"/>
        <result property="followupUserName" column="followup_user_name"/>
        <result property="followupSituation" column="followup_situation"/>
        <result property="followupStatus" column="followup_status"/>
        <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>
 
    <resultMap id="MchFollowupTaskResult" type="com.smartor.domain.MchFollowupTaskVO">
        <result property="itemId" column="item_id"/>
        <result property="planId" column="plan_id"/>
        <result property="taskid" column="taskid"/>
        <result property="taskType" column="task_type"/>
        <result property="taskname" column="task_name"/>
        <result property="archiveType" column="archive_type"/>
        <result property="archiveTypeName" column="archive_type_name"/>
        <result property="archiveId" column="archive_id"/>
        <result property="archiveDetailId" column="archive_detail_id"/>
        <result property="sourceType" column="source_type"/>
        <result property="sourceBizNo" column="source_biz_no"/>
        <result property="patid" column="patid"/>
        <result property="patname" column="patname"/>
        <result property="sendname" column="sendname"/>
        <result property="phone" column="phone"/>
        <result property="idcardno" column="idcardno"/>
        <result property="seq" column="seq"/>
        <result property="outpatientDate" column="outpatient_date"/>
        <result property="plannedFollowTime" column="planned_follow_time"/>
        <result property="plannedFollowDate" column="planned_follow_date"/>
        <result property="followupDate" column="followup_date"/>
        <result property="followupUserId" column="followup_user_id"/>
        <result property="followupUserName" column="followup_user_name"/>
        <result property="followupSituation" column="followup_situation"/>
        <result property="followupStatus" column="followup_status"/>
        <result property="sendStatus" column="send_status"/>
        <result property="sendTimeActual" column="send_time_actual"/>
        <result property="orgid" column="orgid"/>
        <result property="campusid" column="campusid"/>
    </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,
               followup_date, followup_user_id, followup_user_name, followup_situation, followup_status,
               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,
         followup_date, followup_user_id, followup_user_name, followup_situation, followup_status,
         result_msg, provider_msg_id, create_time, update_time)
        values
        (#{planId}, #{seq}, #{sendType}, #{sendTime}, #{titleName}, #{content}, #{templateId}, #{url},
         #{sendStatus}, #{retryCount}, #{nextRetryTime}, #{sendTimeActual},
         #{followupDate}, #{followupUserId}, #{followupUserName}, #{followupSituation},
         COALESCE(#{followupStatus,jdbcType=CHAR}, '0'),
         #{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="followupDate != null">followup_date = #{followupDate},</if>
            <if test="followupUserId != null">followup_user_id = #{followupUserId},</if>
            <if test="followupUserName != null">followup_user_name = #{followupUserName},</if>
            <if test="followupSituation != null">followup_situation = #{followupSituation},</if>
            <if test="followupStatus != null">followup_status = #{followupStatus},</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>
 
    <update id="updateFollowupResult" parameterType="com.smartor.domain.MchFollowupPlanItem">
        update mch_followup_plan_item
        set followup_date = #{followupDate,jdbcType=TIMESTAMP},
            followup_user_id = #{followupUserId,jdbcType=VARCHAR},
            followup_user_name = #{followupUserName,jdbcType=VARCHAR},
            followup_situation = #{followupSituation,jdbcType=VARCHAR},
            followup_status = #{followupStatus,jdbcType=CHAR},
            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.followup_date, i.followup_user_id, i.followup_user_name,
               i.followup_situation, i.followup_status,
               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>
 
    <select id="selectTaskList" parameterType="com.smartor.domain.MchFollowupTaskQuery"
            resultMap="MchFollowupTaskResult">
        select
            i.id as item_id,
            i.plan_id as plan_id,
            cast(null as signed) as taskid,
            'MCH' as task_type,
            case
                when p.archive_type = '1' and m.archive_type = '1' then '早孕关爱随访'
                when p.archive_type = '1' and m.archive_type = '2' then '围绝经期MHI随访'
                when p.archive_type = '2' and c.archive_type = '1' then '营养性疾病随访'
                when p.archive_type = '2' and c.archive_type = '2' then '学习困难随访'
                when p.archive_type = '2' and c.archive_type = '3' then '高危儿专案随访'
                when p.archive_type = '1' then '妇保随访'
                when p.archive_type = '2' then '儿保随访'
                else '妇幼随访'
            end as task_name,
            p.archive_type as archive_type,
            case
                when p.archive_type = '1' and m.archive_type = '1' then '早孕关爱'
                when p.archive_type = '1' and m.archive_type = '2' then '围绝经期MHI'
                when p.archive_type = '2' and c.archive_type = '1' then '营养性疾病'
                when p.archive_type = '2' and c.archive_type = '2' then '学习困难'
                when p.archive_type = '2' and c.archive_type = '3' then '高危儿专案'
                when p.archive_type = '1' then '妇保'
                when p.archive_type = '2' then '儿保'
                else '妇幼'
            end as archive_type_name,
            p.archive_id as archive_id,
            p.archive_detail_id as archive_detail_id,
            p.source_type as source_type,
            p.source_biz_no as source_biz_no,
            p.patid as patid,
            p.patname as patname,
            p.patname as sendname,
            p.phone as phone,
            p.idcardno as idcardno,
            i.seq as seq,
            o.admitdate as outpatient_date,
            p.planned_follow_time as planned_follow_time,
            i.send_time as planned_follow_date,
            i.followup_date as followup_date,
            i.followup_user_id as followup_user_id,
            i.followup_user_name as followup_user_name,
            i.followup_situation as followup_situation,
            i.followup_status as followup_status,
            i.send_status as send_status,
            i.send_time_actual as send_time_actual,
            p.orgid as orgid,
            p.campusid as campusid
        from mch_followup_plan_item i
        inner join mch_followup_plan p on p.id = i.plan_id
        left join pat_maternity_archive_detail m
            on p.archive_type = '1' and m.id = p.archive_detail_id
        left join pat_child_archive_detail c
            on p.archive_type = '2' and c.id = p.archive_detail_id
        left join pat_med_outhosp o
            on p.source_type = '1'
           and o.orgid = p.orgid
           and o.outhospno = p.source_biz_no
        where p.orgid = #{orgid}
          and p.plan_status &lt;&gt; '1'
          and i.send_status &lt;&gt; '5'
          <if test="campusid != null and campusid != ''">and p.campusid = #{campusid}</if>
          <if test="planId != null">and p.id = #{planId}</if>
          <if test="itemId != null">and i.id = #{itemId}</if>
          <if test="archiveType != null and archiveType != ''">and p.archive_type = #{archiveType}</if>
          <if test="sourceType != null and sourceType != ''">and p.source_type = #{sourceType}</if>
          <if test="sendStatus != null and sendStatus != ''">and i.send_status = #{sendStatus}</if>
          <if test="followupStatus != null and followupStatus != ''">and i.followup_status = #{followupStatus}</if>
          <if test="patid != null">and p.patid = #{patid}</if>
          <if test="keyword != null and keyword != ''">
              and (p.patname like concat('%', #{keyword}, '%')
                   or p.phone like concat('%', #{keyword}, '%')
                   or p.idcardno like concat('%', #{keyword}, '%')
                   or p.source_biz_no like concat('%', #{keyword}, '%'))
          </if>
          <if test="beginDate != null">and i.send_time &gt;= #{beginDate}</if>
          <if test="endDate != null">and i.send_time &lt;= #{endDate}</if>
        order by i.send_time asc, i.seq asc, i.id asc
    </select>
 
</mapper>