<?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.goldenwater.slaj.hidd.mapper.BisMajHiddSupMapper">
    <resultMap type="com.goldenwater.slaj.hidd.domain.BisMajHiddSupVo" id="BisMajHiddSupResult">
        <result property="guid" column="guid"/>
        <result property="hiddGuid" column="hidd_guid"/>
        <result property="isList" column="is_list"/>
        <result property="rectPeri" column="rect_peri"/>
        <result property="supLareId" column="sup_lare_id"/>
        <result property="supDate" column="sup_date"/>
        <result property="supWiunCode" column="sup_wiun_code"/>
        <result property="supLegPers" column="sup_leg_pers"/>
        <result property="supOpin" column="sup_opin"/>
        <result property="supStat" column="sup_stat"/>
        <result property="hiddName" column="hidd_name"/>
        <result property="hiddGrad" column="hidd_grad"/>
        <result property="hiddStat" column="hidd_stat"/>
        <result property="note" column="note"/>
        <result property="collTime" column="coll_time"/>
        <result property="updTime" column="upd_time"/>
        <result property="recPers" column="rec_pers"/>
        <!-- 非持久化字段 -->
        <result property="supWiunName" column="sup_wiun_name"/>
        <result property="medGuid" column="med_guid"/>
        <result property="medTitl" column="med_titl"/>
    </resultMap>
    <sql id="selectBisMajHiddSupVo">
        select s.guid, s.hidd_guid, s.is_list, s.rect_peri, s.sup_lare_id, s.sup_date, s.sup_wiun_code, s.sup_leg_pers, s.sup_opin, s.sup_stat, s.note, s.coll_time, s.upd_time, s.rec_pers,
               h.hidd_name, h.hidd_grad, h.hidd_stat,
               org.wiun_name as sup_wiun_name,
               med.med_guid, att.med_titl
        from bis_maj_hidd_sup s
        left join obj_hidd h on h.guid = s.hidd_guid
        left join att_org_ext org on org.org_guid = s.sup_wiun_code
        left join rel_bis_med med on med.bis_guid = s.guid and med.bis_tablename = 'BIS_MAJ_HIDD_SUP'
        left join att_med_base att on att.guid = med.med_guid
    </sql>
    <select id="selectBisMajHiddSupByGuid" parameterType="String" resultMap="BisMajHiddSupResult">
        <include refid="selectBisMajHiddSupVo"/>
        where guid = #{guid}
    </select>
    <select id="selectBisMajHiddSupList" parameterType="com.goldenwater.slaj.hidd.domain.BisMajHiddSupVo" resultMap="BisMajHiddSupResult">
        <include refid="selectBisMajHiddSupVo"/>
        <where>
            <if test="hiddGuid != null and hiddGuid != ''">AND s.hidd_guid = #{hiddGuid}</if>
            <if test="supStat != null and supStat != ''">AND s.sup_stat = #{supStat}</if>
            <if test="guid != null and guid != ''">AND s.guid = #{guid}</if>
            <if test="hiddName != null and hiddName != ''">AND h.hidd_name like concat('%', #{hiddName}, '%')</if>
            <if test="hiddUnit != null and hiddUnit != ''">
                AND h.org_guid in (
                    select guid from att_org_base where wiun_code like concat(
                        case #{hiddUnit}
                            when '0' then '%000000'
                            when '1' then '%0000'
                            when '2' then '%000'
                        end
                    )
                )
            </if>
        </where>
    </select>
    <insert id="insertBisMajHiddSup" parameterType="com.goldenwater.slaj.hidd.domain.BisMajHiddSup">
        insert into bis_maj_hidd_sup (guid, hidd_guid, is_list, rect_peri, sup_lare_id, sup_date, sup_wiun_code, sup_leg_pers, sup_opin, sup_stat, note, coll_time, upd_time, rec_pers)
        values (#{guid}, #{hiddGuid}, #{isList}, #{rectPeri}, #{supLareId}, #{supDate}, #{supWiunCode}, #{supLegPers}, #{supOpin}, #{supStat}, #{note}, #{collTime}, #{updTime}, #{recPers})
    </insert>
    <update id="updateBisMajHiddSup" parameterType="com.goldenwater.slaj.hidd.domain.BisMajHiddSup">
        update bis_maj_hidd_sup
        <set>
            <if test="hiddGuid != null">hidd_guid = #{hiddGuid},</if>
            <if test="isList != null">is_list = #{isList},</if>
            <if test="rectPeri != null">rect_peri = #{rectPeri},</if>
            <if test="supLareId != null">sup_lare_id = #{supLareId},</if>
            <if test="supDate != null">sup_date = #{supDate},</if>
            <if test="supWiunCode != null">sup_wiun_code = #{supWiunCode},</if>
            <if test="supLegPers != null">sup_leg_pers = #{supLegPers},</if>
            <if test="supOpin != null">sup_opin = #{supOpin},</if>
            <if test="supStat != null">sup_stat = #{supStat},</if>
            <if test="note != null">note = #{note},</if>
            <if test="collTime != null">coll_time = #{collTime},</if>
            <if test="updTime != null">upd_time = #{updTime},</if>
            <if test="recPers != null">rec_pers = #{recPers},</if>
        </set>
        where guid = #{guid}
    </update>
    <delete id="deleteBisMajHiddSupByGuid" parameterType="String">
        delete from bis_maj_hidd_sup where guid = #{guid}
    </delete>
    <delete id="deleteBisMajHiddSupByGuids" parameterType="String">
        delete from bis_maj_hidd_sup where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>
</mapper>
