陈昶聿
15 小时以前 2d42d335a0abdabf02601b63b85dda82f5b0781b
smartor/src/main/resources/mapper/smartor/ServiceSubtaskMapper.xml
@@ -73,6 +73,7 @@
        <result property="leavehospitaldistrictname" column="leavehospitaldistrictname"/>
        <result property="excep" column="excep"/>
        <result property="remark" column="remark"/>
        <result property="doctorOpinion" column="doctor_opinion"/>
        <result property="suggest" column="suggest"/>
        <result property="sendstate" column="sendstate"/>
        <result property="inhospid" column="inhospid"/>
@@ -81,6 +82,7 @@
        <result property="visitCount" column="visit_count"/>
        <result property="isVisitAgain" column="is_visit_again"/>
        <result property="upid" column="upid"/>
        <result property="visitType" column="visit_type"/>
        <result property="visitTime" column="visit_time"/>
        <result property="visitDeptName" column="visit_dept_name"/>
        <result property="visitDeptCode" column="visit_dept_code"/>
@@ -183,6 +185,7 @@
               long_send_time,
               openid,
               remark,
               doctor_opinion,
               service_type,
               libtemplateid,
               libtemplatename,
@@ -253,7 +256,7 @@
        from service_subtask
    </sql>
    <!-- 完成时状态(finish_state)计算:仅当本次更新把 sendstate 置为 6(随访完成)时使用。
    <!-- 超时完成、延期完成逻辑 完成时状态(finish_state)计算:仅当本次更新把 sendstate 置为 6(随访完成)时使用。
         基准截止时间 base = endtime + send_day(缺省1) + (Σ service_subtask_preachform.compensate_time + 1) 天,
         与 RyTask/RedisMqReceiver 的 isSubtaskDeadline 口径保持一致;
         delay = COALESCE(service_task.delay_finish_days, 0);
@@ -298,6 +301,11 @@
        THEN 2
        ELSE 3
        END
    </sql>
    <!-- 当前执行方式:首次随访 current_preachform 为空时,取 preachform 的第一个执行方式兜底 -->
    <sql id="effectiveCurrentPreachformExpr">
        COALESCE(NULLIF(TRIM(current_preachform), ''), TRIM(SUBSTRING_INDEX(preachform, ',', 1)))
    </sql>
    <select id="selectServiceSubtaskBySendstate" parameterType="com.smartor.domain.entity.ServiceSubtaskEntity"
@@ -402,6 +410,7 @@
        <if test="managementDoctorCode != null ">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="submit != null ">and submit = #{submit}</if>
        <if test="upid != null ">and upid = #{upid}</if>
        <if test="visitCount != null ">and visit_count = #{visitCount}</if>
        <if test="patfrom != null ">and patfrom = #{patfrom}</if>
        <if test="serviceType != null ">and service_type = #{serviceType}</if>
        <if test="patid != null ">and patid = #{patid}</if>
