<?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.TPublicdocMapper">
    
    <resultMap type="TPublicdoc" id="TPublicdocResult">
        <result property="id"    column="id"    />
        <result property="filename"    column="filename"    />
        <result property="menuid"    column="menuid"    />
        <result property="responsibility"    column="responsibility"    />
        <result property="action"    column="action"    />
        <result property="location"    column="location"    />
        <result property="frequency"    column="frequency"    />
        <result property="filedate"    column="filedate"    />
        <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="deptName" column="dept_name" />
        <result property="menuName" column="cataname" />
        <result property="itemFirst"    column="item_first"    />
        <result property="itemSecond"    column="item_second"    />
        <result property="itemThird"    column="item_third"    />
    </resultMap>

    <sql id="selectTPublicdocVo">
        select p.cataname, d.id, d.filename, d.menuid, d.responsibility, d.action, d.location, d.frequency, d.filedate, 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_publicdoc d
      left join sys_dept s on s.dept_id = d.dept_id
      left join t_publicdocmenu p on p.id = d.menuid
    </sql>

    <select id="selectTPublicdocList" parameterType="TPublicdoc" resultMap="TPublicdocResult">
        <include refid="selectTPublicdocVo"/>
        <where>
            <if test="menuid != null  and menuid != ''"> and menuid = #{menuid}</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="selectTPublicdocById" parameterType="Long" resultMap="TPublicdocResult">
        <include refid="selectTPublicdocVo"/>
        where d.id = #{id}
    </select>
        
    <insert id="insertTPublicdoc" parameterType="TPublicdoc">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_publicdoc.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_publicdoc
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="filename != null and filename != ''">filename,</if>
            <if test="menuid != null and menuid != ''">menuid,</if>
            <if test="responsibility != null">responsibility,</if>
            <if test="action != null">action,</if>
            <if test="location != null">location,</if>
            <if test="frequency != null">frequency,</if>
            <if test="filedate != null">filedate,</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="filename != null and filename != ''">#{filename},</if>
            <if test="menuid != null and menuid != ''">#{menuid},</if>
            <if test="responsibility != null">#{responsibility},</if>
            <if test="action != null">#{action},</if>
            <if test="location != null">#{location},</if>
            <if test="frequency != null">#{frequency},</if>
            <if test="filedate != null">#{filedate},</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="updateTPublicdoc" parameterType="TPublicdoc">
        update t_publicdoc
        <trim prefix="SET" suffixOverrides=",">
            <if test="filename != null and filename != ''">filename = #{filename},</if>
            <if test="menuid != null and menuid != ''">menuid = #{menuid},</if>
            <if test="responsibility != null">responsibility = #{responsibility},</if>
            <if test="action != null">action = #{action},</if>
            <if test="location != null">location = #{location},</if>
            <if test="frequency != null">frequency = #{frequency},</if>
            <if test="filedate != null">filedate = #{filedate},</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="deleteTPublicdocById" parameterType="Long">
        update t_publicdoc set del_flag = 2 where id = #{id}
    </update>

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