<?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.ruoyi.invest.mapper.InvestmentOpportunityMapper">
    
    <resultMap type="TProjectPool" id="TProjectPoolResult">
        <result property="id"    column="id"    />
        <result property="procInstId" column="proc_inst_id"   />
        <result property="projectName"    column="project_name"    />
        <result property="projectGroup"    column="project_group"    />
        <result property="recordDate"    column="record_date"    />
        <result property="projectCode"    column="project_code"    />
        <result property="channel"    column="channel"    />
        <result property="contactDate"    column="contact_date"    />
        <result property="projectDate"    column="project_date"    />
        <result property="decisionDate"    column="decision_date"    />
        <result property="industry"    column="industry"    />
        <result property="company"    column="company"    />
        <result property="description"    column="description"    />
        <result property="projectContacts"    column="project_contacts"    />
        <result property="investHead"    column="invest_head"    />
        <result property="previousFinancing"    column="previous_financing"    />
        <result property="financingStage"    column="financing_stage"    />
        <result property="financingCondition"    column="financing_condition"    />
        <result property="financingMoney"    column="financing_money"    />
        <result property="financingDate"    column="financing_date"    />
        <result property="investSparkle"    column="invest_sparkle"    />
        <result property="investValuation"    column="invest_valuation"    />
        <result property="investMoney"    column="invest_money"    />
        <result property="investType"    column="invest_type"    />
        <result property="investPloy"    column="invest_ploy"    />
        <result property="investWorth"    column="invest_worth"    />
        <result property="shareholding"    column="shareholding"    />
        <result property="projectStage"    column="project_stage"    />
        <result property="projectState"    column="project_state"    />
        <result property="mark"    column="mark"    />
        <result property="approvalFlag"    column="approval_flag"    />
        <result property="investigateFlag"    column="investigate_flag"    />
        <result property="decisionFlag"    column="decision_flag"    />
        <result property="terminationFlag"    column="termination_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="taskDefKey"    column="taskDefKey"/>
        <result property="status"    column="status"    />
        <result property="projectStatus"    column="project_status"    />

        <association property="tProjectCompany" javaType="TProjectCompany"  resultMap="TProjectCompanyResult" />
        <association property="tProjectContacts" javaType="TProjectContacts"  resultMap="TProjectContactsResult" />
        <association property="tProjectChannel" javaType="TProjectChannel"  resultMap="TProjectChannelResult" />
        <association property="tProjectReview" javaType="TProjectReview"  resultMap="TProjectReviewResult" />
    </resultMap>

    <resultMap type="TProjectPoolVo" id="TProjectPoolVoResult">
        <result property="id"    column="id"    />
        <result property="procInstId" column="proc_inst_id"   />
        <result property="projectName"    column="project_name"    />
        <result property="projectGroup"    column="project_group"    />
        <result property="recordDate"    column="record_date"    />
        <result property="projectCode"    column="project_code"    />
        <result property="channel"    column="channel"    />
        <result property="contactDate"    column="contact_date"    />
        <result property="projectDate"    column="project_date"    />
        <result property="decisionDate"    column="decision_date"    />
        <result property="industry"    column="industry"    />
        <result property="company"    column="company"    />
        <result property="description"    column="description"    />
        <result property="projectContacts"    column="project_contacts"    />
        <result property="investHead"    column="invest_head"    />
        <result property="previousFinancing"    column="previous_financing"    />
        <result property="financingStage"    column="financing_stage"    />
        <result property="financingCondition"    column="financing_condition"    />
        <result property="financingMoney"    column="financing_money"    />
        <result property="financingDate"    column="financing_date"    />
        <result property="investSparkle"    column="invest_sparkle"    />
        <result property="investValuation"    column="invest_valuation"    />
        <result property="investMoney"    column="invest_money"    />
        <result property="investType"    column="invest_type"    />
        <result property="investPloy"    column="invest_ploy"    />
        <result property="investWorth"    column="invest_worth"    />
        <result property="shareholding"    column="shareholding"    />
        <result property="projectStage"    column="project_stage"    />
        <result property="projectState"    column="project_state"    />
        <result property="mark"    column="mark"    />
        <result property="approvalFlag"    column="approval_flag"    />
        <result property="investigateFlag"    column="investigate_flag"    />
        <result property="decisionFlag"    column="decision_flag"    />
        <result property="terminationFlag"    column="termination_flag"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"     column="status"  />
        <result property="projectStatus"    column="project_status"    />

        <result property="taskName" column="taskName"/>
        <result property="taskId" column="taskId"/>
        <result property="taskCreateTiem" column="taskCreateTiem"/>
        <result property="assignee" column="assignee"/>
        <result property="assigneeName" column="assigneeName"/>
        <result property="taskDefKey" column="taskDefKey"/>
        <result property="procDefId" column="procDefId"/>
        <result property="procInsId" column="procInsId"/>
        <result property="startUserId" column="startUserId"/>
        <result property="startUserName" column="startUserName"/>
        <result property="startDeptName" column="startDeptName"/>
        <result property="executionId" column="executionId"/>
        <result property="deployId" column="deployId"/>

        <association property="tProjectCompany" javaType="TProjectCompany"  resultMap="TProjectCompanyResult" />
        <association property="tProjectContacts" javaType="TProjectContacts"  resultMap="TProjectContactsResult" />
        <association property="tProjectChannel" javaType="TProjectChannel"  resultMap="TProjectChannelResult" />
        <association property="tProjectReview" javaType="TProjectReview"  resultMap="TProjectReviewResult" />
    </resultMap>

    <resultMap type="TProjectCompany" id="TProjectCompanyResult">
        <result property="companyId"    column="companyId"    />
        <result property="companyName"    column="company_name"    />
        <result property="projectPoolId"    column="project_pool_id"    />
        <result property="companyCode"    column="company_code"    />
        <result property="filingTime"    column="filing_time"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="registeredCapital"    column="registered_capital"    />
        <result property="registeredAddress"    column="registered_address"    />
        <result property="paidCapital"    column="paid_capital"    />
        <result property="businessAddress"    column="business_address"    />
        <result property="actualBod"    column="actual_bod"    />
        <result property="phone"    column="phone"    />
        <result property="type"    column="type"    />
    </resultMap>

    <resultMap type="TProjectContacts" id="TProjectContactsResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="position"    column="position"    />
        <result property="contact"    column="contact"    />
    </resultMap>

    <resultMap type="TProjectChannel" id="TProjectChannelResult">
        <result property="channelName"    column="channel_name"    />
        <result property="channelCode"    column="channel_code"    />
        <result property="channelType"    column="channel_type"    />
        <result property="channelGroup"    column="channel_group"    />
        <result property="channelBlurb"    column="channel_blurb"    />
        <result property="contacts"    column="contacts"    />
        <result property="telephone"    column="telephone"    />
        <result property="address"    column="address"    />
        <result property="channelHead"    column="channel_head"    />
    </resultMap>

    <resultMap type="TProjectReview" id="TProjectReviewResult">
        <!--<result property="id" column="id"    />-->
        <result property="reviewId"    column="reviewId"    />
        <result property="context"    column="context"    />
        <result property="reviewPerson"    column="review_person"    />
        <result property="reviewPersonId"    column="review_person_id"    />
    </resultMap>

    <sql id="selectTProjectPoolVo">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts, a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding, a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time,a.status,a.project_status,
               b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
               c.name, c.position, c.contact,
               d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head
        from t_project_pool a
             left join t_project_company b ON a.id = b.project_pool_id
             left join t_project_contacts c ON a.project_contacts = c.id
             left join t_project_channel d ON a.channel = d.id
    </sql>

    <sql id="selectTProjectPoolReviewVo">
        select a.id,a.proc_inst_id, a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts, a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding, a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time,a.status,a.project_status,
               b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
               c.name, c.position, c.contact,
               d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head,
               r.context, r.review_person, r.review_person_id
        from t_project_pool a
                 left join t_project_company b ON a.id = b.project_pool_id
                 left join t_project_contacts c ON a.project_contacts = c.id
                 left join t_project_channel d ON a.channel = d.id
                 left join t_project_review r ON a.id = r.project_pool_id AND r.review_person_id = #{createBy}
    </sql>
    <!--<sql id="selectTProjectPoolFlowableVo">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts, a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding, a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time,
               b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
               c.id, c.name, c.position, c.contact,
               d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head
        from t_project_pool a
                 left join t_project_company b ON a.id = b.project_pool_id
                 left join t_project_contacts c ON a.project_contacts = c.id
                 left join t_project_channel d ON a.channel = d.id
    </sql>-->
    <sql id="where_sql">
        <if test="projectPool.projectName != null  and projectPool.projectName != ''"> and a.project_name like concat('%', #{projectPool.projectName}, '%')</if>
        <if test="projectPool.projectGroup != null  and projectPool.projectGroup != ''"> and a.project_group = #{projectPool.projectGroup}</if>
        <if test="projectPool.projectCode != null  and projectPool.projectCode != ''"> and a.project_code = #{projectPool.projectCode}</if>
        <if test="projectPool.channel != null  and projectPool.channel != ''"> and a.channel = #{projectPool.channel}</if>
        <if test="projectPool.contactDate != null "> and a.contact_date = #{projectPool.contactDate}</if>
        <if test="projectPool.projectDate != null "> and a.project_date = #{projectPool.projectDate}</if>
        <if test="projectPool.decisionDate != null "> and a.decision_date = #{projectPool.decisionDate}</if>
        <if test="projectPool.industry != null  and projectPool.industry != ''"> and a.industry = #{projectPool.industry}</if>
        <if test="projectPool.company != null  and projectPool.company != ''"> and b.company_name like concat('%', #{projectPool.company}, '%')</if>
        <if test="projectPool.projectContacts != null  and projectPool.projectContacts != ''"> and c.name like concat('%', #{projectPool.projectContacts}, '%')</if>
        <if test="projectPool.investHead != null  and projectPool.investHead != ''"> and a.invest_head like concat('%', #{projectPool.investHead}, '%')</if>
        <if test="projectPool.previousFinancing != null  and projectPool.previousFinancing != ''"> and a.previous_financing = #{projectPool.previousFinancing}</if>
        <if test="projectPool.financingStage != null  and projectPool.financingStage != ''"> and a.financing_stage = #{projectPool.financingStage}</if>
        <if test="projectPool.financingMoney != null  and projectPool.financingMoney != ''"> and a.financing_money = #{projectPool.financingMoney}</if>
        <if test="projectPool.financingDate != null "> and a.financing_date = #{projectPool.financingDate}</if>
        <if test="projectPool.investValuation != null  and projectPool.investValuation != ''"> and a.invest_valuation = #{projectPool.investValuation}</if>
        <if test="projectPool.investMoney != null  and projectPool.investMoney != ''"> and a.invest_money = #{projectPool.investMoney}</if>
        <if test="projectPool.investType != null  and projectPool.investType != ''"> and a.invest_type = #{projectPool.investType}</if>
        <if test="projectPool.investPloy != null  and projectPool.investPloy != ''"> and a.invest_ploy = #{projectPool.investPloy}</if>
        <if test="projectPool.investWorth != null  and projectPool.investWorth != ''"> and a.invest_worth = #{projectPool.investWorth}</if>
        <if test="projectPool.projectStage != null  and projectPool.projectStage != ''"> and a.project_stage = #{projectPool.projectStage}</if>
        <if test="projectPool.projectState != null  and projectPool.projectState != ''"> and a.project_state = #{projectPool.projectState}</if>
        <if test="projectPool.delFlag != null  and projectPool.delFlag != ''"> and a.del_flag = #{projectPool.delFlag}</if>
        <if test="projectPool.status != null"> and a.status = #{projectPool.status}</if>
    </sql>
    <select id="selectProjectList" parameterType="TProjectPool" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolVo"/>
        <where>
            1=1
            <if test="projectName != null  and projectName != ''"> and a.project_name like concat('%', #{projectName}, '%')</if>
            <if test="projectGroup != null  and projectGroup != ''"> and a.project_group = #{projectGroup}</if>
            <if test="projectCode != null  and projectCode != ''"> and a.project_code = #{projectCode}</if>
            <if test="channel != null  and channel != ''"> and a.channel = #{channel}</if>
            <if test="contactDate != null "> and a.contact_date = #{contactDate}</if>
            <if test="projectDate != null "> and a.project_date = #{projectDate}</if>
            <if test="decisionDate != null "> and a.decision_date = #{decisionDate}</if>
            <if test="industry != null  and industry != ''"> and a.industry = #{industry}</if>
            <if test="company != null  and company != ''"> and b.company_name like concat('%', #{company}, '%')</if>
            <if test="projectContacts != null  and projectContacts != ''"> and c.name like concat('%', #{projectContacts}, '%')</if>
            <if test="investHead != null  and investHead != ''"> and a.invest_head like concat('%', #{investHead}, '%')</if>
            <if test="previousFinancing != null  and previousFinancing != ''"> and a.previous_financing = #{previousFinancing}</if>
            <if test="financingStage != null  and financingStage != ''"> and a.financing_stage = #{financingStage}</if>
            <if test="financingMoney != null  and financingMoney != ''"> and a.financing_money = #{financingMoney}</if>
            <if test="financingDate != null "> and a.financing_date = #{financingDate}</if>
            <if test="investValuation != null  and investValuation != ''"> and a.invest_valuation = #{investValuation}</if>
            <if test="investMoney != null  and investMoney != ''"> and a.invest_money = #{investMoney}</if>
            <if test="investType != null  and investType != ''"> and a.invest_type = #{investType}</if>
            <if test="investPloy != null  and investPloy != ''"> and a.invest_ploy = #{investPloy}</if>
            <if test="investWorth != null  and investWorth != ''"> and a.invest_worth = #{investWorth}</if>
            <if test="projectStage != null  and projectStage != ''"> and a.project_stage = #{projectStage}</if>
            <if test="projectState != null  and projectState != ''"> and a.project_state = #{projectState}</if>
            <if test="delFlag != null  and delFlag != ''"> and a.del_flag = #{delFlag}</if>
            <if test="projectStatus != null  and projectStatus != ''"> and a.project_status = #{projectStatus}</if>
            <if test="status != null"> and (a.proc_inst_id is null or (a.proc_inst_id is not null and a.status != #{status}) )</if>
            <if test="approvalFlag != null and approvalFlag  != ''">and a.approval_flag = #{approvalFlag}</if>
            <if test="investigateFlag != null and investigateFlag  != ''">and a.investigate_flag = #{investigateFlag}</if>
            <if test="decisionFlag != null and decisionFlag  != ''">and a.decision_flag = #{decisionFlag}</if>
            <if test="terminationFlag != null and terminationFlag  != ''">and a.termination_flag = #{terminationFlag}</if>
            group by a.id
        </where>
    </select>
    <select id="selectApplicableProjectList" parameterType="TProjectPool" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolVo"/>
        <where>
            1=1
            <if test="projectName != null  and projectName != ''"> and a.project_name like concat('%', #{projectName}, '%')</if>
            <if test="projectGroup != null  and projectGroup != ''"> and a.project_group = #{projectGroup}</if>
            <if test="projectCode != null  and projectCode != ''"> and a.project_code = #{projectCode}</if>
            <if test="channel != null  and channel != ''"> and a.channel = #{channel}</if>
            <if test="contactDate != null "> and a.contact_date = #{contactDate}</if>
            <if test="projectDate != null "> and a.project_date = #{projectDate}</if>
            <if test="decisionDate != null "> and a.decision_date = #{decisionDate}</if>
            <if test="industry != null  and industry != ''"> and a.industry = #{industry}</if>
            <if test="company != null  and company != ''"> and b.company_name like concat('%', #{company}, '%')</if>
            <if test="projectContacts != null  and projectContacts != ''"> and c.name like concat('%', #{projectContacts}, '%')</if>
            <if test="investHead != null  and investHead != ''"> and a.invest_head like concat('%', #{investHead}, '%')</if>
            <if test="previousFinancing != null  and previousFinancing != ''"> and a.previous_financing = #{previousFinancing}</if>
            <if test="financingStage != null  and financingStage != ''"> and a.financing_stage = #{financingStage}</if>
            <if test="financingMoney != null  and financingMoney != ''"> and a.financing_money = #{financingMoney}</if>
            <if test="financingDate != null "> and a.financing_date = #{financingDate}</if>
            <if test="investValuation != null  and investValuation != ''"> and a.invest_valuation = #{investValuation}</if>
            <if test="investMoney != null  and investMoney != ''"> and a.invest_money = #{investMoney}</if>
            <if test="investType != null  and investType != ''"> and a.invest_type = #{investType}</if>
            <if test="investPloy != null  and investPloy != ''"> and a.invest_ploy = #{investPloy}</if>
            <if test="investWorth != null  and investWorth != ''"> and a.invest_worth = #{investWorth}</if>
            <if test="projectStage != null  and projectStage != ''"> and a.project_stage = #{projectStage}</if>
            <if test="projectState != null  and projectState != ''"> and a.project_state = #{projectState}</if>
            <if test="delFlag != null  and delFlag != ''"> and a.del_flag = #{delFlag}</if>
            <if test="projectStatus != null  and projectStatus != ''"> and a.project_status = #{projectStatus}</if>
            <if test="status != null"> and a.status = #{status}</if>
            <if test="approvalFlag != null and approvalFlag  != ''">and a.approval_flag = #{approvalFlag}</if>
            <if test="investigateFlag != null and investigateFlag  != ''">and a.investigate_flag = #{investigateFlag}</if>
            <if test="decisionFlag != null and decisionFlag  != ''">and a.decision_flag = #{decisionFlag}</if>
            <if test="terminationFlag != null and terminationFlag  != ''">and a.termination_flag = #{terminationFlag}</if>
            group by a.id
        </where>
    </select>
    <select id="selectAllInvestmentOpportunityList" resultMap="TProjectPoolVoResult">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts,
        a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding,
        a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.status,a.project_status,
        b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
        c.id, c.name, c.position, c.contact,
        d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head,
        p.PROC_INST_ID_ as 'procInsId',
        p.PROC_DEF_ID_ as 'procDefId',
        date_format(p.START_TIME_, '%Y-%m-%d %H:%i:%s') as 'applyTime',
        date_format(p.END_TIME_, '%Y-%m-%d %H:%i:%s') as 'endTime',
        p.START_USER_ID_ AS 'startUserId',
        uu.nick_name AS 'startUserName',
        dd.dept_name AS 'startDeptName',
        t.NAME_ as 'taskName',
        t.TASK_DEF_KEY_ as 'taskDefKey',
        DATE_FORMAT(t.CREATE_TIME_ ,'%Y-%m-%d %H:%i') as 'taskCreateTiem',
        t.ASSIGNEE_ AS 'assignee',
        ui.nick_name AS 'assigneeName',
        t.ID_ as 'taskId',
        t.EXECUTION_ID_ AS 'executionId',
        rp.DEPLOYMENT_ID_ AS 'deployId'
        from t_project_pool a
        left join t_project_company b ON a.id = b.project_pool_id
        left join t_project_contacts c ON a.project_contacts = c.id
        left join t_project_channel d ON a.channel = d.id
        left join ACT_HI_PROCINST p on a.proc_inst_id = p.PROC_INST_ID_
        LEFT JOIN (SELECT * FROM sys_user LIMIT 100000) uu ON p.START_USER_ID_ = uu.user_id
        LEFT JOIN (SELECT * FROM sys_dept LIMIT 100000) dd ON uu.dept_id = dd.dept_id
        left join ACT_RU_TASK t on a.proc_inst_id = t.PROC_INST_ID_
        left join (select * from sys_user limit 100000) ui on t.ASSIGNEE_ = ui.user_id
        left join ACT_RU_IDENTITYLINK ru on ru.TASK_ID_ = t.ID_
        LEFT JOIN act_re_procdef rp ON t.PROC_DEF_ID_ = rp.ID_
        where a.del_flag in ("0","2") and a.proc_inst_id is not null
        <include refid="where_sql"></include>
    </select>
    <select id="getMyTaskList" resultMap="TProjectPoolVoResult">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts,
        a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding,
        a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.status,a.project_status,
        b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
        c.id contactId, c.name, c.position, c.contact,
        d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head,
        p.PROC_INST_ID_ as 'procInsId',
        p.PROC_DEF_ID_ as 'procDefId',
        date_format(p.START_TIME_, '%Y-%m-%d %H:%i:%s') as 'applyTime',
        date_format(p.END_TIME_, '%Y-%m-%d %H:%i:%s') as 'endTime',
        p.START_USER_ID_ AS 'startUserId',
        uu.nick_name AS 'startUserName',
        dd.dept_name AS 'startDeptName',
        t.NAME_ as 'taskName',
        t.TASK_DEF_KEY_ as 'taskDefKey',
        DATE_FORMAT(t.CREATE_TIME_ ,'%Y-%m-%d %H:%i') as 'taskCreateTiem',
        t.ASSIGNEE_ AS 'assignee',
        ui.nick_name AS 'assigneeName',
        t.ID_ as 'taskId',
        t.EXECUTION_ID_ AS 'executionId',
        rp.DEPLOYMENT_ID_ AS 'deployId'
        from t_project_pool a
        left join t_project_company b ON a.id = b.project_pool_id
        left join t_project_contacts c ON a.project_contacts = c.id
        left join t_project_channel d ON a.channel = d.id
        left join ACT_HI_PROCINST p on a.proc_inst_id = p.PROC_INST_ID_
        LEFT JOIN (SELECT * FROM sys_user LIMIT 100000) uu ON p.START_USER_ID_ = uu.user_id
        LEFT JOIN (SELECT * FROM sys_dept LIMIT 100000) dd ON uu.dept_id = dd.dept_id
        left join ACT_RU_TASK t on a.proc_inst_id = t.PROC_INST_ID_
        left join (select * from sys_user limit 100000) ui on t.ASSIGNEE_ = ui.user_id
        left join ACT_RU_IDENTITYLINK ru on ru.TASK_ID_ = t.ID_
        left join ACT_ID_MEMBERSHIP m on m.GROUP_ID_ = ru.GROUP_ID_ and m.USER_ID_ = #{userId}
        LEFT JOIN act_re_procdef rp ON t.PROC_DEF_ID_ = rp.ID_
        where
        (t.ASSIGNEE_ = #{userId}
        or (t.ASSIGNEE_ is null AND ru.TYPE_ = 'candidate'
        AND (ru.USER_ID_ = #{userId}
        OR ru.GROUP_ID_ IN (
        select g.ID_ from ACT_ID_GROUP g, ACT_ID_MEMBERSHIP membership where g.ID_ = membership.GROUP_ID_ AND
        membership.USER_ID_ = #{userId} )
        )
        )
        )
        and a.del_flag in ("0","2")
        <include refid="where_sql"></include>
        GROUP BY a.id
    </select>
    <select id="getMyDoneTaskList" resultMap="TProjectPoolVoResult">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts,
        a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding,
        a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.status,a.project_status,
        b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
        c.id contactId, c.name, c.position, c.contact,
        d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head,
        p.PROC_INST_ID_ as 'procInsId',
        p.PROC_DEF_ID_ as 'procDefId',
        date_format(p.START_TIME_, '%Y-%m-%d %H:%i:%s') as 'applyTime',
        date_format(p.END_TIME_, '%Y-%m-%d %H:%i:%s') as 'endTime',
        p.START_USER_ID_ AS 'startUserId',
        uu.nick_name AS 'startUserName',
        dd.dept_name AS 'startDeptName',
        t.ID_ AS 'taskId',
        t.NAME_ AS 'taskName',
        t.ASSIGNEE_ AS 'assignee',
        ui.nick_name AS 'assigneeName',
        t.TASK_DEF_KEY_ as 'taskDefKey',
        rp.DEPLOYMENT_ID_ AS 'deployId'
        from t_project_pool a
        left join t_project_company b ON a.id = b.project_pool_id
        left join t_project_contacts c ON a.project_contacts = c.id
        left join t_project_channel d ON a.channel = d.id
        LEFT JOIN (select * from ACT_HI_PROCINST limit 10000000) p on a.proc_inst_id = p.PROC_INST_ID_
        LEFT JOIN ACT_RU_TASK t on a.proc_inst_id = t.PROC_INST_ID_
        LEFT JOIN ACT_RU_IDENTITYLINK ru on a.proc_inst_id = ru.PROC_INST_ID_
        LEFT JOIN (SELECT * FROM sys_user LIMIT 100000) uu ON p.START_USER_ID_ = uu.user_id
        LEFT JOIN (SELECT * FROM sys_dept LIMIT 100000) dd ON uu.dept_id = dd.dept_id
        LEFT JOIN (select * from sys_user limit 100000) ui on t.ASSIGNEE_ = ui.user_id
        LEFT JOIN act_re_procdef rp ON t.PROC_DEF_ID_ = rp.ID_
        where ru.USER_ID_ = #{userId} and a.del_flag in ("0","2")
        <include refid="where_sql"></include>
        GROUP BY a.id
        order by a.create_time desc
    </select>
    <select id="getMyList" resultMap="TProjectPoolVoResult">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts,
        a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding,
        a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time, a.status,a.project_status,
        b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
        c.id contactId, c.name, c.position, c.contact,
        d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head,
        u.nick_name as 'applyUserName',
        p.PROC_INST_ID_ as 'procInsId',
        p.PROC_DEF_ID_ as 'procDefId',
        date_format(p.START_TIME_, '%Y-%m-%d %H:%i:%s') as 'applyTime',
        date_format(p.END_TIME_, '%Y-%m-%d %H:%i:%s') as 'endTime',
        p.START_USER_ID_ AS 'startUserId',
        uu.nick_name AS 'startUserName',
        dd.dept_name AS 'startDeptName',
        t.NAME_ as 'taskName',
        t.TASK_DEF_KEY_ as 'taskDefKey',
        DATE_FORMAT(t.CREATE_TIME_ ,'%Y-%m-%d %H:%i') as 'taskCreateTiem',
        t.ASSIGNEE_ as 'assignee',
        GROUP_CONCAT(DISTINCT ui.nick_name SEPARATOR '\r\n') as 'assigneeName',
        t.ID_ as 'taskId',
        t.EXECUTION_ID_ AS 'executionId',
        rp.DEPLOYMENT_ID_ AS 'deployId'
        from t_project_pool a
        left join t_project_company b ON a.id = b.project_pool_id
        left join t_project_contacts c ON a.project_contacts = c.id
        left join t_project_channel d ON a.channel = d.id
        left join ACT_HI_PROCINST p on a.proc_inst_id = p.PROC_INST_ID_
        LEFT JOIN (SELECT * FROM sys_user LIMIT 100000) uu ON p.START_USER_ID_ = uu.user_id
        LEFT JOIN (SELECT * FROM sys_dept LIMIT 100000) dd ON uu.dept_id = dd.dept_id
        left join sys_user u on a.create_by = u.user_id
        left join ACT_RU_TASK t on a.proc_inst_id = t.PROC_INST_ID_
        left join (select * from sys_user limit 100000) ui on t.ASSIGNEE_ = ui.user_id
        left join ACT_RU_IDENTITYLINK ru on ru.TASK_ID_ = t.ID_
        left join ACT_ID_MEMBERSHIP m on m.GROUP_ID_ = ru.GROUP_ID_ and m.USER_ID_ = #{userId}
        left join act_re_procdef rp ON t.PROC_DEF_ID_ = rp.ID_
        where a.create_by = #{userId} and a.proc_inst_id is not null and a.proc_inst_id != ''
        and a.del_flag in ("0","2")
        <include refid="where_sql"></include>
        GROUP BY a.id
    </select>
    <!--<select id="selectTProjectPoolById" parameterType="String" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolVo"/>
        where a.id = #{id}
    </select>-->
    <select id="selectTProjectPoolByProcInstId" parameterType="java.lang.String" resultMap="TProjectPoolResult">
        select a.id,a.proc_inst_id,a.project_name, d.channel_group project_group, a.record_date, a.project_code, a.channel, a.contact_date, a.project_date, a.decision_date, a.industry, a.company, a.description, a.project_contacts, a.invest_head, a.previous_financing, a.financing_stage, a.financing_condition, a.financing_money, a.financing_date, a.invest_sparkle, a.invest_valuation, a.invest_money, a.invest_type, a.invest_ploy, a.invest_worth, a.shareholding, a.project_stage, a.project_state, a.mark, a.approval_flag, a.investigate_flag, a.decision_flag, a.termination_flag, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time,
               b.id companyId, b.company_name, b.project_pool_id, b.filing_time, b.company_code, b.start_time, b.end_time, b.registered_capital, b.registered_address, b.paid_capital, b.business_address, b.actual_bod, b.phone, b.type,
               c.id contactId, c.name, c.position, c.contact,
               d.channel_name, d.channel_code, d.channel_type, d.channel_group, d.channel_blurb, d.contacts, d.telephone, d.address, d.channel_head,
               r.id reviewId, r.context, r.review_person, r.review_person_id,
               t.TASK_DEF_KEY_ as 'taskDefKey'
        from t_project_pool a
        left join t_project_company b ON a.id = b.project_pool_id
        left join t_project_contacts c ON a.project_contacts = c.id
        left join t_project_channel d ON a.channel = d.id
        left join t_project_review r ON a.id = r.project_pool_id
        left join ACT_RU_TASK t on a.proc_inst_id = t.PROC_INST_ID_
        left join (select * from sys_user limit 100000) ui on t.ASSIGNEE_ = ui.user_id
        left join sys_user u on a.create_by = u.user_id
        where a.proc_inst_id = #{procInstId,jdbcType=VARCHAR}
        GROUP BY a.id
    </select>



</mapper>