<?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.TProjectRecordMapper">
    
    <resultMap type="TProjectRecord" id="TProjectRecordResult">
        <result property="id"    column="id"    />
        <result property="projectId"    column="project_id"    />
        <result property="contacts"    column="contacts"    />
        <result property="realityUpDate"    column="reality_up_date"    />
        <result property="upPerson"    column="up_person"    />
        <result property="upWay"    column="up_way"    />
        <result property="upContent"    column="up_content"    />
        <result property="mark"    column="mark"    />
        <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"    />

        <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"    />
    </resultMap>

    <sql id="selectTProjectRecordVo">
        select a.id, a.project_id, a.contacts, a.reality_up_date, a.up_person, a.up_way, a.up_content, a.mark, a.del_flag, a.create_by, a.create_time, a.update_by, a.update_time,
               b.project_name, b.project_stage, b.project_state
        from t_project_record a
            left join t_project_pool b ON a.project_id = b.id
    </sql>

    <select id="selectTProjectRecordList" parameterType="TProjectRecord" resultMap="TProjectRecordResult">
        <include refid="selectTProjectRecordVo"/>
        <where>
            a.del_flag = 0
            <if test="projectName != null and projectName != ''"> and b.project_name like concat('%', #{projectName}, '%')</if>
            <if test="projectId != null  and projectId != ''"> and a.project_id = #{projectId}</if>
            <if test="contacts != null  and contacts != ''"> and a.contacts like concat('%', #{contacts}, '%')</if>
            <if test="realityUpDate != null "> and a.reality_up_date = #{realityUpDate}</if>
            <if test="upPerson != null  and upPerson != ''"> and a.up_person like concat('%', #{upPerson}, '%')</if>
            <if test="upWay != null  and upWay != ''"> and a.up_way = #{upWay}</if>
        </where>
    </select>
    
    <select id="selectTProjectRecordById" parameterType="String" resultMap="TProjectRecordResult">
        <include refid="selectTProjectRecordVo"/>
        where a.id = #{id}
    </select>
        
    <insert id="insertTProjectRecord" parameterType="TProjectRecord">
        insert into t_project_record
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="contacts != null">contacts,</if>
            <if test="realityUpDate != null">reality_up_date,</if>
            <if test="upPerson != null">up_person,</if>
            <if test="upWay != null">up_way,</if>
            <if test="upContent != null">up_content,</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>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="contacts != null">#{contacts},</if>
            <if test="realityUpDate != null">#{realityUpDate},</if>
            <if test="upPerson != null">#{upPerson},</if>
            <if test="upWay != null">#{upWay},</if>
            <if test="upContent != null">#{upContent},</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>
         </trim>
    </insert>

    <update id="updateTProjectRecord" parameterType="TProjectRecord">
        update t_project_record
        <trim prefix="SET" suffixOverrides=",">
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="contacts != null">contacts = #{contacts},</if>
            <if test="realityUpDate != null">reality_up_date = #{realityUpDate},</if>
            <if test="upPerson != null">up_person = #{upPerson},</if>
            <if test="upWay != null">up_way = #{upWay},</if>
            <if test="upContent != null">up_content = #{upContent},</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>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTProjectRecordById" parameterType="String">
        delete from t_project_record where id = #{id}
    </delete>

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

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

    <select id="listProjectId" parameterType="String" resultMap="TProjectRecordResult">
        <include refid="selectTProjectRecordVo"/>
        where a.project_id = #{projectId} and a.del_flag = 0
    </select>


</mapper>