<?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.jeeplus.centrecareful.reportArchieve.mapper.ZsReportArchieveMapper">
    <sql id="base_column_list">
            a.id,
            a.create_by_id,
            a.create_time,
            a.update_by_id,
            a.update_time,
            a.archieve_no,
            a.office_name,
            a.business_name,
            a.business_type,
            a.project,
            a.report_no,
            a.report_no_type,
            a.reporting_period,
            a.filling_manager,
            a.project_leader,
            a.project_master,
            a.signature_cpa,
            a.signature_parter,
            a.project_level,
            a.report_date,
            a.stamp_date,
            a.archieve_date,
            a.file_box_number,
            a.box_number,
            a.book_numbers,
            a.remarks,
            a.original_contract,
            a.total_assets,
            a.archieve_resever,
            a.storage_place,
            a.status
    </sql>
    <select id="findList" resultType="com.jeeplus.centrecareful.reportArchieve.domain.ZsReportArchieve">
        select
            <include refid="base_column_list"></include>,
            su.name as archieveReseverName
        from zs_report_archieve a
        left join sys_user su on a.archieve_resever = su.id and su.del_flag = '0'
        left join sys_office so on a.office_name = so.name and so.del_flag = '0'
        ${ew.customSqlSegment}
        ORDER BY a.update_time DESC
    </select>

    <select id="exportList" resultType="com.jeeplus.centrecareful.reportArchieve.service.dto.ZsReportArchieveExport">
        select
        <include refid="base_column_list"></include>,
        su.name as archieveReseverName
        from zs_report_archieve a
        left join sys_user su on a.archieve_resever = su.id and su.del_flag = '0'
        left join sys_office so on a.office_name = so.name and so.del_flag = '0'
        ${ew.customSqlSegment}
        ORDER BY a.update_time DESC
    </select>

    <select id="getOfficeNameList" resultType="com.jeeplus.centrecareful.reportArchieve.domain.ZsReportArchieve">
        SELECT office_name from zs_report_archieve where del_flag = '0' GROUP BY office_name
    </select>

    <select id="getOfficeDTOByName" resultType="com.jeeplus.sys.service.dto.OfficeDTO">
        select * from sys_office where name = #{name} and del_flag = '0'
    </select>

    <select id="findById" resultType="com.jeeplus.centrecareful.reportArchieve.domain.ZsReportArchieve">
        select
        <include refid="base_column_list"></include>,
        su.name as archieveReseverName
        from zs_report_archieve a
        left join sys_user su on a.archieve_resever = su.id and su.del_flag = '0'
        left join sys_office so on a.office_name = so.name and so.del_flag = '0'
        where a.id = #{id} and a.del_flag = '0'
    </select>

    <select id="findByReportNoType" resultType="com.jeeplus.centrecareful.reportArchieve.domain.ZsReportArchieve">
        select
        <include refid="base_column_list"></include>,
        su.name as updateName
        from zs_report_archieve a
        left join sys_user su on a.update_by_id = su.id and su.del_flag = '0'
        where a.report_no_type = #{reportNoType} and a.del_flag = '0' order by a.file_box_number DESC limit 1
    </select>

    <select id="findByReportNo" resultType="com.jeeplus.centrecareful.reportArchieve.domain.ZsReportArchieve">
        select
        <include refid="base_column_list"></include>,
        su.name as updateName
        from zs_report_archieve a
        left join sys_user su on a.update_by_id = su.id and su.del_flag = '0'
        where a.report_no = #{reportNo} and a.del_flag = '0' order by a.file_box_number DESC limit 1
    </select>

    <select id="findByFileBoxNumber" resultType="com.jeeplus.centrecareful.reportArchieve.domain.ZsReportArchieve">
        select
        <include refid="base_column_list"></include>,
        su.name as updateName
        from zs_report_archieve a
        left join sys_user su on a.update_by_id = su.id and su.del_flag = '0'
        where a.report_no_type = #{reportNoType} and a.file_box_number = #{fileBoxNumber} and a.del_flag = '0'
    </select>
</mapper>