<?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.srs.comprehensive.mapper.CphLakeTypeMapper">
    
    <resultMap type="CphLakeType" id="CphLakeTypeResult">
        <result property="id"    column="id"    />
        <result property="typeName"    column="type_name"    />
        <result property="typeCode"    column="type_code"    />
        <result property="parentCode"    column="parent_code"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectCphLakeTypeVo">
        select id, type_name, type_code, parent_code, create_by, create_time, update_by, update_time from cph_lake_type
    </sql>

    <select id="selectCphLakeTypeList" parameterType="CphLakeType" resultMap="CphLakeTypeResult">
        <include refid="selectCphLakeTypeVo"/>
        <where>  
            <if test="typeName != null  and typeName != ''"> and type_name like concat('%', #{typeName}, '%')</if>
            <if test="typeCode != null  and typeCode != ''"> and type_code = #{typeCode}</if>
            <if test="parentCode != null  and parentCode != ''"> and parent_code = #{parentCode}</if>
        </where>
    </select>

    <select id="listSelect" resultType="CphLakeType">
        select a.type_name,a.type_code
        from cph_lake_type as a
        where a.type_code &lt;&gt; "BMYXDXS"
    </select>

    <select id="listOneHundred" resultType="CphLakeType">
        select a.type_name,a.type_code
        from cph_lake_type as a
        where a.parent_code = 'BMYXDXS'
    </select>
    
    <select id="selectCphLakeTypeById" parameterType="Long" resultMap="CphLakeTypeResult">
        <include refid="selectCphLakeTypeVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertCphLakeType" parameterType="CphLakeType" useGeneratedKeys="true" keyProperty="id">
        insert into cph_lake_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="typeName != null">type_name,</if>
            <if test="typeCode != null">type_code,</if>
            <if test="parentCode != null">parent_code,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="typeName != null">#{typeName},</if>
            <if test="typeCode != null">#{typeCode},</if>
            <if test="parentCode != null">#{parentCode},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateCphLakeType" parameterType="CphLakeType">
        update cph_lake_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="typeName != null">type_name = #{typeName},</if>
            <if test="typeCode != null">type_code = #{typeCode},</if>
            <if test="parentCode != null">parent_code = #{parentCode},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCphLakeTypeById" parameterType="Long">
        delete from cph_lake_type where id = #{id}
    </delete>

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