<?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.TProjectMeetingMapper">
    
    <resultMap type="TProjectMeeting" id="TProjectMeetingResult">
        <result property="id"    column="id"    />
        <result property="meetingTheme"    column="meeting_theme"    />
        <result property="meetingCode"    column="meeting_code"    />
        <result property="meetingType"    column="meeting_type"    />
        <result property="projectPoolId"    column="project_pool_id"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="place"    column="place"    />
        <result property="promoter"    column="promoter"    />
        <result property="participants"    column="participants"    />
        <result property="promoterId"    column="promoter_id"    />
        <result property="participantsId"    column="participants_id"    />
        <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"    />
        <result property="projectGroup"    column="project_group"    />
        <result property="projectCode"    column="project_code"    />
        <result property="investHead"    column="invest_head"    />
        <result property="company"    column="company_name"    />
    </resultMap>

    <sql id="selectTProjectMeetingVo">
        select a.id, a.meeting_theme, a.meeting_code, a.meeting_type, a.project_pool_id, a.start_time, a.end_time, a.place, a.promoter, a.participants, a.promoter_id, a.participants_id,a.del_flag, 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, b.invest_head,c.company_name
        from t_project_meeting a
             left join t_project_pool b ON a.project_pool_id = b.id
             left join t_project_company c ON b.id = c.project_pool_id
    </sql>

    <select id="selectTProjectMeetingList" parameterType="TProjectMeeting" resultMap="TProjectMeetingResult">
        <include refid="selectTProjectMeetingVo"/>
        <where>
            a.del_flag = 0
            <if test="projectPoolId != null  and projectPoolId != ''"> and a.project_pool_id = #{projectPoolId}</if>
            <if test="meetingTheme != null  and meetingTheme != ''"> and a.meeting_theme like concat('%', #{meetingTheme}, '%')</if>
            <if test="meetingCode != null  and meetingCode != ''"> and a.meeting_code like concat('%', #{meetingCode}, '%')</if>
            <if test="meetingType != null  and meetingType != ''"> and a.meeting_type = #{meetingType}</if>
            <if test="startTime != null "> and DATE_FORMAT(a.start_time, '%Y-%m-%d') &gt;= #{startTime}</if>
            <if test="endTime != null "> and DATE_FORMAT(a.end_time, '%Y-%m-%d') &lt;= #{endTime}</if>
        </where>
    </select>
    
    <select id="selectTProjectMeetingById" parameterType="String" resultMap="TProjectMeetingResult">
        <include refid="selectTProjectMeetingVo"/>
        where a.id = #{id}
    </select>
        
    <insert id="insertTProjectMeeting" parameterType="TProjectMeeting">
        insert into t_project_meeting
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="meetingTheme != null">meeting_theme,</if>
            <if test="meetingCode != null">meeting_code,</if>
            <if test="meetingType != null">meeting_type,</if>
            <if test="projectPoolId != null">project_pool_id,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="place != null">place,</if>
            <if test="promoter != null">promoter,</if>
            <if test="participants != null">participants,</if>
            <if test="promoterId != null">promoter_id,</if>
            <if test="participantsId != null">participants_id,</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="meetingTheme != null">#{meetingTheme},</if>
            <if test="meetingCode != null">#{meetingCode},</if>
            <if test="meetingType != null">#{meetingType},</if>
            <if test="projectPoolId != null">#{projectPoolId},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="place != null">#{place},</if>
            <if test="promoter != null">#{promoter},</if>
            <if test="participants != null">#{participants},</if>
            <if test="promoterId != null">#{promoterId},</if>
            <if test="participantsId != null">#{participantsId},</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="updateTProjectMeeting" parameterType="TProjectMeeting">
        update t_project_meeting
        <trim prefix="SET" suffixOverrides=",">
            <if test="meetingTheme != null">meeting_theme = #{meetingTheme},</if>
            <if test="meetingCode != null">meeting_code = #{meetingCode},</if>
            <if test="meetingType != null">meeting_type = #{meetingType},</if>
            <if test="projectPoolId != null">project_pool_id = #{projectPoolId},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="place != null">place = #{place},</if>
            <if test="promoter != null">promoter = #{promoter},</if>
            <if test="participants != null">participants = #{participants},</if>
            <if test="promoterId != null">promoter_id = #{promoterId},</if>
            <if test="participantsId != null">participants_id = #{participantsId},</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="deleteTProjectMeetingById" parameterType="String">
        delete from t_project_meeting where id = #{id}
    </delete>

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

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

    <select id="listProjectPoolId" parameterType="String" resultMap="TProjectMeetingResult">
        <include refid="selectTProjectMeetingVo"/>
        where a.project_pool_id = #{projectPoolId} and a.del_flag = 0
    </select>

    <select id="listProjectPoolIdNew" parameterType="String" resultMap="TProjectMeetingResult">
        <include refid="selectTProjectMeetingVo"/>
        where a.project_pool_id = #{projectPoolId} and a.meeting_type = #{meetingType} and a.del_flag = 0
        ORDER BY a.create_time DESC LIMIT 1
    </select>

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

</mapper>