<?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.voluntary.mapper.SysLocationsMapper">
    
    <resultMap type="SysLocations" id="SysLocationsResult">
        <result property="id"    column="id"    />
        <result property="code"    column="code"    />
        <result property="name"    column="name"    />
        <result property="sname"    column="sname"    />
        <result property="ename"    column="ename"    />
        <result property="sename"    column="sename"    />
        <result property="parentId"    column="parentId"    />
        <result property="priority"    column="priority"    />
        <result property="level"    column="level"    />
    </resultMap>

    <sql id="selectSysLocationsVo">
        select id, code, name, sname, ename, sename, parentId, priority, level from b_sys_locations
    </sql>

    <select id="selectSysLocationsList" parameterType="SysLocations" resultMap="SysLocationsResult">
        <include refid="selectSysLocationsVo"/>
        where 1=1
            <if test="id != null"> and id = #{id}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="sname != null  and sname != ''"> and sname like concat('%', #{sname}, '%')</if>
            <if test="ename != null  and ename != ''"> and ename like concat('%', #{ename}, '%')</if>
            <if test="sename != null  and sename != ''"> and sename like concat('%', #{sename}, '%')</if>
            <if test="parentId != null "> and parentId = #{parentId}</if>
            <if test="priority != null "> and priority = #{priority}</if>
            <if test="level != null "> and level = #{level}</if>
    </select>
    
    <select id="selectSysLocationsById" parameterType="Long" resultMap="SysLocationsResult">
        <include refid="selectSysLocationsVo"/>
        where id = #{id}
    </select>

    <select id="selectSysLocationsByCode" parameterType="String" resultMap="SysLocationsResult">
        <include refid="selectSysLocationsVo"/>
        where code like concat(#{code}, '%')
        order by code
    </select>

    <select id="selectSysLocationsBySname" parameterType="String" resultMap="SysLocationsResult">
        <include refid="selectSysLocationsVo"/>
        where sname = #{sname}
    </select>
        
    <insert id="insertSysLocations" parameterType="SysLocations" useGeneratedKeys="true" keyProperty="id">
        insert into b_sys_locations
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="code != null and code != ''">code,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="sname != null">sname,</if>
            <if test="ename != null and ename != ''">ename,</if>
            <if test="sename != null and sename != ''">sename,</if>
            <if test="parentId != null">parentId,</if>
            <if test="priority != null">priority,</if>
            <if test="level != null">level,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="code != null and code != ''">#{code},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="sname != null">#{sname},</if>
            <if test="ename != null and ename != ''">#{ename},</if>
            <if test="sename != null and sename != ''">#{sename},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="priority != null">#{priority},</if>
            <if test="level != null">#{level},</if>
         </trim>
    </insert>

    <update id="updateSysLocations" parameterType="SysLocations">
        update b_sys_locations
        <trim prefix="SET" suffixOverrides=",">
            <if test="code != null and code != ''">code = #{code},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="sname != null">sname = #{sname},</if>
            <if test="ename != null and ename != ''">ename = #{ename},</if>
            <if test="sename != null and sename != ''">sename = #{sename},</if>
            <if test="parentId != null">parentId = #{parentId},</if>
            <if test="priority != null">priority = #{priority},</if>
            <if test="level != null">level = #{level},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysLocationsById" parameterType="Long">
        delete from b_sys_locations where id = #{id}
    </delete>

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