Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
customer-service
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Container Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SuperHive
back-end
customer-service
Commits
b2273787
Commit
b2273787
authored
Apr 21, 2020
by
huangcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增货主接口:编辑发货地址
parent
a6879bcf
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
187 additions
and
14 deletions
+187
-14
ErrorMessageComponent.java
...ight/customer/common/component/ErrorMessageComponent.java
+5
-0
DeliveryAddressController.java
...dule/goodsowner/controller/DeliveryAddressController.java
+14
-0
DeliveryAddressForm.java
.../customer/module/goodsowner/form/DeliveryAddressForm.java
+11
-11
DeliveryAddressService.java
...mer/module/goodsowner/service/DeliveryAddressService.java
+9
-0
DeliveryAddressServiceImpl.java
...e/goodsowner/service/impl/DeliveryAddressServiceImpl.java
+27
-2
application-dev.yml
src/main/resources/application-dev.yml
+4
-1
DeliveryAddressControllerTest.java
.../goodsowner/controller/DeliveryAddressControllerTest.java
+117
-0
No files found.
src/main/java/com/esv/freight/customer/common/component/ErrorMessageComponent.java
View file @
b2273787
...
...
@@ -59,4 +59,9 @@ public class ErrorMessageComponent {
@Value
(
"${error-message.goodsowner.delivery-address.add.1001}"
)
private
String
goodsOwnerDeliveryAddressAdd1001
;
@Value
(
"${error-message.goodsowner.delivery-address.edit.1001}"
)
private
String
goodsOwnerDeliveryAddressEdit1001
;
@Value
(
"${error-message.goodsowner.delivery-address.edit.1002}"
)
private
String
goodsOwnerDeliveryAddressEdit1002
;
}
src/main/java/com/esv/freight/customer/module/goodsowner/controller/DeliveryAddressController.java
View file @
b2273787
...
...
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import
com.esv.freight.customer.common.exception.EException
;
import
com.esv.freight.customer.common.response.EResponse
;
import
com.esv.freight.customer.common.validator.groups.ValidatorInsert
;
import
com.esv.freight.customer.common.validator.groups.ValidatorUpdate
;
import
com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants
;
import
com.esv.freight.customer.module.goodsowner.form.DeliveryAddressForm
;
import
com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService
;
...
...
@@ -60,4 +61,17 @@ public class DeliveryAddressController {
data
.
put
(
"id"
,
id
);
return
EResponse
.
ok
(
data
);
}
/**
* description 编辑发货地址
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/21 18:56
**/
@PostMapping
(
"/edit"
)
public
EResponse
edit
(
@RequestBody
@Validated
(
ValidatorUpdate
.
class
)
DeliveryAddressForm
form
)
throws
EException
{
deliveryAddressService
.
editAddress
(
form
);
return
EResponse
.
ok
();
}
}
src/main/java/com/esv/freight/customer/module/goodsowner/form/DeliveryAddressForm.java
View file @
b2273787
...
...
@@ -28,44 +28,44 @@ public class DeliveryAddressForm {
@NotNull
(
message
=
"参数id不能为空"
,
groups
=
{
ValidatorUpdate
.
class
,
ValidatorDetail
.
class
,
ValidatorDelete
.
class
})
private
Long
id
;
@NotNull
(
message
=
"参数ownerId不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
@NotNull
(
message
=
"参数ownerId不能为空"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
private
Long
ownerId
;
@Length
(
max
=
50
,
message
=
"参数addressName长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
max
=
50
,
message
=
"参数addressName长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数addressName不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
addressName
;
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数provinceCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数provinceCode不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
provinceCode
;
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数cityCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数cityCode不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
cityCode
;
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
min
=
6
,
max
=
6
,
message
=
"参数districtCode长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数districtCode不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
districtCode
;
@Length
(
max
=
50
,
message
=
"参数detailAddress长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
max
=
50
,
message
=
"参数detailAddress长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数detailAddress不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
detailAddress
;
@Length
(
max
=
20
,
message
=
"参数deliverer长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
max
=
20
,
message
=
"参数deliverer长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数deliverer不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
deliverer
;
@Length
(
min
=
11
,
max
=
11
,
message
=
"参数delivererPhone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
min
=
11
,
max
=
11
,
message
=
"参数delivererPhone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
@NotBlank
(
message
=
"参数delivererPhone不能为空"
,
groups
=
{
ValidatorInsert
.
class
})
private
String
delivererPhone
;
@Length
(
max
=
20
,
message
=
"参数delivererTelephone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
max
=
20
,
message
=
"参数delivererTelephone长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
private
String
delivererTelephone
;
@Length
(
max
=
10
,
message
=
"参数lon长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
max
=
10
,
message
=
"参数lon长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
private
String
lon
;
@Length
(
max
=
10
,
message
=
"参数lat长度不合法"
,
groups
=
{
ValidatorInsert
.
class
})
@Length
(
max
=
10
,
message
=
"参数lat长度不合法"
,
groups
=
{
ValidatorInsert
.
class
,
ValidatorUpdate
.
class
})
private
String
lat
;
@Pattern
(
regexp
=
"[01]"
,
message
=
"参数addressCopy不合法"
,
groups
=
{
ValidatorInsert
.
class
})
...
...
src/main/java/com/esv/freight/customer/module/goodsowner/service/DeliveryAddressService.java
View file @
b2273787
...
...
@@ -24,6 +24,15 @@ public interface DeliveryAddressService extends IService<DeliveryAddressEntity>
**/
Long
addAddress
(
DeliveryAddressForm
form
);
/**
* description 编辑发货地址
* param [form]
* return int
* author Administrator
* createTime 2020/04/21 17:56
**/
int
editAddress
(
DeliveryAddressForm
form
);
/**
* description 通过地址名称查询地址记录
* param [ownerId, addressName]
...
...
src/main/java/com/esv/freight/customer/module/goodsowner/service/impl/DeliveryAddressServiceImpl.java
View file @
b2273787
...
...
@@ -8,13 +8,13 @@ import com.esv.freight.customer.common.exception.EException;
import
com.esv.freight.customer.common.util.FeignUtils
;
import
com.esv.freight.customer.feign.FeignBaseService
;
import
com.esv.freight.customer.module.goodsowner.dao.DeliveryAddressDao
;
import
com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity
;
import
com.esv.freight.customer.module.goodsowner.entity.DeliveryAddressEntity
;
import
com.esv.freight.customer.module.goodsowner.form.DeliveryAddressForm
;
import
com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService
;
import
org.springframework.beans.BeanUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.List
;
...
...
@@ -33,7 +33,6 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
}
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Long
addAddress
(
DeliveryAddressForm
form
)
{
// 1.判断地址是否重复
List
<
DeliveryAddressEntity
>
deliveryAddressEntityList
=
this
.
getAddressByName
(
form
.
getOwnerId
(),
form
.
getAddressName
());
...
...
@@ -64,6 +63,32 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
return
addressEntity
.
getId
();
}
@Override
public
int
editAddress
(
DeliveryAddressForm
form
)
{
// 1.判断ID是否有效
DeliveryAddressEntity
entity
=
this
.
baseMapper
.
selectById
(
form
.
getId
());
if
(
null
==
entity
)
{
throw
new
EException
(
1001
,
errorMessageComponent
.
getGoodsOwnerDeliveryAddressEdit1001
());
}
// 2.判断地址是否重复
QueryWrapper
<
DeliveryAddressEntity
>
queryWrapper
=
new
QueryWrapper
<>();
queryWrapper
.
ne
(
"id"
,
form
.
getId
());
queryWrapper
.
eq
(
"owner_id"
,
form
.
getOwnerId
());
queryWrapper
.
eq
(
"address_name"
,
form
.
getAddressName
());
List
<
DeliveryAddressEntity
>
deliveryAddressEntityList
=
this
.
baseMapper
.
selectList
(
queryWrapper
);
if
(
0
<
deliveryAddressEntityList
.
size
())
{
throw
new
EException
(
1002
,
errorMessageComponent
.
getGoodsOwnerDeliveryAddressEdit1002
());
}
// 3.更新地址
DeliveryAddressEntity
updateEntity
=
new
DeliveryAddressEntity
();
BeanUtils
.
copyProperties
(
form
,
updateEntity
);
int
flag
=
this
.
baseMapper
.
updateById
(
updateEntity
);
return
flag
;
}
@Override
public
List
<
DeliveryAddressEntity
>
getAddressByName
(
Long
ownerId
,
String
addressName
)
{
QueryWrapper
<
DeliveryAddressEntity
>
queryWrapper
=
new
QueryWrapper
<>();
...
...
src/main/resources/application-dev.yml
View file @
b2273787
...
...
@@ -73,4 +73,7 @@ error-message:
1001
:
帐号已存在
delivery-address
:
add
:
1001
:
重复的发货地址名称
\ No newline at end of file
1001
:
重复的地址名称
edit
:
1001
:
无效的地址ID
1002
:
重复的地址名称
\ No newline at end of file
src/test/java/com/esv/freight/customer/module/goodsowner/controller/DeliveryAddressControllerTest.java
View file @
b2273787
...
...
@@ -151,4 +151,121 @@ public class DeliveryAddressControllerTest extends BaseTestController {
Assert
.
assertEquals
(
ECode
.
PARAM_ERROR
.
code
(),
result
.
getIntValue
(
"code"
));
}
/**
* 编辑发货地址
**/
@Test
@Rollback
public
void
b1_edit_success_test
()
throws
Exception
{
String
url
=
"/goodsowner/delivery/address/edit"
;
// 构造数据
DeliveryAddressForm
form
=
new
DeliveryAddressForm
();
form
.
setId
(
5L
);
form
.
setOwnerId
(
1L
);
form
.
setAddressName
(
"黄朝斌-发货地址-测试01"
);
form
.
setProvinceCode
(
"210000"
);
form
.
setCityCode
(
"210100"
);
form
.
setDistrictCode
(
"210103"
);
form
.
setDetailAddress
(
"朝阳街少帅府巷46号"
);
form
.
setDeliverer
(
"张作霖01"
);
form
.
setDelivererPhone
(
"13912340002"
);
form
.
setDelivererTelephone
(
"(024)24850576"
);
form
.
setLon
(
"123.464053"
);
form
.
setLat
(
"41.800416"
);
JSONObject
reqJson
=
JSONObject
.
parseObject
(
form
.
toString
());
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
headers
(
this
.
getDefaultHttpHeaders
())
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
ECode
.
SUCCESS
.
code
(),
result
.
getIntValue
(
"code"
));
}
/**
* 编辑发货地址:无效的ID
**/
@Test
@Rollback
public
void
b2_edit_wrong_id_failure_test
()
throws
Exception
{
String
url
=
"/goodsowner/delivery/address/edit"
;
// 构造数据
DeliveryAddressForm
form
=
new
DeliveryAddressForm
();
form
.
setId
(
99999L
);
form
.
setOwnerId
(
1L
);
form
.
setAddressName
(
"黄朝斌-发货地址-测试01"
);
form
.
setProvinceCode
(
"210000"
);
form
.
setCityCode
(
"210100"
);
form
.
setDistrictCode
(
"210103"
);
form
.
setDetailAddress
(
"朝阳街少帅府巷46号"
);
form
.
setDeliverer
(
"张作霖01"
);
form
.
setDelivererPhone
(
"13912340002"
);
form
.
setDelivererTelephone
(
"(024)24850576"
);
form
.
setLon
(
"123.464053"
);
form
.
setLat
(
"41.800416"
);
JSONObject
reqJson
=
JSONObject
.
parseObject
(
form
.
toString
());
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
headers
(
this
.
getDefaultHttpHeaders
())
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
1001
,
result
.
getIntValue
(
"code"
));
}
/**
* 编辑发货地址:地址名称重复
**/
@Test
@Rollback
public
void
b3_edit_wrong_addressName_failure_test
()
throws
Exception
{
String
url
=
"/goodsowner/delivery/address/edit"
;
// 构造数据
DeliveryAddressForm
form
=
new
DeliveryAddressForm
();
form
.
setId
(
5L
);
form
.
setOwnerId
(
1L
);
form
.
setAddressName
(
"发货地址"
);
form
.
setProvinceCode
(
"210000"
);
form
.
setCityCode
(
"210100"
);
form
.
setDistrictCode
(
"210103"
);
form
.
setDetailAddress
(
"朝阳街少帅府巷46号"
);
form
.
setDeliverer
(
"张作霖01"
);
form
.
setDelivererPhone
(
"13912340002"
);
form
.
setDelivererTelephone
(
"(024)24850576"
);
form
.
setLon
(
"123.464053"
);
form
.
setLat
(
"41.800416"
);
JSONObject
reqJson
=
JSONObject
.
parseObject
(
form
.
toString
());
MvcResult
mvcResult
=
this
.
getMockMvc
().
perform
(
MockMvcRequestBuilders
.
post
(
url
)
.
contentType
(
MediaType
.
APPLICATION_JSON_UTF8_VALUE
)
.
headers
(
this
.
getDefaultHttpHeaders
())
.
content
(
reqJson
.
toJSONString
()))
.
andDo
(
MockMvcResultHandlers
.
print
())
.
andExpect
(
MockMvcResultMatchers
.
status
().
isOk
())
.
andReturn
();
String
responseStr
=
mvcResult
.
getResponse
().
getContentAsString
();
log
.
info
(
responseStr
);
JSONObject
result
=
JSONObject
.
parseObject
(
responseStr
);
Assert
.
assertEquals
(
1002
,
result
.
getIntValue
(
"code"
));
}
}
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