<?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.rocketmq.mapper.InitialSwitchFanInfoMapper">
    
    <resultMap type="InitialSwitchFanInfo" id="InitialSwitchFanInfoResult">
        <result property="id"    column="id"    />
        <result property="fanEntIndex"    column="fan_ent_index"    />
        <result property="fanName"    column="fan_name"    />
        <result property="fanEntityFanState"    column="fan_entity_fan_state"    />
        <result property="clientId"    column="client_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectInitialSwitchFanInfoVo">
        select id, fan_ent_index, fan_name, fan_entity_fan_state, client_id, create_time, update_time, create_by, update_by from initial_switch_fan_info
    </sql>

    <select id="selectInitialSwitchFanInfoList" parameterType="InitialSwitchFanInfo" resultMap="InitialSwitchFanInfoResult">
        <include refid="selectInitialSwitchFanInfoVo"/>
        <where>  
            <if test="fanEntIndex != null  and fanEntIndex != ''"> and fan_ent_index = #{fanEntIndex}</if>
            <if test="fanName != null  and fanName != ''"> and fan_name like concat('%', #{fanName}, '%')</if>
            <if test="fanEntityFanState != null  and fanEntityFanState != ''"> and fan_entity_fan_state = #{fanEntityFanState}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
    </select>
    
    <select id="selectInitialSwitchFanInfoById" parameterType="Long" resultMap="InitialSwitchFanInfoResult">
        <include refid="selectInitialSwitchFanInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertInitialSwitchFanInfo" parameterType="InitialSwitchFanInfo" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into initial_switch_fan_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fanEntIndex != null">fan_ent_index,</if>
            <if test="fanName != null">fan_name,</if>
            <if test="fanEntityFanState != null">fan_entity_fan_state,</if>
            <if test="clientId != null">client_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fanEntIndex != null">#{fanEntIndex},</if>
            <if test="fanName != null">#{fanName},</if>
            <if test="fanEntityFanState != null">#{fanEntityFanState},</if>
            <if test="clientId != null">#{clientId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
         </trim>
    </insert>

    <update id="updateInitialSwitchFanInfo" parameterType="InitialSwitchFanInfo">
        update initial_switch_fan_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="fanEntIndex != null">fan_ent_index = #{fanEntIndex},</if>
            <if test="fanName != null">fan_name = #{fanName},</if>
            <if test="fanEntityFanState != null">fan_entity_fan_state = #{fanEntityFanState},</if>
            <if test="clientId != null">client_id = #{clientId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteInitialSwitchFanInfoById" parameterType="Long">
        delete from initial_switch_fan_info where id = #{id}
    </delete>

    <delete id="deleteInitialSwitchFanInfoByIds" parameterType="String">
        delete from initial_switch_fan_info where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <insert id="insertBatchInitialSwitchFanInfo" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="id">
        insert IGNORE into initial_switch_fan_info
        (
        fan_ent_index,
        fan_name,
        fan_entity_fan_state,
        client_id,
        create_time,
        update_time,
        create_by,
        update_by
        )
        values
        <foreach collection="list" item="item" separator=",">
            (
            #{item.fanEntIndex},
            #{item.fanName},
            #{item.fanEntityFanState},
            #{item.clientId},
            #{item.createTime},
            #{item.updateTime},
            #{item.createBy},
            #{item.updateBy}
            )
        </foreach>
    </insert>
    <select id="getAllFanName" parameterType="InitialSwitchFanInfo" resultType="java.util.Map">
        select fan_name fanName from initial_switch_fan_info
        <where>
            <if test="fanEntIndex != null  and fanEntIndex != ''"> and fan_ent_index = #{fanEntIndex}</if>
            <if test="fanName != null  and fanName != ''"> and fan_name like concat('%', #{fanName}, '%')</if>
            <if test="fanEntityFanState != null  and fanEntityFanState != ''"> and fan_entity_fan_state = #{fanEntityFanState}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        group by fan_name
    </select>
    <select id="getFanMsg" parameterType="InitialSwitchFanInfo" resultMap="InitialSwitchFanInfoResult">
        <include refid="selectInitialSwitchFanInfoVo"/>
        <where>
            <if test="fanEntIndex != null  and fanEntIndex != ''"> and fan_ent_index = #{fanEntIndex}</if>
            <if test="fanName != null  and fanName != ''"> and fan_name like concat('%', #{fanName}, '%')</if>
            <if test="fanEntityFanState != null  and fanEntityFanState != ''"> and fan_entity_fan_state = #{fanEntityFanState}</if>
            <if test="clientId != null  and clientId != ''"> and client_id = #{clientId}</if>
        </where>
        order by create_time desc limit 1
    </select>
</mapper>