Helius
2022-02-21 f54f8a92c09a2cd76b3bbb796df680215b63ab8a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?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.xzx.gc.user.mapper.AddressMapper">
    <resultMap id="AddressMap" type="com.xzx.gc.model.user.AddressVo">
        <result column="address_id" jdbcType="INTEGER" property="addressId"/>
        <result column="mobile_phone" jdbcType="VARCHAR" property="mobilePhone"/>
        <result column="user_id" jdbcType="VARCHAR" property="userId"/>
        <result column="province_id" jdbcType="VARCHAR" property="provinceId"/>
        <result column="city_id" jdbcType="VARCHAR" property="cityId"/>
        <result column="township_id" jdbcType="VARCHAR" property="townshipId"/>
        <result column="detail_address" jdbcType="VARCHAR" property="detailAddress"/>
        <result column="address_area" jdbcType="VARCHAR" property="addressArea"/>
        <result column="stair_type" jdbcType="VARCHAR" property="stairType"/>
        <result column="rela_phone" jdbcType="VARCHAR" property="relaPhone"/>
        <result column="rela_name" jdbcType="VARCHAR" property="relaName"/>
        <result column="del_flag" jdbcType="VARCHAR" property="delFlag"/>
        <result column="tag_name" jdbcType="VARCHAR" property="tagName"/>
        <result column="unit_name" jdbcType="VARCHAR" property="unitName"/>
        <result column="house_number" jdbcType="VARCHAR" property="houseNumber"/>
        <result column="receive_address" jdbcType="VARCHAR" property="receiveAddress"/>
        <result column="house_name" jdbcType="VARCHAR" property="houseName"/>
    </resultMap>
 
    <!-- 地址查询 -->
    <select id="addressQuery" parameterType="java.util.Map" resultMap="AddressMap">
        select a.*,b.level_1_name provinceName,b.level_2_name cityName,
        b.level_3_name townshipName,c.config_value_name stairTypeName
        from xzx_user_address_info a
        left OUTER join xzx_sys_address_level_info b on a.province_id=b.level_1_id and a.city_id=b.level_2_id and a.township_id=b.level_3_id
        left OUTER join xzx_sys_config_info c on a.stair_type=c.config_value and c.config_type_code='STAIR_TYPE'
        where 1=1 and a.del_flag='0'
        <if test="addressId!=null">
            and a.address_id=#{addressId}
        </if>
        <if test="userId!=null">
            and a.user_id=#{userId}
        </if>
    </select>
 
    <!-- 根据区域名称查询ID -->
    <select id="queryAreaIdByName" parameterType="java.util.Map" resultMap="AddressMap">
        select level_1_id province_id,level_2_id city_id,level_3_id township_id,citycode,adcode,pcode
        from xzx_sys_address_level_info
        where level_1_name=#{provinceName}
        and level_2_name=#{cityName} and level_3_name=#{townshipName}
    </select>
 
    <select id="queryAreaIdById" parameterType="java.util.Map" resultMap="AddressMap">
        select level_1_id province_id,level_2_id city_id,level_3_id township_id,citycode,adcode
        from xzx_sys_address_level_info
        where level_1_id=#{provinceId}
              and level_2_id=#{cityId}  and level_3_id=#{townshipId}
    </select>
 
    <!-- 更新用户其它地址标志(当某一地址设为默认时,其它地址为非默认)   -->
    <update id="updateAddressFlag" parameterType="java.util.Map">
        update xzx_user_address_info
        set flag="0"
        where mobile_phone=#{mobilePhone} and address_id!=#{addressId}
    </update>
    <!-- 逻辑删除地址   -->
    <update id="deleteAddress">
        update
          xzx_user_address_info
        set
          del_flag="1"
        where
          address_id=#{addressId}
    </update>
 
    <!-- 自动设置最小ID为默认地址   -->
    <update id="autoSetDefaultAddress"  >
        update
          xzx_user_address_info a
        set
          a.flag="1"
        where
          a.address_id =
          (
            select c.minid from (select min(b.address_id) as minid
            from xzx_user_address_info b where b.del_flag='0' and b.user_id=#{userId})c)
    </update>
 
    <select id="queryCuserAddress" resultType="java.util.HashMap">
        SELECT address_area as addressArea,del_flag as delFlag,flag,create_time as createTime
            ,township_id as townShipId, detail_address as detailAddress ,latitude ,longitude,rela_name as relaName,
               address_id as addressId,rela_phone as relaPhone ,user_id as userId FROM xzx_user_address_info
        WHERE mobile_phone=#{phone} and user_id=#{userId} and del_flag = 0
    </select>
</mapper>