<?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.jeethink.manage.mapper.AuthenticateMapper">
    
    <resultMap type="ArchivesMaster" id="archiveAuthenticateResult">
        <result property="archivesId"    column="archives_id"    />
        <result property="name"    column="name"    />
        <result property="archiveNo"    column="archive_no"    />
        <result property="type"    column="type"    />
        <result property="peopleType"    column="people_type"    />
        <result property="tier"    column="tier"    />
        <result property="classified"    column="classified"    />
        <result property="duration"    column="duration"    />
        <result property="ifPaper"    column="if_paper"    />
        <result property="gdPeopleId"    column="gd_people_id"    />
        <result property="userId"    column="user_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createUser"    column="create_user"    />
        <result property="updateUser"    column="update_user"    />
        <result property="deleted"    column="deleted"    />
        <result property="userNumber"    column="user_number"    />
        <result property="deptId"    column="dept_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectarchiveAuthenticateVo">
        select am.archives_id, am.name, am.archive_no, am.type, am.people_type, am.tier, am.classified, am.duration,
               am.if_paper, am.gd_people_id, am.destroy_type, am.put_type,am.out_type, am.user_id, am.create_time,
               am.update_time, am.create_user, am.update_user, am.deleted,am.user_name,am.user_number,
               su.nick_name,sd.dept_name
        from archives_master am left JOIN sys_user su on am.user_id = su.user_id
                                left JOIN sys_dept sd on su.dept_id = sd.dept_id
    </sql>

    <select id="selectarchiveAuthenticateList" parameterType="ArchivesMaster" resultMap="archiveAuthenticateResult">
        <include refid="selectarchiveAuthenticateVo"/>
        <where>
            1=1
            and am.deleted = '0'
            and am.destroy_type='0'
            <if test="name != null  and name != ''"> and am.name like  concat('%', #{name}, '%')</if>
            <if test="peopleType != null  and peopleType != ''"> and  am.people_type = #{peopleType}</if>
            <if test="userId != null  and userId != ''"> and su.user_id = #{userId}</if>
            <if test="deptId != null  and deptId != '' and deptId != 100"> and (sd.dept_id = #{deptId} or sd.parent_id=#{deptId})</if>
        </where>
    </select>
    
    <select id="selectarchiveAuthenticateById" parameterType="String" resultMap="archiveAuthenticateResult">
        select archives_id, name, archive_no, type, people_type, tier, classified, duration, if_paper, gd_people_id, destroy_type, put_type,
               out_type, am.user_id, am.create_time, am.update_time, am.create_user, am.update_user, deleted ,u.nick_name user_name,u.user_num user_number
        from archives_master am
                 left join sys_user u on u.user_id=am.user_id
        where  archives_id = #{archivesId}
    </select>
        
    <insert id="insertarchiveAuthenticate" parameterType="ArchivesMaster">
        insert into archives_master
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="archivesId != null">archives_id,</if>
            <if test="name != null">name,</if>
            <if test="archiveNo != null">archive_no,</if>
            <if test="type != null">type,</if>
            <if test="peopleType != null">people_type,</if>
            <if test="tier != null">tier,</if>
            <if test="classified != null">classified,</if>
            <if test="duration != null">duration,</if>
            <if test="ifPaper != null">if_paper,</if>
            <if test="gdPeopleId != null">gd_people_id,</if>
            <if test="destroyType != null">destroy_type,</if>
            <if test="putType != null">put_type,</if>
            <if test="outType != null">out_type,</if>
            <if test="userId != null">user_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createUser != null">create_user,</if>
            <if test="updateUser != null">update_user,</if>
            <if test="deleted != null">deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="archivesId != null">#{archivesId},</if>
            <if test="name != null">#{name},</if>
            <if test="archiveNo != null">#{archiveNo},</if>
            <if test="type != null">#{type},</if>
            <if test="peopleType != null">#{peopleType},</if>
            <if test="tier != null">#{tier},</if>
            <if test="classified != null">#{classified},</if>
            <if test="duration != null">#{duration},</if>
            <if test="ifPaper != null">#{ifPaper},</if>
            <if test="gdPeopleId != null">#{gdPeopleId},</if>
            <if test="destroyType != null">#{destroyType},</if>
            <if test="putType != null">#{putType},</if>
            <if test="outType != null">#{outType},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="deleted != null">#{deleted},</if>
         </trim>
    </insert>

    <update id="updatearchiveAuthenticate" parameterType="ArchivesMaster">
        update archives_master
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="archiveNo != null">archive_no = #{archiveNo},</if>
            <if test="type != null">type = #{type},</if>
            <if test="peopleType != null">people_type = #{peopleType},</if>
            <if test="tier != null">tier = #{tier},</if>
            <if test="classified != null">classified = #{classified},</if>
            <if test="duration != null">duration = #{duration},</if>
            <if test="ifPaper != null">if_paper = #{ifPaper},</if>
            <if test="gdPeopleId != null">gd_people_id = #{gdPeopleId},</if>
            <if test="destroyType != null">destroy_type = #{destroyType},</if>
            <if test="putType != null">put_type = #{putType},</if>
            <if test="outType != null">out_type = #{outType},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createUser != null">create_user = #{createUser},</if>
            <if test="updateUser != null">update_user = #{updateUser},</if>
            <if test="deleted != null">deleted = #{deleted},</if>
        </trim>
        where archives_id = #{archivesId}
    </update>

    <delete id="deletearchiveAuthenticateById" parameterType="String">
        delete from archives_master where archives_id = #{archivesId}
    </delete>

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