<?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.projectRecords.mapper.CwProjectRecordsMapper">

    <resultMap id="BaseResultMap" type="com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="createBy.id" column="create_by_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy.id" column="update_by_id" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
        <result property="remarks" column="remarks" jdbcType="VARCHAR"/>

        <result property="projectNumber" column="project_number" jdbcType="VARCHAR"/>
        <result property="projectName" column="project_name" jdbcType="VARCHAR"/>
        <result property="officeId" column="office_id" jdbcType="VARCHAR"/>
        <result property="projectMoney" column="project_money" jdbcType="VARCHAR"/>
        <result property="auditYear" column="audit_year" jdbcType="VARCHAR"/>
        <result property="planStartDate" column="plan_start_date" jdbcType="TIMESTAMP"/>
        <result property="planEndDate" column="plan_end_date" jdbcType="TIMESTAMP"/>
        <result property="projectMasterId" column="project_master_id" jdbcType="VARCHAR"/>
        <result property="projectLeaderId" column="project_leader_id" jdbcType="VARCHAR"/>
        <result property="procInsId" column="proc_ins_id" jdbcType="VARCHAR"/>
        <result property="processDefinitionId" column="process_definition_id" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="VARCHAR"/>
        <result property="createBy.name" column="user_name" jdbcType="VARCHAR"/>
        <result property="projectMasterName" column="project_master_name" jdbcType="VARCHAR"/>
        <result property="projectMasterName2" column="project_master_name" jdbcType="VARCHAR"/>
        <result property="contractId" column="contract_id" jdbcType="VARCHAR"/>
        <result property="contractName" column="contract_name" jdbcType="VARCHAR"/>
        <result property="contractAmount" column="contract_amount" jdbcType="VARCHAR"/>
        <result property="contractNum" column="contract_num" jdbcType="VARCHAR"/>
        <result property="payerSubject" column="payer_subject" jdbcType="VARCHAR"/>
        <result property="paymentMethod" column="payment_method" jdbcType="VARCHAR"/>
        <result property="createName" column="user_name" jdbcType="VARCHAR"/>
        <result property="createDateT" column="create_time" jdbcType="VARCHAR"/>
        <result property="businessType" column="business_type" jdbcType="VARCHAR"/>
        <result property="riskLevel" column="risk_level" jdbcType="VARCHAR"/>
        <result property="businessTypeName" column="business_type_name" jdbcType="VARCHAR"/>
        <result property="realHeader" column="real_header" jdbcType="VARCHAR"/>
        <result property="clientContactsName" column="client_contacts_name" jdbcType="VARCHAR"/>
        <result property="reportType" column="report_type" jdbcType="VARCHAR"/>
        <result property="memberCount" column="member_count" jdbcType="VARCHAR"/>
        <result property="realHeaderName" column="real_header_name" jdbcType="VARCHAR"/>
        <result property="reportReview" column="report_review" jdbcType="VARCHAR"/>
        <collection property="cwProjectClientInfoDTOList" ofType="com.jeeplus.finance.workClientInfo.service.dto.CwWorkClientBaseDTO" column="id" select="getProjectClient"></collection>
        <collection property="workAttachmentDtoList" ofType="com.jeeplus.sys.service.dto.WorkAttachmentInfoDTO" column="id" select="getFileList"></collection>
        <collection property="cwProjectClientContactDTOList" ofType="com.jeeplus.finance.projectRecords.service.dto.CwProjectClientContactDTO" column="id" select="getContact"></collection>
        <collection property="cwProjectMembersDTOList" ofType="com.jeeplus.finance.projectRecords.service.dto.CwProjectMembersDTO" column="id" select="getMembers"></collection>
        <collection property="cwProjectConstructionList" ofType="com.jeeplus.finance.projectRecords.domain.PartialCustomerInfo" column="id" select="getConstructionList"></collection>

    </resultMap>

    <resultMap id="AttachmentMap" type="com.jeeplus.sys.service.dto.WorkAttachmentInfoDTO">
        <id property="id" column="id" jdbcType="VARCHAR"/>
        <result property="createBy.id" column="create_by_id" jdbcType="VARCHAR"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateBy.id" column="update_by_id" jdbcType="VARCHAR"/>
        <result property="createBy.name" column="create_name" jdbcType="VARCHAR"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
        <result property="delFlag" column="del_flag" jdbcType="VARCHAR"/>
        <result property="url" column="url" jdbcType="VARCHAR"/>
        <result property="name" column="attachment_name" jdbcType="VARCHAR"/>
        <result property="size" column="file_size" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        a.id,
        a.create_by_id,
        a.create_time,
        a.update_by_id,
        a.update_time,
        a.del_flag,
        a.remarks,
        a.project_number,
        a.project_name,
        a.office_id,
        a.project_money,
        a.audit_year,
        a.plan_start_date,
        a.plan_end_date,
        a.project_master_id,
        a.project_leader_id,
        a.proc_ins_id,
        a.status,
        a.process_definition_id,
        a.contract_id,
        a.business_type,
        a.risk_level,
        a.real_header,
        a.report_type,
        a.report_review,
        a.project_type,
        a.project_level,
        a.project_start_time,
        a.project_end_time,
        a.engineering_type
    </sql>
    <sql id="File_Column_List">
        wa.id,
        wa.create_by_id,
        wa.create_time,
        wa.update_by_id,
        wa.update_time,
        wa.remarks,
        wa.del_flag,
        wa.url,
        wa.type,
        wa.attachment_id,
        wa.attachment_name,
        wa.attachment_flag,
        wa.module_type,
        wa.attachment_type,
        wa.file_size,
        wa.sort,
        wa.description
    </sql>
    <sql id="Contact_Column_List">
        cw_pcc.id,
        cw_pcc.create_by_id,
        cw_pcc.create_time,
        cw_pcc.update_by_id,
        cw_pcc.update_time,
        cw_pcc.del_flag,
        cw_pcc.remarks,
        cw_pcc.project_id,
        cw_pcc.client_id,
        cw_pcc.name,
        cw_pcc.sex,
        cw_pcc.office_id,
        cw_pcc.position,
        cw_pcc.contact_first,
        cw_pcc.contact_second,
        cw_pcc.fax,
        cw_pcc.email,
        cw_pcc.client_contact_id
    </sql>
    <sql id="Project_Client_List">
        cw_pci.project_id,
        cw_pci.client_id,
        cw_wcb.no as clientNumber,
        cw_wcb.name as clientName,
        cw_wcb.company_level as companyLevel
    </sql>
    <sql id="Client_Column_List">
        cw_wcb.id,
        cw_wcb.create_by_id,
        cw_wcb.create_time,
        cw_wcb.update_by_id,
        cw_wcb.update_time,
        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>
    <sql id="Members_Column_List">
        cw_pm.id,
        cw_pm.create_by_id,
        cw_pm.create_time,
        cw_pm.update_by_id,
        cw_pm.update_time,
        cw_pm.del_flag,
        cw_pm.remarks,
        cw_pm.project_id,
        cw_pm.user_id,
        cw_pm.status,
        cw_pm.is_important
    </sql>

    <select id="getProjectClient" resultType="com.jeeplus.finance.workClientInfo.service.dto.CwWorkClientBaseDTO">
        select
        <include refid="Client_Column_List"></include>
        from cw_project_client_info cw_pci
        left join cw_work_client_base cw_wcb on cw_wcb.id = cw_pci.client_id and cw_wcb.del_flag = '0'
        where cw_pci.project_id = #{id}
    </select>

    <select id="getFileList" resultMap="AttachmentMap">
        select
        <include refid="File_Column_List"></include>,
        su.name as create_name
        from work_attachment wa
        left join sys_user su on su.id = wa.create_by_id and su.del_flag = '0'
        where wa.del_flag = '0' and wa.attachment_id = #{id}
    </select>

    <select id="getContact" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectClientContactDTO">
        select
        <include refid="Contact_Column_List"></include>
        from cw_project_client_contact cw_pcc
        where cw_pcc.project_id = #{id} and cw_pcc.del_flag = '0'
    </select>
    <select id="getMembers" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectMembersDTO">
        select
        <include refid="Members_Column_List"></include>
        from cw_project_members cw_pm
        where cw_pm.project_id = #{id} and cw_pm.del_flag = '0'
    </select>
    <select id="getConstructionList" resultType="com.jeeplus.finance.projectRecords.domain.PartialCustomerInfo">
        select
        name,client_name,contact_first,contact_second
        from cw_project_records_customer cu
        where cu.records_id = #{id} and cu.del_flag = '0'
    </select>


    <!--<select id="findList" resultMap="BaseResultMap">
        select
        DISTINCT
        <include refid="Base_Column_List"></include>,
        su.name as user_name,
        su2.name as project_master_name,
        su3.name as real_header_name,
        cw_wci.contract_name,
        cw_wci.contract_amount,
        cw_wci.contract_num,
        cw_wci.payer_subject,
        cw_wci.payment_method,
        cw_wcb.name as client_contacts_name,
        cw_pbt.name as business_type_name,
        b.member_count
        from cw_project_records a
        left join sys_user su on su.id = a.create_by and su.del_flag = '0'
        left join sys_user_manage_office sumo on sumo.office_id = su.office_id
        left join sys_user su2 on su2.id = a.project_master_id and su2.del_flag = '0'
        left join sys_user su3 on su3.id = a.real_header and su3.del_flag = '0'
        left join cw_work_contract_info cw_wci on cw_wci.id = a.contract_id and cw_wci.del_flag = '0'
        left join cw_work_client_base cw_wcb on cw_wci.client_contacts = cw_wcb.id and cw_wcb.del_flag = '0'
        left join cw_project_business_type cw_pbt on cw_pbt.id = a.business_type and cw_pbt.del_flag = '0'
        left join (select rec.id,count(cw_pm.id) as member_count
                    from cw_project_records rec
                    left join cw_project_members cw_pm on cw_pm.project_id = rec.id and cw_pm.del_flag = '0'
                    group by rec.id
                    ) b on b.id = a.id
        ${ew.customSqlSegment}
        <if test="currentUser.id != '1'.toString">
            <if test="isBmzr == '0'.toString">
                and (a.create_by = #{currentUser.id} or a.id in (
                select cw_pm.project_id
                from cw_project_members cw_pm
                where cw_pm.user_id = #{currentUser.id} and cw_pm.del_flag = '0' and cw_pm.status = '0'
                ))
            </if>
            <if test="isBmzr == '1'.toString">
                and (a.create_by in (
                select su.id from sys_user su where su.del_flag = '0' and su.office_id in
                (select so.id from sys_office so where so.id = #{currentUser.officeDTO.id} or so.parent_ids like concat('%',#{currentUser.officeDTO.id},'%') and so.del_flag = '0')
                ) or a.id in (
                select cw_pm.project_id
                from cw_project_members cw_pm
                where cw_pm.user_id = #{currentUser.id} and cw_pm.del_flag = '0' and cw_pm.status = '0'
                ))
            </if>
        </if>
        ORDER BY a.create_date DESC
    </select>-->


    <select id="findList" resultMap="BaseResultMap">
        select
        DISTINCT
        <include refid="Base_Column_List"></include>,
        su.name as user_name,
        su2.name as project_master_name,
        su2.name as projectMasterName2,
        su3.name as real_header_name,
        cw_wci.contract_name,
        cw_wci.contract_amount,
        cw_wci.contract_num,
        cw_wci.payer_subject,
        cw_wci.payment_method,
        cw_wcb.name as client_contacts_name,
        cw_pbt.name as business_type_name,
        cw_pp.id as planId,
        b.member_count,
        prnl.report_no
        from cw_project_records a
        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 = a.project_master_id and su2.del_flag = '0'
        left join sys_user su3 on su3.id = a.real_header and su3.del_flag = '0'
        left join cw_work_contract_info cw_wci on cw_wci.id = a.contract_id and cw_wci.del_flag = '0'
        left join cw_work_client_base cw_wcb on cw_wci.client_contacts = cw_wcb.id and cw_wcb.del_flag = '0'
        left join cw_project_business_type cw_pbt on cw_pbt.id = a.business_type and cw_pbt.del_flag = '0'
        left join (select rec.id,count(cw_pm.id) as member_count
                    from cw_project_records rec
                    left join cw_project_members cw_pm on cw_pm.project_id = rec.id and cw_pm.del_flag = '0'
                    group by rec.id
                    ) b on b.id = a.id
        left join cw_project_members cpm on a.id = cpm.project_id
        left join sys_user sub on cpm.user_id = sub.id
        left join sys_user_manage_office sumo on sumo.office_id = sub.office_id
        LEFT JOIN cw_project_report pr on pr.project_id=a.id and pr.del_flag = '0'
        LEFT JOIN cw_project_report_new_line prnl on pr.id=prnl.report_id and prnl.del_flag = '0'
        left join cw_project_plan cw_pp on cw_pp.project_id = a.id and cw_pp.del_flag = '0'
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>
    <select id="findList2" resultMap="BaseResultMap">
        select
        DISTINCT
        <include refid="Base_Column_List"></include>,
        su.name as user_name,
        su2.name as project_master_name,
        su3.name as real_header_name,
        cw_wci.contract_name,
        cw_wci.contract_amount,
        cw_wci.contract_num,
        cw_wci.payer_subject,
        cw_wci.payment_method,
        cw_wcb.name as client_contacts_name,
        cw_pbt.name as business_type_name,
        b.member_count
        from cw_project_records a
        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 = a.project_master_id and su2.del_flag = '0'
        left join sys_user su3 on su3.id = a.real_header and su3.del_flag = '0'
        left join cw_work_contract_info cw_wci on cw_wci.id = a.contract_id and cw_wci.del_flag = '0'
        left join cw_work_client_base cw_wcb on cw_wci.client_contacts = cw_wcb.id and cw_wcb.del_flag = '0'
        left join cw_project_business_type cw_pbt on cw_pbt.id = a.business_type and cw_pbt.del_flag = '0'
        left join (select rec.id,count(cw_pm.id) as member_count
        from cw_project_records rec
        left join cw_project_members cw_pm on cw_pm.project_id = rec.id and cw_pm.del_flag = '0'
        group by rec.id
        ) b on b.id = a.id
        left join cw_project_members cpm on a.id = cpm.project_id
        left join sys_user sub on cpm.user_id = sub.id
        left join sys_user_manage_office sumo on sumo.office_id = sub.office_id
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>

    <select id="queryById" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"></include>,
        su.name as user_name,
        su2.name as project_master_name,
        su3.name as real_header_name,
        cw_wci.contract_name,
        cw_wci.contract_amount,
        cw_wci.contract_num,
        cw_wci.payer_subject,
        cw_wci.payment_method,
        cw_wcb.name as client_contacts_name,
        cw_pbt.name as business_type_name,
        cw_re.id as reportId
        from cw_project_records a
        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 = a.project_master_id and su2.del_flag = '0'
        left join sys_user su3 on su3.id = a.real_header and su3.del_flag = '0'
        left join cw_work_contract_info cw_wci on cw_wci.id = a.contract_id and cw_wci.del_flag = '0'
        left join cw_work_client_base cw_wcb on cw_wci.client_contacts = cw_wcb.id and cw_wcb.del_flag = '0'
        left join cw_project_business_type cw_pbt on cw_pbt.id = a.business_type and cw_pbt.del_flag = '0'
        left join cw_project_report cw_re on cw_re.project_id = a.id and cw_re.del_flag = '0'
        where a.del_flag = '0' and a.id = #{id}
    </select>

    <delete id="deleteProjectClientInfoByProjectId">
        delete from cw_project_client_info where project_id = #{projectId}
    </delete>

    <insert id="insertProjectClientInfoList">
        INSERT INTO cw_project_client_info (project_id, client_id) VALUES
        <foreach collection="cwProjectClientInfoList" item="item" separator=",">
            (#{item.projectId}, #{item.clientId})
        </foreach>
    </insert>

    <select id="getProjectIdByClientId" resultType="string">
        select
            cw_pci.project_id
        from cw_project_client_info cw_pci
        where cw_pci.client_id = #{id}
    </select>

    <select id="getProjectByIdList" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO" parameterType="string">
        select
        <include refid="Base_Column_List"></include>,
        su.name as create_name,
        su2.name as project_master_name
        from cw_project_records a
        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 = a.project_master_id and su2.del_flag = '0'
        ${ew.customSqlSegment}
    </select>

    <select id="getByContractId" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO">
        select
            <include refid="Base_Column_List"></include>,
            su.name as create_name,
            su2.name as project_master_name
        from cw_project_records a
        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 = a.project_master_id and su2.del_flag = '0'
        ${ew.customSqlSegment}
    </select>

    <select id="getHaveProjectIds" resultType="string">
        select
            distinct id
        from
        (select cw_pm.project_id as id
        from cw_project_members cw_pm
        where cw_pm.user_id = #{currentUser.id} and cw_pm.del_flag = '0' and cw_pm.status = '0'
        union
        select cw_pr.id as id
        from cw_project_records cw_pr
        where cw_pr.create_by_id = #{currentUser.id} and cw_pr.del_flag = '0') a
    </select>

    <select id="isUseByReport" resultType="string">
        select distinct cw_pro.project_name
        from cw_project_report cw_pr
        left join cw_project_records cw_pro on cw_pro.id = cw_pr.project_id and cw_pro.del_flag = '0'
        where cw_pr.del_flag = '0' and cw_pr.project_id in
        <foreach collection="idArray" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </select>

    <select id="isUseByReim" resultType="string">
        select distinct cw_pro.project_name
        from cw_reimbursement_detail_info cw_reim
        inner join cw_reimbursement_info cw_info on cw_info.id = cw_reim.info_id and cw_info.del_flag = '0'
        left join cw_project_records cw_pro on cw_pro.id = cw_reim.project_id and cw_pro.del_flag = '0'
        where cw_reim.del_flag = '0' and cw_reim.project_id in
        <foreach collection="idArray" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </select>

    <select id="isUseByFinance" resultType="string">
        select distinct cw_pro.project_name
        from cw_finance_invoice_base cw_fib
        inner join cw_finance_invoice cw_fi on cw_fi.id = cw_fib.invoice_id and cw_fi.del_flag = '0'
        left join cw_project_records cw_pro on cw_pro.id = cw_fib.program_id and cw_pro.del_flag = '0'
        where cw_fib.del_flag = '0' and cw_fib.program_id in
        <foreach collection="idArray" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </select>

    <update id="updatereportReviewById">
        UPDATE cw_project_records
        SET
        <if test="reportReview != null and reportReview != ''">
            report_review = #{reportReview},
        </if>
        update_by_id = #{updateById},
        update_time = #{updateTime}
        WHERE
            id = #{id}
            AND del_flag = 0
    </update>
    <update id="projectUpgrade">
        UPDATE cw_project_records set project_level = #{level} where id = #{id}
    </update>

    <select id="getListByIds" resultType="com.jeeplus.finance.projectRecords.domain.CwProjectRecords">
        SELECT  id,remarks,project_number,project_name,office_id,project_money,audit_year,plan_start_date,plan_end_date,project_master_id,project_leader_id,proc_ins_id,process_definition_id,status,contract_id,business_type,risk_level,real_header,report_type,report_review,create_time,create_by_id,update_time,update_by_id,del_flag,tenant_id  FROM cw_project_records
         <where>
             del_flag=0
             and id in
             <foreach collection="ids" open="(" close=")" separator="," item="id">
                 #{id}
             </foreach>
         </where>

    </select>

    <select id="selectLabel" resultType="String">
        SELECT id FROM sys_dict_type WHERE type='cw_work_client_report_type'
    </select>

    <select id="getReportById" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO">
        SELECT
        distinct
        cpr.project_name,
        prnl.report_no,
        fi.no,
        fid.number,
        fid.account,
        fi.billing_people,
        fi.billing_date
        FROM cw_project_report_archive a
        LEFT JOIN cw_project_records cpr on a.project_id=cpr.id
        LEFT JOIN cw_project_report pr on pr.project_id=cpr.id
        LEFT JOIN cw_finance_invoice_base fib on cpr.id=fib.program_id
        LEFT JOIN cw_finance_invoice fi on fi.id=fib.invoice_id
        LEFT JOIN cw_project_report_new_line prnl on pr.id=prnl.report_id
        LEFT JOIN cw_finance_invoice_detail fid on fi.id=fid.invoice_id
        <where>
        <if test="null!=cwProjectRecordsDTO.number and cwProjectRecordsDTO.number!=''">
           and fid.number=#{cwProjectRecordsDTO.number}
        </if>
        <if test="cwProjectRecordsDTO.no!=null and cwProjectRecordsDTO.no!=''">
           and fi.no=#{cwProjectRecordsDTO.no}
        </if>
        <if test="cwProjectRecordsDTO.reportNo!=null and cwProjectRecordsDTO.reportNo!=''">
           and prnl.report_no=#{cwProjectRecordsDTO.reportNo}
        </if>
            and (a.id=#{id} or fib.program_id=(SELECT project_id FROM cw_project_report_archive where id=#{id}))
            and (fib.account is not null or fib.account != '')
        </where>
    </select>

    <select id="getReportByProjectId" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO">
        select
        cpr.project_name,
        prnl.report_no,
        su.login_name,
        pr.create_time,
        pr.audit_money as "auditFees",
        pr.report_id
        from cw_project_report_archive pr
        left join cw_project_report_new_line prnl on pr.report_id=prnl.report_id
        left join cw_project_records cpr on pr.project_id=cpr.id
        left join sys_user su on pr.create_by_id = su.id
        <where>
            pr.audit_money >'0'
            and pr.project_id=#{projectId}
            and pr.id != #{id}
        </where>
    </select>
    <select id="getMembersId" resultType="java.lang.String">
        SELECT  id FROM cw_project_members
        <where>
            del_flag=0
            and project_id = #{id}
        </where>
    </select>
    <select id="findAllList" resultType="java.lang.String">
        select id from cw_project_records where create_by_id = #{id} and del_flag=0
    </select>

    <select id="queryPlanById" resultType="com.jeeplus.finance.projectRecords.service.dto.CwProjectRecordsDTO">
        select
            a.id,
            a.create_by_id,
            a.create_time,
            a.project_number,
            a.plan_start_date,
            a.plan_end_date,
            a.project_name,
            su.name as createName,
            cw_pp.id as planId
        from cw_project_records a
        left join sys_user su on su.id = a.create_by_id and su.del_flag = '0'
        left join cw_project_plan cw_pp on cw_pp.project_id = a.id and cw_pp.del_flag = '0'
        where a.id = #{id}
    </select>

    <select id="findPlanList" resultType="com.jeeplus.finance.projectRecords.domain.CwProjectPlanDetails">
        select
            a.task_phase,
            a.plan_start_date,
            a.plan_end_date,
            a.warn_user,
            a.achiever,
            su.name as warnName,
            su1.name as achieverName
        from cw_project_records pr
        left join cw_project_plan cw_pp on cw_pp.project_id = pr.id
        left join cw_project_plan_details a on cw_pp.id = a.plan_id
        left join sys_user su on su.id = a.warn_user
        left join sys_user su1 on su1.id = a.achiever
        where pr.id = #{id}
    </select>

    <select id="findOfficeList"
            resultType="com.jeeplus.finance.projectRecords.service.dto.CwTreeUserDto">
		SELECT so.id,so.`name`,so.parent_id FROM sys_office so left join sys_user su WHERE so.del_flag = 0
	</select>
    <select id="findUserList"
            resultType="com.jeeplus.finance.projectRecords.service.dto.CwTreeUserDto">
        SELECT
        a.id,
        a.`name`,
        a.office_id AS parent_id,
        b.`name` AS office_name,
        true AS is_user
        FROM
        sys_user a
        LEFT JOIN sys_office b ON a.office_id = b.id
        WHERE
        a.del_flag = 0 and a.id = #{s}
        <if test="name != null and name != ''">
            and a.`name` LIKE CONCAT ('%', #{name}, '%')
        </if>
    </select>

    <select id="getMemberId" resultType="java.lang.String">
        SELECT  user_id FROM cw_project_members
        <where>
            del_flag=0
            and project_id = #{id}
        </where>
    </select>

    <select id="getListByPlanId" resultType="com.jeeplus.finance.projectRecords.domain.CwProjectPlanDetails">
        select
            a.task_phase,
            a.plan_start_date,
            a.plan_end_date,
            a.warn_user,
            a.achiever,
            su.name as warnName,
            su1.name as achieverName
        from cw_project_plan_details a
        left join sys_user su on su.id = a.warn_user
        left join sys_user su1 on su1.id = a.achiever
        where a.plan_id = #{planId} and a.del_flag = '0'

    </select>

    <select id="getTaskPhase" resultType="string">
        select task_phase from cw_project_plan_details
    </select>

    <select id="getPlanDetails" resultType="com.jeeplus.finance.projectRecords.domain.CwProjectPlanDetails">
        select
            a.id,
            a.task_phase,
            a.plan_start_date,
            a.plan_end_date,
            a.warn_user,
            a.achiever,
            pr.id as projectId,
            pr.project_name
        from cw_project_records pr
        left join cw_project_plan cw_pp on cw_pp.project_id = pr.id
        left join cw_project_plan_details a on cw_pp.id = a.plan_id
        where a.del_flag = '0'
    </select>
    <select id="partialCustomerInfoList"
            resultType="com.jeeplus.finance.projectRecords.domain.PartialCustomerInfo">
        SELECT a.id as clientId, a.name,a.usc_code,su.`name` as createUserName,cli.name as clientName,cli.contact_first,cli.contact_second
        FROM cw_work_client_base a
        LEFT JOIN sys_user su on a.create_by_id = su.id and su.del_flag = 0
        LEFT JOIN cw_work_client_contact cli on a.id = cli.client_id and cli.del_flag = 0
        ${ew.customSqlSegment}
        ORDER BY a.create_time DESC
    </select>

</mapper>
