陈昶聿
2 天以前 67d0eef6ef56713345e03afdfd7e5badf4d4ad3d
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
<?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.MchFollowupSubtaskMapper">
 
    <resultMap id="MchSubtaskResult" type="com.ruoyi.task.domain.ServiceSubtask">
        <id property="id" column="id"/>
        <result property="taskid" column="taskid"/>
        <result property="taskName" column="task_name"/>
        <result property="taskDesc" column="task_desc"/>
        <result property="sendname" column="sendname"/>
        <result property="patid" column="patid"/>
        <result property="phone" column="phone"/>
        <result property="sfzh" column="sfzh"/>
        <result property="hospno" column="hospno"/>
        <result property="visitTime" column="visit_time"/>
        <result property="sendstate" column="sendstate"/>
        <result property="orgid" column="orgid"/>
        <result property="campusid" column="campusid"/>
        <result property="serviceType" column="service_type"/>
        <result property="type" column="type"/>
        <result property="currentPreachform" column="current_preachform"/>
        <result property="templateid" column="templateid"/>
        <result property="templatename" column="templatename"/>
        <result property="isVisitAgain" column="is_visit_again"/>
        <result property="delFlag" column="del_flag"/>
        <result property="mchArchiveDetailId" column="mch_archive_detail_id"/>
        <result property="mchNodeSeq" column="mch_node_seq"/>
        <result property="mchPlanHash" column="mch_plan_hash"/>
        <result property="mchNodeJson" column="mch_node_json"/>
    </resultMap>
 
    <select id="selectCandidates" resultType="com.smartor.domain.MchFollowupArchiveCandidate">
        select '1' as archiveType, d.archiveid as archiveId, d.id as archiveDetailId
        from pat_maternity_archive_detail d
        where d.orgid = #{orgid}
          and (d.del_flag is null or d.del_flag = '0')
          and d.followup_status = '1'
          and d.planned_follow_time is not null
          and d.followup_period is not null
          and d.followup_period &lt;&gt; ''
          and d.archiveid is not null
          and (d.mch_next_due_time is null or d.mch_next_due_time &lt;= #{dueBefore})
        union all
        select '2' as archiveType, d.archiveid as archiveId, d.id as archiveDetailId
        from pat_child_archive_detail d
        where d.orgid = #{orgid}
          and (d.del_flag is null or d.del_flag = '0')
          and d.followup_status = '1'
          and d.planned_follow_time is not null
          and d.followup_period is not null
          and d.followup_period &lt;&gt; ''
          and d.archiveid is not null
          and (d.mch_next_due_time is null or d.mch_next_due_time &lt;= #{dueBefore})
        limit #{limit}
    </select>
 
    <select id="selectMchCursor" resultType="com.smartor.domain.MchFollowupArchiveCursor">
        <choose>
            <when test='archiveType == "1"'>
                select mch_plan_hash as planHash, mch_next_due_time as nextDueTime
                from pat_maternity_archive_detail
                where id = #{detailId}
            </when>
            <otherwise>
                select mch_plan_hash as planHash, mch_next_due_time as nextDueTime
                from pat_child_archive_detail
                where id = #{detailId}
            </otherwise>
        </choose>
    </select>
 
    <update id="updateMchCursor">
        <choose>
            <when test='archiveType == "1"'>
                update pat_maternity_archive_detail
                set mch_plan_hash = #{planHash},
                    mch_next_due_time = #{nextDueTime}
                where id = #{detailId}
            </when>
            <otherwise>
                update pat_child_archive_detail
                set mch_plan_hash = #{planHash},
                    mch_next_due_time = #{nextDueTime}
                where id = #{detailId}
            </otherwise>
        </choose>
    </update>
 
    <select id="selectByArchiveDetailId" resultMap="MchSubtaskResult">
        select id, taskid, task_name, task_desc, sendname, patid, phone, sfzh, hospno,
               visit_time, sendstate, orgid, campusid, service_type, type,
               current_preachform, templateid, templatename, is_visit_again, del_flag,
               mch_archive_detail_id, mch_node_seq, mch_plan_hash, mch_node_json
        from service_subtask
        where mch_archive_detail_id = #{detailId}
          and (del_flag is null or del_flag = '0')
        order by mch_node_seq asc, id asc
    </select>
 
    <insert id="insertMchSubtask" parameterType="com.ruoyi.task.domain.ServiceSubtask"
            useGeneratedKeys="true" keyProperty="id">
        insert into service_subtask
        (taskid, task_name, task_desc, sendname, patid, phone, sfzh, hospno,
         visit_time, sendstate, orgid, campusid, service_type, type,
         current_preachform, templateid, templatename, is_visit_again,
         create_time, update_time, del_flag,
         mch_archive_detail_id, mch_node_seq, mch_plan_hash, mch_node_json)
        values
        (#{taskid}, #{taskName}, #{taskDesc}, #{sendname}, #{patid}, #{phone}, #{sfzh}, #{hospno},
         #{visitTime}, #{sendstate}, #{orgid}, #{campusid}, #{serviceType}, #{type},
         #{currentPreachform}, #{templateid}, #{templatename}, #{isVisitAgain},
         #{createTime}, #{updateTime}, #{delFlag},
         #{mchArchiveDetailId}, #{mchNodeSeq}, #{mchPlanHash}, #{mchNodeJson})
    </insert>
 
    <update id="cancelPendingByArchiveDetailId">
        update service_subtask
        set sendstate = 4,
            remark = concat(ifnull(remark, ''), ';妇幼计划变更,取消未发送任务'),
            update_time = #{now}
        where mch_archive_detail_id = #{detailId}
          and sendstate = 2
          and (mch_plan_hash is null or mch_plan_hash &lt;&gt; #{planHash})
          and (del_flag is null or del_flag = '0')
    </update>
 
    <select id="selectNodeJsonById" resultType="java.lang.String">
        select mch_node_json
        from service_subtask
        where id = #{id}
    </select>
 
    <update id="claimMchSubtask">
        update service_subtask
        set sendstate = 1,
            update_time = #{now}
        where id = #{id}
          and (sendstate = 2
               or (sendstate = 1 and update_time &lt; date_sub(#{now}, interval 10 minute)))
    </update>
 
    <update id="updateMchSendResult">
        update service_subtask
        set sendstate = #{sendstate},
            result = #{result},
            remark = #{remark},
            finishtime = #{finishtime},
            update_time = #{now}
        where id = #{id}
          and sendstate = 1
    </update>
 
</mapper>