<?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.hxhq.business.mapper.SjMapper">
    <update id="updateKcBatch">
        UPDATE t_sj SET kc = #{kc} WHERE bh in
        <foreach item="item" index="index" collection="bhList" separator=",">
            (#{item})
        </foreach>
    </update>
    <update id="updateCc">
        UPDATE t_sj SET cctj = #{cctj}, ccwz = #{ccwz} WHERE bh in
        <foreach item="item" index="index" collection="bhList" separator=",">
            (#{item})
        </foreach>
    </update>
    <update id="updateKc">
        UPDATE t_sj SET kc = #{kc} WHERE id = #{id}
    </update>
    <select id="queryStudyList" resultType="com.hxhq.business.dto.sj.SjListDto">
        select t.id,t.mc,t.bh,t.nd,t.nddw,t.kc,t.kcdw,t.sxr,t.zjzt,t.ly
        FROM `t_study_sj` ts
        join  `t_sj` t on t.id=ts.resource_id
        <if test="ew.sqlSegment != '' and ew.sqlSegment != null">
            <where>
                ${ew.sqlSegment}
            </where>
        </if>
    </select>
    <select id="queryList" resultType="com.hxhq.business.dto.sj.SjListDto">
        SELECT s.* , t.name AS studyName, d.dept_name AS deptName
        FROM t_sj s
        LEFT JOIN t_study t ON s.study_id = t.id
        LEFT JOIN sys_dept d ON d.dept_id = s.dept_id
        <if test="ew.sqlSegment != '' and ew.sqlSegment != null">
            <where>
                ${ew.sqlSegment}
            </where>
        </if>
    </select>
    <!--  试剂详情  -->
    <select id="queryInfo" resultType="com.hxhq.business.dto.sj.SjListDto">
        SELECT sj.*, s.name AS studyName, f.bdmc AS formName, f.user_mc AS formUserName, d.dept_name AS deptName FROM t_sj sj
        LEFT JOIN t_study s ON s.id = sj.study_id
        LEFT JOIN t_study_form_fill f ON f.id = sj.study_form_id
        LEFT JOIN sys_dept d ON d.dept_id = sj.dept_id
        WHERE sj.id = #{id}
    </select>
</mapper>