<?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.ruoyi.project.document.mapper.TPublicdocmenuMapper">
    
    <resultMap type="TPublicdocmenu" id="TPublicdocmenuResult">
        <result property="id"    column="id"    />
        <result property="cataname"    column="cataname"    />
        <result property="catano"    column="catano"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="remarks"    column="remarks"    />
        <result property="deptId"    column="dept_id"    />
        <result property="itemFirst"    column="item_first"    />
        <result property="itemSecond"    column="item_second"    />
        <result property="itemThird"    column="item_third"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTPublicdocmenuVo">
        select d.id, d.cataname, d.catano, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id, d.item_first, d.item_second, d.item_third ,s.dept_name from t_publicdocmenu d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTPublicdocmenuList" parameterType="TPublicdocmenu" resultMap="TPublicdocmenuResult">
        <include refid="selectTPublicdocmenuVo"/>
        <where>
            <if test="cataname != null and cataname != ''">
                AND cataname like concat(concat('%',#{cataname}),'%')
            </if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        ORDER BY d.item_first asc, d.item_second asc, d.item_third asc
    </select>
    
    <select id="selectTPublicdocmenuById" parameterType="Long" resultMap="TPublicdocmenuResult">
        <include refid="selectTPublicdocmenuVo"/>
        where id = #{id}
    </select>

    <select id="selectTPublicdocmenuByCatano" parameterType="String" resultMap="TPublicdocmenuResult">
        <include refid="selectTPublicdocmenuVo"/>
        where cataname = #{cataname}
    </select>
        
    <insert id="insertTPublicdocmenu" parameterType="TPublicdocmenu">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_publicdocmenu.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_publicdocmenu
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="cataname != null and cataname != ''">cataname,</if>
            <if test="catano != null and catano != ''">catano,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="remarks != null">remarks,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="itemFirst != null">item_first,</if>
            <if test="itemSecond != null">item_second,</if>
            <if test="itemThird != null">item_third,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="cataname != null and cataname != ''">#{cataname},</if>
            <if test="catano != null and catano != ''">#{catano},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="itemFirst != null">#{itemFirst},</if>
            <if test="itemSecond != null">#{itemSecond},</if>
            <if test="itemThird != null">#{itemThird},</if>
         </trim>
    </insert>

    <update id="updateTPublicdocmenu" parameterType="TPublicdocmenu">
        update t_publicdocmenu
        <trim prefix="SET" suffixOverrides=",">
            <if test="cataname != null and cataname != ''">cataname = #{cataname},</if>
            <if test="catano != null and catano != ''">catano = #{catano},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="itemFirst != null">item_first = #{itemFirst},</if>
            <if test="itemSecond != null">item_second = #{itemSecond},</if>
            <if test="itemThird != null">item_third = #{itemThird},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTPublicdocmenuById" parameterType="Long">
        update t_publicdocmenu set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTPublicdocmenuByIds" parameterType="String">
        update t_publicdocmenu set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>