<?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.system.mapper.TKufangMapper">
    
    <resultMap type="TKufang" id="TKufangResult">
        <result property="id"    column="id"    />
        <result property="kfName"    column="kf_name"    />
        <result property="kfAddress"    column="kf_address"    />
        <result property="kfAdmin"    column="kf_admin"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTKufangVo">
        select id, kf_name, kf_address, kf_admin, create_time from t_kufang
    </sql>

    <select id="selectTKufangList" parameterType="TKufang" resultMap="TKufangResult">
        <include refid="selectTKufangVo"/>
        <where>  
            <if test="kfName != null  and kfName != ''"> and kf_name like '%'+#{kfName}+'%'</if>
            <if test="kfAddress != null  and kfAddress != ''"> and kf_address = #{kfAddress}</if>
            <if test="kfAdmin != null "> and kf_admin = #{kfAdmin}</if>
        </where>
    </select>
    
    <select id="selectTKufangById" parameterType="Long" resultMap="TKufangResult">
        <include refid="selectTKufangVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTKufang" parameterType="TKufang" useGeneratedKeys="true" keyProperty="id">
        insert into t_kufang
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="kfName != null">kf_name,</if>
            <if test="kfAddress != null">kf_address,</if>
            <if test="kfAdmin != null">kf_admin,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="kfName != null">#{kfName},</if>
            <if test="kfAddress != null">#{kfAddress},</if>
            <if test="kfAdmin != null">#{kfAdmin},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTKufang" parameterType="TKufang">
        update t_kufang
        <trim prefix="SET" suffixOverrides=",">
            <if test="kfName != null">kf_name = #{kfName},</if>
            <if test="kfAddress != null">kf_address = #{kfAddress},</if>
            <if test="kfAdmin != null">kf_admin = #{kfAdmin},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTKufangById" parameterType="Long">
        delete from t_kufang where id = #{id}
    </delete>

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

    <select id="getUserByRole" resultType="java.util.Map">
        SELECT su.user_id userId, su.user_name userName FROM (
             SELECT sur.user_id FROM sys_user_role sur
             WHERE sur.role_id > 2
             GROUP BY sur.user_id
         ) tmp
         LEFT JOIN sys_user su ON tmp.user_id = su.user_id
    </select>
</mapper>