AddressMapper.xml
4.2 KB
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
91
92
93
94
95
96
97
98
99
<?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.sibu.orderHelper.integral.dao.AddressDao">
<resultMap id="MemberAddressResponse" type="com.sibu.orderHelper.integral.reponse.MemberAddressResponse" >
<id column="address_id" property="addressId" jdbcType="VARCHAR" />
<result column="member_id" property="memberId" jdbcType="VARCHAR" />
<result column="contact" property="contact" jdbcType="VARCHAR" />
<result column="phone" property="phone" jdbcType="VARCHAR" />
<result column="province" property="province" jdbcType="VARCHAR" />
<result column="city" property="city" jdbcType="VARCHAR" />
<result column="area" property="area" jdbcType="VARCHAR" />
<result column="zip_code" property="zipCode" jdbcType="VARCHAR" />
<result column="detail" property="detail" jdbcType="VARCHAR" />
<result column="is_default" property="isDefault" jdbcType="INTEGER" />
</resultMap>
<sql id="memberAddressSql">
address_id, member_id, contact, phone, province, city, area, detail,zip_code, is_default
</sql>
<!-- 分页查询用户收货地址 -->
<select id="listAddress" resultMap="MemberAddressResponse" parameterType="java.util.Map">
select <include refid="memberAddressSql"/>
from t_member_address where member_id = #{memberId,jdbcType=VARCHAR} and delete_flag = 0
ORDER BY is_default DESC, address_id DESC
LIMIT ${pageNow}, ${pageSize}
</select>
<select id="countAddress" resultType="java.lang.Integer" parameterType="java.util.Map">
select count(*) from t_member_address
where member_id = #{memberId,jdbcType=VARCHAR} and delete_flag = 0
</select>
<!-- 添加收货地址 -->
<insert id="addAddress" useGeneratedKeys="true" keyProperty="addressId" parameterType="com.sibu.orderHelper.integral.request.MemberAddressAddRequest" >
insert into t_member_address (member_id, contact,
phone, province, city,
area, detail, is_default, zip_code,
create_dt
)
values (#{memberId,jdbcType=VARCHAR}, #{contact,jdbcType=VARCHAR},
#{phone,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, #{city,jdbcType=VARCHAR},
#{area,jdbcType=VARCHAR}, #{detail,jdbcType=VARCHAR}, #{isDefault,jdbcType=INTEGER}, #{zipCode,jdbcType=VARCHAR},
now()
)
</insert>
<!-- 更新收货地址信息 -->
<update id="editAddress" parameterType="com.sibu.orderHelper.integral.request.MemberAddressAddRequest" >
update t_member_address set
contact = #{contact,jdbcType=VARCHAR},
phone = #{phone,jdbcType=VARCHAR},
province = #{province,jdbcType=VARCHAR},
city = #{city,jdbcType=VARCHAR},
area = #{area,jdbcType=VARCHAR},
detail = #{detail,jdbcType=VARCHAR},
zip_code = #{zipCode,jdbcType=VARCHAR},
is_default = #{isDefault,jdbcType=INTEGER},
update_dt = sysdate()
where address_id = #{addressId,jdbcType=INTEGER} and member_id = #{memberId,jdbcType=VARCHAR} limit 1
</update>
<!-- 更新默认收货地址 -->
<update id="updateDefaultAddress" parameterType="java.util.Map" >
update t_member_address
set is_default = #{isDefault,jdbcType=INTEGER},
update_dt = now()
where delete_flag = 0 and member_id = #{memberId,jdbcType=VARCHAR}
<if test="addressId != null and addressId != ''">
and address_id != #{addressId,jdbcType=INTEGER}
</if>
</update>
<!-- 查询收货详情 -->
<select id="getAddressDetail" resultMap="MemberAddressResponse" parameterType="java.lang.Integer" >
select <include refid="memberAddressSql"/>, create_dt, update_dt, delete_flag
from t_member_address
where address_id = #{addressId,jdbcType=INTEGER} and delete_flag = 0 limit 1
</select>
<!--查询用户默认地址-->
<select id="getDefalutAddress" resultMap="MemberAddressResponse" parameterType="java.util.Map">
select <include refid="memberAddressSql"/>
from t_member_address where delete_flag = 0 and member_id = #{memberId,jdbcType=VARCHAR}
<if test="isDefault != null">
and is_default = #{isDefault,jdbcType=INTEGER}
</if>
limit 1
</select>
<!--删除地址-->
<update id="delAddress" parameterType="java.util.Map">
update t_member_address set delete_flag = 1 where address_id = #{addressId,jdbcType=INTEGER} and member_id = #{memberId,jdbcType=VARCHAR} limit 1
</update>
</mapper>