<?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.huashe.park.core.mapper.ProjectInfoMapper">

    <resultMap type="ProjectInfo" id="ProjectInfoResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="updateTime" column="update_time"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
        <result property="tenantId" column="tenant_id"/>
    </resultMap>

    <sql id="selectProjectInfoVo">
        select id, name, update_time, create_time, create_by, update_by, tenant_id
        from cons_project_info
    </sql>

    <select id="selectProjectInfoList" parameterType="ProjectInfo" resultMap="ProjectInfoResult">
        <include refid="selectProjectInfoVo"/>
        <where>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
        </where>
    </select>

    <select id="selectProjectInfoById" parameterType="Long" resultMap="ProjectInfoResult">
        <include refid="selectProjectInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertProjectInfo" parameterType="ProjectInfo" useGeneratedKeys="true" keyProperty="id">
        insert into cons_project_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="tenantId != null">tenant_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="tenantId != null">#{tenantId},</if>
        </trim>
    </insert>

    <update id="updateProjectInfo" parameterType="ProjectInfo">
        update cons_project_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteProjectInfoById" parameterType="Long">
        delete
        from cons_project_info
        where id = #{id}
    </delete>

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