<?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.emr.dao.ExportTaskDetailsMapper">
    <update id="upStatc">
        update  Export_Task_Details set state=#{state} where id=#{id}
    </update>

    <select id="selectAllByTaskId" resultType="com.emr.vo.ExportTaskDetailsVo">
        SELECT id,
               taskId,
               inpNo,
               CONVERT(VARCHAR (100), dischargeDateTime, 23) as dischargeDateTime
        FROM Export_Task_Details
        WHERE taskId = #{taskId}
          AND (state = 0 or state = 1)
    </select>
    <select id="getfilePath" resultType="com.emr.vo.ExportDetailsVo">
        SELECT
            c.file_path+'\'+t.scan_page as filePath,
            t.assort_id as assortId,
            e.gj_assort_name as assortName
        FROM
            commomtable c
                LEFT JOIN t_scan_assort t ON t.patient_id= c.patient_id
                LEFT JOIN  export_zd_assort e on e.assort_id=t.assort_id
        WHERE
            c.inpatient_no= #{inpNo}
          AND CONVERT ( VARCHAR ( 100 ), c.dis_date, 23 )  = #{dischargeDateTime}
          AND e.export_flag=1
          AND t.is_del=0
        ORDER BY e.assort_sort,t.scan_page
    </select>


    <resultMap id="BaseResultMap" type="com.emr.entity.ExportTaskDetails">
        <id column="id" jdbcType="INTEGER" property="id" />
        <result column="taskId" jdbcType="INTEGER" property="taskid" />
        <result column="inpNo" jdbcType="VARCHAR" property="inpno" />
        <result column="dischargeDateTime" jdbcType="TIMESTAMP" property="dischargedatetime" />
        <result column="state" jdbcType="INTEGER" property="state" />
    </resultMap>
    <sql id="Base_Column_List">
        id, taskId, inpNo, dischargeDateTime, state
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from Export_Task_Details
        where id = #{id,jdbcType=INTEGER}
    </select>
    <select id="selectExportTaskDetailsByInpNo" resultType="com.emr.entity.ExportTaskDetails">
        select  <include refid="Base_Column_List" /> from Export_Task_Details where inpNo =#{inpNo}
    </select>
    <select id="getExportTaskDetailsList" resultType="com.emr.vo.ExportTaskDetailsVo">

        select
        a.id,
        a.taskId,
        a.inpNo,
        a.dischargeDateTime,
        a.state,
        b.create_date as createDate
        from Export_Task_Details a
        left join  export_task b on a.taskId = b.task_id
        where 1 = 1
        <if test="record.taskid != null and record.taskid != ''">
            and a.taskId= #{record.taskid}
        </if>
        <if test="record.state != null">
            and a.state= #{record.state}
        </if>
        <if test="startTime != '' and startTime != null">
            AND CONVERT ( VARCHAR ( 100 ), b.create_date, 23 )  &gt;=  #{startTime}
            <if test="endTime != '' and endTime != null">
                AND CONVERT ( VARCHAR ( 100 ), b.create_date, 23 )  &lt;= #{endTime}
            </if>
        </if>

    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from Export_Task_Details
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insert" parameterType="com.emr.entity.ExportTaskDetails">
        insert into Export_Task_Details (id, taskId, inpNo,
                                         dischargeDateTime, state)
        values (#{id,jdbcType=INTEGER}, #{taskid,jdbcType=INTEGER}, #{inpno,jdbcType=VARCHAR},
                #{dischargedatetime,jdbcType=TIMESTAMP}, #{state,jdbcType=INTEGER})
    </insert>
    <insert id="insertSelective" parameterType="com.emr.entity.ExportTaskDetails">
        insert into Export_Task_Details
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="taskid != null">
                taskId,
            </if>
            <if test="inpno != null">
                inpNo,
            </if>
            <if test="dischargedatetime != null">
                dischargeDateTime,
            </if>
            <if test="state != null">
                state,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="taskid != null">
                #{taskid,jdbcType=INTEGER},
            </if>
            <if test="inpno != null">
                #{inpno,jdbcType=VARCHAR},
            </if>
            <if test="dischargedatetime != null">
                #{dischargedatetime,jdbcType=TIMESTAMP},
            </if>
            <if test="state != null">
                #{state,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
    <insert id="SimpleInsert" parameterType="java.util.List">
        INSERT INTO Export_Task_Details(taskId,inpNo,dischargeDateTime,state)
        VALUES
        <foreach collection ="list" item="item" index= "index" separator =",">
            (
            #{item.taskid,jdbcType=INTEGER},
            #{item.inpno,jdbcType=VARCHAR},
            #{item.dischargedatetime,jdbcType=TIMESTAMP},
            #{item.state,jdbcType=INTEGER}
            )
        </foreach >
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.emr.entity.ExportTaskDetails">
        update Export_Task_Details
        <set>
            <if test="taskid != null">
                taskId = #{taskid,jdbcType=INTEGER},
            </if>
            <if test="inpno != null">
                inpNo = #{inpno,jdbcType=VARCHAR},
            </if>
            <if test="dischargedatetime != null">
                dischargeDateTime = #{dischargedatetime,jdbcType=TIMESTAMP},
            </if>
            <if test="state != null">
                state = #{state,jdbcType=INTEGER},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.emr.entity.ExportTaskDetails">
        update Export_Task_Details
        set taskId = #{taskid,jdbcType=INTEGER},
            inpNo = #{inpno,jdbcType=VARCHAR},
            dischargeDateTime = #{dischargedatetime,jdbcType=TIMESTAMP},
            state = #{state,jdbcType=INTEGER}
        where id = #{id,jdbcType=INTEGER}
    </update>

</mapper>