<?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.TProjectPoolMapper">
    
    <resultMap type="TProjectPool" id="TProjectPoolResult">
        <result property="id"    column="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="procInstId"    column="proc_inst_id"    />
        <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="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="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.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
        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.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,
               r.id, 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>

    <select id="selectTProjectPoolList" parameterType="TProjectPool" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolVo"/>
        <where>
            a.project_state != '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>
        </where>
    </select>

    <select id="selectTProjectPoolListStage" parameterType="TProjectPool" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolVo"/>
        <where>
            <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>
        </where>
    </select>


    <select id="selectTProjectPoolById" parameterType="String" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolVo"/>
        where a.id = #{id}
    </select>
        
    <insert id="insertTProjectPool" parameterType="TProjectPool">
        insert into t_project_pool
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="procInstId != null">proc_inst_id,</if>
            <if test="projectName != null">project_name,</if>
            <if test="projectGroup != null">project_group,</if>
            <if test="recordDate != null">record_date,</if>
            <if test="projectCode != null">project_code,</if>
            <if test="channel != null">channel,</if>
            <if test="contactDate != null">contact_date,</if>
            <if test="projectDate != null">project_date,</if>
            <if test="decisionDate != null">decision_date,</if>
            <if test="industry != null">industry,</if>
            <if test="company != null">company,</if>
            <if test="description != null">description,</if>
            <if test="projectContacts != null">project_contacts,</if>
            <if test="investHead != null">invest_head,</if>
            <if test="previousFinancing != null">previous_financing,</if>
            <if test="financingStage != null">financing_stage,</if>
            <if test="financingCondition != null">financing_condition,</if>
            <if test="financingMoney != null">financing_money,</if>
            <if test="financingDate != null">financing_date,</if>
            <if test="investSparkle != null">invest_sparkle,</if>
            <if test="investValuation != null">invest_valuation,</if>
            <if test="investMoney != null">invest_money,</if>
            <if test="investType != null">invest_type,</if>
            <if test="investPloy != null">invest_ploy,</if>
            <if test="investWorth != null">invest_worth,</if>
            <if test="shareholding != null">shareholding,</if>
            <if test="projectStage != null">project_stage,</if>
            <if test="projectState != null">project_state,</if>
            <if test="mark != null">mark,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="procInstId != null">#{procInstId},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="projectGroup != null">#{projectGroup},</if>
            <if test="recordDate != null">#{recordDate},</if>
            <if test="projectCode != null">#{projectCode},</if>
            <if test="channel != null">#{channel},</if>
            <if test="contactDate != null">#{contactDate},</if>
            <if test="projectDate != null">#{projectDate},</if>
            <if test="decisionDate != null">#{decisionDate},</if>
            <if test="industry != null">#{industry},</if>
            <if test="company != null">#{company},</if>
            <if test="description != null">#{description},</if>
            <if test="projectContacts != null">#{projectContacts},</if>
            <if test="investHead != null">#{investHead},</if>
            <if test="previousFinancing != null">#{previousFinancing},</if>
            <if test="financingStage != null">#{financingStage},</if>
            <if test="financingCondition != null">#{financingCondition},</if>
            <if test="financingMoney != null">#{financingMoney},</if>
            <if test="financingDate != null">#{financingDate},</if>
            <if test="investSparkle != null">#{investSparkle},</if>
            <if test="investValuation != null">#{investValuation},</if>
            <if test="investMoney != null">#{investMoney},</if>
            <if test="investType != null">#{investType},</if>
            <if test="investPloy != null">#{investPloy},</if>
            <if test="investWorth != null">#{investWorth},</if>
            <if test="shareholding != null">#{shareholding},</if>
            <if test="projectStage != null">#{projectStage},</if>
            <if test="projectState != null">#{projectState},</if>
            <if test="mark != null">#{mark},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateTProjectPool" parameterType="TProjectPool">
        update t_project_pool
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="projectGroup != null">project_group = #{projectGroup},</if>
            <if test="recordDate != null">record_date = #{recordDate},</if>
            <if test="projectCode != null">project_code = #{projectCode},</if>
            <if test="channel != null">channel = #{channel},</if>
            <if test="contactDate != null">contact_date = #{contactDate},</if>
            <if test="projectDate != null">project_date = #{projectDate},</if>
            <if test="decisionDate != null">decision_date = #{decisionDate},</if>
            <if test="industry != null">industry = #{industry},</if>
            <if test="company != null">company = #{company},</if>
            <if test="description != null">description = #{description},</if>
            <if test="projectContacts != null">project_contacts = #{projectContacts},</if>
            <if test="investHead != null">invest_head = #{investHead},</if>
            <if test="previousFinancing != null">previous_financing = #{previousFinancing},</if>
            <if test="financingStage != null">financing_stage = #{financingStage},</if>
            <if test="financingCondition != null">financing_condition = #{financingCondition},</if>
            <if test="financingMoney != null">financing_money = #{financingMoney},</if>
            <if test="financingDate != null">financing_date = #{financingDate},</if>
            <if test="investSparkle != null">invest_sparkle = #{investSparkle},</if>
            <if test="investValuation != null">invest_valuation = #{investValuation},</if>
            <if test="investMoney != null">invest_money = #{investMoney},</if>
            <if test="investType != null">invest_type = #{investType},</if>
            <if test="investPloy != null">invest_ploy = #{investPloy},</if>
            <if test="investWorth != null">invest_worth = #{investWorth},</if>
            <if test="shareholding != null">shareholding = #{shareholding},</if>
            <if test="projectStage != null">project_stage = #{projectStage},</if>
            <if test="projectState != null">project_state = #{projectState},</if>
            <if test="approvalFlag != null">approval_flag = #{approvalFlag},</if>
            <if test="investigateFlag != null">investigate_flag = #{investigateFlag},</if>
            <if test="decisionFlag != null">decision_flag = #{decisionFlag},</if>
            <if test="terminationFlag != null">termination_flag = #{terminationFlag},</if>
            <if test="mark != null">mark = #{mark},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="projectStatus != null">project_status = #{projectStatus},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTProjectPoolById" parameterType="String">
        delete from t_project_pool where id = #{id}
    </delete>

    <delete id="deleteTProjectPoolByIds" parameterType="String">
        delete from t_project_pool where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateTProjectPoolByIds" parameterType="String">
        update t_project_pool
        set del_flag = 1
        where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="selectTProjectPoolCode" parameterType="String" resultType="java.lang.Integer">
        select count(*) from t_project_pool
        where project_code like concat('%', #{year}, '%')
    </select>

    <select id="selectTProjectPoolReviewList" parameterType="TProjectPool" resultMap="TProjectPoolResult">
        <include refid="selectTProjectPoolReviewVo"/>
        <where>
            <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>
        </where>
    </select>

    <update id="updateTProjectPoolByApprovalFlag" parameterType="String">
        update t_project_pool
        set approval_flag = #{flag}
        where id = #{id}
    </update>

    <update id="updateTProjectPoolByInvestigateFlag" parameterType="String">
        update t_project_pool
        set investigate_flag = #{flag}
        where id = #{id}
    </update>

    <update id="updateTProjectPoolByDecisionFlag" parameterType="String">
        update t_project_pool
        set decision_flag = #{flag}
        where id = #{id}
    </update>
    <update id="updateTProjectPoolByTerminationFlag" parameterType="String">
        update t_project_pool
        set termination_flag = #{flag}
        where id = #{id}
    </update>

    <update id="updateTProjectPoolByDelFlag" parameterType="String">
        update t_project_pool
        set del_flag = #{flag}
        where id = #{id}
    </update>

</mapper>