<?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.scriptinfotaskinfo.ScriptInfoTaskInfoMapper">

	<resultMap type="ScriptInfoTaskInfo" id="ScriptInfoTaskInfoResult">
		<result property="id" column="id"/>
		<result property="scriptInfoId" column="script_info_id"/>
		<result property="robotId" column="robot_id"/>
		<result property="taskId" column="task_id"/>
		<result property="signPatientManageRouteNodeId" column="sign_patient_manage_route_node_id"/>
		<result property="signPatientManageRouteId" column="sign_patient_manage_route_id"/>
		<result property="sn" column="sn"/>
		<result property="executeTime" column="execute_time"/>
		<result property="aiobTaskType" column="aiob_task_type"/>
		<result property="executeStatus" column="execute_status"/>
		<result property="createTime" column="create_time"/>
	</resultMap>

	<sql id="selectScriptInfoTaskInfoVo">
		select id,
		       script_info_id,
		       robot_id,
		       task_id,
		       sign_patient_manage_route_node_id,
		       execute_time,
		       aiob_task_type,
		       execute_status,
		       create_time
		from script_info_task_info
	</sql>

	<select id="getByNodeId" resultType="java.lang.String" parameterType="ScriptInfoTaskInfo">
		select task_id
		from script_info_task_info
		where 1=1
		<if test="signPatientManageRouteNodeId!=null">
		  AND sign_patient_manage_route_node_id = #{signPatientManageRouteNodeId}
		</if>
		<if test="sn!=null">
			AND sn = #{sn}
		</if>
		<if test="signPatientManageRouteId!=null">
			AND sign_patient_manage_route_id = #{signPatientManageRouteId}
		</if>
		<if test="aiobTaskType !=null">
		  and aiob_task_type = #{aiobTaskType}
		</if>
		limit 1
	</select>

	<select id="selectList" resultType="com.xinelu.manage.domain.scriptinfotaskinfo.ScriptInfoTaskInfo">
		<include refid="selectScriptInfoTaskInfoVo"/>
		<where>
			<if test="signPatientManageRouteNodeId != null ">
				and sign_patient_manage_route_node_id = #{signPatientManageRouteNodeId}
			</if>
			<if test="aiobTaskType != null ">
				and aiob_task_type = #{aiobTaskType}
			</if>
			<if test="executeStatus != null ">
				and execute_status = #{executeStatus}
			</if>
		</where>
	</select>

	<insert id="insertScriptInfoTaskInfo" parameterType="ScriptInfoTaskInfo" useGeneratedKeys="true"
		keyProperty="id">
		insert into script_info_task_info
		<trim prefix="(" suffix=")" suffixOverrides=",">
			<if test="scriptInfoId != null">script_info_id,
			</if>
			<if test="robotId != null">robot_id,
			</if>
			<if test="taskId != null">task_id,
			</if>
			<if test="signPatientManageRouteNodeId != null">sign_patient_manage_route_node_id,
			</if>
			<if test="signPatientManageRouteId != null">sign_patient_manage_route_id,
			</if>
			<if test="sn != null">sn,
			</if>
			<if test="executeTime != null">execute_time,
			</if>
			<if test="aiobTaskType != null">aiob_task_type,
			</if>
			<if test="executeStatus != null">execute_status,
			</if>
			<if test="createTime != null">create_time,
			</if>
		</trim>
		<trim prefix="values (" suffix=")" suffixOverrides=",">
			<if test="scriptInfoId != null">#{scriptInfoId},
			</if>
			<if test="robotId != null">#{robotId},
			</if>
			<if test="taskId != null">#{taskId},
			</if>
			<if test="signPatientManageRouteNodeId != null">#{signPatientManageRouteNodeId},
			</if>
		    <if test="signPatientManageRouteId != null">#{signPatientManageRouteId},
			</if>
			<if test="sn != null">#{sn},
			</if>
			<if test="executeTime != null">#{executeTime},
			</if>
			<if test="aiobTaskType != null">#{aiobTaskType},
			</if>
			<if test="executeStatus != null">#{executeStatus},
			</if>
			<if test="createTime != null">#{createTime},
			</if>
		</trim>
	</insert>

	<update id="updateExecuteStatusByNodeId" parameterType="java.lang.Long">
		update script_info_task_info set execute_status = 'EXECUTED'
		where sign_patient_manage_route_node_id = #{signPatientManageRouteNodeId}
	</update>
</mapper>
