<?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.TProjectContractMapper">
    
    <resultMap type="TProjectContract" id="TProjectContractResult">
        <result property="id"    column="id"    />
        <result property="contractName"    column="contract_name"    />
        <result property="contractType"    column="contract_type"    />
        <result property="projectPoolId"    column="project_pool_id"    />
        <result property="projectStage"    column="project_stage"    />
        <result property="meetingCode"    column="meeting_code"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="fileBusinessId"    column="file_business_id"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <association property="tProjectPool" javaType="TProjectPool"  resultMap="TProjectPoolResult" />
    </resultMap>

    <resultMap type="TProjectPool" id="TProjectPoolResult">
        <result property="projectName"    column="project_name"    />
        <result property="projectStage"    column="project_stage"    />
        <result property="projectState"    column="project_state"    />
        <result property="projectGroup"    column="project_group"    />
        <result property="projectCode"    column="project_code"    />
    </resultMap>

    <sql id="selectTProjectContractVo">
        select a.id, a.contract_name, a.contract_type, a.project_pool_id, a.project_stage, a.meeting_code, a.del_flag, a.file_business_id, a.remark, a.create_by, a.create_time, a.update_by, a.update_time,
                b.project_name, b.project_stage, b.project_state, b.project_group ,b.project_code
        from t_project_contract a
             left join t_project_pool b ON a.project_pool_id = b.id
    </sql>

    <select id="selectTProjectContractList" parameterType="TProjectContract" resultMap="TProjectContractResult">
        <include refid="selectTProjectContractVo"/>
        <where>
            a.del_flag = 0
            <if test="contractName != null  and contractName != ''"> and a.contract_name like concat('%', #{contractName}, '%')</if>
            <if test="contractType != null  and contractType != ''"> and a.contract_type = #{contractType}</if>
            <if test="projectPoolId != null  and projectPoolId != ''"> and a.project_pool_id = #{projectPoolId}</if>
            <if test="projectStage != null  and projectStage != ''"> and a.project_stage = #{projectStage}</if>
            <if test="meetingCode != null  and meetingCode != ''"> and a.meeting_code = #{meetingCode}</if>
        </where>
    </select>
    
    <select id="selectTProjectContractById" parameterType="String" resultMap="TProjectContractResult">
        <include refid="selectTProjectContractVo"/>
        where a.id = #{id}
    </select>
        
    <insert id="insertTProjectContract" parameterType="TProjectContract">
        insert into t_project_contract
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="contractName != null">contract_name,</if>
            <if test="contractType != null">contract_type,</if>
            <if test="projectPoolId != null">project_pool_id,</if>
            <if test="projectStage != null">project_stage,</if>
            <if test="meetingCode != null">meeting_code,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="fileBusinessId != null">file_business_id,</if>
            <if test="remark != null">remark,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="contractName != null">#{contractName},</if>
            <if test="contractType != null">#{contractType},</if>
            <if test="projectPoolId != null">#{projectPoolId},</if>
            <if test="projectStage != null">#{projectStage},</if>
            <if test="meetingCode != null">#{meetingCode},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="fileBusinessId != null">#{fileBusinessId},</if>
            <if test="remark != null">#{remark},</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>
         </trim>
    </insert>

    <update id="updateTProjectContract" parameterType="TProjectContract">
        update t_project_contract
        <trim prefix="SET" suffixOverrides=",">
            <if test="contractName != null">contract_name = #{contractName},</if>
            <if test="contractType != null">contract_type = #{contractType},</if>
            <if test="projectPoolId != null">project_pool_id = #{projectPoolId},</if>
            <if test="projectStage != null">project_stage = #{projectStage},</if>
            <if test="meetingCode != null">meeting_code = #{meetingCode},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="fileBusinessId != null">file_business_id = #{fileBusinessId},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTProjectContractById" parameterType="String">
        delete from t_project_contract where id = #{id}
    </delete>

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