Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
O
on-site-service
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
external
on-site-service
Commits
4598abb1
Commit
4598abb1
authored
Jul 20, 2022
by
lining
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 逻辑删除地址
parent
2452c0df
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
31 deletions
+25
-31
ServiceAddressController.java
.../miniapp/controller/address/ServiceAddressController.java
+1
-1
ServiceAddressService.java
...ervice/miniapp/service/address/ServiceAddressService.java
+24
-30
No files found.
mini-app/src/main/java/com/onsiteservice/miniapp/controller/address/ServiceAddressController.java
View file @
4598abb1
...
@@ -67,7 +67,7 @@ public class ServiceAddressController {
...
@@ -67,7 +67,7 @@ public class ServiceAddressController {
@ApiOperation
(
value
=
"修改服务地址"
)
@ApiOperation
(
value
=
"修改服务地址"
)
@PutMapping
(
"update"
)
@PutMapping
(
"update"
)
public
Result
saveOrU
pdate
(
@RequestBody
@NonNull
@Validated
UpdateServiceAddressDTO
dto
,
@CurrentUserId
Long
userId
)
{
public
Result
u
pdate
(
@RequestBody
@NonNull
@Validated
UpdateServiceAddressDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceAddressService
.
update
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"修改失败"
);
return
serviceAddressService
.
update
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"修改失败"
);
}
}
...
...
mini-app/src/main/java/com/onsiteservice/miniapp/service/address/ServiceAddressService.java
View file @
4598abb1
...
@@ -8,7 +8,9 @@ import com.onsiteservice.core.result.Result;
...
@@ -8,7 +8,9 @@ import com.onsiteservice.core.result.Result;
import
com.onsiteservice.core.result.ResultGenerator
;
import
com.onsiteservice.core.result.ResultGenerator
;
import
com.onsiteservice.dao.common.AbstractMapper
;
import
com.onsiteservice.dao.common.AbstractMapper
;
import
com.onsiteservice.dao.common.page.PageInfoVO
;
import
com.onsiteservice.dao.common.page.PageInfoVO
;
import
com.onsiteservice.dao.mapper.service.ServiceAddressMapper
;
import
com.onsiteservice.dao.mapper.service.ServiceAreaMapper
;
import
com.onsiteservice.dao.mapper.service.ServiceAreaMapper
;
import
com.onsiteservice.dao.mapper.service.ServiceOrderMapper
;
import
com.onsiteservice.entity.address.ServiceAddress
;
import
com.onsiteservice.entity.address.ServiceAddress
;
import
com.onsiteservice.entity.area.ServiceArea
;
import
com.onsiteservice.entity.area.ServiceArea
;
import
com.onsiteservice.miniapp.controller.address.dto.PageServiceAddressDTO
;
import
com.onsiteservice.miniapp.controller.address.dto.PageServiceAddressDTO
;
...
@@ -37,6 +39,9 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -37,6 +39,9 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
@Resource
@Resource
private
ServiceAddressBizMapper
serviceAddressBizMapper
;
private
ServiceAddressBizMapper
serviceAddressBizMapper
;
@Resource
private
ServiceAddressMapper
serviceAddressMapper
;
@Resource
@Resource
private
ServiceAreaMapper
serviceAreaMapper
;
private
ServiceAreaMapper
serviceAreaMapper
;
...
@@ -57,11 +62,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -57,11 +62,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
public
ServiceAddressVO
selectById
(
Long
id
,
Long
userId
)
{
public
ServiceAddressVO
selectById
(
Long
id
,
Long
userId
)
{
log
.
info
(
"address selectById id: {}, userId: {}"
,
id
,
userId
);
log
.
info
(
"address selectById id: {}, userId: {}"
,
id
,
userId
);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
List
<
ServiceAddress
>
serviceAddressList
=
serviceAddressMapper
.
selectByCondition
(
generateCondition
(
id
,
userId
));
c
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
)
.
andEqualTo
(
BizConstants
.
CommonConstants
.
DELETED
,
false
);
List
<
ServiceAddress
>
serviceAddressList
=
this
.
selectByCondition
(
c
);
if
(
CollectionUtils
.
isEmpty
(
serviceAddressList
))
{
if
(
CollectionUtils
.
isEmpty
(
serviceAddressList
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ADDRESS_NOT_EXIST
);
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ADDRESS_NOT_EXIST
);
}
}
...
@@ -70,17 +71,6 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -70,17 +71,6 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
}
}
public
List
<
ServiceAddressVO
>
selectByUserId
(
Long
userId
)
{
Condition
condition
=
new
Condition
(
ServiceAddress
.
class
);
condition
.
createCriteria
().
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
List
<
ServiceAddress
>
serviceAddresses
=
this
.
selectByCondition
(
condition
);
return
serviceAddresses
.
parallelStream
()
.
map
(
e
->
AttrCopyUtils
.
copy
(
e
,
new
ServiceAddressVO
()))
.
collect
(
Collectors
.
toList
());
}
public
int
save
(
SaveServiceAddressDTO
dto
,
Long
userId
)
{
public
int
save
(
SaveServiceAddressDTO
dto
,
Long
userId
)
{
log
.
info
(
"address save dto: {}, userId: {}"
,
dto
,
userId
);
log
.
info
(
"address save dto: {}, userId: {}"
,
dto
,
userId
);
...
@@ -91,7 +81,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -91,7 +81,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
// 有默认收货地址的话,置为非默认
// 有默认收货地址的话,置为非默认
// checkAndCancelDefaultServiceAddress(serviceAddress, userId);
// checkAndCancelDefaultServiceAddress(serviceAddress, userId);
return
this
.
insertSelective
(
serviceAddress
);
return
serviceAddressMapper
.
insertSelective
(
serviceAddress
);
}
}
...
@@ -102,21 +92,18 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -102,21 +92,18 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
ServiceAddress
serviceAddress
=
AttrCopyUtils
.
copy
(
dto
,
new
ServiceAddress
());
ServiceAddress
serviceAddress
=
AttrCopyUtils
.
copy
(
dto
,
new
ServiceAddress
());
serviceAddress
.
setAccountNo
(
userId
);
serviceAddress
.
setAccountNo
(
userId
);
// checkAndCancelDefaultServiceAddress(serviceAddress, userId);
// checkAndCancelDefaultServiceAddress(serviceAddress, userId);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
return
serviceAddressMapper
.
updateByConditionSelective
(
serviceAddress
,
generateCondition
(
dto
.
getId
(),
userId
));
c
.
createCriteria
().
andEqualTo
(
"id"
,
dto
.
getId
()).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
return
this
.
updateByConditionSelective
(
serviceAddress
,
c
);
}
}
public
int
delete
(
Long
id
,
Long
userId
)
{
public
int
delete
(
Long
id
,
Long
userId
)
{
log
.
info
(
"address delete id: {}, userId: {}"
,
id
,
userId
);
log
.
info
(
"address delete id: {}, userId: {}"
,
id
,
userId
);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
// 删除条件里加上账户号防越权攻击
// 删除条件里加上账户号防越权攻击
c
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
return
serviceAddressMapper
.
deleteByCondition
(
generateCondition
(
id
,
userId
));
return
this
.
deleteByCondition
(
c
);
}
}
...
@@ -142,12 +129,12 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -142,12 +129,12 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
c
.
createCriteria
().
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
)
c
.
createCriteria
().
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
)
.
andEqualTo
(
"def"
,
true
);
.
andEqualTo
(
"def"
,
true
);
List
<
ServiceAddress
>
defaultServiceAddressList
=
this
.
selectByCondition
(
c
);
List
<
ServiceAddress
>
defaultServiceAddressList
=
serviceAddressMapper
.
selectByCondition
(
c
);
if
(!
CollectionUtils
.
isEmpty
(
defaultServiceAddressList
))
{
if
(!
CollectionUtils
.
isEmpty
(
defaultServiceAddressList
))
{
defaultServiceAddressList
.
forEach
(
defaultServiceAddress
->
{
defaultServiceAddressList
.
forEach
(
defaultServiceAddress
->
{
defaultServiceAddress
.
setDef
(
false
);
defaultServiceAddress
.
setDef
(
false
);
this
.
updateByPrimaryKeySelective
(
defaultServiceAddress
);
serviceAddressMapper
.
updateByPrimaryKeySelective
(
defaultServiceAddress
);
});
});
}
}
...
@@ -159,9 +146,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -159,9 +146,7 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
checkAndCancelDefaultServiceAddress
(
userId
);
checkAndCancelDefaultServiceAddress
(
userId
);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
List
<
ServiceAddress
>
serviceAddressList
=
serviceAddressMapper
.
selectByCondition
(
generateCondition
(
id
,
userId
));
c
.
createCriteria
().
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
).
andEqualTo
(
"id"
,
id
);
List
<
ServiceAddress
>
serviceAddressList
=
this
.
selectByCondition
(
c
);
if
(
CollectionUtils
.
isEmpty
(
serviceAddressList
))
{
if
(
CollectionUtils
.
isEmpty
(
serviceAddressList
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ADDRESS_NOT_EXIST
);
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ADDRESS_NOT_EXIST
);
}
}
...
@@ -169,9 +154,18 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -169,9 +154,18 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
ServiceAddress
serviceAddress
=
serviceAddressList
.
get
(
0
);
ServiceAddress
serviceAddress
=
serviceAddressList
.
get
(
0
);
serviceAddress
.
setDef
(
true
);
serviceAddress
.
setDef
(
true
);
return
this
.
updateByPrimaryKeySelective
(
serviceAddress
);
return
serviceAddressMapper
.
updateByPrimaryKeySelective
(
serviceAddress
);
}
}
private
Condition
generateCondition
(
Long
id
,
Long
userId
)
{
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
c
.
createCriteria
()
.
andEqualTo
(
"id"
,
id
)
.
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
)
.
andEqualTo
(
BizConstants
.
CommonConstants
.
DELETED
,
false
);
return
c
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment