<?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.MallAppAddressMapper">

    <resultMap type="MallAppAddress" id="MallAppAddressResult">
        <result property="addressId"    column="address_id"    />
        <result property="sysUserId"    column="sys_user_id"    />
        <result property="addressType"    column="address_type"    />
        <result property="name"    column="name"    />
        <result property="phone"    column="phone"    />
        <result property="provinceId"    column="province_id"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityId"    column="city_id"    />
        <result property="cityName"    column="city_name"    />
        <result property="areaId"    column="area_id"    />
        <result property="areaName"    column="area_name"    />
        <result property="address"    column="address"    />
        <result property="isDefault"    column="is_default"    />
        <result property="status"    column="status"    />
        <result property="remarks"    column="remarks"    />
        <result property="content"    column="content"    />
        <result property="sort"    column="sort"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMallAppAddressVo">
        select address_id, sys_user_id, address_type, name, phone, province_id, province_name, city_id, city_name, area_id, area_name, address, is_default, status, remarks, content, sort, create_at, update_at, del_flag from mall_app_address
    </sql>

    <select id="selectMallAppAddressList" parameterType="MallAppAddress" resultMap="MallAppAddressResult">
        <include refid="selectMallAppAddressVo"/>
        <where>
            <if test="sysUserId != null "> and sys_user_id = #{sysUserId}</if>
            <if test="addressType != null  and addressType != ''"> and address_type = #{addressType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="provinceId != null "> and province_id = #{provinceId}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="address != null  and address != ''"> and address like concat('%', #{address}, '%')</if>
            <if test="isDefault != null  and isDefault != ''"> and is_default = #{isDefault}</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="remarks != null  and remarks != ''"> and remarks like concat('%', #{remarks}, '%')</if>
            <if test="content != null  and content != ''"> and content like concat('%', #{content}, '%')</if>
            <if test="sort != null "> and sort = #{sort}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
            <if test="updateAt != null  and updateAt != ''"> and update_at = #{updateAt}</if>
            <if test="delFlag != null  and delFlag != ''"> and del_flag = #{delFlag}</if>
        </where>
    </select>

    <select id="selectMallAppAddressByAddressId" parameterType="Long" resultMap="MallAppAddressResult">
        <include refid="selectMallAppAddressVo"/>
        where address_id = #{addressId}
    </select>

    <insert id="insertMallAppAddress" parameterType="MallAppAddress" useGeneratedKeys="true" keyProperty="addressId">
        insert into mall_app_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sysUserId != null">sys_user_id,</if>
            <if test="addressType != null">address_type,</if>
            <if test="name != null">name,</if>
            <if test="phone != null">phone,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="cityId != null">city_id,</if>
            <if test="cityName != null">city_name,</if>
            <if test="areaId != null">area_id,</if>
            <if test="areaName != null">area_name,</if>
            <if test="address != null">address,</if>
            <if test="isDefault != null">is_default,</if>
            <if test="status != null">status,</if>
            <if test="remarks != null">remarks,</if>
            <if test="content != null">content,</if>
            <if test="sort != null">sort,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sysUserId != null">#{sysUserId},</if>
            <if test="addressType != null">#{addressType},</if>
            <if test="name != null">#{name},</if>
            <if test="phone != null">#{phone},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="address != null">#{address},</if>
            <if test="isDefault != null">#{isDefault},</if>
            <if test="status != null">#{status},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="content != null">#{content},</if>
            <if test="sort != null">#{sort},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallAppAddress" parameterType="MallAppAddress">
        update mall_app_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="sysUserId != null">sys_user_id = #{sysUserId},</if>
            <if test="addressType != null">address_type = #{addressType},</if>
            <if test="name != null">name = #{name},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="address != null">address = #{address},</if>
            <if test="isDefault != null">is_default = #{isDefault},</if>
            <if test="status != null">status = #{status},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="content != null">content = #{content},</if>
            <if test="sort != null">sort = #{sort},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where address_id = #{addressId}
    </update>

    <delete id="deleteMallAppAddressByAddressId" parameterType="Long">
        delete from mall_app_address where address_id = #{addressId}
    </delete>

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

    <select id="getAddressManageList" parameterType="MallAppAddress" resultMap="MallAppAddressResult">
        <include refid="selectMallAppAddressVo"/>
        <where>
            <if test="sysUserId != null "> and sys_user_id = #{sysUserId}</if>
            <if test="addressType != null  and addressType != ''"> and address_type = #{addressType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="phone != null  and phone != ''"> and phone like concat('%', #{phone}, '%')</if>
            <if test="provinceId != null "> and province_id = #{provinceId}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="address != null  and address != ''"> and address like concat('%', #{address}, '%')</if>
            <if test="keyword != null  and keyword != ''">
             and (
                name like concat('%', #{keyword}, '%') or
                phone like concat('%', #{keyword}, '%') or
                province_name like concat('%', #{keyword}, '%') or
                city_name like concat('%', #{keyword}, '%') or
                area_name like concat('%', #{keyword}, '%') or
                address like concat('%', #{keyword}, '%')
                )
            </if>
            and del_flag = '0'
        </where>
        order by create_at desc
    </select>
</mapper>
