<?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.mall.mapper.MallRegionMapper">

    <resultMap type="MallRegion" id="MallRegionResult">
        <result property="id"    column="id"    />
        <result property="pid"    column="pid"    />
        <result property="shortname"    column="shortname"    />
        <result property="name"    column="name"    />
        <result property="mergerName"    column="merger_name"    />
        <result property="type"    column="type"    />
        <result property="pinyin"    column="pinyin"    />
        <result property="phoneCode"    column="phone_code"    />
        <result property="code"    column="code"    />
        <result property="first"    column="first"    />
        <result property="lng"    column="lng"    />
        <result property="lat"    column="lat"    />
    </resultMap>

    <sql id="selectMallRegionVo">
        select id, pid, shortname, name, merger_name, type, pinyin, phone_code, code, first, lng, lat from mall_region
    </sql>

    <select id="selectMallRegionList" parameterType="MallRegion" resultMap="MallRegionResult">
        <include refid="selectMallRegionVo"/>
        <where>
            <if test="id != null "> and id = #{id}</if>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="shortname != null  and shortname != ''"> and shortname like concat('%', #{shortname}, '%')</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="mergerName != null  and mergerName != ''"> and merger_name like concat('%', #{mergerName}, '%')</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="pinyin != null  and pinyin != ''"> and pinyin = #{pinyin}</if>
            <if test="phoneCode != null  and phoneCode != ''"> and phone_code = #{phoneCode}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="first != null  and first != ''"> and first = #{first}</if>
            <if test="lng != null  and lng != ''"> and lng = #{lng}</if>
            <if test="lat != null  and lat != ''"> and lat = #{lat}</if>
        </where>
    </select>

    <select id="selectList" parameterType="integer" resultMap="MallRegionResult">
        <include refid="selectMallRegionVo"/>
        <where>
            <if test="pid != null "> and pid = #{pid}</if>
        </where>
    </select>

    <select id="selectMallRegionById" parameterType="Integer" resultMap="MallRegionResult">
        <include refid="selectMallRegionVo"/>
        where id = #{id}
    </select>

    <insert id="insertMallRegion" parameterType="MallRegion">
        insert into mall_region
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="pid != null">pid,</if>
            <if test="shortname != null">shortname,</if>
            <if test="name != null">name,</if>
            <if test="mergerName != null">merger_name,</if>
            <if test="type != null">type,</if>
            <if test="pinyin != null">pinyin,</if>
            <if test="phoneCode != null">phone_code,</if>
            <if test="code != null">code,</if>
            <if test="first != null">first,</if>
            <if test="lng != null">lng,</if>
            <if test="lat != null">lat,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="pid != null">#{pid},</if>
            <if test="shortname != null">#{shortname},</if>
            <if test="name != null">#{name},</if>
            <if test="mergerName != null">#{mergerName},</if>
            <if test="type != null">#{type},</if>
            <if test="pinyin != null">#{pinyin},</if>
            <if test="phoneCode != null">#{phoneCode},</if>
            <if test="code != null">#{code},</if>
            <if test="first != null">#{first},</if>
            <if test="lng != null">#{lng},</if>
            <if test="lat != null">#{lat},</if>
        </trim>
    </insert>

    <update id="updateMallRegion" parameterType="MallRegion">
        update mall_region
        <trim prefix="SET" suffixOverrides=",">
            <if test="pid != null">pid = #{pid},</if>
            <if test="shortname != null">shortname = #{shortname},</if>
            <if test="name != null">name = #{name},</if>
            <if test="mergerName != null">merger_name = #{mergerName},</if>
            <if test="type != null">type = #{type},</if>
            <if test="pinyin != null">pinyin = #{pinyin},</if>
            <if test="phoneCode != null">phone_code = #{phoneCode},</if>
            <if test="code != null">code = #{code},</if>
            <if test="first != null">first = #{first},</if>
            <if test="lng != null">lng = #{lng},</if>
            <if test="lat != null">lat = #{lat},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMallRegionById" parameterType="Integer">
        delete from mall_region where id = #{id}
    </delete>

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

    <select id="getRegionByPid" parameterType="Integer" resultMap="MallRegionResult">
        <include refid="selectMallRegionVo"/>
        where pid = #{pid}
    </select>

    <select id="getRegionName" parameterType="long" resultType="String">
        select name from mall_region
        where id = #{id}
    </select>

    <select id="getRegionIdByRegionName" resultType="Integer">
        select id from mall_region
        <where>
            <if test="pid != null "> and pid = #{pid}</if>
            <if test="regionName != null  and regionName != ''"> and name = #{regionName}</if>
        </where>
    </select>
</mapper>
