<?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.da.dangan.mapper.DaCatalogMapper">
    
    <resultMap type="DaCatalog" id="DaCatalogResult">
        <result property="id"    column="id"    />
        <result property="muName"    column="mu_name"    />
        <result property="pid"    column="pid"    />
        <result property="ancestors"    column="ancestors"    />
        <result property="orderNum"    column="order_num"    />
        <result property="ywType"    column="yw_type"    />
        <result property="status"    column="status"    />
        <result property="remark"    column="remark"    />
        <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="selectDaCatalogVo">
        select id, mu_name, pid, ancestors, order_num, yw_type, status, remark, create_by, create_time, update_by, update_time from da_catalog
    </sql>

    <select id="selectDaCatalogList" parameterType="DaCatalog" resultMap="DaCatalogResult">
        <include refid="selectDaCatalogVo"/>
        <where>  
            <if test="muName != null  and muName != ''"> and mu_name like concat('%', #{muName}, '%')</if>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="ancestors != null  and ancestors != ''"> and ancestors = #{ancestors}</if>
            <if test="orderNum != null "> and order_num = #{orderNum}</if>
            <if test="ywType != null  and ywType != ''"> and yw_type = #{ywType}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectDaCatalogById" parameterType="Long" resultMap="DaCatalogResult">
        <include refid="selectDaCatalogVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertDaCatalog" parameterType="DaCatalog" useGeneratedKeys="true" keyProperty="id">
        insert into da_catalog
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="muName != null and muName != ''">mu_name,</if>
            <if test="pid != null">pid,</if>
            <if test="ancestors != null">ancestors,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="ywType != null">yw_type,</if>
            <if test="status != null">status,</if>
            <if test="remark != null">remark,</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="muName != null and muName != ''">#{muName},</if>
            <if test="pid != null">#{pid},</if>
            <if test="ancestors != null">#{ancestors},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="ywType != null">#{ywType},</if>
            <if test="status != null">#{status},</if>
            <if test="remark != null">#{remark},</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="updateDaCatalog" parameterType="DaCatalog">
        update da_catalog
        <trim prefix="SET" suffixOverrides=",">
            <if test="muName != null and muName != ''">mu_name = #{muName},</if>
            <if test="pid != null">pid = #{pid},</if>
            <if test="ancestors != null">ancestors = #{ancestors},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="ywType != null">yw_type = #{ywType},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remark != null">remark = #{remark},</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="deleteDaCatalogById" parameterType="Long">
        delete from da_catalog where id = #{id}
    </delete>

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