<?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.frequency.malladdress.mapper.MallAddressMapper">

    <resultMap type="com.ruoyi.frequency.malladdress.entity.MallAddress" id="MallAddressResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="userType"    column="user_type"    />
        <result property="userId"    column="user_id"    />
        <result property="username"    column="username"    />
        <result property="mobile"    column="mobile"    />
        <result property="province"    column="province"    />
        <result property="city"    column="city"    />
        <result property="area"    column="area"    />
        <result property="address"    column="address"    />
        <result property="detail"    column="detail"    />
        <result property="isDefault"    column="is_default"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="areaCode"    column="area_code"    />
    </resultMap>

    <sql id="selectMallAddressVo">
        select
            t.id ,
            t.del_flag ,
            t.update_time ,
            t.create_time ,
            t.create_by ,
            t.update_by ,
            t.user_type ,
            t.user_id ,
            t.username ,
            t.mobile ,
            t.province ,
            t.city ,
            t.area ,
            t.address ,
            t.detail ,
            t.is_default ,
            t.longitude ,
            t.latitude ,
            t.area_code
        from mall_address AS t
    </sql>

    <select id="selectMallAddressList" parameterType="com.ruoyi.frequency.malladdress.entity.MallAddress" resultMap="MallAddressResult">
        <include refid="selectMallAddressVo"/>
        <where> AND t.del_flag != 2
            <if test="userType != null "> and t.user_type = #{userType}</if>
            <if test="userId != null "> and t.user_id = #{userId}</if>
            <if test="username != null  and username != ''"> and t.username like concat('%', #{username}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and t.mobile = #{mobile}</if>
            <if test="province != null  and province != ''"> and t.province = #{province}</if>
            <if test="city != null  and city != ''"> and t.city = #{city}</if>
            <if test="area != null  and area != ''"> and t.area = #{area}</if>
            <if test="address != null  and address != ''"> and t.address = #{address}</if>
            <if test="detail != null  and detail != ''"> and t.detail = #{detail}</if>
            <if test="isDefault != null "> and t.is_default = #{isDefault}</if>
            <if test="longitude != null  and longitude != ''"> and t.longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and t.latitude = #{latitude}</if>
            <if test="areaCode != null  and areaCode != ''"> and t.area_code = #{areaCode}</if>
            <if test="delFlag != null and delFlag != ''"> and t.del_flag = #{delFlag}</if>
        </where>
        order by t.create_time desc
    </select>

    <select id="selectMallAddressById" parameterType="Long" resultMap="MallAddressResult">
        <include refid="selectMallAddressVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertMallAddress" parameterType="com.ruoyi.frequency.malladdress.entity.MallAddress">
        insert into mall_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="userType != null">user_type,</if>
            <if test="userId != null">user_id,</if>
            <if test="username != null">username,</if>
            <if test="mobile != null">mobile,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="area != null">area,</if>
            <if test="address != null">address,</if>
            <if test="detail != null">detail,</if>
            <if test="isDefault != null">is_default,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="areaCode != null">area_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="userType != null">#{userType},</if>
            <if test="userId != null">#{userId},</if>
            <if test="username != null">#{username},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="area != null">#{area},</if>
            <if test="address != null">#{address},</if>
            <if test="detail != null">#{detail},</if>
            <if test="isDefault != null">#{isDefault},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="areaCode != null">#{areaCode},</if>
        </trim>
    </insert>

    <update id="updateMallAddress" parameterType="com.ruoyi.frequency.malladdress.entity.MallAddress">
        update mall_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="userType != null">user_type = #{userType},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="username != null">username = #{username},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="area != null">area = #{area},</if>
            <if test="address != null">address = #{address},</if>
            <if test="detail != null">detail = #{detail},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
        </trim>
        where id = #{id}
    </update>
                                                                                                                        </mapper>
