<?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.relationaddress.mapper.RelationAddressMapper">
    
    <resultMap type="com.ruoyi.frequency.relationaddress.entity.RelationAddress" id="RelationAddressResult">
        <result property="id"    column="id"    />
        <result property="delFlag"    column="del_flag"    />
        <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="customerId"    column="customer_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="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="relationType"    column="relation_type"    />
        <result property="relationId"    column="relation_id"    />
    </resultMap>

    <sql id="selectRelationAddressVo">
        select id, del_flag, create_by, create_time, update_by, update_time, customer_id, username, mobile, province, city, area, address, detail, longitude, latitude, relation_type, relation_id from t_relation_address
    </sql>

    <select id="selectRelationAddressList" parameterType="com.ruoyi.frequency.relationaddress.entity.RelationAddress" resultMap="RelationAddressResult">
        <include refid="selectRelationAddressVo"/>
        <where>  
            <if test="createBy != null "> and create_by = #{createBy}</if>
            <if test="updateBy != null "> and update_by = #{updateBy}</if>
            <if test="customerId != null "> and customer_id = #{customerId}</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="province != null  and province != ''"> and province = #{province}</if>
            <if test="city != null  and city != ''"> and city = #{city}</if>
            <if test="area != null  and area != ''"> and area = #{area}</if>
            <if test="address != null  and address != ''"> and address = #{address}</if>
            <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="relationType != null "> and relation_type = #{relationType}</if>
            <if test="relationId != null "> and relation_id = #{relationId}</if>
        </where>
    </select>
    
    <select id="selectRelationAddressById" parameterType="Long" resultMap="RelationAddressResult">
        <include refid="selectRelationAddressVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertRelationAddress" parameterType="com.ruoyi.frequency.relationaddress.entity.RelationAddress">
        insert into t_relation_address
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="delFlag != null">del_flag,</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="customerId != null">customer_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="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="relationType != null">relation_type,</if>
            <if test="relationId != null">relation_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="delFlag != null">#{delFlag},</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="customerId != null">#{customerId},</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="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="relationType != null">#{relationType},</if>
            <if test="relationId != null">#{relationId},</if>
         </trim>
    </insert>

    <update id="updateRelationAddress" parameterType="com.ruoyi.frequency.relationaddress.entity.RelationAddress">
        update t_relation_address
        <trim prefix="SET" suffixOverrides=",">
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <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="customerId != null">customer_id = #{customerId},</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="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="relationType != null">relation_type = #{relationType},</if>
            <if test="relationId != null">relation_id = #{relationId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteRelationAddressById" parameterType="Long">
        delete from t_relation_address where id = #{id}
    </delete>

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