<?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.bean.mapper.ArchivesMapper">
    <sql id="selectArchivesVo">
        select a.archives_id, a.name, a.archive_no, a.type, a.people_type, a.tier, a.classified, a.duration, a.if_paper,
               a.gd_people_id, a.create_time, a.update_time, a.now_status, u.nick_name user_name, u.user_num user_number,
               d.dept_name, su.nick_name as updater_name,a.warehouse_type
        from archives_master a
        left join sys_user u on a.user_id = a.user_id
        left join sys_dept d on u.dept_id = d.dept_id
        left join sys_user su on su.user_id = a.update_user
        where a.deleted = '0'
    </sql>
    <sql id="selectHistory">
        select a.archives_id, a.name, a.archive_no, a.type, a.people_type, a.tier, a.classified, a.duration, a.if_paper,
               a.gd_people_id, a.create_time, a.update_time, a.now_status, u.nick_name user_name, u.user_num user_number,
               d.dept_name, su.nick_name as updater_name
        from archives_master a
        left join sys_user u on a.user_id = a.user_id
        left join sys_dept d on u.dept_id = d.dept_id
        left join sys_user su on su.user_id = a.update_user
        left join flow f on f.object_id = a.archives_id
        where a.deleted = '0' and f.deleted = '0'
    </sql>

    <update id="changeNowStatus">
        update archives_master set now_status = #{nowStatus}, update_user = #{updateUser}, update_time = now() where archives_id = #{archivesId}
    </update>
    <select id="selectArchivesById" resultMap="archivesMap">
        <include refid="selectArchivesVo"/>
        and a.archives_id = #{0}
    </select>
    <select id="selectStatusArchivesList" resultMap="archivesMap">
        <include refid="selectArchivesVo"/>
        and a.now_status = #{nowStatus}
        /*todo 其他查询条件*/
    </select>
    <select id="selectArchivesHistory" resultMap="archivesMap">
        <include refid="selectHistory"/>
        and f.flow_type = #{flowType}
        /*todo 其他查询条件*/
    </select>
    <select id="selectUserArchivesHistory" resultMap="archivesMap">
        <include refid="selectHistory"/>
        and f.flow_type = #{flowType} and f.create_by = #{userName}
        /*todo 其他查询条件*/
    </select>


    <resultMap id="archivesMap" type="ArchivesMaster">
        <id column="archives_id" property="archivesId"/>
        <result column="name" property="name"/>
        <result column="archive_no" property="archiveNo"/>
        <result column="type" property="type"/>
        <result column="people_type" property="peopleType"/>
        <result column="tier" property="tier"/>
        <result column="classified" property="classified"/>
        <result column="duration" property="duration"/>
        <result column="if_paper" property="ifPaper"/>
        <result column="gd_people_id" property="gdPeopleId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="now_status" property="nowStatus"/>
        <result column="nick_name" property="nickName"/>
        <result column="user_number" property="userNumber"/>
        <result column="dept_name" property="deptName"/>
        <result column="updater_name" property="updaterName"/>
    </resultMap>
</mapper>