@@ -564,7 +573,10 @@
        <if test="campusid != null  and campusid != ''">and campusid = #{campusid}</if>
        <if test="pid != null ">and pid = #{pid}</if>
        <if test="preachform != null ">and preachform = #{preachform}</if>
        <if test="currentPreachform != null ">and current_preachform = #{currentPreachform}</if>
        <if test="currentPreachform != null and currentPreachform != '' ">and current_preachform = #{currentPreachform}</if>
        <if test="currentPreachforms != null and currentPreachforms != ''">
            and FIND_IN_SET(<include refid="effectiveCurrentPreachformExpr"/>, #{currentPreachforms})
        </if>
        <if test="guid != null  and guid != ''">and guid = #{guid}</if>
        <if test="textParam != null  and textParam != ''">and text_param = #{textParam}</if>
        <if test="bedNo != null">and bed_no = #{bedNo}</if>
@@ -594,6 +606,7 @@
            AND visit_count > 1
        </if>
        <if test="remark != null">and remark = #{remark}</if>
        <if test="doctorOpinion != null and doctorOpinion != ''">and doctor_opinion like concat('%', #{doctorOpinion}, '%')</if>
        <if test="suggest != null">and suggest = #{suggest}</if>
        <if test="createBy != null">and create_by = #{createBy}</if>
        <if test="taskGuid != null">and task_guid = #{taskGuid}</if>
@@ -710,7 +723,7 @@
        <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="managementDoctor != null">and management_doctor = #{managementDoctor}</if>
        <if test="currentPreachform != null">and current_preachform = #{currentPreachform}</if>
        <if test="currentPreachform != null and currentPreachform != '' ">and current_preachform = #{currentPreachform}</if>
        <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
        <if test="continueFlag != null ">and continue_flag = #{continueFlag}</if>
        <if test="continueTimeNow != null ">and continue_time_now = #{continueTimeNow,jdbcType=TIMESTAMP}</if>
@@ -770,7 +783,7 @@
        <if test="visitTime != null ">and visit_time = #{visitTime}</if>
        <if test="visitDeptCode != null">and visit_dept_code = #{visitDeptCode}</if>
        <if test="visitDeptName != null">and visit_dept_name = #{visitDeptName}</if>
        <if test="currentPreachform != null">and current_preachform = #{currentPreachform}</if>
        <if test="currentPreachform != null and currentPreachform != '' ">and current_preachform = #{currentPreachform}</if>
        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="isabnormal != null">and isabnormal = #{isabnormal}</if>
        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
@@ -946,6 +959,12 @@
        </if>
        <if test="managementDoctorCode != null">and management_doctor_code = #{managementDoctorCode}</if>
        <if test="managementDoctor != null">and management_doctor like concat('%',#{managementDoctor}, '%')</if>
        <if test="startOutHospTime != null">
            AND date_format(endtime,'%y%m%d') &gt;= date_format(#{startOutHospTime},'%y%m%d')
        </if>
        <if test="endOutHospTime != null">
            AND date_format(endtime,'%y%m%d') &lt;= date_format(#{endOutHospTime},'%y%m%d')
        </if>
        ) a where a.finished =1)
    </select>
@@ -1053,6 +1072,7 @@
            <if test="nurseName != null ">nurse_name,</if>
            <if test="nurseId != null ">nurse_id,</if>
            <if test="remark != null ">remark,</if>
            <if test="doctorOpinion != null ">doctor_opinion,</if>
            <if test="suggest != null ">suggest,</if>
            <if test="sendstate != null ">sendstate,</if>
            <if test="inhospid != null ">inhospid,</if>
@@ -1067,7 +1087,7 @@
            <if test="visitDeptName != null">visit_dept_name,</if>
            <if test="managementDoctorCode != null">management_doctor_code,</if>
            <if test="managementDoctor != null">management_doctor,</if>
            <if test="currentPreachform != null">current_preachform,</if>
            <if test="currentPreachform != null and currentPreachform != '' ">current_preachform,</if>
            <if test="taskSituation != null">task_situation,</if>
            <if test="isabnormal != null">isabnormal,</if>
            <if test="continueFlag != null ">continue_flag,</if>
@@ -1152,6 +1172,7 @@
            <if test="nurseName != null ">#{nurseName},</if>
            <if test="nurseId != null ">#{nurseId},</if>
            <if test="remark != null ">#{remark},</if>
            <if test="doctorOpinion != null ">#{doctorOpinion},</if>
            <if test="suggest != null ">#{suggest},</if>
            <if test="sendstate != null ">#{sendstate},</if>
            <if test="inhospid != null ">#{inhospid},</if>
@@ -1166,7 +1187,7 @@
            <if test="visitDeptName != null">#{visitDeptName},</if>
            <if test="managementDoctorCode != null">#{managementDoctorCode},</if>
            <if test="managementDoctor != null">#{managementDoctor},</if>
            <if test="currentPreachform != null">#{currentPreachform},</if>
            <if test="currentPreachform != null and currentPreachform != '' ">#{currentPreachform},</if>
            <if test="taskSituation != null">#{taskSituation},</if>
            <if test="isabnormal != null">#{isabnormal},</if>
            <if test="continueFlag != null ">#{continueFlag},</if>
@@ -1182,6 +1203,15 @@
            <if test="isManuallyCalled != null ">#{isManuallyCalled},</if>
        </trim>
    </insert>
    <!-- 二次随访幂等:仅当 is_visit_again 不是目标值时更新,返回受影响行数 -->
    <update id="updateIsVisitAgainById">
        update service_subtask
        set is_visit_again = #{isVisitAgain},
            update_time = now()
        where id = #{id}
          and (is_visit_again is null or is_visit_again &lt;&gt; #{isVisitAgain})
    </update>
    <update id="updateServiceSubtask" parameterType="com.smartor.domain.ServiceSubtask">
        update service_subtask
@@ -1257,6 +1287,7 @@
            <if test="nurseName != null ">nurse_name=#{nurseName},</if>
            <if test="nurseId != null ">nurse_id=#{nurseId},</if>
            <if test="remark != null ">remark=#{remark},</if>
            <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if>
            <if test="suggest != null ">suggest=#{suggest},</if>
            <if test="inhospid != null ">inhospid=#{inhospid},</if>
            <if test="patfrom != null ">patfrom=#{patfrom},</if>
@@ -1270,7 +1301,7 @@
            <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if>
            <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if>
            <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if>
            <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
            <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if>
            <if test="taskSituation != null">task_situation=#{taskSituation},</if>
            <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
@@ -1363,6 +1394,7 @@
            <if test="nurseName != null ">nurse_name=#{nurseName},</if>
            <if test="nurseId != null ">nurse_id=#{nurseId},</if>
            <if test="remark != null ">remark=#{remark},</if>
            <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if>
            <if test="suggest != null ">suggest=#{suggest},</if>
            <if test="inhospid != null ">inhospid=#{inhospid},</if>
            <if test="patfrom != null ">patfrom=#{patfrom},</if>
@@ -1375,7 +1407,7 @@
            <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if>
            <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if>
            <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if>
            <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
            <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if>
            <if test="taskSituation != null">task_situation=#{taskSituation},</if>
            <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
@@ -1468,6 +1500,7 @@
            <if test="nurseName != null ">nurse_name=#{nurseName},</if>
            <if test="nurseId != null ">nurse_id=#{nurseId},</if>
            <if test="remark != null ">remark=#{remark},</if>
            <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if>
            <if test="suggest != null ">suggest=#{suggest},</if>
            <if test="inhospid != null ">inhospid=#{inhospid},</if>
            <if test="patfrom != null ">patfrom=#{patfrom},</if>
@@ -1479,7 +1512,7 @@
            <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if>
            <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if>
            <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if>
            <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
            <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if>
            <if test="taskSituation != null">task_situation=#{taskSituation},</if>
            <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
@@ -1580,6 +1613,7 @@
            <if test="nurseName != null ">nurse_name=#{nurseName},</if>
            <if test="nurseId != null ">nurse_id=#{nurseId},</if>
            <if test="remark != null ">remark=#{remark},</if>
            <if test="doctorOpinion != null ">doctor_opinion=#{doctorOpinion},</if>
            <if test="suggest != null ">suggest=#{suggest},</if>
            <if test="inhospid != null ">inhospid=#{inhospid},</if>
            <if test="patfrom != null ">patfrom=#{patfrom},</if>
@@ -1591,7 +1625,7 @@
            <if test="visitDeptName != null">visit_dept_name = #{visitDeptName},</if>
            <if test="managementDoctorCode != null">management_doctor_code = #{managementDoctorCode},</if>
            <if test="managementDoctor != null">management_doctor=#{managementDoctor},</if>
            <if test="currentPreachform != null">current_preachform=#{currentPreachform},</if>
            <if test="currentPreachform != null and currentPreachform != '' ">current_preachform=#{currentPreachform},</if>
            <if test="taskSituation != null">task_situation=#{taskSituation},</if>
            <if test="isabnormal != null">isabnormal=#{isabnormal},</if>
            <if test="continueFlag != null ">continue_flag = #{continueFlag},</if>
@@ -1621,6 +1655,35 @@
        where patid = #{patid} and taskid = #{taskid}
    </update>
    <!-- 人工随访:软删除患者出院记录对应的未完成随访任务 -->
    <update id="deleteUnfinishedServiceSubtaskByInhospids">
        update service_subtask
        set del_flag = 1
        where del_flag = 0
          and patid = #{patid}
          and sendstate in
          <foreach collection="sendstates" item="sendstate" open="(" separator="," close=")">
              #{sendstate}
          </foreach>
          and inhospid in
          <foreach collection="inhospids" item="inhospid" open="(" separator="," close=")">
              #{inhospid}
          </foreach>
    </update>
    <!-- 人工随访重复校验:同一患者同一任务下是否已有未完成随访任务 -->
    <select id="countUnfinishedServiceSubtaskByPatidAndTaskid" resultType="int">
        select count(1)
        from service_subtask
        where del_flag = 0
          and patid = #{patid}
          and taskid = #{taskid}
          and sendstate in
          <foreach collection="sendstates" item="sendstate" open="(" separator="," close=")">
              #{sendstate}
          </foreach>
    </select>
    <select id="getSfStatistics" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultMap="ServiceSubtaskResult">
        select id,
@@ -1638,13 +1701,14 @@
        deptname,
        sendstate,
        preachform,
        current_preachform,
        <include refid="effectiveCurrentPreachformExpr"/> AS current_preachform,
        excep,
        nurse_id,
        nurse_name,
        taskid,
        task_name,
        visit_time,
        visit_dept_code,
        finishtime,
        endtime,
        senddate,
@@ -1663,6 +1727,7 @@
        continue_count,
        continue_time_next,
        task_situation,
        finish_state,
        is_manually_called
        from service_subtask
        where 1=1
@@ -1905,9 +1970,6 @@
        <if test="groupKey != null and groupKey != ''">
            group by ${groupKey}
        </if>
        <if test="pageSize != null  and pageNum != null">
            limit ${pageSize} OFFSET ${pageNum}
        </if>
    </select>
    <select id="getSfStatisticsHyperlink" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
@@ -1925,13 +1987,15 @@
        deptname,
        sendstate,
        preachform,
        current_preachform,
        <include refid="effectiveCurrentPreachformExpr"/> AS current_preachform,
        excep,
        nurse_id,
        nurse_name,
        taskid,
        task_name,
        visit_time,
        visit_dept_code,
        visit_dept_name,
        finishtime,
        endtime,
        senddate,
@@ -1951,6 +2015,8 @@
        continue_time_next,
        task_situation,
        remark,
        doctor_opinion,
        finish_state,
        is_manually_called
        from service_subtask
        where 1=1
@@ -2021,8 +2087,8 @@
                #{state}
            </foreach>
        </if>
        <if test="currentPreachform != null">
            AND current_preachform = #{currentPreachform}
        <if test="currentPreachform != null and currentPreachform != '' ">
            AND <include refid="effectiveCurrentPreachformExpr"/> = #{currentPreachform}
            <if test="followUpCountStyle != null and followUpCountStyle = '1'">
                AND sendstate != 4
            </if>
@@ -2032,6 +2098,9 @@
        </if>
        <if test="taskSituation != null">
            AND task_situation = #{taskSituation}
        </if>
        <if test="finishState != null">
            AND finish_state = #{finishState}
        </if>
        <if test="drcode != null and drcode != ''">
            AND drcode = #{drcode}
@@ -2044,6 +2113,9 @@
        </if>
        <if test="isManuallyCalled != null">
            AND is_manually_called = #{isManuallyCalled}
        </if>
        <if test="suggest != null and suggest != ''">
            AND TRIM(suggest) = #{suggest}
        </if>
        order by endtime desc
        <if test="pageSize != null  and pageNum != null">
@@ -2257,14 +2329,14 @@
    <select id="getSfStatisticsScriptDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultMap="ServiceSubtaskScriptCountResult">
        SELECT
        a.id as scriptid,
        a.templateid as templateid,
        a.script_type,
        MIN(a.id) as scriptid,
        MIN(a.templateid) as templateid,
        MIN(a.script_type) as script_type,
        a.script_content,
        b.subtask_type,
        b.completed_quantity,
        b.all_quantity,
        ROUND(b.completed_quantity/b.all_quantity,2) as completed_percentage
        SUM(b.completed_quantity) as completed_quantity,
        SUM(b.all_quantity) as all_quantity,
        ROUND(SUM(b.completed_quantity)/SUM(b.all_quantity),2) as completed_percentage
        FROM
        <if test="type == 1">
            ivr_task_template_script a
@@ -2327,25 +2399,37 @@
        group by ssd.scriptid) b
        ON a.id = b.scriptid
        <!-- 适用单条查询 -->
        <if test="scriptids != null">
        <if test="scriptids != null and scriptids != ''">
            AND a.scriptid in
            (SELECT lib_script.scriptid FROM
            svy_lib_template_script lib_script
            WHERE lib_script.scriptid in (${scriptids}))
        </if>
        <!-- 同一道题会被复制到多个任务模板,按题目内容合并,保证一道题只返回一条 -->
        GROUP BY a.script_content, b.subtask_type
        ORDER BY MIN(a.id)
    </select>
    <select id="getSfStatisticsScriptItemDetails" parameterType="com.smartor.domain.ServiceSubtaskCountReq"
            resultMap="ServiceSubtaskScriptCountResult">
        SELECT
        ssd.scriptid,
        a.script_content,
        ss.type as subtask_type,
        IFNULL(ssd.matchedtext,ssd.asrtext) AS option_text,
        COUNT(*) AS chosen_quantity
        FROM
        service_subtask_detail ssd
        INNER JOIN service_subtask ss ON ssd.sub_id = ss.id
        INNER JOIN
        <if test="type == 1">
            ivr_task_template_script a ON a.id = ssd.scriptid
        </if>
        <if test="type == 2">
            svy_task_template_script a ON a.id = ssd.scriptid
        </if>
        where 1=1
        and ss.del_flag=0
        and ssd.del_flag=0
        <if test="orgid != null and orgid != ''">
            and ss.orgid = #{orgid}
        </if>
@@ -2384,7 +2468,7 @@
        <if test="configValue != null and configValue != ''">
            AND ssd.categoryid IN (${configValue})
        </if>
        group by ssd.scriptid, IFNULL(ssd.matchedtext,ssd.asrtext)
        group by a.script_content, ss.type, IFNULL(ssd.matchedtext,ssd.asrtext)
    </select>
    <select id="getDataByTime" resultMap="ServiceSubtaskResult">
@@ -2455,6 +2539,7 @@
               nurse_id,
               nurse_name,
               remark,
               doctor_opinion,
               inhospid,
               patfrom,
               task_guid,
@@ -2873,6 +2958,9 @@
            <foreach collection="sendstates" item="state" open="(" separator="," close=")">
                #{state}
            </foreach>
        </if>
        <if test="currentPreachforms != null and currentPreachforms != ''">
            AND FIND_IN_SET(<include refid="effectiveCurrentPreachformExpr"/>, #{currentPreachforms})
        </if>
        <if test="orgid != null and orgid != ''">
            AND orgid = #{orgid}
@@ -3348,7 +3436,8 @@
        continue_count,
        continue_time_next,
        task_situation,
        remark
        remark,
        doctor_opinion
        from service_subtask
        where 1=1
        and del_flag = 0