Commit b1ef2de4 authored by huangcb's avatar huangcb

新增货主接口:新增发货、收货地址时,增加复制功能

parent 80e5931c
......@@ -7,10 +7,12 @@ import com.esv.freight.customer.common.validator.groups.*;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.form.DeleteAddressForm;
import com.esv.freight.customer.module.goodsowner.form.DeliveryAddressForm;
import com.esv.freight.customer.module.goodsowner.form.ReceiveAddressForm;
import com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService;
import com.esv.freight.customer.module.goodsowner.service.ReceiveAddressService;
import com.esv.freight.customer.module.goodsowner.validator.groups.AddressBrief;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -52,14 +54,25 @@ public class DeliveryAddressController {
**/
@PostMapping("/add")
public EResponse add(@RequestBody @Validated(ValidatorInsert.class) DeliveryAddressForm form) throws EException {
Long id = deliveryAddressService.addAddress(form);
JSONObject data = new JSONObject();
data.put("id", id);
// 判断是否复制地址
if (GoodsOwnerConstants.ADDRESS_COPY_YES.equals(form.getAddressCopy())) {
ReceiveAddressForm receiveAddressForm = new ReceiveAddressForm();
BeanUtils.copyProperties(form, receiveAddressForm);
receiveAddressForm.setReceiver(form.getDeliverer());
receiveAddressForm.setReceiverPhone(form.getDelivererPhone());
receiveAddressForm.setReceiverTelephone(form.getDelivererTelephone());
try {
receiveAddressService.addAddress(receiveAddressForm);
} catch (Exception e) {
log.error("复制为收货地址时发生错误");
log.error(e.getMessage(), e);
}
}
Long id = deliveryAddressService.addAddress(form);
JSONObject data = new JSONObject();
data.put("id", id);
return EResponse.ok(data);
}
......
......@@ -6,11 +6,13 @@ import com.esv.freight.customer.common.response.EResponse;
import com.esv.freight.customer.common.validator.groups.*;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.form.DeleteAddressForm;
import com.esv.freight.customer.module.goodsowner.form.DeliveryAddressForm;
import com.esv.freight.customer.module.goodsowner.form.ReceiveAddressForm;
import com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService;
import com.esv.freight.customer.module.goodsowner.service.ReceiveAddressService;
import com.esv.freight.customer.module.goodsowner.validator.groups.AddressBrief;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
......@@ -52,14 +54,25 @@ public class ReceiveAddressController {
**/
@PostMapping("/add")
public EResponse add(@RequestBody @Validated(ValidatorInsert.class) ReceiveAddressForm form) throws EException {
Long id = receiveAddressService.addAddress(form);
JSONObject data = new JSONObject();
data.put("id", id);
// 判断是否复制地址
if (GoodsOwnerConstants.ADDRESS_COPY_YES.equals(form.getAddressCopy())) {
DeliveryAddressForm deliveryAddressForm = new DeliveryAddressForm();
BeanUtils.copyProperties(form, deliveryAddressForm);
deliveryAddressForm.setDeliverer(form.getReceiver());
deliveryAddressForm.setDeliverer(form.getReceiverPhone());
deliveryAddressForm.setDeliverer(form.getReceiverTelephone());
try {
deliveryAddressService.addAddress(deliveryAddressForm);
} catch (Exception e) {
log.error("复制为发货地址时发生错误");
log.error(e.getMessage(), e);
}
}
Long id = receiveAddressService.addAddress(form);
JSONObject data = new JSONObject();
data.put("id", id);
return EResponse.ok(data);
}
......
......@@ -60,6 +60,7 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
batchIdResJson = FeignUtils.getFeignResultData(feignBaseService.getBatchId(batchIdReqJson));
} catch (Exception e) {
log.error("调用[基础服务]生成发货地址编号失败");
log.error(e.getMessage(), e);
throw new EException("生成发货地址编号时发生错误");
}
String addressNumber = batchIdResJson.getString("batchId");
......
......@@ -60,6 +60,7 @@ public class ReceiveAddressServiceImpl extends ServiceImpl<ReceiveAddressDao, Re
batchIdResJson = FeignUtils.getFeignResultData(feignBaseService.getBatchId(batchIdReqJson));
} catch (Exception e) {
log.error("调用[基础服务]生成收货地址编号失败");
log.error(e.getMessage(), e);
throw new EException("生成收货地址编号时发生错误");
}
String addressNumber = batchIdResJson.getString("batchId");
......
......@@ -76,12 +76,51 @@ public class DeliveryAddressControllerTest extends BaseTestController {
Assert.assertTrue(result.getJSONObject("data").containsKey("id"));
}
/**
* 新增发货地址:同时复制为收货地址
**/
@Test
public void a2_add_with_copy_success_test() throws Exception {
String url = "/goodsowner/delivery/address/add";
// 构造数据
DeliveryAddressForm form = new DeliveryAddressForm();
form.setOwnerId(1L);
form.setAddressName("沈阳故宫博物院");
form.setProvinceCode("210000");
form.setCityCode("210100");
form.setDistrictCode("210103");
form.setDetailAddress("沈阳路171号");
form.setDeliverer("黄皇");
form.setDelivererPhone("13912340001");
form.setDelivererTelephone("(024)24850576");
form.setLon("123.464052");
form.setLat("41.800415");
form.setAddressCopy("1");
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"));
Assert.assertTrue(result.getJSONObject("data").containsKey("id"));
}
/**
* 新增发货地址:地址名称重复
**/
@Test
@Rollback
public void a2_add_repeat_addressName_failure_test() throws Exception {
public void a3_add_repeat_addressName_failure_test() throws Exception {
String url = "/goodsowner/delivery/address/add";
// 构造数据
......@@ -119,7 +158,7 @@ public class DeliveryAddressControllerTest extends BaseTestController {
**/
@Test
@Rollback
public void a3_add_wrong_param_failure_test() throws Exception {
public void a4_add_wrong_param_failure_test() throws Exception {
String url = "/goodsowner/delivery/address/add";
// 构造数据
......
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