<?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.project.business.mapper.TiTemplatesMapper">
    
    <resultMap type="TiTemplates" id="TiTemplatesResult">
        <result property="id"    column="id"    />
        <result property="templateName"    column="template_name"    />
        <result property="elevatorPosition"    column="elevator_position"    />
        <result property="elevatorQuantity"    column="elevator_quantity"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectTiTemplatesVo">
        select id, template_name, elevator_position, elevator_quantity, del_flag, create_time, create_by, update_time, update_by, remark from ti_templates
    </sql>

    <select id="selectTiTemplatesList" parameterType="TiTemplates" resultMap="TiTemplatesResult">
        <include refid="selectTiTemplatesVo"/>
        <where>  
            <if test="templateName != null and templateName != ''"> and template_name like concat('%', #{templateName}, '%')</if>
            <if test="elevatorPosition != null and elevatorPosition != ''"> and elevator_position like concat('%', #{elevatorPosition}, '%')</if>
            <if test="elevatorQuantity != null "> and elevator_quantity = #{elevatorQuantity}</if>
            and del_flag = '0'
        </where>
    </select>
    
    <select id="selectTiTemplatesById" parameterType="Long" resultMap="TiTemplatesResult">
        <include refid="selectTiTemplatesVo"/>
        where id = #{id}
    </select>

    <select id="selectTiTemplatesByIds" resultType="java.lang.Integer">
        select count(1) from tj_civil_engineering where del_flag = '0' and template_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>

    <insert id="insertTiTemplates" parameterType="TiTemplates" useGeneratedKeys="true" keyProperty="id">
        insert into ti_templates
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="templateName != null">template_name,</if>
            <if test="elevatorPosition != null and elevatorPosition != ''">elevator_position,</if>
            <if test="elevatorQuantity != null">elevator_quantity,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="templateName != null">#{templateName},</if>
            <if test="elevatorPosition != null and elevatorPosition != ''">#{elevatorPosition},</if>
            <if test="elevatorQuantity != null">#{elevatorQuantity},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateTiTemplates" parameterType="TiTemplates">
        update ti_templates
        <trim prefix="SET" suffixOverrides=",">
            <if test="templateName != null">template_name = #{templateName},</if>
            <if test="elevatorPosition != null and elevatorPosition != ''">elevator_position = #{elevatorPosition},</if>
            <if test="elevatorQuantity != null">elevator_quantity = #{elevatorQuantity},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTiTemplatesById" parameterType="Long">
        update ti_templates set del_flag = '1' where id = #{id}
    </update>

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