Commit d4944841 authored by huangcb's avatar huangcb

新增货主接口:删除发货地址

parent b2273787
...@@ -3,9 +3,11 @@ package com.esv.freight.customer.module.goodsowner.controller; ...@@ -3,9 +3,11 @@ package com.esv.freight.customer.module.goodsowner.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.exception.EException; import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.response.EResponse; 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.ValidatorInsert; import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate; import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants; 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.DeliveryAddressForm;
import com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService; 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.service.ReceiveAddressService;
...@@ -74,4 +76,19 @@ public class DeliveryAddressController { ...@@ -74,4 +76,19 @@ public class DeliveryAddressController {
deliveryAddressService.editAddress(form); deliveryAddressService.editAddress(form);
return EResponse.ok(); return EResponse.ok();
} }
/**
* description 删除发货地址
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/21 19:27
**/
@PostMapping("/delete")
public EResponse delete(@RequestBody @Validated(ValidatorDelete.class) DeleteAddressForm form) throws EException {
int count = deliveryAddressService.deleteAddress(form);
JSONObject data = new JSONObject();
data.put("count", count);
return EResponse.ok(data);
}
} }
package com.esv.freight.customer.module.goodsowner.form;
import com.esv.freight.customer.common.validator.groups.ValidatorDelete;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import javax.validation.constraints.NotBlank;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.goodsowner.form.DeleteAddressForm
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/17 16:11
* @version:1.0
*/
@Data
public class DeleteAddressForm {
@NotBlank(message = "参数id不能为空", groups = {ValidatorDelete.class})
private String id;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
package com.esv.freight.customer.module.goodsowner.form; package com.esv.freight.customer.module.goodsowner.form;
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.ValidatorDetail;
import com.esv.freight.customer.common.validator.groups.ValidatorInsert; import com.esv.freight.customer.common.validator.groups.ValidatorInsert;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate; import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
...@@ -25,7 +24,7 @@ import javax.validation.constraints.Pattern; ...@@ -25,7 +24,7 @@ import javax.validation.constraints.Pattern;
@Data @Data
public class DeliveryAddressForm { public class DeliveryAddressForm {
@NotNull(message = "参数id不能为空", groups = {ValidatorUpdate.class, ValidatorDetail.class, ValidatorDelete.class}) @NotNull(message = "参数id不能为空", groups = {ValidatorUpdate.class, ValidatorDetail.class})
private Long id; private Long id;
@NotNull(message = "参数ownerId不能为空", groups = {ValidatorInsert.class, ValidatorUpdate.class}) @NotNull(message = "参数ownerId不能为空", groups = {ValidatorInsert.class, ValidatorUpdate.class})
......
...@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.goodsowner.service; ...@@ -2,6 +2,7 @@ package com.esv.freight.customer.module.goodsowner.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.module.goodsowner.entity.DeliveryAddressEntity; 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.form.DeliveryAddressForm;
import java.util.List; import java.util.List;
...@@ -33,6 +34,15 @@ public interface DeliveryAddressService extends IService<DeliveryAddressEntity> ...@@ -33,6 +34,15 @@ public interface DeliveryAddressService extends IService<DeliveryAddressEntity>
**/ **/
int editAddress(DeliveryAddressForm form); int editAddress(DeliveryAddressForm form);
/**
* description 删除发货地址
* param [form]
* return int
* author Administrator
* createTime 2020/04/21 19:23
**/
int deleteAddress(DeleteAddressForm form);
/** /**
* description 通过地址名称查询地址记录 * description 通过地址名称查询地址记录
* param [ownerId, addressName] * param [ownerId, addressName]
......
...@@ -10,12 +10,14 @@ import com.esv.freight.customer.feign.FeignBaseService; ...@@ -10,12 +10,14 @@ import com.esv.freight.customer.feign.FeignBaseService;
import com.esv.freight.customer.module.goodsowner.dao.DeliveryAddressDao; 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.AuditHistoryEntity;
import com.esv.freight.customer.module.goodsowner.entity.DeliveryAddressEntity; 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.form.DeliveryAddressForm;
import com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService; import com.esv.freight.customer.module.goodsowner.service.DeliveryAddressService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -89,6 +91,13 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao, ...@@ -89,6 +91,13 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
return flag; return flag;
} }
@Override
public int deleteAddress(DeleteAddressForm form) {
String[] ids = form.getId().split(",");
int count = this.baseMapper.deleteBatchIds(Arrays.asList(ids));
return count;
}
@Override @Override
public List<DeliveryAddressEntity> getAddressByName(Long ownerId, String addressName) { public List<DeliveryAddressEntity> getAddressByName(Long ownerId, String addressName) {
QueryWrapper<DeliveryAddressEntity> queryWrapper = new QueryWrapper<>(); QueryWrapper<DeliveryAddressEntity> queryWrapper = new QueryWrapper<>();
......
...@@ -3,6 +3,7 @@ package com.esv.freight.customer.module.goodsowner.controller; ...@@ -3,6 +3,7 @@ package com.esv.freight.customer.module.goodsowner.controller;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.BaseTestController; import com.esv.freight.customer.BaseTestController;
import com.esv.freight.customer.common.response.ECode; import com.esv.freight.customer.common.response.ECode;
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.DeliveryAddressForm;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
...@@ -268,4 +269,33 @@ public class DeliveryAddressControllerTest extends BaseTestController { ...@@ -268,4 +269,33 @@ public class DeliveryAddressControllerTest extends BaseTestController {
Assert.assertEquals(1002, result.getIntValue("code")); Assert.assertEquals(1002, result.getIntValue("code"));
} }
/**
* 删除发货地址
**/
@Test
@Rollback
public void c1_delete_success_test() throws Exception {
String url = "/goodsowner/delivery/address/delete";
// 构造数据
DeleteAddressForm form = new DeleteAddressForm();
form.setId("1,2,3,4,5");
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("count"));
}
} }
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