<?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.hazard.mapper.ObjHachMapper">
    <resultMap type="com.goldenwater.slaj.hazard.domain.ObjHachVo" id="ObjHachResult">
        <result property="guid" column="guid"/>
        <result property="hachName" column="hach_name"/>
        <result property="orgGuid" column="org_guid"/>
        <result property="chemName" column="chem_name"/>
        <result property="locName" column="loc_name"/>
        <result property="toxicSubsNum" column="toxic_subs_num"/>
        <result property="dangNum" column="dang_num"/>
        <result property="currRese" column="curr_rese"/>
        <result property="storPack" column="stor_pack"/>
        <result property="ovduProcMode" column="ovdu_proc_mode"/>
        <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="toDate" column="to_date"/>
        <result property="orgName" column="org_name"/>
    </resultMap>
    <sql id="selectObjHachVo">
        select h.guid, h.hach_name, h.org_guid, h.chem_name, h.loc_name, h.toxic_subs_num,
               h.dang_num, h.curr_rese, h.stor_pack, h.ovdu_proc_mode, h.note, h.coll_time,
               h.upd_time, h.rec_pers, h.to_date,
               o.org_name
        from obj_hach h
        left join att_org_base o on h.org_guid = o.guid
    </sql>
    <select id="selectObjHachByGuid" parameterType="String" resultMap="ObjHachResult">
        <include refid="selectObjHachVo"/>
        where h.guid = #{guid}
    </select>
    <select id="selectObjHachList" parameterType="com.goldenwater.slaj.hazard.domain.ObjHachVo" resultMap="ObjHachResult">
        <include refid="selectObjHachVo"/>
        <where>
            <if test="hachName != null and hachName != ''">AND h.hach_name like '%' || #{hachName} || '%'</if>
            <if test="orgGuid != null and orgGuid != ''">AND h.org_guid = #{orgGuid}</if>
            <if test="chemName != null and chemName != ''">AND h.chem_name like '%' || #{chemName} || '%'</if>
            <if test="guid != null and guid != ''">AND h.guid = #{guid}</if>
            <if test="orgName != null and orgName != ''">AND o.org_name like '%' || #{orgName} || '%'</if>
            <if test="wiunProp != null and wiunProp != ''">AND EXISTS (SELECT 1 FROM att_org_ext ext WHERE ext.org_guid = h.org_guid AND ext.wiun_prop = #{wiunProp})</if>
            <if test="beginCollTime != null and beginCollTime != ''">AND h.coll_time >= #{beginCollTime}</if>
            <if test="endCollTime != null and endCollTime != ''">AND h.coll_time &lt;= #{endCollTime}</if>
        </where>
    </select>
    <insert id="insertObjHach" parameterType="com.goldenwater.slaj.hazard.domain.ObjHach">
        insert into obj_hach (
            guid, hach_name, org_guid, chem_name, loc_name, toxic_subs_num,
            dang_num, curr_rese, stor_pack, ovdu_proc_mode, note, coll_time,
            upd_time, rec_pers, to_date
        ) values (
            #{guid}, #{hachName}, #{orgGuid}, #{chemName}, #{locName}, #{toxicSubsNum},
            #{dangNum}, #{currRese}, #{storPack}, #{ovduProcMode}, #{note}, #{collTime},
            #{updTime}, #{recPers}, #{toDate}
        )
    </insert>
    <update id="updateObjHach" parameterType="com.goldenwater.slaj.hazard.domain.ObjHach">
        update obj_hach
        <set>
            <if test="hachName != null">hach_name = #{hachName},</if>
            <if test="orgGuid != null">org_guid = #{orgGuid},</if>
            <if test="chemName != null">chem_name = #{chemName},</if>
            <if test="locName != null">loc_name = #{locName},</if>
            <if test="toxicSubsNum != null">toxic_subs_num = #{toxicSubsNum},</if>
            <if test="dangNum != null">dang_num = #{dangNum},</if>
            <if test="currRese != null">curr_rese = #{currRese},</if>
            <if test="storPack != null">stor_pack = #{storPack},</if>
            <if test="ovduProcMode != null">ovdu_proc_mode = #{ovduProcMode},</if>
            <if test="note != null">note = #{note},</if>
            <if test="updTime != null">upd_time = #{updTime},</if>
            <if test="recPers != null">rec_pers = #{recPers},</if>
            <if test="toDate != null">to_date = #{toDate},</if>
        </set>
        where guid = #{guid}
    </update>
    <delete id="deleteObjHachByGuid" parameterType="String">
        delete from obj_hach where guid = #{guid}
    </delete>
    <delete id="deleteObjHachByGuids" parameterType="String">
        delete from obj_hach where guid in
        <foreach item="guid" collection="array" open="(" separator="," close=")">
            #{guid}
        </foreach>
    </delete>
</mapper>
