<?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.BisHiddRecRepMapper">
    <resultMap type="com.goldenwater.slaj.hidd.domain.BisHiddRecRep" id="BisHiddRecRepResult">
        <result property="guid" column="guid"/>
        <result property="hiddGuid" column="hidd_guid"/>
        <result property="repOrgGuid" column="rep_org_guid"/>
        <result property="repAct" column="rep_act"/>
        <result property="returnDesc" column="return_desc"/>
        <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="repGuid" column="rep_guid"/>
    </resultMap>
    <sql id="selectBisHiddRecRepVo">
        select guid, hidd_guid, rep_org_guid, rep_act, return_desc, note, coll_time, upd_time, rec_pers, rep_guid
        from bis_hidd_rec_rep
    </sql>
    <select id="selectBisHiddRecRepByGuid" parameterType="String" resultMap="BisHiddRecRepResult">
        <include refid="selectBisHiddRecRepVo"/>
        where guid = #{guid}
    </select>
    <select id="selectBisHiddRecRepList" parameterType="com.goldenwater.slaj.hidd.domain.BisHiddRecRep" resultMap="BisHiddRecRepResult">
        <include refid="selectBisHiddRecRepVo"/>
        <where>
            <if test="hiddGuid != null and hiddGuid != ''">AND hidd_guid = #{hiddGuid}</if>
            <if test="repOrgGuid != null and repOrgGuid != ''">AND rep_org_guid = #{repOrgGuid}</if>
            <if test="guid != null and guid != ''">AND guid = #{guid}</if>
        </where>
    </select>
    <insert id="insertBisHiddRecRep" parameterType="com.goldenwater.slaj.hidd.domain.BisHiddRecRep">
        insert into bis_hidd_rec_rep (guid, hidd_guid, rep_org_guid, rep_act, return_desc, note, coll_time, upd_time, rec_pers, rep_guid)
        values (#{guid}, #{hiddGuid}, #{repOrgGuid}, #{repAct}, #{returnDesc}, #{note}, #{collTime}, #{updTime}, #{recPers}, #{repGuid})
    </insert>
    <update id="updateBisHiddRecRep" parameterType="com.goldenwater.slaj.hidd.domain.BisHiddRecRep">
        update bis_hidd_rec_rep
        <set>
            <if test="hiddGuid != null">hidd_guid = #{hiddGuid},</if>
            <if test="repOrgGuid != null">rep_org_guid = #{repOrgGuid},</if>
            <if test="repAct != null">rep_act = #{repAct},</if>
            <if test="returnDesc != null">return_desc = #{returnDesc},</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>
            <if test="repGuid != null">rep_guid = #{repGuid},</if>
        </set>
        where guid = #{guid}
    </update>
    <delete id="deleteBisHiddRecRepByGuid" parameterType="String">
        delete from bis_hidd_rec_rep where guid = #{guid}
    </delete>
    <delete id="deleteBisHiddRecRepByGuids" parameterType="String">
        delete from bis_hidd_rec_rep where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>
    <delete id="deleteBisHiddRecRepByRepGuid" parameterType="String">
        delete from bis_hidd_rec_rep where rep_guid = #{repGuid}
    </delete>

    <resultMap type="java.util.Map" id="BisHiddRecRepWithHiddResult">
        <result property="guid" column="guid"/>
        <result property="hiddGuid" column="hidd_guid"/>
        <result property="repGuid" column="rep_guid"/>
        <result property="hiddName" column="hidd_name"/>
        <result property="hiddGrad" column="hidd_grad"/>
        <result property="hiddStat" column="hidd_stat"/>
        <result property="proPart" column="pro_part"/>
        <result property="collTime" column="coll_time"/>
        <result property="orgName" column="org_name"/>
        <result property="engName" column="eng_name"/>
        <result property="inspDate" column="insp_date"/>
        <result property="requCompDate" column="requ_comp_date"/>
        <result property="factCompDate" column="fact_comp_date"/>
    </resultMap>
    <select id="selectBisHiddRecRepWithHiddByRepGuid" parameterType="String" resultMap="BisHiddRecRepWithHiddResult">
        SELECT r.guid, r.hidd_guid, r.rep_guid,
               h.hidd_name, h.hidd_grad, h.hidd_stat, h.pro_part, r.coll_time,
               ao.org_name,
               e.eng_name,
               bi.insp_date,
               ri.requ_comp_date,
               ra.accep_date AS fact_comp_date
        FROM bis_hidd_rec_rep r
        LEFT JOIN obj_hidd h ON r.hidd_guid = h.guid
        LEFT JOIN att_org_base ao ON h.org_guid = ao.guid
        LEFT JOIN obj_eng e ON h.eng_guid = e.guid
        LEFT JOIN bis_hidd_inve bi ON h.insp_rec_guid = bi.guid
        LEFT JOIN bis_hidd_rect_impl ri ON h.guid = ri.hidd_guid
        LEFT JOIN bis_hidd_rect_acce ra ON h.guid = ra.hidd_guid
        WHERE r.rep_guid = #{repGuid}
    </select>
</mapper>
