Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Y
yudao-cloud
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
hblj
yudao-cloud
Commits
22d73605
提交
22d73605
authored
4月 10, 2019
作者:
sin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 用户地址 添加 hasDefault
上级
dd452f81
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
121 行增加
和
37 行删除
+121
-37
UserAddressController.java
...r/application/controller/users/UserAddressController.java
+4
-1
UserAddressUpdatePO.java
...iocoder/mall/user/application/po/UserAddressUpdatePO.java
+6
-2
UserAddressBO.java
.../main/java/cn/iocoder/mall/user/api/bo/UserAddressBO.java
+4
-2
UserAddressPageBO.java
...n/java/cn/iocoder/mall/user/api/bo/UserAddressPageBO.java
+0
-28
UserAddressHasDefaultEnum.java
...der/mall/user/api/constant/UserAddressHasDefaultEnum.java
+30
-0
UserAddressAddDTO.java
.../java/cn/iocoder/mall/user/api/dto/UserAddressAddDTO.java
+7
-1
UserAddressUpdateDTO.java
...va/cn/iocoder/mall/user/api/dto/UserAddressUpdateDTO.java
+4
-1
UserAddressMapper.java
.../java/cn/iocoder/mall/user/biz/dao/UserAddressMapper.java
+6
-0
UserAddressDO.java
...va/cn/iocoder/mall/user/biz/dataobject/UserAddressDO.java
+4
-0
UserAddressServiceImpl.java
...iocoder/mall/user/biz/service/UserAddressServiceImpl.java
+46
-2
UserAddress.xml
...er-service-impl/src/main/resources/mapper/UserAddress.xml
+10
-0
没有找到文件。
user/user-application/src/main/java/cn/iocoder/mall/user/application/controller/users/UserAddressController.java
浏览文件 @
22d73605
package
cn
.
iocoder
.
mall
.
user
.
application
.
controller
.
users
;
package
cn
.
iocoder
.
mall
.
user
.
application
.
controller
.
users
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.user.api.bo.UserAddressBO
;
import
cn.iocoder.mall.user.application.convert.UserAddressConvert
;
import
cn.iocoder.mall.user.application.convert.UserAddressConvert
;
import
cn.iocoder.mall.user.application.po.UserAddressAddPO
;
import
cn.iocoder.mall.user.application.po.UserAddressAddPO
;
import
cn.iocoder.mall.user.application.po.UserAddressUpdatePO
;
import
cn.iocoder.mall.user.application.po.UserAddressUpdatePO
;
...
@@ -14,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -14,6 +15,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
/**
/**
* 用户地址
* 用户地址
*
*
...
@@ -55,7 +58,7 @@ public class UserAddressController {
...
@@ -55,7 +58,7 @@ public class UserAddressController {
@GetMapping
(
"list"
)
@GetMapping
(
"list"
)
@ApiOperation
(
value
=
"用户地址列表"
)
@ApiOperation
(
value
=
"用户地址列表"
)
public
CommonResult
addressList
()
{
public
CommonResult
<
List
<
UserAddressBO
>>
addressList
()
{
Integer
userId
=
UserSecurityContextHolder
.
getContext
().
getUserId
();
Integer
userId
=
UserSecurityContextHolder
.
getContext
().
getUserId
();
return
userAddressService
.
addressList
(
userId
);
return
userAddressService
.
addressList
(
userId
);
}
}
...
...
user/user-application/src/main/java/cn/iocoder/mall/user/application/po/UserAddressUpdatePO.java
浏览文件 @
22d73605
...
@@ -20,7 +20,6 @@ import java.io.Serializable;
...
@@ -20,7 +20,6 @@ import java.io.Serializable;
@Accessors
(
chain
=
true
)
@Accessors
(
chain
=
true
)
public
class
UserAddressUpdatePO
implements
Serializable
{
public
class
UserAddressUpdatePO
implements
Serializable
{
/**
/**
* 收件区域编号
* 收件区域编号
*/
*/
...
@@ -53,5 +52,10 @@ public class UserAddressUpdatePO implements Serializable {
...
@@ -53,5 +52,10 @@ public class UserAddressUpdatePO implements Serializable {
@NotNull
(
message
=
"详细地址不能为空"
)
@NotNull
(
message
=
"详细地址不能为空"
)
@Size
(
min
=
10
,
max
=
100
,
message
=
"地址在 10 ~ 100 字之间!"
)
@Size
(
min
=
10
,
max
=
100
,
message
=
"地址在 10 ~ 100 字之间!"
)
private
String
address
;
private
String
address
;
/**
* 是否设置默认
*/
@ApiModelProperty
(
"是否设置默认"
)
@NotNull
(
message
=
"是否设置默认不能为空"
)
private
Integer
hasDefault
;
}
}
user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/UserAddressBO.java
浏览文件 @
22d73605
...
@@ -13,7 +13,6 @@ import java.io.Serializable;
...
@@ -13,7 +13,6 @@ import java.io.Serializable;
@Accessors
(
chain
=
true
)
@Accessors
(
chain
=
true
)
public
class
UserAddressBO
implements
Serializable
{
public
class
UserAddressBO
implements
Serializable
{
/**
/**
* 编号
* 编号
*/
*/
...
@@ -38,5 +37,8 @@ public class UserAddressBO implements Serializable {
...
@@ -38,5 +37,8 @@ public class UserAddressBO implements Serializable {
* 收件详细地址
* 收件详细地址
*/
*/
private
String
address
;
private
String
address
;
/**
* 是否默认
*/
private
Integer
hasDefault
;
}
}
user/user-service-api/src/main/java/cn/iocoder/mall/user/api/bo/UserAddressPageBO.java
deleted
100644 → 0
浏览文件 @
dd452f81
package
cn
.
iocoder
.
mall
.
user
.
api
.
bo
;
import
lombok.Data
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.util.List
;
/**
* 用户地址 page
*
* @author Sin
* @time 2019-04-06 13:56
*/
@Data
@Accessors
(
chain
=
true
)
public
class
UserAddressPageBO
implements
Serializable
{
/**
* 总量
*/
private
Integer
total
;
/**
* 地址
*/
private
List
<
UserAddressBO
>
list
;
}
user/user-service-api/src/main/java/cn/iocoder/mall/user/api/constant/UserAddressHasDefaultEnum.java
0 → 100644
浏览文件 @
22d73605
package
cn
.
iocoder
.
mall
.
user
.
api
.
constant
;
/**
* 用户地址 - 用户默认地址
*
* @author Sin
* @time 2019-04-10 22:02
*/
public
enum
UserAddressHasDefaultEnum
{
DEFAULT_ADDRESS_NO
(
1
,
"不是默认地址"
),
DEFAULT_ADDRESS_YES
(
2
,
"不是默认地址"
)
;
private
final
int
value
;
private
final
String
name
;
UserAddressHasDefaultEnum
(
int
value
,
String
name
)
{
this
.
value
=
value
;
this
.
name
=
name
;
}
public
int
getValue
()
{
return
value
;
}
public
String
getName
()
{
return
name
;
}
}
user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAddressAddDTO.java
浏览文件 @
22d73605
...
@@ -35,5 +35,11 @@ public class UserAddressAddDTO implements Serializable {
...
@@ -35,5 +35,11 @@ public class UserAddressAddDTO implements Serializable {
* 收件详细地址
* 收件详细地址
*/
*/
private
String
address
;
private
String
address
;
/**
* 是否默认
*
* - 1 不是
* - 2 是
*/
private
Integer
hasDefault
;
}
}
user/user-service-api/src/main/java/cn/iocoder/mall/user/api/dto/UserAddressUpdateDTO.java
浏览文件 @
22d73605
...
@@ -39,5 +39,8 @@ public class UserAddressUpdateDTO implements Serializable {
...
@@ -39,5 +39,8 @@ public class UserAddressUpdateDTO implements Serializable {
* 收件详细地址
* 收件详细地址
*/
*/
private
String
address
;
private
String
address
;
/**
* 是否默认地址
*/
private
Integer
hasDefault
;
}
}
user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dao/UserAddressMapper.java
浏览文件 @
22d73605
...
@@ -31,4 +31,10 @@ public interface UserAddressMapper {
...
@@ -31,4 +31,10 @@ public interface UserAddressMapper {
Integer
userId
,
Integer
userId
,
Integer
id
Integer
id
);
);
UserAddressDO
selectHasDefault
(
Integer
deleted
,
Integer
userId
,
Integer
hasDefault
);
}
}
user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/dataobject/UserAddressDO.java
浏览文件 @
22d73605
...
@@ -38,5 +38,9 @@ public class UserAddressDO extends DeletableDO {
...
@@ -38,5 +38,9 @@ public class UserAddressDO extends DeletableDO {
* 收件详细地址
* 收件详细地址
*/
*/
private
String
address
;
private
String
address
;
/**
* 是否为默认
*/
private
Integer
hasDefault
;
}
}
user/user-service-impl/src/main/java/cn/iocoder/mall/user/biz/service/UserAddressServiceImpl.java
浏览文件 @
22d73605
...
@@ -3,6 +3,7 @@ package cn.iocoder.mall.user.biz.service;
...
@@ -3,6 +3,7 @@ package cn.iocoder.mall.user.biz.service;
import
cn.iocoder.common.framework.constant.DeletedStatusEnum
;
import
cn.iocoder.common.framework.constant.DeletedStatusEnum
;
import
cn.iocoder.common.framework.util.ServiceExceptionUtil
;
import
cn.iocoder.common.framework.util.ServiceExceptionUtil
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.common.framework.vo.CommonResult
;
import
cn.iocoder.mall.user.api.constant.UserAddressHasDefaultEnum
;
import
cn.iocoder.mall.user.api.constant.UserErrorCodeEnum
;
import
cn.iocoder.mall.user.api.constant.UserErrorCodeEnum
;
import
cn.iocoder.mall.user.biz.convert.UserAddressConvert
;
import
cn.iocoder.mall.user.biz.convert.UserAddressConvert
;
import
cn.iocoder.mall.user.biz.dao.UserAddressMapper
;
import
cn.iocoder.mall.user.biz.dao.UserAddressMapper
;
...
@@ -13,6 +14,7 @@ import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
...
@@ -13,6 +14,7 @@ import cn.iocoder.mall.user.api.dto.UserAddressAddDTO;
import
cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO
;
import
cn.iocoder.mall.user.api.dto.UserAddressUpdateDTO
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -31,12 +33,28 @@ public class UserAddressServiceImpl implements UserAddressService {
...
@@ -31,12 +33,28 @@ public class UserAddressServiceImpl implements UserAddressService {
private
UserAddressMapper
userAddressMapper
;
private
UserAddressMapper
userAddressMapper
;
@Override
@Override
@Transactional
public
CommonResult
addAddress
(
UserAddressAddDTO
userAddressAddDTO
)
{
public
CommonResult
addAddress
(
UserAddressAddDTO
userAddressAddDTO
)
{
UserAddressDO
userAddressDO
=
UserAddressConvert
.
INSTANCE
.
convert
(
userAddressAddDTO
);
UserAddressDO
userAddressDO
=
UserAddressConvert
.
INSTANCE
.
convert
(
userAddressAddDTO
);
userAddressDO
.
setCreateTime
(
new
Date
());
userAddressDO
.
setCreateTime
(
new
Date
());
userAddressDO
.
setDeleted
(
DeletedStatusEnum
.
DELETED_NO
.
getValue
());
userAddressDO
.
setDeleted
(
DeletedStatusEnum
.
DELETED_NO
.
getValue
());
userAddressMapper
.
insert
(
userAddressDO
);
return
CommonResult
.
success
(
null
);
// 检查是否设置为默认地址
if
(
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_YES
.
getValue
()
==
userAddressAddDTO
.
getHasDefault
())
{
UserAddressDO
defaultUserAddress
=
userAddressMapper
.
selectHasDefault
(
DeletedStatusEnum
.
DELETED_NO
.
getValue
(),
userAddressAddDTO
.
getUserId
(),
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_YES
.
getValue
());
if
(
defaultUserAddress
!=
null
)
{
userAddressMapper
.
updateById
(
defaultUserAddress
.
getId
(),
new
UserAddressDO
()
.
setHasDefault
(
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_NO
.
getValue
())
);
}
}
int
result
=
userAddressMapper
.
insert
(
userAddressDO
);
return
CommonResult
.
success
(
result
);
}
}
@Override
@Override
...
@@ -52,6 +70,32 @@ public class UserAddressServiceImpl implements UserAddressService {
...
@@ -52,6 +70,32 @@ public class UserAddressServiceImpl implements UserAddressService {
return
ServiceExceptionUtil
.
error
(
UserErrorCodeEnum
.
USER_ADDRESS_NOT_EXISTENT
.
getCode
());
return
ServiceExceptionUtil
.
error
(
UserErrorCodeEnum
.
USER_ADDRESS_NOT_EXISTENT
.
getCode
());
}
}
// 检查是否设置为默认地址
if
(
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_YES
.
getValue
()
==
userAddressAddDTO
.
getHasDefault
())
{
UserAddressDO
defaultUserAddress
=
userAddressMapper
.
selectHasDefault
(
DeletedStatusEnum
.
DELETED_NO
.
getValue
(),
userAddressAddDTO
.
getUserId
(),
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_YES
.
getValue
());
if
(
defaultUserAddress
!=
null
&&
!
userAddressAddDTO
.
getId
().
equals
(
defaultUserAddress
.
getId
()))
{
userAddressMapper
.
updateById
(
defaultUserAddress
.
getId
(),
new
UserAddressDO
()
.
setHasDefault
(
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_NO
.
getValue
())
);
}
}
UserAddressDO
defaultUserAddress
=
userAddressMapper
.
selectHasDefault
(
DeletedStatusEnum
.
DELETED_NO
.
getValue
(),
userAddressAddDTO
.
getUserId
(),
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_YES
.
getValue
());
if
(
defaultUserAddress
!=
null
&&
!
userAddressAddDTO
.
getId
().
equals
(
defaultUserAddress
.
getId
()))
{
userAddressMapper
.
updateById
(
defaultUserAddress
.
getId
(),
new
UserAddressDO
()
.
setHasDefault
(
UserAddressHasDefaultEnum
.
DEFAULT_ADDRESS_NO
.
getValue
())
);
}
UserAddressDO
userAddressDO
=
UserAddressConvert
.
INSTANCE
.
convert
(
userAddressAddDTO
);
UserAddressDO
userAddressDO
=
UserAddressConvert
.
INSTANCE
.
convert
(
userAddressAddDTO
);
userAddressDO
.
setUpdateTime
(
new
Date
());
userAddressDO
.
setUpdateTime
(
new
Date
());
userAddressMapper
.
updateById
(
userAddressDO
.
getId
(),
userAddressDO
);
userAddressMapper
.
updateById
(
userAddressDO
.
getId
(),
userAddressDO
);
...
...
user/user-service-impl/src/main/resources/mapper/UserAddress.xml
浏览文件 @
22d73605
...
@@ -57,4 +57,13 @@
...
@@ -57,4 +57,13 @@
WHERE deleted = #{deleted}
WHERE deleted = #{deleted}
AND `user_id` = #{userId}
AND `user_id` = #{userId}
</select>
</select>
<select
id=
"selectHasDefault"
resultType=
"cn.iocoder.mall.user.biz.dataobject.UserAddressDO"
>
SELECT
<include
refid=
"FIELDS"
/>
FROM user_address
WHERE deleted = #{deleted}
AND `user_id` = #{userId}
AND `has_default` = #{hasDefault}
</select>
</mapper>
</mapper>
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论