<?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.xinelu.manage.mapper.signpatientmanageroutenode.SignPatientManageRouteNodeMapper">

    <resultMap type="SignPatientManageRouteNode" id="SignPatientManageRouteNodeResult">
            <result property="id" column="id"/>
            <result property="manageRouteId" column="manage_route_id"/>
            <result property="manageRouteName" column="manage_route_name"/>
	        <result property="routeNodeId" column="route_node_id"/>
            <result property="routeNodeName" column="route_node_name"/>
            <result property="routeNodeDay" column="route_node_day"/>
            <result property="taskType" column="task_type"/>
            <result property="taskStatus" column="task_status"/>
            <result property="taskSubdivision" column="task_subdivision"/>
            <result property="taskNodeType" column="task_node_type"/>
            <result property="secondClassifyDescribe" column="second_classify_describe"/>
            <result property="executeTime" column="execute_time"/>
            <result property="phonePushSign" column="phone_push_sign"/>
            <result property="scriptInfoId" column="script_info_id"/>
            <result property="phoneTemplateId" column="phone_template_id"/>
            <result property="phoneTemplateName" column="phone_template_name"/>
            <result property="phoneNodeContent" column="phone_node_content"/>
            <result property="phoneRedialTimes" column="phone_redial_times"/>
            <result property="phoneTimeInterval" column="phone_time_interval"/>
            <result property="phoneMessageRemind" column="phone_message_remind"/>
            <result property="phoneMessageTemplateId" column="phone_message_template_id"/>
            <result property="phoneMessageTemplateName" column="phone_message_template_name"/>
	        <result property="phoneMessageTemplateContent" column="phone_message_template_content"/>
            <result property="questionInfoId" column="question_info_id"/>
            <result property="questionnaireName" column="questionnaire_name"/>
            <result property="questionnaireContent" column="questionnaire_content"/>
            <result property="questionExpirationDate" column="question_expiration_date"/>
            <result property="propagandaInfoId" column="propaganda_info_id"/>
            <result property="propagandaTitle" column="propaganda_title"/>
            <result property="propagandaContent" column="propaganda_content"/>
            <result property="messagePushSign" column="message_push_sign"/>
            <result property="messageTemplateId" column="message_template_id"/>
	        <result property="messageTemplateCode" column="message_template_code"/>
            <result property="messageTemplateName" column="message_template_name"/>
            <result property="messagePreview" column="message_preview"/>
            <result property="messageNodeContent" column="message_node_content"/>
            <result property="officialPushSign" column="official_push_sign"/>
            <result property="officialTemplateId" column="official_template_id"/>
	        <result property="officialTemplateCode" column="official_template_code"/>
            <result property="officialTemplateName" column="official_template_name"/>
            <result property="officialRemindContent" column="official_remind_content"/>
            <result property="officialNodeContent" column="official_node_content"/>
            <result property="appletPushSign" column="applet_push_sign"/>
            <result property="appletTemplateId" column="applet_template_id"/>
	        <result property="appletTemplateCode" column="applet_template_code"/>
            <result property="appletTemplateName" column="applet_template_name"/>
            <result property="appletRemindContent" column="applet_remind_content"/>
            <result property="appletPromptDescription" column="applet_prompt_description"/>
            <result property="appletNodeContent" column="applet_node_content"/>
            <result property="followTemplateId" column="follow_template_id"/>
            <result property="followTemplateName" column="follow_template_name"/>
            <result property="routeCheckStatus" column="route_check_status"/>
            <result property="routeCheckPerson" column="route_check_person"/>
            <result property="routeCheckDate" column="route_check_date"/>
            <result property="routeCheckRemark" column="route_check_remark"/>
            <result property="routeNodeRemark" column="route_node_remark"/>
            <result property="nodeExecuteStatus" column="node_execute_status"/>
            <result property="routeHandleRemark" column="route_handle_remark"/>
            <result property="routeHandleId" column="route_handle_id"/>
            <result property="routeHandlePerson" column="route_handle_person"/>
            <result property="routeLink" column="route_link"/>
            <result property="textRemindContent" column="text_remind_content"/>
	        <result property="nodeContent" column="node_content"/>
            <result property="messageStatus" column="message_status"/>
	        <result property="delFlag" column="del_flag"/>
            <result property="createBy" column="create_by"/>
            <result property="createTime" column="create_time"/>
            <result property="updateBy" column="update_by"/>
            <result property="updateTime" column="update_time"/>
            <result property="phoneDialMethod" column="phone_dial_method"/>
            <result property="phoneNodeExecuteResultStatus" column="phone_node_execute_result_status"/>
            <result property="messageNodeExecuteResultStatus" column="message_node_execute_result_status"/>
            <result property="officialNodeExecuteResultStatus" column="official_node_execute_result_status"/>
            <result property="appletNodeExecuteResultStatus" column="applet_node_execute_result_status"/>
            <result property="nodeFinishDate" column="node_finish_date"/>
    </resultMap>

    <sql id="selectSignPatientManageRouteNodeVo">
        select id, manage_route_id, manage_route_name, route_node_id, route_node_name, route_node_day, task_type, task_status, task_subdivision, task_node_type, second_classify_describe, execute_time, phone_push_sign, script_info_id, phone_template_id, phone_template_name, phone_node_content, phone_redial_times, phone_time_interval, phone_message_remind, phone_message_template_id, phone_message_template_name,phone_message_template_content,question_info_id, questionnaire_name, questionnaire_content, question_expiration_date, propaganda_info_id, propaganda_title, propaganda_content, message_push_sign, message_template_id, message_template_code, message_template_name, message_preview, message_node_content, official_push_sign, official_template_id, official_template_code, official_template_name, official_remind_content, official_node_content, follow_template_id, follow_template_name, applet_push_sign, applet_template_id, applet_template_code, applet_template_name, applet_remind_content, applet_prompt_description, applet_node_content, route_check_status, route_check_person, route_check_date, route_check_remark, route_node_remark, node_execute_status, route_handle_remark, route_handle_id, route_handle_person, route_link,text_remind_content, node_content,message_status, del_flag, create_by, create_time, update_by, update_time, phone_dial_method, phone_node_execute_result_status, message_node_execute_result_status, official_node_execute_result_status, applet_node_execute_result_status, node_finish_date from sign_patient_manage_route_node
    </sql>

    <select id="selectSignPatientManageRouteNodeList" parameterType="com.xinelu.manage.dto.signpatientmanageroutenode.SignPatientManageRouteNodeDto" resultMap="SignPatientManageRouteNodeResult">
        <include refid="selectSignPatientManageRouteNodeVo"/>
        <where>
			del_flag = 0
            <if test="manageRouteId != null ">
                and manage_route_id = #{manageRouteId}
            </if>
            <if test="manageRouteName != null  and manageRouteName != ''">
                and manage_route_name like concat('%', #{manageRouteName}, '%')
            </if>
	        <if test="routeNodeId != null">
		        and route_node_id = #{routeNodeId}
	        </if>
            <if test="routeNodeName != null  and routeNodeName != ''">
                and route_node_name like concat('%', #{routeNodeName}, '%')
            </if>
            <if test="routeNodeDay != null ">
                and route_node_day = #{routeNodeDay}
            </if>
            <if test="taskType != null  and taskType != ''">
                and task_type = #{taskType}
            </if>
            <if test="taskStatus != null  and taskStatus != ''">
                and task_status = #{taskStatus}
            </if>
            <if test="taskNodeType != null  and taskNodeType != ''">
                and task_node_type = #{taskStatus}
            </if>
	        <if test="taskTypeList != null and taskTypeList.size > 0">
		        and
		        <foreach collection="taskTypeList" item="item" index="index" open="(" close=")" separator="or">
		        task_type = #{item}
		        </foreach>
	        </if>
	        <if test="nodeExecuteStatus != null  and nodeExecuteStatus != ''">
		        and node_execute_status = #{nodeExecuteStatus}
	        </if>
            <if test="phoneDialMethod != null and phoneDialMethod != ''">
                and phone_dial_method = #{phoneDialMethod}
            </if>
        </where>
    </select>

	<select id="selectPatientManageNodeList" parameterType="com.xinelu.manage.dto.signpatientmanageroutenode.SignPatientManageRouteNodeDto"
		resultType="com.xinelu.manage.vo.signpatientmanageroutenode.PatientManageNodeListVo">
		select node.id, node.manage_route_id, node.manage_route_name, node.route_node_id, node.route_node_name, node.route_node_day,
		node.task_type, node.task_subdivision, node.execute_time,
		node.node_execute_status, type.task_type_name as taskTypeName, part.task_partition_name as taskPartitionDictName
        from sign_patient_manage_route_node node
        left join task_type_dict type on node.task_type = type.task_type_code
        left join task_partition_dict part on part.task_partition_code = node.task_subdivision
		<where>
			node.del_flag = 0
			<if test="manageRouteId != null ">
				and node.manage_route_id = #{manageRouteId}
			</if>
			<if test="taskStatus != null  and taskStatus != ''">
				and node.task_status = #{taskStatus}
			</if>
			<if test="nodeExecuteStatus != null  and nodeExecuteStatus != ''">
				and node.node_execute_status = #{nodeExecuteStatus}
			</if>
		</where>
	</select>

    <select id="selectSignPatientManageRouteNodeById" parameterType="Long" resultMap="SignPatientManageRouteNodeResult">
	    <include refid="selectSignPatientManageRouteNodeVo"/>
	    where id = #{id}
    </select>

	<select id="getNodeList" parameterType="com.xinelu.manage.dto.signpatientmanageroutenode.PatientTaskDto"
		resultMap="SignPatientManageRouteNodeResult">
		select node.id, node.manage_route_id, node.manage_route_name, node.route_node_id, node.route_node_name, node.route_node_day, node.task_type,
		node.task_status, node.task_subdivision,node.second_classify_describe, node.execute_time, node.phone_push_sign, node.script_info_id,
		node.phone_template_id, node.phone_template_name, node.phone_node_content, node.phone_redial_times, node.phone_time_interval,
		node.phone_message_remind, node.phone_message_template_id, node.phone_message_template_name,node.phone_message_template_content,
		node.question_info_id, node.questionnaire_name, node.questionnaire_content, node.question_expiration_date,
		node.propaganda_info_id, node.propaganda_title, node.propaganda_content,node.follow_template_id, node.follow_template_name,
		node.message_push_sign, node.message_template_id, node.message_template_code, node.message_template_name,node.message_preview, node.message_node_content,
		node.official_push_sign, node.official_template_id, node.official_template_code, node.official_template_name, node.official_remind_content, node.official_node_content,
		node.applet_push_sign, node.applet_template_id, node.applet_template_code, node.applet_template_name, node.applet_remind_content, node.applet_prompt_description, node.applet_node_content,
		node.route_check_status, node.route_check_person, node.route_check_date, node.route_check_remark, node.route_node_remark,
		node.node_execute_status, node.route_handle_remark, node.route_handle_id, node.route_handle_person, node.route_link,node.text_remind_content,node.node_content,node.phone_dial_method,node.task_node_type
		from sign_patient_manage_route_node node
		left join sign_patient_manage_route route on node.manage_route_id = route.id
		<where>
             node.del_flag = 0
			<if test="patientId != null">
				and route.patient_id = #{patientId}
			</if>
			<if test="taskType != null and taskType != ''">
				<choose>
					<when test="taskType == 'PROPAGANDA_ARTICLE'.toString()">
						and node.propaganda_info_id is not null
					</when>
					<otherwise>
						and node.task_type = #{taskType}
					</otherwise>
				</choose>
			</if>
			<if test="taskCreateType != null and taskCreateType != ''">
				and route.task_create_type = #{taskCreateType}
			</if>
			<choose>
				<when test="routeCheckStatus != null and routeCheckStatus == 'UNAUDITED'">
					and node.route_check_status is null
				</when>
				<when test="routeCheckStatus != null and routeCheckStatus == 'AGREE'">
					and node.route_check_status = #{routeCheckStatus}
				</when>
				<when test="routeCheckStatus != null and routeCheckStatus == 'DISAGREE'">
					and node.route_check_status = #{routeCheckStatus}
				</when>
			</choose>
			<if test="signPatientRecordId != null">
				and route.sign_patient_record_id = #{signPatientRecordId}
			</if>
		</where>
	</select>

    <insert id="insertSignPatientManageRouteNode" parameterType="SignPatientManageRouteNode" useGeneratedKeys="true"
            keyProperty="id">
        insert into sign_patient_manage_route_node
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="manageRouteId != null">manage_route_id,
                    </if>
                    <if test="manageRouteName != null">manage_route_name,
                    </if>
			        <if test="routeNodeId != null">route_node_id,
			        </if>
                    <if test="routeNodeName != null">route_node_name,
                    </if>
                    <if test="routeNodeDay != null">route_node_day,
                    </if>
                    <if test="taskType != null">task_type,
                    </if>
                    <if test="taskStatus != null">task_status,
                    </if>
                    <if test="taskSubdivision != null">task_subdivision,
                    </if>
                    <if test="taskNodeType != null">task_node_type,
                    </if>
                    <if test="secondClassifyDescribe != null">second_classify_describe,
                    </if>
                    <if test="executeTime != null">execute_time,
                    </if>
                    <if test="phonePushSign != null">phone_push_sign,
                    </if>
                    <if test="scriptInfoId != null">script_info_id,
                    </if>
                    <if test="phoneTemplateId != null">phone_template_id,
                    </if>
                    <if test="phoneTemplateName != null">phone_template_name,
                    </if>
                    <if test="phoneNodeContent != null">phone_node_content,
                    </if>
                    <if test="phoneRedialTimes != null">phone_redial_times,
                    </if>
                    <if test="phoneTimeInterval != null">phone_time_interval,
                    </if>
                    <if test="phoneMessageRemind != null">phone_message_remind,
                    </if>
                    <if test="phoneMessageTemplateId != null">phone_message_template_id,
                    </if>
                    <if test="phoneMessageTemplateName != null">phone_message_template_name,
                    </if>
			        <if test="phoneMessageTemplateContent != null">phone_message_template_content,
			        </if>
                    <if test="questionInfoId != null">question_info_id,
                    </if>
                    <if test="questionnaireName != null">questionnaire_name,
                    </if>
                    <if test="questionnaireContent != null">questionnaire_content,
                    </if>
                    <if test="questionExpirationDate != null">question_expiration_date,
                    </if>
                    <if test="propagandaInfoId != null">propaganda_info_id,
                    </if>
                    <if test="propagandaTitle != null">propaganda_title,
                    </if>
                    <if test="propagandaContent != null">propaganda_content,
                    </if>
                    <if test="messagePushSign != null">message_push_sign,
                    </if>
                    <if test="messageTemplateId != null">message_template_id,
                    </if>
			        <if test="messageTemplateCode != null">message_template_code,
			        </if>
                    <if test="messageTemplateName != null">message_template_name,
                    </if>
                    <if test="messagePreview != null">message_preview,
                    </if>
                    <if test="messageNodeContent != null">message_node_content,
                    </if>
                    <if test="officialPushSign != null">official_push_sign,
                    </if>
                    <if test="officialTemplateId != null">official_template_id,
                    </if>
			        <if test="officialTemplateCode != null">official_template_code,
			        </if>
                    <if test="officialTemplateName != null">official_template_name,
                    </if>
                    <if test="officialRemindContent != null">official_remind_content,
                    </if>
                    <if test="officialNodeContent != null">official_node_content,
                    </if>
                    <if test="appletPushSign != null">applet_push_sign,
                    </if>
                    <if test="appletTemplateId != null">applet_template_id,
                    </if>
			        <if test="appletTemplateCode != null">applet_template_code,
			        </if>
                    <if test="appletTemplateName != null">applet_template_name,
                    </if>
                    <if test="appletRemindContent != null">applet_remind_content,
                    </if>
                    <if test="appletPromptDescription != null">applet_prompt_description,
                    </if>
                    <if test="appletNodeContent != null">applet_node_content,
                    </if>
                    <if test="routeCheckStatus != null">route_check_status,
                    </if>
                    <if test="routeCheckPerson != null">route_check_person,
                    </if>
                    <if test="routeCheckDate != null">route_check_date,
                    </if>
                    <if test="routeCheckRemark != null">route_check_remark,
                    </if>
                    <if test="routeNodeRemark != null">route_node_remark,
                    </if>
                    <if test="nodeExecuteStatus != null">node_execute_status,
                    </if>
                    <if test="routeHandleRemark != null">route_handle_remark,
                    </if>
                    <if test="phoneConnectStatus != null">phone_connect_status,
                    </if>
                    <if test="routeHandleId != null">route_handle_id,
                    </if>
                    <if test="routeHandlePerson != null">route_handle_person,
                    </if>
                    <if test="routeLink != null">route_link,
                    </if>
                    <if test="textRemindContent != null">text_remind_content,
                    </if>
			        <if test="nodeContent != null">node_content,
			        </if>
			        <if test="delFlag != null">del_flag,
			        </if>
                    <if test="createBy != null">create_by,
                    </if>
                    <if test="createTime != null">create_time,
                    </if>
                    <if test="updateBy != null">update_by,
                    </if>
                    <if test="updateTime != null">update_time,
                    </if>
                    <if test="phoneDialMethod != null">phone_dial_method,
                    </if>
                    <if test="followTemplateId != null">follow_template_id,
                    </if>
                    <if test="followTemplateName != null">follow_template_name,
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="manageRouteId != null">#{manageRouteId},
                    </if>
                    <if test="manageRouteName != null">#{manageRouteName},
                    </if>
			        <if test="routeNodeId != null">#{routeNodeId},
			        </if>
                    <if test="routeNodeName != null">#{routeNodeName},
                    </if>
                    <if test="routeNodeDay != null">#{routeNodeDay},
                    </if>
                    <if test="taskType != null">#{taskType},
                    </if>
                    <if test="taskStatus != null">#{taskStatus},
                    </if>
                    <if test="taskSubdivision != null">#{taskSubdivision},
                    </if>
                    <if test="taskNodeType != null">#{taskNodeType},
                    </if>
                    <if test="secondClassifyDescribe != null">#{secondClassifyDescribe},
                    </if>
                    <if test="executeTime != null">#{executeTime},
                    </if>
                    <if test="phonePushSign != null">#{phonePushSign},
                    </if>
                    <if test="scriptInfoId != null">#{scriptInfoId},
                    </if>
                    <if test="phoneTemplateId != null">#{phoneTemplateId},
                    </if>
                    <if test="phoneTemplateName != null">#{phoneTemplateName},
                    </if>
                    <if test="phoneNodeContent != null">#{phoneNodeContent},
                    </if>
                    <if test="phoneRedialTimes != null">#{phoneRedialTimes},
                    </if>
                    <if test="phoneTimeInterval != null">#{phoneTimeInterval},
                    </if>
                    <if test="phoneMessageRemind != null">#{phoneMessageRemind},
                    </if>
                    <if test="phoneMessageTemplateId != null">#{phoneMessageTemplateId},
                    </if>
                    <if test="phoneMessageTemplateName != null">#{phoneMessageTemplateName},
                    </if>
			        <if test="phoneMessageTemplateContent != null">#{phoneMessageTemplateContent},
			        </if>
                    <if test="questionInfoId != null">#{questionInfoId},
                    </if>
                    <if test="questionnaireName != null">#{questionnaireName},
                    </if>
                    <if test="questionnaireContent != null">#{questionnaireContent},
                    </if>
                    <if test="questionExpirationDate != null">#{questionExpirationDate},
                    </if>
                    <if test="propagandaInfoId != null">#{propagandaInfoId},
                    </if>
                    <if test="propagandaTitle != null">#{propagandaTitle},
                    </if>
                    <if test="propagandaContent != null">#{propagandaContent},
                    </if>
                    <if test="messagePushSign != null">#{messagePushSign},
                    </if>
                    <if test="messageTemplateId != null">#{messageTemplateId},
                    </if>
			        <if test="messageTemplateCode != null">#{messageTemplateCode},
			        </if>
                    <if test="messageTemplateName != null">#{messageTemplateName},
                    </if>
                    <if test="messagePreview != null">#{messagePreview},
                    </if>
                    <if test="messageNodeContent != null">#{messageNodeContent},
                    </if>
                    <if test="officialPushSign != null">#{officialPushSign},
                    </if>
                    <if test="officialTemplateId != null">#{officialTemplateId},
                    </if>
			        <if test="officialTemplateCode != null">#{officialTemplateCode},
			        </if>
                    <if test="officialTemplateName != null">#{officialTemplateName},
                    </if>
                    <if test="officialRemindContent != null">#{officialRemindContent},
                    </if>
                    <if test="officialNodeContent != null">#{officialNodeContent},
                    </if>
                    <if test="appletPushSign != null">#{appletPushSign},
                    </if>
                    <if test="appletTemplateId != null">#{appletTemplateId},
                    </if>
			        <if test="appletTemplateCode != null">#{appletTemplateCode},
			        </if>
                    <if test="appletTemplateName != null">#{appletTemplateName},
                    </if>
                    <if test="appletRemindContent != null">#{appletRemindContent},
                    </if>
                    <if test="appletPromptDescription != null">#{appletPromptDescription},
                    </if>
                    <if test="appletNodeContent != null">#{appletNodeContent},
                    </if>
                    <if test="routeCheckStatus != null">#{routeCheckStatus},
                    </if>
                    <if test="routeCheckPerson != null">#{routeCheckPerson},
                    </if>
                    <if test="routeCheckDate != null">#{routeCheckDate},
                    </if>
                    <if test="routeCheckRemark != null">#{routeCheckRemark},
                    </if>
                    <if test="routeNodeRemark != null">#{routeNodeRemark},
                    </if>
                    <if test="nodeExecuteStatus != null">#{nodeExecuteStatus},
                    </if>
                    <if test="routeHandleRemark != null">#{routeHandleRemark},
                    </if>
                    <if test="phoneConnectStatus != null">#{phoneConnectStatus},
                    </if>
                    <if test="routeHandleId != null">#{routeHandleId},
                    </if>
                    <if test="routeHandlePerson != null">#{routeHandlePerson},
                    </if>
                    <if test="routeLink != null">#{routeLink},
                    </if>
                    <if test="textRemindContent != null">#{textRemindContent},
                    </if>
			        <if test="nodeContent != null">#{nodeContent},
			        </if>
			        <if test="delFlag != null">#{delFlag},
			        </if>
                    <if test="createBy != null">#{createBy},
                    </if>
                    <if test="createTime != null">#{createTime},
                    </if>
                    <if test="updateBy != null">#{updateBy},
                    </if>
                    <if test="updateTime != null">#{updateTime},
                    </if>
                    <if test="phoneDialMethod != null ">#{phoneDialMethod},
                    </if>
                    <if test="followTemplateId != null">#{followTemplateId},
                    </if>
                    <if test="followTemplateName != null">#{followTemplateName},
                    </if>
        </trim>
    </insert>
	<insert id="insertBatch">
		insert into sign_patient_manage_route_node(manage_route_id, manage_route_name, route_node_id, route_node_name, route_node_day, task_type, task_status, task_subdivision, task_node_type, second_classify_describe,
		execute_time, phone_push_sign, script_info_id, phone_template_id, phone_template_name, phone_node_content, phone_redial_times, phone_time_interval, phone_message_remind, phone_message_template_id,
		phone_message_template_name, phone_message_template_content,question_info_id, questionnaire_name, questionnaire_content, question_expiration_date, propaganda_info_id, propaganda_title, propaganda_content, message_push_sign,
		message_template_id, message_template_code, message_template_name, message_preview, message_node_content, official_push_sign, official_template_id, official_template_code,official_template_name, official_remind_content,
		official_node_content, applet_push_sign, applet_template_id, applet_template_code, applet_template_name, applet_remind_content, applet_prompt_description, applet_node_content,
		route_check_status, route_check_person, route_check_date, route_check_remark, route_node_remark, node_execute_status, route_handle_remark,phone_connect_status,
		route_handle_id, route_handle_person, route_link, text_remind_content,node_content, del_flag, create_by, create_time, update_by, update_time,phone_dial_method,follow_template_id, follow_template_name)
		values
		<foreach collection="nodeList" item="item" separator=",">
			(#{item.manageRouteId},#{item.manageRouteName},#{item.routeNodeId},#{item.routeNodeName},#{item.routeNodeDay},#{item.taskType},#{item.taskStatus},#{item.taskSubdivision},#{item.taskNodeType},#{item.secondClassifyDescribe},
			 #{item.executeTime},#{item.phonePushSign},#{item.scriptInfoId},#{item.phoneTemplateId},#{item.phoneTemplateName},#{item.phoneNodeContent},#{item.phoneRedialTimes},#{item.phoneTimeInterval},#{item.phoneMessageRemind},#{item.phoneMessageTemplateId},
			 #{item.phoneMessageTemplateName},#{item.phoneMessageTemplateContent},
			 #{item.questionInfoId},#{item.questionnaireName},#{item.questionnaireContent},#{item.questionExpirationDate},#{item.propagandaInfoId},#{item.propagandaTitle},#{item.propagandaContent},#{item.messagePushSign},
			 #{item.messageTemplateId}, #{item.messageTemplateCode},
			 #{item.messageTemplateName},#{item.messagePreview},#{item.messageNodeContent},#{item.officialPushSign},#{item.officialTemplateId},#{item.officialTemplateCode},#{item.officialTemplateName},#{item.officialRemindContent},#{item.officialNodeContent},
			 #{item.appletPushSign},#{item.appletTemplateId},#{item.appletTemplateCode},#{item.appletTemplateName},#{item.appletRemindContent},#{item.appletPromptDescription},#{item.appletNodeContent},
			 #{item.routeCheckStatus},#{item.routeCheckPerson},#{item.routeCheckDate},#{item.routeCheckRemark},#{item.routeNodeRemark},#{item.nodeExecuteStatus},#{item.routeHandleRemark},#{item.phoneConnectStatus},
			 #{item.routeHandleId},#{item.routeHandlePerson},#{item.routeLink},#{item.textRemindContent},#{item.nodeContent},0,#{item.createBy},#{item.createTime},#{item.updateBy},#{item.updateTime},#{item.phoneDialMethod},#{item.followTemplateId},#{item.followTemplateName})
		</foreach>
	</insert>
    <update id="updateSignPatientManageRouteNode" parameterType="SignPatientManageRouteNode">
        update sign_patient_manage_route_node
        <trim prefix="SET" suffixOverrides=",">
                    <if test="manageRouteId != null">manage_route_id =
                        #{manageRouteId},
                    </if>
                    <if test="manageRouteName != null">manage_route_name =
                        #{manageRouteName},
                    </if>
			        <if test="routeNodeId != null">route_node_id =
				        #{routeNodeId},
			        </if>
                    <if test="routeNodeName != null">route_node_name =
                        #{routeNodeName},
                    </if>
                    <if test="routeNodeDay != null">route_node_day =
                        #{routeNodeDay},
                    </if>
                    <if test="taskType != null">task_type =
                        #{taskType},
                    </if>
                    <if test="taskStatus != null">task_status =
                        #{taskStatus},
                    </if>
                    <if test="taskSubdivision != null">task_subdivision =
                        #{taskSubdivision},
                    </if>
                    <if test="taskNodeType != null">task_node_type =
                        #{taskNodeType},
                    </if>
                    <if test="secondClassifyDescribe != null">second_classify_describe =
                        #{secondClassifyDescribe},
                    </if>
                    <if test="executeTime != null">execute_time =
                        #{executeTime},
                    </if>
                    <if test="phonePushSign != null">phone_push_sign =
                        #{phonePushSign},
                    </if>
                    <if test="scriptInfoId != null">script_info_id =
                        #{scriptInfoId},
                    </if>
                    <if test="phoneTemplateId != null">phone_template_id =
                        #{phoneTemplateId},
                    </if>
                    <if test="phoneTemplateName != null">phone_template_name =
                        #{phoneTemplateName},
                    </if>
                    <if test="phoneNodeContent != null">phone_node_content =
                        #{phoneNodeContent},
                    </if>
                    <if test="phoneRedialTimes != null">phone_redial_times =
                        #{phoneRedialTimes},
                    </if>
                    <if test="phoneTimeInterval != null">phone_time_interval =
                        #{phoneTimeInterval},
                    </if>
                    <if test="phoneMessageRemind != null">phone_message_remind =
                        #{phoneMessageRemind},
                    </if>
                    <if test="phoneMessageTemplateId != null">phone_message_template_id =
                        #{phoneMessageTemplateId},
                    </if>
                    <if test="phoneMessageTemplateName != null">phone_message_template_name =
                        #{phoneMessageTemplateName},
                    </if>
			        <if test="phoneMessageTemplateContent != null">phone_message_template_content =
				        #{phoneMessageTemplateContent},
			        </if>
                    <if test="questionInfoId != null">question_info_id =
                        #{questionInfoId},
                    </if>
                    <if test="questionnaireName != null">questionnaire_name =
                        #{questionnaireName},
                    </if>
                    <if test="questionnaireContent != null">questionnaire_content =
                        #{questionnaireContent},
                    </if>
                    <if test="questionExpirationDate != null">question_expiration_date =
                        #{questionExpirationDate},
                    </if>
                    <if test="propagandaInfoId != null">propaganda_info_id =
                        #{propagandaInfoId},
                    </if>
                    <if test="propagandaTitle != null">propaganda_title =
                        #{propagandaTitle},
                    </if>
                    <if test="propagandaContent != null">propaganda_content =
                        #{propagandaContent},
                    </if>
                    <if test="messagePushSign != null">message_push_sign =
                        #{messagePushSign},
                    </if>
                    <if test="messageTemplateId != null">message_template_id =
                        #{messageTemplateId},
                    </if>
			        <if test="messageTemplateCode != null">message_template_code =
				        #{messageTemplateCode},
			        </if>
                    <if test="messageTemplateName != null">message_template_name =
                        #{messageTemplateName},
                    </if>
                    <if test="messagePreview != null">message_preview =
                        #{messagePreview},
                    </if>
                    <if test="messageNodeContent != null">message_node_content =
                        #{messageNodeContent},
                    </if>
                    <if test="officialPushSign != null">official_push_sign =
                        #{officialPushSign},
                    </if>
                    <if test="officialTemplateId != null">official_template_id =
                        #{officialTemplateId},
                    </if>
			        <if test="officialTemplateCode != null">official_template_code =
				        #{officialTemplateCode},
			        </if>
                    <if test="officialTemplateName != null">official_template_name =
                        #{officialTemplateName},
                    </if>
                    <if test="officialRemindContent != null">official_remind_content =
                        #{officialRemindContent},
                    </if>
                    <if test="officialNodeContent != null">official_node_content =
                        #{officialNodeContent},
                    </if>
                    <if test="appletPushSign != null">applet_push_sign =
                        #{appletPushSign},
                    </if>
                    <if test="appletTemplateId != null">applet_template_id =
                        #{appletTemplateId},
                    </if>
			        <if test="appletTemplateCode != null">applet_template_code =
				        #{appletTemplateCode},
			        </if>
                    <if test="appletTemplateName != null">applet_template_name =
                        #{appletTemplateName},
                    </if>
                    <if test="appletRemindContent != null">applet_remind_content =
                        #{appletRemindContent},
                    </if>
                    <if test="appletPromptDescription != null">applet_prompt_description =
                        #{appletPromptDescription},
                    </if>
                    <if test="appletNodeContent != null">applet_node_content =
                        #{appletNodeContent},
                    </if>
                    <if test="routeCheckStatus != null">route_check_status =
                        #{routeCheckStatus},
                    </if>
                    <if test="routeCheckPerson != null">route_check_person =
                        #{routeCheckPerson},
                    </if>
                    <if test="routeCheckDate != null">route_check_date =
                        #{routeCheckDate},
                    </if>
                    <if test="routeCheckRemark != null">route_check_remark =
                        #{routeCheckRemark},
                    </if>
                    <if test="routeNodeRemark != null">route_node_remark =
                        #{routeNodeRemark},
                    </if>
                    <if test="nodeExecuteStatus != null">node_execute_status =
                        #{nodeExecuteStatus},
                    </if>
                    <if test="routeHandleRemark != null">route_handle_remark =
                        #{routeHandleRemark},
                    </if>
                    <if test="phoneConnectStatus != null">phone_connect_status =
                        #{phoneConnectStatus},
                    </if>
                    <if test="routeHandleId != null">route_handle_id =
                        #{routeHandleId},
                    </if>
                    <if test="routeHandlePerson != null">route_handle_person =
                        #{routeHandlePerson},
                    </if>
                    <if test="routeLink != null">route_link =
                        #{routeLink},
                    </if>
                    <if test="textRemindContent != null">text_remind_content =
                        #{textRemindContent},
                    </if>
			        <if test="nodeContent != null">node_content =
				        #{nodeContent},
			        </if>
			        <if test="delFlag != null">del_flag =
				        #{delFlag},
			        </if>
                    <if test="createBy != null">create_by =
                        #{createBy},
                    </if>
                    <if test="createTime != null">create_time =
                        #{createTime},
                    </if>
                    <if test="updateBy != null">update_by =
                        #{updateBy},
                    </if>
                    <if test="updateTime != null">update_time =
                        #{updateTime},
                    </if>
                    <if test="phoneDialMethod != null ">phone_dial_method =
                        #{phoneDialMethod},
                    </if>
                    <if test="followTemplateId != null">follow_template_id =
                        #{followTemplateId},
                    </if>
                    <if test="followTemplateName != null">follow_template_name =
                        #{followTemplateName},
                    </if>
                    <if test="phoneNodeExecuteResultStatus != null">phone_node_execute_result_status =
                        #{phoneNodeExecuteResultStatus},
                    </if>
                    <if test="phoneMessageNodeExecuteResultStatus != null">phone_message_node_execute_result_status =
                        #{phoneMessageNodeExecuteResultStatus},
                    </if>
                    <if test="messageNodeExecuteResultStatus != null">message_node_execute_result_status =
                        #{messageNodeExecuteResultStatus},
                    </if>
                    <if test="officialNodeExecuteResultStatus != null">official_node_execute_result_status =
                        #{officialNodeExecuteResultStatus},
                    </if>
                    <if test="appletNodeExecuteResultStatus != null">applet_node_execute_result_status =
                        #{appletNodeExecuteResultStatus},
                    </if>
                    <if test="nodeFinishDate != null">node_finish_date =
                        #{nodeFinishDate},
                    </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSignPatientManageRouteNodeById" parameterType="Long">
        delete from sign_patient_manage_route_node where id = #{id}
    </delete>

    <update id="deleteSignPatientManageRouteNodeByIds" parameterType="String">
        update sign_patient_manage_route_node set del_flag = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <update id="deleteRouteNodeByManageRouteId">
        update sign_patient_manage_route_node set del_flag = 1
        where manage_route_id = #{manageRouteId}
    </update>

    <select id="selectPatientTaskList" parameterType="com.xinelu.manage.dto.signpatientmanageroutenode.PatientTaskDto" resultType="com.xinelu.manage.vo.signpatientmanageroutenode.PatientTaskVo">
		select patient.id as patientId, patient.patient_name,
		patient.patient_phone,
		patient.family_member_phone,
		patient.birth_date,
		patient.card_no,
		patient.sex,
		patient.address,
		patient.patient_type, patient.visit_method, patient.attending_physician_id, patient.attending_physician_name, patient.main_diagnosis,
		patient.hospital_agency_id, patient.hospital_agency_name, patient.campus_agency_id, patient.campus_agency_name,
		patient.department_id, patient.department_name,patient.ward_id, patient.ward_name, patient.patient_visit_record_id,patient.in_hospital_number, patient.visit_date, patient.discharge_time,
		patient.patient_source, patient.surgical_name,route.sign_patient_record_id, node.id as manageRouteNodeId, node.manage_route_id, node.manage_route_name,node.route_check_status
		from sign_patient_manage_route_node node
		    left join sign_patient_manage_route route on node.manage_route_id = route.id
	    left join patient_info patient on route.patient_id = patient.id
		<where>
           node.del_flag = 0
			<if test="patientName != null  and patientName != ''">
				and patient.patient_name = #{patientName}
			</if>
			<if test="mainDiagnosis != null  and mainDiagnosis != ''">
				and patient.main_diagnosis like concat('%', #{mainDiagnosis}, '%')
			</if>
			<choose>
				<when test="routeCheckStatus != null and routeCheckStatus == 'UNAUDITED'.toString()">
					and node.route_check_status is null
				</when>
				<when test="routeCheckStatus != null and routeCheckStatus == 'AGREE'.toString()">
					and node.route_check_status = #{routeCheckStatus}
				</when>
				<when test="routeCheckStatus != null and routeCheckStatus == 'DISAGREE'.toString()">
					and node.route_check_status = #{routeCheckStatus}
				</when>
			</choose>
			<if test="hospitalAgencyId != null ">
				and patient.hospital_agency_id = #{hospitalAgencyId}
			</if>
			<if test="campusAgencyId != null ">
				and patient.campus_agency_id = #{campusAgencyId}
			</if>
			<if test="departmentId != null ">
				and patient.department_id = #{departmentId}
			</if>
			<if test="wardId != null ">
				and patient.ward_id = #{wardId}
			</if>
			<if test="dischargeTimeStart != null ">
				and date_format(patient.discharge_time,'%y%m%d') &gt;= date_format(#{dischargeTimeStart},'%y%m%d')
			</if>
			<if test="dischargeTimeEnd != null ">
				and date_format(patient.discharge_time,'%y%m%d') &lt;= date_format(#{dischargeTimeEnd},'%y%m%d')
			</if>
			<if test="taskCreateType != null ">
				and route.task_create_type = #{taskCreateType}
			</if>
			<if test="patientSource != null ">
				and patient.patient_source like concat('%', #{patientSource}, '%')
			</if>
			<!-- 数据范围过滤 -->
			${params.dataScope}
		</where>
		group by patient.hospital_agency_id, patient.id
	</select>

    <update id="updateMessageStatus">
        update sign_patient_manage_route_node
        set message_status = #{messageStatus}
        where id = #{id}
    </update>

	<select id="selectByRouteId" resultType="com.xinelu.manage.vo.specialdiseasenode.SpecialDiseaseNodeAuditVo">
		select
			sdn.route_node_name     routeNodeName,
			sdn.route_node_day      routeNodeDay,
			sdn.execute_time executionTime,
			GROUP_CONCAT(sdn.task_node_type SEPARATOR ',') as taskPartitionCodes,
			GROUP_CONCAT(dic.dict_label SEPARATOR ',') as taskPartitionDictNames
		from  sign_patient_manage_route_node sdn
		left join sys_dict_data dic on sdn.task_node_type = dic.dict_value
		where sdn.manage_route_id = #{manageRouteId} and dic.dict_type ='task_node_type'
		group by sdn.route_node_name, sdn.route_node_day
	</select>

	<select id="selectAuditNodeInfo" resultType="com.xinelu.manage.vo.signpatientmanageroutenode.SignPatientManageNodeAuditVo">
		select
		node.*,
		dic.dict_label as taskTypeName
		from sign_patient_manage_route_node node
        left join sys_dict_data dic on node.task_node_type = dic.dict_value
		where node.manage_route_id in
		<foreach item="manageRouteId" collection="manageRouteIds" open="(" separator="," close=")">
			#{manageRouteId}
		</foreach>
		  and dic.dict_type ='task_node_type'
	</select>

	<select id="selectNodeInfoByManageIds" resultType="com.xinelu.manage.vo.signpatientmanageroutenode.SignPatientTaskVo">
		select
		node.*,
		ttd.task_type_name as taskTypeName,
		tpd.task_partition_name as taskPartitionDictName,
		dic.dict_label as taskNodeTypeName
		from sign_patient_manage_route_node node
		left join task_type_dict ttd on node.task_type = ttd.task_type_code
		left join sys_dict_data dic on node.task_node_type = dic.dict_value
		left join task_partition_dict tpd on node.task_subdivision = tpd.task_partition_code
		where node.manage_route_id in
		<foreach item="manageRouteId" collection="manageRouteIds" open="(" separator="," close=")">
			#{manageRouteId}
		</foreach>
		and dic.dict_type ='task_node_type'
	</select>

	<select id="selectNodesByManageIds" resultMap="SignPatientManageRouteNodeResult">
		<include refid="selectSignPatientManageRouteNodeVo"/>
		where manage_route_id in
		<foreach item="manageRouteId" collection="manageRouteIds" open="(" separator="," close=")">
			#{manageRouteId}
		</foreach>
	</select>

    <select id="getRouteNodeContentList"
            resultType="com.xinelu.manage.domain.signpatientmanageroutenode.SignPatientManageRouteNode">
        select node_content
        from sign_patient_manage_route spmr
                 LEFT JOIN special_disease_route sdr ON spmr.route_id = sdr.id
                 LEFT JOIN special_disease_node sdn ON sdn.route_id = sdr.id
        where spmr.patient_id = #{patientId}
    </select>

    <select id="selectMessagePushSign"
            resultType="com.xinelu.manage.vo.signpatientmanageroutenode.TextMessage">
        select spmrn.id signPatientManageRouteNodeId,
               spmrn.manage_route_name,
               spmrn.message_push_sign,
               spmrn.message_node_content,
               spmrn.node_execute_status,
               spmrn.route_node_name,
               spmrn.route_node_day,
               spmrn.task_node_type,
               spmr.id  manageRouteId,
               pi.patient_phone,
               pi.patient_type,
               pi.admission_time,
               pi.discharge_time,
               pi.visit_date,
               pi.visit_method,
               tm.text_message_id
        from sign_patient_manage_route_node spmrn
                 LEFT JOIN sign_patient_manage_route spmr ON spmr.id = spmrn.manage_route_id
                 LEFT JOIN patient_info pi ON pi.id = spmr.patient_id
                 LEFT JOIN text_message tm ON tm.id = spmrn.message_template_id
        where spmrn.message_push_sign = 1
          and spmrn.del_flag = 0
          and spmrn.node_execute_status = 'UNEXECUTED'
          and (spmrn.message_node_execute_result_status is null or spmrn.message_node_execute_result_status = ' ')
    </select>

    <update id="updateNodeExecuteStatusByIds">
        update sign_patient_manage_route_node
        <trim prefix="SET" suffixOverrides=",">
            <if test="nodeExecuteStatus != null">node_execute_status =
                #{nodeExecuteStatus},
            </if>
            <if test="appletStatus != null">applet_node_execute_result_status =
                #{appletStatus},
            </if>
            <if test="messageStatus != null">message_node_execute_result_status =
                #{messageStatus},
            </if>
            <if test="officialStatus != null">official_node_execute_result_status =
                #{officialStatus},
            </if>
        </trim>
        where id in
        <foreach item="manageRouteNodeIds" collection="manageRouteNodeIds" open="(" separator="," close=")">
            #{manageRouteNodeIds}
        </foreach>
    </update>
</mapper>