<?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.finance.reportCancellApply.mapper.ReportCancellApplyMapper">
    <select id="findList" resultType="com.jeeplus.finance.reportCancellApply.service.dto.ReportInfoDto">
        SELECT a.document_no,
         case a.`status` WHEN '5' THEN '已完成' END as documentStatus,
         su3.name as reportSponsor,
        b.report_no,
        cw_re.review_status,
        c.project_name,
        c.project_master_id,
        c.real_header as project_master2_id,
        su.name as user_name,
        su2.name as project_master_name,
        suu.name as project_master2_name,
        b.id as report_new_line_id
        FROM cw_project_report a
        left join cw_project_report_new_line b
        on a.id = b.report_id and b.del_flag = '0'
        LEFT JOIN cw_project_records c
        on a.project_id = c.id and c.del_flag = '0'
        left join cw_project_report_review cw_re on a.id = cw_re.id and cw_re.del_flag = '0'
        left join sys_user su on su.id = a.create_by_id and su.del_flag = '0'
        left join sys_user suu on suu.id = c.real_header and suu.del_flag = '0'
        left join sys_user su2 on su2.id = c.project_master_id and su2.del_flag = '0'
        left join sys_user su3 on su3.id = a.create_by_id and su3.del_flag = '0'
        ${ew.customSqlSegment}
    </select>
    <select id="queryById" resultType="com.jeeplus.finance.reportCancellApply.service.dto.ReportInfoDto">
        SELECT a.id,a.create_by_id,a.create_time,
        a.report_new_line_id,
        a.cancellate_reason,a.report_no,a.proc_ins_id,a.status,a.process_definition_id,
        c.document_no,case c.`status` WHEN '5' THEN '已完成' END as documentStatus,
        su3.name as reportSponsor,
        d.project_name,
        d.project_master_id,
        d.real_header as project_master2_id,
        su.name as user_name,
        su2.name as project_master_name,
        suu.name as project_master2_name
        FROM cw_project_report_cancell_apply a
        LEFT JOIN cw_project_report_new_line b
        on a.report_new_line_id = b.id
        LEFT JOIN cw_project_report c
        on b.report_id = c.id
        LEFT JOIN cw_project_records d
        on c.project_id = d.id
        left join sys_user su on su.id = a.create_by_id and su.del_flag = '0'
        left join sys_user su2 on su2.id = d.project_master_id and su2.del_flag = '0'
        left join sys_user suu on suu.id = d.real_header and suu.del_flag = '0'
        left join sys_user su3 on su3.id = c.create_by_id and su3.del_flag = '0'
        where a.del_flag = '0' and a.id = #{id}
    </select>
    <select id="getList" resultType="com.jeeplus.finance.reportCancellApply.service.dto.ReportInfoDto">
        SELECT
        DISTINCT a.id,
        a.create_by_id as createById,
        a.create_time as "createDateT",
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.remarks,
        a.status,
        a.apply_file_type,
				a.proc_ins_id,
        a.process_definition_id,
				c.document_no,
				c.office_id,
				d.project_number as projectNumber,
				d.project_name ,
				d.project_master_id,
				e.name as departmentName,
				f.name as userName,
				g.name as projectMasterName,
				h.name as reportSponsor,
				d.project_master_id as projectMasterId,
				cw_ar.proc_ins_id as cwProcInsId,
				cw_ar.process_definition_id as cwProDefId,
				d.real_header as projectMaster2Id,
                k.name as projectMaster2Name,
                art.ID_ as task_id,
                b.report_no as report_no,
                b.report_id as report_id

				FROM cw_project_report_cancell_apply a
				LEFT JOIN cw_project_report_new_line b
				on a.report_new_line_id = b.id
				LEFT JOIN cw_project_report c
				on b.report_id = c.id
				LEFT JOIN cw_project_records d
				on c.project_id = d.id
				LEFT JOIN sys_office e
        on c.office_id = e.id
				LEFT JOIN sys_user f
        on a.create_by_id = f.id
        left join sys_user_manage_office sumo on sumo.office_id = f.office_id
				LEFT JOIN sys_user g
        on d.project_master_id = g.id
        LEFT JOIN sys_user k on d.real_header = k.id
        LEFT JOIN sys_user h
        on c.create_by_id = h.id
        left join cw_project_report_cancell_apply_archived cw_ar
        on a.id = cw_ar.archive_id
        left join cw_project_report_review cw_rev on c.id = cw_rev.report_id and cw_rev.del_flag = '0'
        left join act_ru_task art ON a.proc_ins_id = art.PROC_INST_ID_
        ${ew.customSqlSegment}
        order by a.create_time desc
    </select>
    <select id="selectByArchivedId"
            resultType="com.jeeplus.finance.reportCancellApply.domain.ReportCancellApply">
        select a.* from cw_project_report_cancell_apply a
        left join cw_project_report_cancell_apply_archived b on a.id = b.archive_id
        where b.id = #{id}
    </select>
    <select id="queryReportIdByReportNo" resultType="string">
        select report_id
        from cw_project_report_new_line where report_no = #{no}
    </select>

    <select id="getById" resultType="com.jeeplus.finance.reportCancellApply.domain.ReportCancellApply">
        select
          id,
          create_by_id,
          create_time,
          update_by_id,
          update_time,
          del_flag,
          remarks,
          report_new_line_id,
          cancellate_reason,
          report_no,
          proc_ins_id,
          status,
          process_definition_id,
          apply_file_type,
          tenant_id
        from
          cw_project_report_cancell_apply
        WHERE
            id =#{id}
            AND del_flag =0
    </select>
</mapper>
