<?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.fs.store.mapper.FsTestReportMapper">

    <resultMap type="FsTestReport" id="FsTestReportResult">
        <result property="reportId"    column="report_id"    />
        <result property="userId"    column="user_id"    />
        <result property="patientId"    column="patient_id"    />
        <result property="patientJson"    column="patient_json"    />
        <result property="reportSn"    column="report_sn"    />
        <result property="testResult"    column="test_result"    />
        <result property="formJson"    column="form_json"    />
        <result property="conditioningPlanJson"    column="conditioning_plan_json"    />
        <result property="tempId"    column="temp_id"    />
        <result property="score"    column="score"    />
        <result property="createTime"    column="create_time"    />
        <result property="remark"    column="remark"    />
        <result property="imgUrl"    column="img_url"    />
    </resultMap>

    <sql id="selectFsTestReportVo">
        select report_id, user_id, patient_id, patient_json,img_url, report_sn,  test_result, form_json, conditioning_plan_json, temp_id, score, create_time, remark from fs_test_report
    </sql>

    <select id="selectFsTestReportList" parameterType="FsTestReport" resultMap="FsTestReportResult">
        <include refid="selectFsTestReportVo"/>
        <where>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="patientId != null "> and patient_id = #{patientId}</if>
            <if test="reportSn != null  and reportSn != ''"> and report_sn = #{reportSn}</if>
            <if test="tempId != null "> and temp_id = #{tempId}</if>
            <if test="createTime != null "> and create_time = #{createTime}</if>
        </where>
    </select>

    <select id="selectFsTestReportByReportId" parameterType="Long" resultMap="FsTestReportResult">
        <include refid="selectFsTestReportVo"/>
        where report_id = #{reportId}
    </select>

    <insert id="insertFsTestReport" parameterType="FsTestReport" useGeneratedKeys="true" keyProperty="reportId">
        insert into fs_test_report
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="patientId != null">patient_id,</if>
            <if test="patientJson != null">patient_json,</if>
            <if test="reportSn != null">report_sn,</if>
            <if test="testResult != null">test_result,</if>
            <if test="formJson != null">form_json,</if>
            <if test="conditioningPlanJson != null">conditioning_plan_json,</if>
            <if test="tempId != null">temp_id,</if>
            <if test="score != null">score,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remark != null">remark,</if>
            <if test="imgUrl != null">img_url,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">#{userId},</if>
            <if test="patientId != null">#{patientId},</if>
            <if test="patientJson != null">#{patientJson},</if>
            <if test="reportSn != null">#{reportSn},</if>
            <if test="testResult != null">#{testResult},</if>
            <if test="formJson != null">#{formJson},</if>
            <if test="conditioningPlanJson != null">#{conditioningPlanJson},</if>
            <if test="tempId != null">#{tempId},</if>
            <if test="score != null">#{score},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remark != null">#{remark},</if>
            <if test="imgUrl != null">#{imgUrl},</if>
         </trim>
    </insert>

    <update id="updateFsTestReport" parameterType="FsTestReport">
        update fs_test_report
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="patientId != null">patient_id = #{patientId},</if>
            <if test="patientJson != null">patient_json = #{patientJson},</if>
            <if test="reportSn != null">report_sn = #{reportSn},</if>
            <if test="testResult != null">test_result = #{testResult},</if>
            <if test="formJson != null">form_json = #{formJson},</if>
            <if test="conditioningPlanJson != null">conditioning_plan_json = #{conditioningPlanJson},</if>
            <if test="tempId != null">temp_id = #{tempId},</if>
            <if test="score != null">score = #{score},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="imgUrl != null">img_url = #{imgUrl},</if>
        </trim>
        where report_id = #{reportId}
    </update>

    <delete id="deleteFsTestReportByReportId" parameterType="Long">
        delete from fs_test_report where report_id = #{reportId}
    </delete>

    <delete id="deleteFsTestReportByReportIds" parameterType="String">
        delete from fs_test_report where report_id in
        <foreach item="reportId" collection="array" open="(" separator="," close=")">
            #{reportId}
        </foreach>
    </delete>
</mapper>
