<?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.projectReport.mapper.CwProjectReportMapper">

    <sql id="Base_Column_List">
        cw_wcb.id,
        cw_wcb.create_by,
        cw_wcb.create_date,
        cw_wcb.update_by,
        cw_wcb.update_date,
        cw_wcb.del_flag,
        cw_wcb.remarks,
        cw_wcb.no,
        cw_wcb.name,
        cw_wcb.abbreviation,
        cw_wcb.english_name,
        cw_wcb.type,
        cw_wcb.usc_code,
        cw_wcb.sc_type,
        cw_wcb.manage_level_type,
        cw_wcb.one_up_company,
        cw_wcb.company_level,
        cw_wcb.business_scope,
        cw_wcb.key_responsibilities,
        cw_wcb.industry,
        cw_wcb.affiliation,
        cw_wcb.organization_type,
        cw_wcb.report_type,
        cw_wcb.one_up_office,
        cw_wcb.registration_cert,
        cw_wcb.approving_bodies,
        cw_wcb.office_id,
        cw_wcb.proc_ins_id,
        cw_wcb.process_definition_id,
        cw_wcb.status,
        cw_wcb.agree_date,
        cw_wcb.agree_user_id
    </sql>

    <select id="findList" resultType="com.jeeplus.test.cw.projectReport.domain.CwProjectReportData">
        SELECT
        a.id,
        a.create_by as createById,
        a.create_date,
        a.update_by,
        a.update_date,
        a.del_flag,
        a.remarks,
        a.status,
        a.document_no,
        a.project_report_number,
        a.project_id,
        a.office_id,
        a.signature_type,
        a.signature_annotator1,
        a.signature_annotator2,
        a.signature_contract_id,
        a.real_create,
        a.proc_ins_id,
        a.process_definition_id,
        b.project_number as projectNumber,
        b.project_name as projectName,
        b.project_master_id as projectMasterId,
        c.name as departmentName,
        d.name as userName,
        a.create_date,
        e.name as projectMasterName,
        cw_prs1.proc_ins_id as proc_ins_id1,
        cw_prs1.process_definition_id as process_definition_id1,
        cw_prs1.status as status1,
        cw_prs1.id as sid1,
        cw_prs2.proc_ins_id as proc_ins_id2,
        cw_prs2.process_definition_id as process_definition_id2,
        cw_prs2.status as status2,
        cw_prs2.id as sid2
        FROM cw_project_report a
        left join cw_project_records b on a.project_id = b.id
        LEFT JOIN sys_office c on a.office_id = c.id
        LEFT JOIN sys_user d on a.create_by = d.id
        LEFT JOIN sys_user e on b.project_master_id = e.id
        LEFT JOIN cw_project_report_signature cw_prs1 on cw_prs1.report_id = a.id and cw_prs1.type = '1' and cw_prs1.del_flag = '0'
        LEFT JOIN cw_project_report_signature cw_prs2 on cw_prs2.report_id = a.id and cw_prs2.type = '2' and cw_prs2.del_flag = '0'
        ${ew.customSqlSegment}
    </select>
    <select id="queryById" resultType="com.jeeplus.test.cw.projectReport.domain.CwProjectReportData">
        SELECT
        a.id,
        a.create_by as createById,
        a.create_date,
        a.update_by,
        a.update_date,
        a.del_flag,
        a.remarks,
        a.status,
        a.document_no,
        a.project_report_number,
        a.project_id,
        a.office_id,
        a.signature_type,
        a.signature_annotator1,
        a.signature_annotator2,
        a.signature_contract_id,
        a.proc_ins_id,
        a.process_definition_id,
        b.project_number as projectNumber,
        b.project_name as projectName,
        c.name as departmentName,
        d.name as userName,
        a.create_date,
        e.name as projectMasterName,
        a.real_create,
        cw_prs1.proc_ins_id as proc_ins_id1,
        cw_prs1.process_definition_id as process_definition_id1,
        cw_prs1.status as status1,
        cw_prs1.id as sid1,
        cw_prs2.proc_ins_id as proc_ins_id2,
        cw_prs2.process_definition_id as process_definition_id2,
        cw_prs2.status as status2,
        cw_prs2.id as sid2
        FROM cw_project_report a
        left join cw_project_records b on a.project_id = b.id
        LEFT JOIN sys_office c on a.office_id = c.id
        LEFT JOIN sys_user d on a.create_by = d.id
        LEFT JOIN sys_user e on b.project_master_id = e.id
        LEFT JOIN cw_project_report_signature cw_prs1 on cw_prs1.report_id = a.id and cw_prs1.type = '1' and cw_prs1.del_flag = '0'
        LEFT JOIN cw_project_report_signature cw_prs2 on cw_prs2.report_id = a.id and cw_prs2.type = '2' and cw_prs2.del_flag = '0'
        where a.id = #{id}
    </select>
    <select id="findClineList" resultType="com.jeeplus.test.cw.workClientInfo.service.dto.CwWorkClientBaseDTO">
        select
        <include refid="Base_Column_List"></include>,
        su.name as user_name
        from cw_work_client_base cw_wcb
        left join sys_user su on su.id = cw_wcb.create_by
        left join cw_work_client_type cw_wct on cw_wct.client_id = cw_wcb.id and cw_wct.del_flag = '0'
        left join cw_project_client_info cw_info on cw_wcb.id = cw_info.client_id
        LEFT JOIN cw_project_records cw_pro on cw_info.project_id = cw_pro.id
        ${ew.customSqlSegment}
    </select>
    <select id="getUserNameById" resultType="java.lang.String">
        select name from sys_user where id = #{id}
    </select>

    <update id="updateSignatureInfo">
        update cw_project_report set
        signature_contract_id = #{signatureContractId}
        where id = #{id}
    </update>

    <update id="updateSignatureUrl">
        update cw_project_report set
        signature_url = #{signatureUrl}
        where id = #{id}
    </update>

    <update id="updateReportSealType">
        update cw_project_report_new_line set
        seal_type = '已盖章'
        where report_id = #{id}
    </update>

    <update id="updateDelFlag">
        UPDATE cw_project_report SET del_flag = #{flag} where id = #{id}
    </update>




    <select id="queryByContractId" resultType="com.jeeplus.test.cw.projectReport.domain.CwProjectReportData">
        SELECT
        a.id,
        a.create_by as createById,
        a.create_date,
        a.update_by,
        a.update_date,
        a.del_flag,
        a.remarks,
        a.status,
        a.document_no,
        a.project_report_number,
        a.project_id,
        a.office_id,
        a.signature_type,
        a.signature_annotator1,
        a.signature_annotator2,
        a.signature_contract_id,
        a.proc_ins_id,
        a.process_definition_id,
        b.project_number as projectNumber,
        b.project_name as projectName,
        c.name as departmentName,
        d.name as userName,
        a.create_date,
        e.name as projectMasterName,
        cw_prs1.proc_ins_id as proc_ins_id1,
        cw_prs1.process_definition_id as process_definition_id1,
        cw_prs1.status as status1,
        cw_prs1.id as sid1,
        cw_prs2.proc_ins_id as proc_ins_id2,
        cw_prs2.process_definition_id as process_definition_id2,
        cw_prs2.status as status2,
        cw_prs2.id as sid2
        FROM cw_project_report a
        left join cw_project_records b on a.project_id = b.id
        LEFT JOIN sys_office c on a.office_id = c.id
        LEFT JOIN sys_user d on a.create_by = d.id
        LEFT JOIN sys_user e on b.project_master_id = e.id
        LEFT JOIN cw_project_report_signature cw_prs1 on cw_prs1.report_id = a.id and cw_prs1.type = '1' and cw_prs1.del_flag = '0'
        LEFT JOIN cw_project_report_signature cw_prs2 on cw_prs2.report_id = a.id and cw_prs2.type = '2' and cw_prs2.del_flag = '0'
        where a.signature_contract_id = #{contractId}
    </select>
    <select id="getByProjectId" resultType="com.jeeplus.test.cw.projectReport.domain.CwProjectReportData">
        SELECT
        a.id,
        a.create_by as createById,
        a.create_date,
        a.update_by,
        a.update_date,
        a.del_flag,
        a.remarks,
        a.status,
        a.document_no,
        a.project_report_number,
        a.project_id,
        a.office_id,
        a.signature_type,
        a.signature_annotator1,
        a.signature_annotator2,
        a.signature_contract_id,
        a.proc_ins_id,
        a.process_definition_id,
        b.project_number as projectNumber,
        b.project_name as projectName,
        c.name as departmentName,
        d.name as userName,
        a.create_date,
        e.name as projectMasterName,
        cw_prs1.proc_ins_id as proc_ins_id1,
        cw_prs1.process_definition_id as process_definition_id1,
        cw_prs1.status as status1,
        cw_prs1.id as sid1,
        cw_prs2.proc_ins_id as proc_ins_id2,
        cw_prs2.process_definition_id as process_definition_id2,
        cw_prs2.status as status2,
        cw_prs2.id as sid2
        FROM cw_project_report a
        left join cw_project_records b on a.project_id = b.id
        LEFT JOIN sys_office c on a.office_id = c.id
        LEFT JOIN sys_user d on a.create_by = d.id
        LEFT JOIN sys_user e on b.project_master_id = e.id
        LEFT JOIN cw_project_report_signature cw_prs1 on cw_prs1.report_id = a.id and cw_prs1.type = '1' and cw_prs1.del_flag = '0'
        LEFT JOIN cw_project_report_signature cw_prs2 on cw_prs2.report_id = a.id and cw_prs2.type = '2' and cw_prs2.del_flag = '0'
        where a.project_id = #{projectId} and a.del_flag = '0'
    </select>
</mapper>
