<?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.mallorderaddress.mapper.MallOrderAddressMapper">

    <resultMap type="com.ruoyi.frequency.mallorderaddress.entity.MallOrderAddress" id="MallOrderAddressResult">
        <result property="id"    column="id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="consigneeUsername"    column="consignee_username"    />
        <result property="consigneeMobile"    column="consignee_mobile"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityName"    column="city_name"    />
        <result property="areaName"    column="area_name"    />
        <result property="address"    column="address"    />
        <result property="orderId"    column="order_id"    />
        <result property="detail"    column="detail"    />
        <result property="areaCode"    column="area_code"    />
        </resultMap>

    
    
    <sql id="selectMallOrderAddressVo">
        select
            t.id ,
            t.create_by ,
            t.create_time ,
            t.update_by ,
            t.update_time ,
            t.del_flag ,
            t.consignee_username ,
            t.consignee_mobile ,
            t.province_name ,
            t.city_name ,
            t.area_name ,
            t.address ,
            t.order_id ,
            t.detail ,
            t.area_code 
        from mall_order_address AS t
                
    </sql>

    <select id="selectMallOrderAddressList" parameterType="com.ruoyi.frequency.mallorderaddress.entity.MallOrderAddress" resultMap="MallOrderAddressResult">
        <include refid="selectMallOrderAddressVo"/>
        <where> AND t.del_flag != 2
            <if test="consigneeUsername != null  and consigneeUsername != ''"> and t.consignee_username like concat('%', #{consigneeUsername}, '%')</if>
            <if test="consigneeMobile != null  and consigneeMobile != ''"> and t.consignee_mobile = #{consigneeMobile}</if>
            <if test="provinceName != null  and provinceName != ''"> and t.province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityName != null  and cityName != ''"> and t.city_name like concat('%', #{cityName}, '%')</if>
            <if test="areaName != null  and areaName != ''"> and t.area_name like concat('%', #{areaName}, '%')</if>
            <if test="address != null  and address != ''"> and t.address = #{address}</if>
            <if test="orderId != null "> and t.order_id = #{orderId}</if>
            <if test="detail != null  and detail != ''"> and t.detail = #{detail}</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="selectMallOrderAddressById" parameterType="Long" resultMap="MallOrderAddressResult">
        <include refid="selectMallOrderAddressVo"/>
        where t.id = #{id}
    </select>

    <insert id="insertMallOrderAddress" parameterType="com.ruoyi.frequency.mallorderaddress.entity.MallOrderAddress">
        insert into mall_order_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="consigneeUsername != null">consignee_username,</if>
            <if test="consigneeMobile != null">consignee_mobile,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="cityName != null">city_name,</if>
            <if test="areaName != null">area_name,</if>
            <if test="address != null">address,</if>
            <if test="orderId != null">order_id,</if>
            <if test="detail != null">detail,</if>
            <if test="areaCode != null">area_code,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="consigneeUsername != null">#{consigneeUsername},</if>
            <if test="consigneeMobile != null">#{consigneeMobile},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="address != null">#{address},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="detail != null">#{detail},</if>
            <if test="areaCode != null">#{areaCode},</if>
        </trim>
    </insert>

    <update id="updateMallOrderAddress" parameterType="com.ruoyi.frequency.mallorderaddress.entity.MallOrderAddress">
        update mall_order_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="consigneeUsername != null">consignee_username = #{consigneeUsername},</if>
            <if test="consigneeMobile != null">consignee_mobile = #{consigneeMobile},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="address != null">address = #{address},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="detail != null">detail = #{detail},</if>
            <if test="areaCode != null">area_code = #{areaCode},</if>
        </trim>
        where id = #{id}
    </update>
                                                                                                                        </mapper>