<?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.test.cw.projectReportArchive.mapper.CwProjectReportArchiveDetailMapper">

    <select id="findList" resultType="com.jeeplus.test.cw.projectReportArchive.service.dto.CwProjectReportArchiveDetailDTO">
        select a.id as 'id',
        a.report_no as 'reportNo',
        date_format(a.report_date,'%Y-%m-%d') as 'reportDate',
        date_format(pra.audit_date,'%Y-%m-%d') as 'auditDate',
        p.id as 'projectId',
        p.id as 'cwProjectRecordsDTO.id',
        pm.name as 'projectMasterName',
        pm.name as 'cwProjectRecordsDTO.projectMasterName',
        p.project_name as 'projectName',
        p.project_name as 'cwProjectRecordsDTO.projectName',
        su1.name as 'signatureAnnotatorName1',
        su2.name as 'signatureAnnotatorName2',
        pra.number as 'number',
        (case when pra.audit_date is null then timestampdiff(day,a.report_date,now()) when pra.audit_date is not null then timestampdiff(day,a.report_date,pra.audit_date) end) as archiveDay
        from cw_project_report_new_line a
        LEFT JOIN cw_project_report pr ON pr.id = a.report_id
        LEFT JOIN sys_user su1 ON su1.id = pr.signature_annotator1
        LEFT JOIN sys_user su2 ON su2.id = pr.signature_annotator2
        LEFT JOIN cw_project_records p ON p.id = pr.project_id
        LEFT JOIN sys_user pm ON pm.id = p.project_master_id
        LEFT JOIN cw_project_report_archive_report prar ON a.id = prar.report_id
        LEFT JOIN cw_project_report_archive pra ON pr.id = pra.report_id
        ${ew.customSqlSegment}
        and a.report_number is not null and a.report_date is not null
        <if test="cwProjectReportArchiveDetailDTO.status == '超期未归档'">
            and pra.audit_date is null and timestampdiff(day,a.report_date,now())>60
        </if>
        <if test="cwProjectReportArchiveDetailDTO.status == '暂时未归档'">
            and pra.audit_date is null and timestampdiff(day,a.report_date,now()) &lt;= 60
        </if>
        <if test="cwProjectReportArchiveDetailDTO.status == '已超期归档'">
            and pra.audit_date is not null and timestampdiff(day,a.report_date,pra.audit_date)>60
        </if>
        <if test="cwProjectReportArchiveDetailDTO.status == '已按时归档'">
            and pra.audit_date is not null and timestampdiff(day,a.report_date,pra.audit_date) &lt;= 60
        </if>

        order by a.report_date asc
    </select>
</mapper>
