Commit 865af84a authored by huangcb's avatar huangcb

新增货主接口:查看发货地址详情

parent d4944841
......@@ -64,4 +64,7 @@ public class ErrorMessageComponent {
@Value("${error-message.goodsowner.delivery-address.edit.1002}")
private String goodsOwnerDeliveryAddressEdit1002;
@Value("${error-message.goodsowner.delivery-address.detail.1001}")
private String goodsOwnerDeliveryAddressDetail1001;
}
......@@ -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.ValidatorDelete;
import com.esv.freight.customer.common.validator.groups.ValidatorDetail;
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;
......@@ -77,6 +78,18 @@ public class DeliveryAddressController {
return EResponse.ok();
}
/**
* description 查看发货地址详情
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/21 19:55
**/
@PostMapping("/detail")
public EResponse detail(@RequestBody @Validated(ValidatorDetail.class) DeliveryAddressForm form) throws EException {
return EResponse.ok(deliveryAddressService.getAddressDetail(form));
}
/**
* description 删除发货地址
* param [form]
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.goodsowner.entity.DeliveryAddressEntity;
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.vo.DeliveryAddressVO;
import java.util.List;
......@@ -43,6 +44,15 @@ public interface DeliveryAddressService extends IService<DeliveryAddressEntity>
**/
int deleteAddress(DeleteAddressForm form);
/**
* description 查看发货地址详情
* param [form]
* return com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressVO
* author Administrator
* createTime 2020/04/21 19:50
**/
DeliveryAddressVO getAddressDetail(DeliveryAddressForm form);
/**
* description 通过地址名称查询地址记录
* param [ownerId, addressName]
......
......@@ -13,10 +13,13 @@ import com.esv.freight.customer.module.goodsowner.entity.DeliveryAddressEntity;
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.service.DeliveryAddressService;
import com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.List;
......@@ -60,6 +63,12 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
DeliveryAddressEntity addressEntity = new DeliveryAddressEntity();
BeanUtils.copyProperties(form, addressEntity);
addressEntity.setAddressNumber(addressNumber);
if (StringUtils.isNotBlank(form.getLon())) {
addressEntity.setLon(new BigDecimal(form.getLon()));
}
if (StringUtils.isNotBlank(form.getLat())) {
addressEntity.setLat(new BigDecimal(form.getLat()));
}
this.baseMapper.insert(addressEntity);
return addressEntity.getId();
......@@ -86,6 +95,12 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
// 3.更新地址
DeliveryAddressEntity updateEntity = new DeliveryAddressEntity();
BeanUtils.copyProperties(form, updateEntity);
if (StringUtils.isNotBlank(form.getLon())) {
updateEntity.setLon(new BigDecimal(form.getLon()));
}
if (StringUtils.isNotBlank(form.getLat())) {
updateEntity.setLat(new BigDecimal(form.getLat()));
}
int flag = this.baseMapper.updateById(updateEntity);
return flag;
......@@ -98,6 +113,21 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
return count;
}
@Override
public DeliveryAddressVO getAddressDetail(DeliveryAddressForm form) {
// 1.判断ID是否有效
DeliveryAddressEntity entity = this.baseMapper.selectById(form.getId());
if (null == entity) {
throw new EException(1001, errorMessageComponent.getGoodsOwnerDeliveryAddressDetail1001());
}
// 数据转换
DeliveryAddressVO addressVO = new DeliveryAddressVO();
BeanUtils.copyProperties(entity, addressVO);
return addressVO;
}
@Override
public List<DeliveryAddressEntity> getAddressByName(Long ownerId, String addressName) {
QueryWrapper<DeliveryAddressEntity> queryWrapper = new QueryWrapper<>();
......
package com.esv.freight.customer.module.goodsowner.vo;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/21 19:39
* @version:1.0
*/
@Data
public class DeliveryAddressVO {
/**
*
*/
private Long id;
/**
* 地址编码
*/
private String addressNumber;
/**
* 地址名称
*/
private String addressName;
/**
* 省份代码
*/
private String provinceCode;
/**
* 市代码
*/
private String cityCode;
/**
* 区县代码
*/
private String districtCode;
/**
* 详细地址
*/
private String detailAddress;
/**
* 发货人
*/
private String deliverer;
/**
* 发货人电话
*/
private String delivererPhone;
/**
* 发货人座机
*/
private String delivererTelephone;
/**
* 经度
*/
private BigDecimal lon;
/**
* 纬度
*/
private BigDecimal lat;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -76,4 +76,6 @@ error-message:
1001: 重复的地址名称
edit:
1001: 无效的地址ID
1002: 重复的地址名称
\ No newline at end of file
1002: 重复的地址名称
detail:
1001: 无效的地址ID
\ No newline at end of file
......@@ -298,4 +298,61 @@ public class DeliveryAddressControllerTest extends BaseTestController {
Assert.assertTrue(result.getJSONObject("data").containsKey("count"));
}
/**
* 查看发货地址详情
**/
@Test
@Rollback
public void d1_detail_success_test() throws Exception {
String url = "/goodsowner/delivery/address/detail";
// 构造数据
DeliveryAddressForm form = new DeliveryAddressForm();
form.setId(5L);
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.assertFalse(result.getJSONObject("data").isEmpty());
}
/**
* 查看发货地址详情:无效的ID
**/
@Test
@Rollback
public void d2_detail_wrong_id_failure_test() throws Exception {
String url = "/goodsowner/delivery/address/detail";
// 构造数据
DeliveryAddressForm form = new DeliveryAddressForm();
form.setId(9999L);
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"));
}
}
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