Commit b2273787 authored by huangcb's avatar huangcb

新增货主接口:编辑发货地址

parent a6879bcf
......@@ -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;
}
......@@ -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();
}
}
......@@ -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})
......
......@@ -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]
......
......@@ -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<>();
......
......@@ -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
......@@ -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"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment