陈昶聿
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
<?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.MchFollowupPlanMapper">
 
    <resultMap id="MchFollowupPlanResult" type="com.smartor.domain.MchFollowupPlan">
        <id property="id" column="id"/>
        <result property="orgid" column="orgid"/>
        <result property="campusid" column="campusid"/>
        <result property="archiveType" column="archive_type"/>
        <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="phone" column="phone"/>
        <result property="idcardno" column="idcardno"/>
        <result property="plannedFollowTime" column="planned_follow_time"/>
        <result property="followupPeriod" column="followup_period"/>
        <result property="planStatus" column="plan_status"/>
        <result property="remark" column="remark"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>
 
    <sql id="selectPlanVo">
        select id, orgid, campusid, archive_type, archive_id, archive_detail_id,
               source_type, source_biz_no, patid, patname, phone, idcardno,
               planned_follow_time, followup_period, plan_status, remark,
               create_time, update_time
        from mch_followup_plan
    </sql>
 
    <insert id="insertMchFollowupPlan" parameterType="com.smartor.domain.MchFollowupPlan"
            useGeneratedKeys="true" keyProperty="id">
        insert into mch_followup_plan
        (orgid, campusid, archive_type, archive_id, archive_detail_id,
         source_type, source_biz_no, patid, patname, phone, idcardno,
         planned_follow_time, followup_period, plan_status, remark,
         create_time, update_time)
        values
        (#{orgid}, #{campusid}, #{archiveType}, #{archiveId}, #{archiveDetailId},
         #{sourceType}, #{sourceBizNo}, #{patid}, #{patname}, #{phone}, #{idcardno},
         #{plannedFollowTime}, #{followupPeriod}, #{planStatus}, #{remark},
         #{createTime}, #{updateTime})
    </insert>
 
    <update id="updateMchFollowupPlan" parameterType="com.smartor.domain.MchFollowupPlan">
        update mch_followup_plan
        <set>
            <if test="orgid != null">orgid = #{orgid},</if>
            <if test="campusid != null">campusid = #{campusid},</if>
            <if test="archiveType != null">archive_type = #{archiveType},</if>
            <if test="archiveId != null">archive_id = #{archiveId},</if>
            <if test="archiveDetailId != null">archive_detail_id = #{archiveDetailId},</if>
            <if test="sourceType != null">source_type = #{sourceType},</if>
            <if test="sourceBizNo != null">source_biz_no = #{sourceBizNo},</if>
            <if test="patid != null">patid = #{patid},</if>
            <if test="patname != null">patname = #{patname},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idcardno != null">idcardno = #{idcardno},</if>
            <if test="plannedFollowTime != null">planned_follow_time = #{plannedFollowTime},</if>
            <if test="followupPeriod != null">followup_period = #{followupPeriod},</if>
            <if test="planStatus != null">plan_status = #{planStatus},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </set>
        where id = #{id}
    </update>
 
    <select id="selectMchFollowupPlanById" resultMap="MchFollowupPlanResult">
        <include refid="selectPlanVo"/>
        where id = #{id}
    </select>
 
    <select id="selectActiveByArchive" resultMap="MchFollowupPlanResult">
        <include refid="selectPlanVo"/>
        where archive_type = #{archiveType}
          and archive_id = #{archiveId}
        <if test="archiveDetailId != null">
            and archive_detail_id = #{archiveDetailId}
        </if>
          and plan_status in ('0', '3')
        order by id desc
    </select>
 
    <update id="cancelById">
        update mch_followup_plan
        set plan_status = '1',
            update_time = #{updateTime}
        where id = #{id}
          and plan_status in ('0', '3')
    </update>
 
    <update id="completeById">
        update mch_followup_plan
        set plan_status = '2',
            update_time = #{updateTime}
        where id = #{id}
          and plan_status = '0'
    </update>
 
    <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 not exists (
              select 1 from mch_followup_plan p
              where p.archive_type = '1'
                and p.archive_detail_id = d.id
                and p.plan_status in ('0', '3')
          )
        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 not exists (
              select 1 from mch_followup_plan p
              where p.archive_type = '2'
                and p.archive_detail_id = d.id
                and p.plan_status in ('0', '3')
          )
        limit #{limit}
    </select>
 
</mapper>