<?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.TProjectInvestigateMapper">
    
    <resultMap type="TProjectInvestigate" id="TProjectInvestigateResult">
        <result property="id"    column="id"    />
        <result property="investigateName"    column="investigate_name"    />
        <result property="investigateCode"    column="investigate_code"    />
        <result property="projectPoolId"    column="project_pool_id"    />
        <result property="investigatePerson"    column="investigate_person"    />
        <result property="investigatePersonId"    column="investigate_person_id"    />
        <result property="investigateCost"    column="investigate_cost"    />
        <result property="describe"    column="describe_"    />
        <result property="investigatePlace"    column="investigate_place"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="readiness"    column="readiness"    />
        <result property="thirdParty"    column="third_party"    />
        <result property="deadDate"    column="dead_date"    />
        <result property="remark"    column="remark"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectTProjectInvestigateVo">
        select id, investigate_name, investigate_code, project_pool_id, investigate_place, start_time, end_time, readiness, third_party, dead_date, investigate_person, investigate_person_id, investigate_cost, describe_, remark, status, del_flag, create_by, create_time, update_by, update_time from t_project_investigate
    </sql>

    <select id="selectTProjectInvestigateList" parameterType="TProjectInvestigate" resultMap="TProjectInvestigateResult">
        <include refid="selectTProjectInvestigateVo"/>
        <where>
            del_flag = 0
            <if test="investigateName != null  and investigateName != ''"> and investigate_name like concat('%', #{investigateName}, '%')</if>
            <if test="investigateCode != null  and investigateCode != ''"> and investigate_code = #{investigateCode}</if>
            <if test="projectPoolId != null  and projectPoolId != ''"> and project_pool_id = #{projectPoolId}</if>
            <if test="investigatePerson != null  and investigatePerson != ''"> and investigate_person = #{investigatePerson}</if>
            <if test="investigateCost != null  and investigateCost != ''"> and investigate_cost = #{investigateCost}</if>
            <if test="describe != null  and describe != ''"> and describe = #{describe}</if>
        </where>
    </select>
    
    <select id="selectTProjectInvestigateById" parameterType="String" resultMap="TProjectInvestigateResult">
        <include refid="selectTProjectInvestigateVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTProjectInvestigate" parameterType="TProjectInvestigate">
        insert into t_project_investigate
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="investigateName != null">investigate_name,</if>
            <if test="investigateCode != null">investigate_code,</if>
            <if test="projectPoolId != null">project_pool_id,</if>
            <if test="investigatePerson != null">investigate_person,</if>
            <if test="investigatePersonId != null">investigate_person_id,</if>
            <if test="investigateCost != null">investigate_cost,</if>
            <if test="describe != null">describe_,</if>
            <if test="investigatePlace != null">investigate_place,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="readiness != null">readiness,</if>
            <if test="thirdParty != null">third_party,</if>
            <if test="deadDate != null">dead_date,</if>
            <if test="remark != null">remark,</if>
            <if test="status != null">status,</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="investigateName != null">#{investigateName},</if>
            <if test="investigateCode != null">#{investigateCode},</if>
            <if test="projectPoolId != null">#{projectPoolId},</if>
            <if test="investigatePerson != null">#{investigatePerson},</if>
            <if test="investigatePersonId != null">#{investigatePersonId},</if>
            <if test="investigateCost != null">#{investigateCost},</if>
            <if test="describe != null">#{describe},</if>
            <if test="investigatePlace != null">#{investigatePlace},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="readiness != null">#{readiness},</if>
            <if test="thirdParty != null">#{thirdParty},</if>
            <if test="deadDate != null">#{deadDate},</if>
            <if test="remark != null">#{remark},</if>
            <if test="status != null">#{status},</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="updateTProjectInvestigate" parameterType="TProjectInvestigate">
        update t_project_investigate
        <trim prefix="SET" suffixOverrides=",">
            <if test="investigateName != null">investigate_name = #{investigateName},</if>
            <if test="investigateCode != null">investigate_code = #{investigateCode},</if>
            <if test="projectPoolId != null">project_pool_id = #{projectPoolId},</if>
            <if test="investigatePerson != null">investigate_person = #{investigatePerson},</if>
            <if test="investigatePersonId != null">investigate_person_id = #{investigatePersonId},</if>
            <if test="investigateCost != null">investigate_cost = #{investigateCost},</if>
            <if test="describe != null">describe_ = #{describe},</if>
            <if test="investigatePlace != null">investigate_place = #{investigatePlace},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="readiness != null">readiness = #{readiness},</if>
            <if test="thirdParty != null">third_party = #{thirdParty},</if>
            <if test="deadDate != null">dead_date = #{deadDate},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="status != null">status = #{status},</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="deleteTProjectInvestigateById" parameterType="String">
        delete from t_project_investigate where id = #{id}
    </delete>

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

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

    <select id="listProjectPoolId" parameterType="String" resultMap="TProjectInvestigateResult">
        <include refid="selectTProjectInvestigateVo"/>
        where project_pool_id = #{projectPoolId} and del_flag = 0
    </select>

    <select id="listProjectPoolIdNew" parameterType="String" resultMap="TProjectInvestigateResult">
        <include refid="selectTProjectInvestigateVo"/>
        where project_pool_id = #{projectPoolId} and del_flag = 0
        ORDER BY create_time DESC LIMIT 1
    </select>

    <update id="editStatus" parameterType="String">
        update t_project_investigate
        set status = 1
        where id = #{id}
    </update>

</mapper>