<?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.zehong.system.mapper.TPlanInfoMapper">
    
    <resultMap type="TPlanInfo" id="TPlanInfoResult">
        <result property="planId"    column="plan_id"    />
        <result property="planTitle"    column="plan_title"    />
        <result property="planType"    column="plan_type"    />
        <result property="planLevel"    column="plan_level"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="planContents"    column="plan_contents"    />
        <result property="planEquipment"    column="plan_equipment"    />
        <result property="iconUrl"    column="icon_url"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTPlanInfoVo">
        select plan_id, plan_title, plan_type, plan_level, beyond_enterprise_id, beyond_enterprise_name, plan_contents, plan_equipment, icon_url, create_by, create_time, update_by, update_time, is_del, remarks from t_plan_info
    </sql>

    <select id="selectTPlanInfoList" parameterType="TPlanInfo" resultMap="TPlanInfoResult">
        <include refid="selectTPlanInfoVo"/>
        <where>  
            <if test="planTitle != null  and planTitle != ''"> and plan_title = #{planTitle}</if>
            <if test="planType != null  and planType != ''"> and plan_type = #{planType}</if>
            <if test="planLevel != null  and planLevel != ''"> and plan_level = #{planLevel}</if>
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != ''"> and beyond_enterprise_id = #{beyondEnterpriseId}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectTPlanInfoById" parameterType="Long" resultMap="TPlanInfoResult">
        <include refid="selectTPlanInfoVo"/>
        where plan_id = #{planId}
    </select>
        
    <insert id="insertTPlanInfo" parameterType="TPlanInfo" useGeneratedKeys="true" keyProperty="planId">
        insert into t_plan_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planTitle != null">plan_title,</if>
            <if test="planType != null">plan_type,</if>
            <if test="planLevel != null">plan_level,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="planContents != null">plan_contents,</if>
            <if test="planEquipment != null">plan_equipment,</if>
            <if test="iconUrl != null">icon_url,</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>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="planTitle != null">#{planTitle},</if>
            <if test="planType != null">#{planType},</if>
            <if test="planLevel != null">#{planLevel},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="planContents != null">#{planContents},</if>
            <if test="planEquipment != null">#{planEquipment},</if>
            <if test="iconUrl != null">#{iconUrl},</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>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTPlanInfo" parameterType="TPlanInfo">
        update t_plan_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="planTitle != null">plan_title = #{planTitle},</if>
            <if test="planType != null">plan_type = #{planType},</if>
            <if test="planLevel != null">plan_level = #{planLevel},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="planContents != null">plan_contents = #{planContents},</if>
            <if test="planEquipment != null">plan_equipment = #{planEquipment},</if>
            <if test="iconUrl != null">icon_url = #{iconUrl},</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>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where plan_id = #{planId}
    </update>

    <delete id="deleteTPlanInfoById" parameterType="Long">
        delete from t_plan_info where plan_id = #{planId}
    </delete>

    <delete id="deleteTPlanInfoByIds" parameterType="String">
        delete from t_plan_info where plan_id in 
        <foreach item="planId" collection="array" open="(" separator="," close=")">
            #{planId}
        </foreach>
    </delete>
    <select id="selectEnterprise" resultType="java.util.HashMap">
        SELECT enterprise_id as enterpriseId,enterprise_name as enterpriseName FROM t_enterprise_info
        WHERE is_del = 0
    </select>
</mapper>