<?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="cn.gov.customs.wxjy.base.dao.ChemicalsCatalogMapper">

    <resultMap type="ChemicalsCatalog" id="ChemicalsCatalogResult">
        <result property="id" column="ID"/>
        <result property="dangerName" column="DANGER_NAME"/>
        <result property="enName" column="EN_NAME"/>
        <result property="chAlias" column="CH_ALIAS"/>
        <result property="enAlias" column="EN_ALIAS"/>
        <result property="chemicalsEq" column="CHEMICALS_EQ"/>
        <result property="cas" column="CAS"/>
        <result property="unCode" column="UN_CODE"/>
        <result property="dangerStatement" column="DANGER_STATEMENT"/>
        <result property="preventStatement" column="PREVENT_STATEMENT"/>
        <result property="chSignalWord" column="CH_SIGNAL_WORD"/>
        <result property="enSignalWord" column="EN_SIGNAL_WORD"/>
        <result property="signs" column="SIGNS"/>
        <result property="remark" column="REMARK"/>
        <result property="createUser" column="CREATE_USER"/>
        <result property="createDept" column="CREATE_DEPT"/>
        <result property="createTime" column="CREATE_TIME"/>
        <result property="updateUser" column="UPDATE_USER"/>
        <result property="updateTime" column="UPDATE_TIME"/>
        <result property="isDeleted" column="IS_DELETED"/>
        <result property="status" column="STATUS"/>
        <result property="indexNum" column="INDEX_NUM"/>
    </resultMap>

    <sql id="baseVo">
        select ID, DANGER_NAME, EN_NAME, CH_ALIAS, EN_ALIAS, CHEMICALS_EQ, CAS, UN_CODE, DANGER_STATEMENT, PREVENT_STATEMENT, CH_SIGNAL_WORD, EN_SIGNAL_WORD, SIGNS, REMARK, CREATE_USER, CREATE_DEPT, CREATE_TIME, UPDATE_USER, UPDATE_TIME, IS_DELETED, STATUS, INDEX_NUM
        from WXJY_CHEMICALS_CATALOG
    </sql>

    <select id="selectList" parameterType="ChemicalsCatalogQuery" resultMap="ChemicalsCatalogResult">
        <include refid="baseVo"/>
        <where>
            and IS_DELETED = 0
        <if test="dangerName != null  and dangerName != ''">
            and DANGER_NAME like concat('%', #{dangerName}, '%')
        </if>
        <if test="enName != null  and enName != ''">
            and EN_NAME like concat('%', #{enName}, '%')
        </if>
        <if test="chAlias != null  and chAlias != ''">
            and CH_ALIAS = #{chAlias}
        </if>
        <if test="enAlias != null  and enAlias != ''">
            and EN_ALIAS = #{enAlias}
        </if>
        <if test="chemicalsEq != null  and chemicalsEq != ''">
            and CHEMICALS_EQ = #{chemicalsEq}
        </if>
        <if test="cas != null  and cas != ''">
            and CAS like concat('%', #{cas}, '%')
        </if>
        <if test="unCode != null  and unCode != ''">
            and UN_CODE = #{unCode}
        </if>
        <if test="dangerStatement != null  and dangerStatement != ''">
            and DANGER_STATEMENT = #{dangerStatement}
        </if>
        <if test="preventStatement != null  and preventStatement != ''">
            and PREVENT_STATEMENT = #{preventStatement}
        </if>
        <if test="chSignalWord != null  and chSignalWord != ''">
            and CH_SIGNAL_WORD = #{chSignalWord}
        </if>
        <if test="enSignalWord != null  and enSignalWord != ''">
            and EN_SIGNAL_WORD = #{enSignalWord}
        </if>
        <if test="signs != null  and signs != ''">
            and SIGNS = #{signs}
        </if>
        <if test="remark != null  and remark != ''">
            and REMARK = #{remark}
        </if>
        <if test="createUser != null  and createUser != ''">
            and CREATE_USER = #{createUser}
        </if>
        <if test="createDept != null  and createDept != ''">
            and CREATE_DEPT = #{createDept}
        </if>
        <if test="createTime != null  and createTime != ''">
            and CREATE_TIME = #{createTime}
        </if>
        <if test="updateUser != null  and updateUser != ''">
            and UPDATE_USER = #{updateUser}
        </if>
        <if test="updateTime != null ">
            and UPDATE_TIME &gt;= #{updateTime}
        </if>
        <if test="isDeleted != null  and isDeleted != ''">
            and IS_DELETED = #{isDeleted}
        </if>
        <if test="status != null  and status != ''">
            and STATUS = #{status}
        </if>
        <if test="indexNum != null  and indexNum != ''">
            and INDEX_NUM = #{indexNum}
        </if>
        </where>
        order by update_time desc
    </select>

    <select id="selectByID" parameterType="String"
        resultMap="ChemicalsCatalogResult">
        <include refid="baseVo"/>
        where ID = #{ID}
    </select>

    <insert id="insert" parameterType="ChemicalsCatalog">
        insert into WXJY_CHEMICALS_CATALOG
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">id,
            </if>
            <if test="dangerName != null">DANGER_NAME,
            </if>
            <if test="enName != null">EN_NAME,
            </if>
            <if test="chAlias != null">CH_ALIAS,
            </if>
            <if test="enAlias != null">EN_ALIAS,
            </if>
            <if test="chemicalsEq != null">CHEMICALS_EQ,
            </if>
            <if test="cas != null">CAS,
            </if>
            <if test="unCode != null">UN_CODE,
            </if>
            <if test="dangerStatement != null">DANGER_STATEMENT,
            </if>
            <if test="preventStatement != null">PREVENT_STATEMENT,
            </if>
            <if test="chSignalWord != null">CH_SIGNAL_WORD,
            </if>
            <if test="enSignalWord != null">EN_SIGNAL_WORD,
            </if>
            <if test="signs != null">SIGNS,
            </if>
            <if test="remark != null">REMARK,
            </if>
            <if test="createUser != null">CREATE_USER,
            </if>
            <if test="createDept != null">CREATE_DEPT,
            </if>
            <if test="createTime != null">CREATE_TIME,
            </if>
            <if test="updateUser != null">UPDATE_USER,
            </if>
            <if test="updateTime != null">UPDATE_TIME,
            </if>
            <if test="isDeleted != null">IS_DELETED,
            </if>
            <if test="status != null">STATUS,
            </if>
            <if test="indexNum != null">INDEX_NUM,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null and id != ''">#{id},
            </if>
            <if test="dangerName != null">#{dangerName},
            </if>
            <if test="enName != null">#{enName},
            </if>
            <if test="chAlias != null">#{chAlias},
            </if>
            <if test="enAlias != null">#{enAlias},
            </if>
            <if test="chemicalsEq != null">#{chemicalsEq},
            </if>
            <if test="cas != null">#{cas},
            </if>
            <if test="unCode != null">#{unCode},
            </if>
            <if test="dangerStatement != null">#{dangerStatement},
            </if>
            <if test="preventStatement != null">#{preventStatement},
            </if>
            <if test="chSignalWord != null">#{chSignalWord},
            </if>
            <if test="enSignalWord != null">#{enSignalWord},
            </if>
            <if test="signs != null">#{signs},
            </if>
            <if test="remark != null">#{remark},
            </if>
            <if test="createUser != null">#{createUser},
            </if>
            <if test="createDept != null">#{createDept},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateUser != null">#{updateUser},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="isDeleted != null">#{isDeleted},
            </if>
            <if test="status != null">#{status},
            </if>
            <if test="indexNum != null">#{indexNum},
            </if>
        </trim>
    </insert>

    <update id="update" parameterType="ChemicalsCatalog">
        update WXJY_CHEMICALS_CATALOG
        <trim prefix="SET" suffixOverrides=",">
            <if test="dangerName != null">DANGER_NAME =
                #{dangerName},
            </if>
            <if test="enName != null">EN_NAME =
                #{enName},
            </if>
            <if test="chAlias != null">CH_ALIAS =
                #{chAlias},
            </if>
            <if test="enAlias != null">EN_ALIAS =
                #{enAlias},
            </if>
            <if test="chemicalsEq != null">CHEMICALS_EQ =
                #{chemicalsEq},
            </if>
            <if test="cas != null">CAS =
                #{cas},
            </if>
            <if test="unCode != null">UN_CODE =
                #{unCode},
            </if>
            <if test="dangerStatement != null">DANGER_STATEMENT =
                #{dangerStatement},
            </if>
            <if test="preventStatement != null">PREVENT_STATEMENT =
                #{preventStatement},
            </if>
            <if test="chSignalWord != null">CH_SIGNAL_WORD =
                #{chSignalWord},
            </if>
            <if test="enSignalWord != null">EN_SIGNAL_WORD =
                #{enSignalWord},
            </if>
            <if test="signs != null">SIGNS =
                #{signs},
            </if>
            <if test="remark != null">REMARK =
                #{remark},
            </if>
            <if test="createUser != null">CREATE_USER =
                #{createUser},
            </if>
            <if test="createDept != null">CREATE_DEPT =
                #{createDept},
            </if>
            <if test="createTime != null">CREATE_TIME =
                #{createTime},
            </if>
            <if test="updateUser != null">UPDATE_USER =
                #{updateUser},
            </if>
            <if test="updateTime != null">UPDATE_TIME =
                #{updateTime},
            </if>
            <if test="isDeleted != null">IS_DELETED =
                #{isDeleted},
            </if>
            <if test="status != null">STATUS =
                #{status},
            </if>
            <if test="indexNum != null">INDEX_NUM =
                #{indexNum},
            </if>
        </trim>
        where ID = #{id}
    </update>

    <delete id="deleteByID" parameterType="String">
        delete
        from WXJY_CHEMICALS_CATALOG where ID = #{id}
    </delete>

    <delete id="deleteByIDs" parameterType="String">
        delete from WXJY_CHEMICALS_CATALOG where ID in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="logicDelete" parameterType="String">
        update  WXJY_CHEMICALS_CATALOG set is_del = 1  where ID = #{id}
    </delete>
</mapper>