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
6faa77d2
Commit
6faa77d2
authored
Jul 08, 2022
by
kretee
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: address接口修改
parent
7e72c62b
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
214 additions
and
36 deletions
+214
-36
BizConstants.java
...ava/com/onsiteservice/constant/constant/BizConstants.java
+4
-0
BizCodeEnum.java
...in/java/com/onsiteservice/constant/enums/BizCodeEnum.java
+11
-1
ServiceAddressStatusEnum.java
...nsiteservice/constant/enums/ServiceAddressStatusEnum.java
+32
-0
ServiceAddressController.java
.../miniapp/controller/address/ServiceAddressController.java
+6
-6
SaveServiceAddressDTO.java
...miniapp/controller/address/dto/SaveServiceAddressDTO.java
+13
-1
UpdateServiceAddressDTO.java
...niapp/controller/address/dto/UpdateServiceAddressDTO.java
+13
-1
ServiceOrderController.java
...vice/miniapp/controller/order/ServiceOrderController.java
+6
-6
ServiceAddressService.java
...ervice/miniapp/service/address/ServiceAddressService.java
+60
-14
ServiceOrderService.java
...iteservice/miniapp/service/order/ServiceOrderService.java
+23
-7
pom.xml
test/pom.xml
+15
-0
JwtTest.java
test/src/main/java/com/onsiteservice/JwtTest.java
+31
-0
No files found.
constant/src/main/java/com/onsiteservice/constant/constant/BizConstants.java
View file @
6faa77d2
...
@@ -5,4 +5,8 @@ package com.onsiteservice.constant.constant;
...
@@ -5,4 +5,8 @@ package com.onsiteservice.constant.constant;
*/
*/
public
class
BizConstants
{
public
class
BizConstants
{
public
static
class
UserConstants
{
public
static
final
String
ACCOUNT_NO
=
"accountNo"
;
}
}
}
constant/src/main/java/com/onsiteservice/constant/enums/BizCodeEnum.java
View file @
6faa77d2
...
@@ -11,6 +11,7 @@ import lombok.Getter;
...
@@ -11,6 +11,7 @@ import lombok.Getter;
*/
*/
public
enum
BizCodeEnum
{
public
enum
BizCodeEnum
{
/**
/**
* 订单分组
* 订单分组
*/
*/
...
@@ -20,13 +21,22 @@ public enum BizCodeEnum {
...
@@ -20,13 +21,22 @@ public enum BizCodeEnum {
/**
/**
* 区域分组
* 区域分组
*/
*/
SERVICE_AREA_NOT_EXIST
(
"区域不存在"
);
SERVICE_AREA_NOT_EXIST
(
"区域不存在"
),
/**
* 服务地址模块
*/
SERVICE_ADDRESS_NOT_EXIST
(
"服务地址不存在"
);
@Getter
@Getter
private
String
msg
;
private
String
msg
;
private
BizCodeEnum
(
String
msg
){
private
BizCodeEnum
(
String
msg
){
this
.
msg
=
msg
;
this
.
msg
=
msg
;
}
}
}
}
constant/src/main/java/com/onsiteservice/constant/enums/ServiceAddressStatusEnum.java
0 → 100644
View file @
6faa77d2
package
com
.
onsiteservice
.
constant
.
enums
;
import
lombok.Getter
;
/**
* <P>服务地址枚举</P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/8 10:16
*/
public
enum
ServiceAddressStatusEnum
{
/**
* 是默认收货地址
*/
DEFAULT_STATUS
(
1
),
/**
* 非默认收货地址
*/
COMMON_STATUS
(
0
);
@Getter
private
int
status
;
private
ServiceAddressStatusEnum
(
int
status
)
{
this
.
status
=
status
;
}
}
mini-app/src/main/java/com/onsiteservice/miniapp/controller/address/ServiceAddressController.java
View file @
6faa77d2
...
@@ -49,8 +49,8 @@ public class ServiceAddressController {
...
@@ -49,8 +49,8 @@ public class ServiceAddressController {
@ApiOperation
(
value
=
"根据id查询服务地址"
)
@ApiOperation
(
value
=
"根据id查询服务地址"
)
@GetMapping
(
"get/{id}"
)
@GetMapping
(
"get/{id}"
)
public
Result
<
ServiceAddressVO
>
getDetails
(
@ApiParam
(
name
=
"id"
,
value
=
"服务地址id"
)
@PathVariable
@Positive
Long
id
)
{
public
Result
<
ServiceAddressVO
>
getDetails
(
@ApiParam
(
name
=
"id"
,
value
=
"服务地址id"
)
@PathVariable
@Positive
Long
id
,
@CurrentUserId
Long
userId
)
{
return
success
(
serviceAddressService
.
selectById
(
id
));
return
success
(
serviceAddressService
.
selectById
(
id
,
userId
));
}
}
@ApiOperation
(
value
=
"新增服务地址"
)
@ApiOperation
(
value
=
"新增服务地址"
)
...
@@ -61,14 +61,14 @@ public class ServiceAddressController {
...
@@ -61,14 +61,14 @@ public class ServiceAddressController {
@ApiOperation
(
value
=
"修改服务地址"
)
@ApiOperation
(
value
=
"修改服务地址"
)
@PutMapping
(
"update"
)
@PutMapping
(
"update"
)
public
Result
saveOrUpdate
(
@RequestBody
@NonNull
@Validated
UpdateServiceAddressDTO
dto
)
{
public
Result
saveOrUpdate
(
@RequestBody
@NonNull
@Validated
UpdateServiceAddressDTO
dto
,
@CurrentUserId
Long
userId
)
{
return
serviceAddressService
.
update
(
dto
)
==
1
?
success
()
:
fail
(
"修改失败"
);
return
serviceAddressService
.
update
(
dto
,
userId
)
==
1
?
success
()
:
fail
(
"修改失败"
);
}
}
@ApiOperation
(
value
=
"根据id删除服务地址"
)
@ApiOperation
(
value
=
"根据id删除服务地址"
)
@DeleteMapping
(
"delete/{id}"
)
@DeleteMapping
(
"delete/{id}"
)
public
Result
deleteById
(
@ApiParam
(
name
=
"id"
,
value
=
"服务地址id"
)
@PathVariable
@Positive
Long
id
)
{
public
Result
deleteById
(
@ApiParam
(
name
=
"id"
,
value
=
"服务地址id"
)
@PathVariable
@Positive
Long
id
,
@CurrentUserId
Long
userId
)
{
return
serviceAddressService
.
delete
ByPrimaryKey
(
i
d
)
==
1
?
success
()
:
fail
(
"删除失败"
);
return
serviceAddressService
.
delete
(
id
,
userI
d
)
==
1
?
success
()
:
fail
(
"删除失败"
);
}
}
}
}
mini-app/src/main/java/com/onsiteservice/miniapp/controller/address/dto/SaveServiceAddressDTO.java
View file @
6faa77d2
...
@@ -4,6 +4,10 @@ import io.swagger.annotations.ApiModel;
...
@@ -4,6 +4,10 @@ import io.swagger.annotations.ApiModel;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
@Data
@Data
@ApiModel
(
"保存服务地址请求模型"
)
@ApiModel
(
"保存服务地址请求模型"
)
public
class
SaveServiceAddressDTO
{
public
class
SaveServiceAddressDTO
{
...
@@ -12,12 +16,15 @@ public class SaveServiceAddressDTO {
...
@@ -12,12 +16,15 @@ public class SaveServiceAddressDTO {
* 姓名
* 姓名
*/
*/
@ApiModelProperty
(
value
=
"姓名"
,
required
=
true
)
@ApiModelProperty
(
value
=
"姓名"
,
required
=
true
)
@NotBlank
(
message
=
"请输入联系人"
)
private
String
name
;
private
String
name
;
/**
/**
* 手机或电话
* 手机或电话
*/
*/
@ApiModelProperty
(
value
=
"手机或电话"
,
required
=
true
)
@ApiModelProperty
(
value
=
"手机"
,
required
=
true
)
@NotBlank
(
message
=
"请输入手机号"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
private
String
phone
;
private
String
phone
;
/**
/**
...
@@ -30,12 +37,17 @@ public class SaveServiceAddressDTO {
...
@@ -30,12 +37,17 @@ public class SaveServiceAddressDTO {
* 区域名称路径
* 区域名称路径
*/
*/
@ApiModelProperty
(
value
=
"区域名称路径"
,
required
=
true
)
@ApiModelProperty
(
value
=
"区域名称路径"
,
required
=
true
)
@NotBlank
(
message
=
"请选择区域"
)
private
String
namePath
;
private
String
namePath
;
/**
/**
* 地址
* 地址
*/
*/
@ApiModelProperty
(
value
=
"地址"
,
required
=
true
)
@ApiModelProperty
(
value
=
"地址"
,
required
=
true
)
@NotBlank
(
message
=
"请输入详细地址"
)
private
String
address
;
private
String
address
;
@ApiModelProperty
(
value
=
"是否默认收货地址"
,
required
=
true
)
private
Integer
def
;
}
}
\ No newline at end of file
mini-app/src/main/java/com/onsiteservice/miniapp/controller/address/dto/UpdateServiceAddressDTO.java
View file @
6faa77d2
...
@@ -4,6 +4,10 @@ import io.swagger.annotations.ApiModel;
...
@@ -4,6 +4,10 @@ import io.swagger.annotations.ApiModel;
import
io.swagger.annotations.ApiModelProperty
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
lombok.Data
;
import
javax.validation.constraints.NotBlank
;
import
javax.validation.constraints.NotNull
;
import
javax.validation.constraints.Pattern
;
@Data
@Data
@ApiModel
(
"修改服务地址请求模型"
)
@ApiModel
(
"修改服务地址请求模型"
)
public
class
UpdateServiceAddressDTO
{
public
class
UpdateServiceAddressDTO
{
...
@@ -15,12 +19,15 @@ public class UpdateServiceAddressDTO {
...
@@ -15,12 +19,15 @@ public class UpdateServiceAddressDTO {
* 姓名
* 姓名
*/
*/
@ApiModelProperty
(
value
=
"姓名"
,
required
=
true
)
@ApiModelProperty
(
value
=
"姓名"
,
required
=
true
)
@NotBlank
(
message
=
"请输入联系人"
)
private
String
name
;
private
String
name
;
/**
/**
* 手机或电话
* 手机或电话
*/
*/
@ApiModelProperty
(
value
=
"手机或电话"
,
required
=
true
)
@ApiModelProperty
(
value
=
"手机"
,
required
=
true
)
@NotBlank
(
message
=
"请输入手机号"
)
@Pattern
(
regexp
=
"^1[3456789]\\d{9}$"
,
message
=
"手机号格式不正确"
)
private
String
phone
;
private
String
phone
;
/**
/**
...
@@ -33,12 +40,17 @@ public class UpdateServiceAddressDTO {
...
@@ -33,12 +40,17 @@ public class UpdateServiceAddressDTO {
* 区域名称路径
* 区域名称路径
*/
*/
@ApiModelProperty
(
value
=
"区域名称路径"
,
required
=
true
)
@ApiModelProperty
(
value
=
"区域名称路径"
,
required
=
true
)
@NotBlank
(
message
=
"请选择区域"
)
private
String
namePath
;
private
String
namePath
;
/**
/**
* 地址
* 地址
*/
*/
@ApiModelProperty
(
value
=
"地址"
,
required
=
true
)
@ApiModelProperty
(
value
=
"地址"
,
required
=
true
)
@NotBlank
(
message
=
"请输入详细地址"
)
private
String
address
;
private
String
address
;
@ApiModelProperty
(
value
=
"是否默认收货地址"
,
required
=
true
)
private
Integer
def
;
}
}
\ No newline at end of file
mini-app/src/main/java/com/onsiteservice/miniapp/controller/order/ServiceOrderController.java
View file @
6faa77d2
...
@@ -45,20 +45,20 @@ public class ServiceOrderController {
...
@@ -45,20 +45,20 @@ public class ServiceOrderController {
@ApiOperation
(
value
=
"根据id查询订单详情"
)
@ApiOperation
(
value
=
"根据id查询订单详情"
)
@GetMapping
(
"get/{id}"
)
@GetMapping
(
"get/{id}"
)
public
Result
<
ServiceOrderVO
>
getDetail
(
@ApiParam
(
name
=
"id"
,
value
=
"订单id"
)
@PathVariable
@Positive
Long
id
)
{
public
Result
<
ServiceOrderVO
>
getDetail
(
@ApiParam
(
name
=
"id"
,
value
=
"订单id"
)
@PathVariable
@Positive
Long
id
,
@CurrentUserId
Long
userId
)
{
return
success
(
serviceOrderService
.
selectById
(
id
),
"根据id查询订单详情"
);
return
success
(
serviceOrderService
.
selectById
(
id
,
userId
),
"根据id查询订单详情"
);
}
}
@ApiOperation
(
value
=
"分页查询订单"
)
@ApiOperation
(
value
=
"分页查询订单"
)
@PostMapping
(
"page"
)
@PostMapping
(
"page"
)
public
Result
<
PageInfoVO
<
ServiceOrderVO
>>
getPage
(
@RequestBody
@NonNull
@Validated
PageServiceOrderDTO
dto
,
@CurrentUserId
Long
u
i
d
)
{
public
Result
<
PageInfoVO
<
ServiceOrderVO
>>
getPage
(
@RequestBody
@NonNull
@Validated
PageServiceOrderDTO
dto
,
@CurrentUserId
Long
u
serI
d
)
{
return
serviceOrderService
.
selectByUserId
(
dto
,
u
i
d
);
return
serviceOrderService
.
selectByUserId
(
dto
,
u
serI
d
);
}
}
@ApiOperation
(
value
=
"订单预约"
)
@ApiOperation
(
value
=
"订单预约"
)
@PostMapping
(
"reserve"
)
@PostMapping
(
"reserve"
)
public
Result
save
(
@RequestBody
@NonNull
@Validated
SaveServiceOrderDTO
dto
,
@CurrentUserId
Long
u
i
d
)
{
public
Result
save
(
@RequestBody
@NonNull
@Validated
SaveServiceOrderDTO
dto
,
@CurrentUserId
Long
u
serI
d
)
{
return
serviceOrderService
.
save
(
dto
,
u
i
d
)
==
1
?
success
()
:
fail
(
"已预约"
);
return
serviceOrderService
.
save
(
dto
,
u
serI
d
)
==
1
?
success
()
:
fail
(
"已预约"
);
}
}
@ApiOperation
(
value
=
"订单估计"
)
@ApiOperation
(
value
=
"订单估计"
)
...
...
mini-app/src/main/java/com/onsiteservice/miniapp/service/address/ServiceAddressService.java
View file @
6faa77d2
package
com
.
onsiteservice
.
miniapp
.
service
.
address
;
package
com
.
onsiteservice
.
miniapp
.
service
.
address
;
import
com.github.pagehelper.PageHelper
;
import
com.onsiteservice.constant.constant.BizConstants
;
import
com.onsiteservice.constant.enums.BizCodeEnum
;
import
com.onsiteservice.constant.enums.BizCodeEnum
;
import
com.onsiteservice.constant.enums.ServiceAddressStatusEnum
;
import
com.onsiteservice.core.exception.ServiceException
;
import
com.onsiteservice.core.exception.ServiceException
;
import
com.onsiteservice.core.result.Result
;
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.page.PageInfoVO
;
import
com.onsiteservice.dao.mapper.service.ServiceAreaMapper
;
import
com.onsiteservice.dao.mapper.service.ServiceAreaMapper
;
import
com.onsiteservice.entity.address.ServiceAddress
;
import
com.onsiteservice.entity.address.ServiceAddress
;
import
com.onsiteservice.entity.area.ServiceArea
;
import
com.onsiteservice.entity.area.ServiceArea
;
...
@@ -12,23 +17,17 @@ import com.onsiteservice.miniapp.controller.address.dto.SaveServiceAddressDTO;
...
@@ -12,23 +17,17 @@ import com.onsiteservice.miniapp.controller.address.dto.SaveServiceAddressDTO;
import
com.onsiteservice.miniapp.controller.address.dto.UpdateServiceAddressDTO
;
import
com.onsiteservice.miniapp.controller.address.dto.UpdateServiceAddressDTO
;
import
com.onsiteservice.miniapp.controller.address.vo.ServiceAddressVO
;
import
com.onsiteservice.miniapp.controller.address.vo.ServiceAddressVO
;
import
com.onsiteservice.miniapp.mapper.address.ServiceAddressBizMapper
;
import
com.onsiteservice.miniapp.mapper.address.ServiceAddressBizMapper
;
import
com.onsiteservice.dao.common.AbstractMapper
;
import
com.onsiteservice.dao.common.page.PageInfoVO
;
import
com.github.pagehelper.PageHelper
;
import
com.onsiteservice.util.AttrCopyUtils
;
import
com.onsiteservice.util.AttrCopyUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
tk.mybatis.mapper.entity.Condition
;
import
tk.mybatis.mapper.entity.Condition
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Objects
;
import
java.util.Objects
;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
import
static
com
.
onsiteservice
.
core
.
result
.
ResultGenerator
.
success
;
@Service
@Service
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
ServiceAddressService
extends
AbstractMapper
<
ServiceAddress
>
{
public
class
ServiceAddressService
extends
AbstractMapper
<
ServiceAddress
>
{
...
@@ -52,15 +51,22 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -52,15 +51,22 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
}
}
public
ServiceAddressVO
selectById
(
Long
id
)
{
public
ServiceAddressVO
selectById
(
Long
id
,
Long
userId
)
{
ServiceAddress
serviceAddress
=
this
.
selectByPrimaryKey
(
id
);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
return
AttrCopyUtils
.
copy
(
serviceAddress
,
new
ServiceAddressVO
());
c
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
List
<
ServiceAddress
>
serviceAddressList
=
this
.
selectByCondition
(
c
);
if
(
CollectionUtils
.
isEmpty
(
serviceAddressList
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ADDRESS_NOT_EXIST
);
}
return
AttrCopyUtils
.
copy
(
serviceAddressList
.
get
(
0
),
new
ServiceAddressVO
());
}
}
public
List
<
ServiceAddressVO
>
selectByUserId
(
Long
userId
)
{
public
List
<
ServiceAddressVO
>
selectByUserId
(
Long
userId
)
{
Condition
condition
=
new
Condition
(
ServiceAddress
.
class
);
Condition
condition
=
new
Condition
(
ServiceAddress
.
class
);
condition
.
createCriteria
().
andEqualTo
(
"account_no"
,
userId
);
condition
.
createCriteria
().
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
List
<
ServiceAddress
>
serviceAddresses
=
this
.
selectByCondition
(
condition
);
List
<
ServiceAddress
>
serviceAddresses
=
this
.
selectByCondition
(
condition
);
return
serviceAddresses
.
parallelStream
()
return
serviceAddresses
.
parallelStream
()
...
@@ -74,23 +80,40 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -74,23 +80,40 @@ 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
);
return
this
.
insertSelective
(
serviceAddress
);
return
this
.
insertSelective
(
serviceAddress
);
}
}
public
int
update
(
UpdateServiceAddressDTO
dto
)
{
public
int
update
(
UpdateServiceAddressDTO
dto
,
Long
userId
)
{
checkServiceArea
(
dto
.
getAreaId
());
checkServiceArea
(
dto
.
getAreaId
());
ServiceAddress
serviceAddress
=
AttrCopyUtils
.
copy
(
dto
,
new
ServiceAddress
());
ServiceAddress
serviceAddress
=
AttrCopyUtils
.
copy
(
dto
,
new
ServiceAddress
());
return
this
.
updateByPrimaryKey
(
serviceAddress
);
serviceAddress
.
setAccountNo
(
userId
);
checkAndCancelDefaultServiceAddress
(
serviceAddress
,
userId
);
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
c
.
createCriteria
().
andEqualTo
(
"id"
,
dto
.
getId
()).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
return
this
.
updateByConditionSelective
(
serviceAddress
,
c
);
}
public
int
delete
(
Long
id
,
Long
userId
)
{
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
// 删除条件里加上账户号防越权攻击
c
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
return
this
.
deleteByCondition
(
c
);
}
}
/**
/**
* 判断区域存在
* 判断区域存在
*
*
* @param areaId 区域id
* @param areaId 区域id
*/
*/
private
void
checkServiceArea
(
long
areaId
){
private
void
checkServiceArea
(
long
areaId
)
{
ServiceArea
serviceArea
=
serviceAreaMapper
.
selectByPrimaryKey
(
areaId
);
ServiceArea
serviceArea
=
serviceAreaMapper
.
selectByPrimaryKey
(
areaId
);
if
(
Objects
.
isNull
(
serviceArea
))
{
if
(
Objects
.
isNull
(
serviceArea
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_AREA_NOT_EXIST
);
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_AREA_NOT_EXIST
);
...
@@ -98,4 +121,27 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
...
@@ -98,4 +121,27 @@ public class ServiceAddressService extends AbstractMapper<ServiceAddress> {
}
}
/**
* 判断有没有默认收货地址,有的话取消
*
* @param serviceAddress 服务地址DO
* @param userId 用户id
*/
private
void
checkAndCancelDefaultServiceAddress
(
ServiceAddress
serviceAddress
,
Long
userId
)
{
if
(
serviceAddress
.
getDef
()
==
ServiceAddressStatusEnum
.
DEFAULT_STATUS
.
getStatus
())
{
Condition
c
=
new
Condition
(
ServiceAddress
.
class
);
c
.
createCriteria
().
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
)
.
andEqualTo
(
"def"
,
ServiceAddressStatusEnum
.
DEFAULT_STATUS
.
getStatus
());
List
<
ServiceAddress
>
defaultServiceAddressList
=
this
.
selectByCondition
(
c
);
if
(!
CollectionUtils
.
isEmpty
(
defaultServiceAddressList
))
{
defaultServiceAddressList
.
forEach
(
defaultServiceAddress
->
{
defaultServiceAddress
.
setDef
(
ServiceAddressStatusEnum
.
COMMON_STATUS
.
getStatus
());
this
.
updateByPrimaryKeySelective
(
defaultServiceAddress
);
});
}
}
}
}
}
mini-app/src/main/java/com/onsiteservice/miniapp/service/order/ServiceOrderService.java
View file @
6faa77d2
package
com
.
onsiteservice
.
miniapp
.
service
.
order
;
package
com
.
onsiteservice
.
miniapp
.
service
.
order
;
import
com.github.pagehelper.PageHelper
;
import
com.github.pagehelper.PageHelper
;
import
com.onsiteservice.constant.constant.BizConstants
;
import
com.onsiteservice.constant.enums.BizCodeEnum
;
import
com.onsiteservice.constant.enums.BizCodeEnum
;
import
com.onsiteservice.core.exception.ServiceException
;
import
com.onsiteservice.core.exception.ServiceException
;
import
com.onsiteservice.core.result.Result
;
import
com.onsiteservice.core.result.Result
;
...
@@ -17,8 +18,11 @@ import com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper;
...
@@ -17,8 +18,11 @@ import com.onsiteservice.miniapp.mapper.order.ServiceOrderBizMapper;
import
com.onsiteservice.miniapp.service.address.ServiceAddressService
;
import
com.onsiteservice.miniapp.service.address.ServiceAddressService
;
import
com.onsiteservice.util.AttrCopyUtils
;
import
com.onsiteservice.util.AttrCopyUtils
;
import
com.onsiteservice.util.RandomUtils
;
import
com.onsiteservice.util.RandomUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.CollectionUtils
;
import
tk.mybatis.mapper.entity.Condition
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.List
;
...
@@ -26,6 +30,7 @@ import java.util.Objects;
...
@@ -26,6 +30,7 @@ import java.util.Objects;
import
java.util.stream.Collectors
;
import
java.util.stream.Collectors
;
@Service
@Service
@Slf4j
@Transactional
(
rollbackFor
=
Exception
.
class
)
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
class
ServiceOrderService
extends
AbstractMapper
<
ServiceOrder
>
{
public
class
ServiceOrderService
extends
AbstractMapper
<
ServiceOrder
>
{
...
@@ -36,17 +41,28 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
...
@@ -36,17 +41,28 @@ public class ServiceOrderService extends AbstractMapper<ServiceOrder> {
private
ServiceAddressService
serviceAddressService
;
private
ServiceAddressService
serviceAddressService
;
public
ServiceOrderVO
selectById
(
Long
id
)
{
public
ServiceOrderVO
selectById
(
Long
id
,
Long
userId
)
{
// 订单信息
// 订单信息
ServiceOrder
serviceOrder
=
this
.
selectByPrimaryKey
(
id
);
Condition
c
=
new
Condition
(
ServiceOrder
.
class
);
c
.
createCriteria
().
andEqualTo
(
"id"
,
id
).
andEqualTo
(
BizConstants
.
UserConstants
.
ACCOUNT_NO
,
userId
);
List
<
ServiceOrder
>
serviceOrderList
=
this
.
selectByCondition
(
c
);
if
(
CollectionUtils
.
isEmpty
(
serviceOrderList
))
{
throw
new
ServiceException
(
BizCodeEnum
.
SERVICE_ORDER_NOT_EXIST
);
}
ServiceOrder
serviceOrder
=
serviceOrderList
.
get
(
0
);
ServiceOrderVO
serviceOrderVO
=
AttrCopyUtils
.
copy
(
serviceOrder
,
new
ServiceOrderVO
());
ServiceOrderVO
serviceOrderVO
=
AttrCopyUtils
.
copy
(
serviceOrder
,
new
ServiceOrderVO
());
// 订单地址信息
// 订单地址信息
ServiceAddressVO
serviceAddressVO
=
serviceAddressService
.
selectById
(
serviceOrder
.
getAddressId
());
try
{
ServiceAddressVO
serviceAddressVO
=
serviceAddressService
.
selectById
(
serviceOrder
.
getAddressId
(),
userId
);
serviceOrderVO
.
setAddress
(
serviceAddressVO
.
getAddress
());
serviceOrderVO
.
setAddress
(
serviceAddressVO
.
getAddress
());
serviceOrderVO
.
setName
(
serviceOrderVO
.
getName
());
serviceOrderVO
.
setName
(
serviceOrderVO
.
getName
());
serviceOrderVO
.
setPhone
(
serviceOrderVO
.
getPhone
());
serviceOrderVO
.
setPhone
(
serviceOrderVO
.
getPhone
());
}
catch
(
Exception
e
)
{
log
.
error
(
"根据id查询订单详情,服务地址不存在"
);
}
return
serviceOrderVO
;
return
serviceOrderVO
;
}
}
...
...
test/pom.xml
View file @
6faa77d2
...
@@ -14,6 +14,17 @@
...
@@ -14,6 +14,17 @@
<dependencies>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-test
</artifactId>
</dependency>
<dependency>
<groupId>
com.onsiteservice
</groupId>
<artifactId>
mini-app
</artifactId>
<version>
1.0.0
</version>
</dependency>
<!--依赖公共通用模块-->
<!--依赖公共通用模块-->
<dependency>
<dependency>
<groupId>
com.onsiteservice
</groupId>
<groupId>
com.onsiteservice
</groupId>
...
@@ -31,6 +42,10 @@
...
@@ -31,6 +42,10 @@
<artifactId>
mybatis-generator-core
</artifactId>
<artifactId>
mybatis-generator-core
</artifactId>
<version>
1.3.7
</version>
<version>
1.3.7
</version>
</dependency>
</dependency>
<dependency>
<groupId>
junit
</groupId>
<artifactId>
junit
</artifactId>
</dependency>
</dependencies>
</dependencies>
...
...
test/src/main/java/com/onsiteservice/JwtTest.java
0 → 100644
View file @
6faa77d2
package
com
.
onsiteservice
;
import
com.onsiteservice.core.security.jwt.JwtManager
;
import
com.onsiteservice.miniapp.MiniAppApplication
;
import
lombok.extern.log4j.Log4j2
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.test.context.junit4.SpringRunner
;
import
java.util.Map
;
/**
* <P></P>
*
* @author 李宁
* @version v1.0
* @since 2022/7/8 09:58
*/
@RunWith
(
SpringRunner
.
class
)
@SpringBootTest
(
classes
=
MiniAppApplication
.
class
)
@Log4j2
public
class
JwtTest
{
@Test
public
void
testGenerateJetToken
(){
System
.
out
.
println
(
JwtManager
.
createToken
(
Map
.
of
(
JwtManager
.
USER_ID
,
100
)));
}
}
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