Commit d6f4008e authored by huangcb's avatar huangcb

新增货主接口:分页查询发货地址列表

parent d3c04e69
......@@ -3,10 +3,7 @@ package com.esv.freight.customer.module.goodsowner.controller;
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.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;
......@@ -117,4 +114,16 @@ public class DeliveryAddressController {
data.put("count", count);
return EResponse.ok(data);
}
/**
* description 分页查询发货地址列表
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/22 9:28
**/
@PostMapping("/list")
public EResponse list(@RequestBody @Validated(ValidatorList.class) DeliveryAddressForm form) throws EException {
return EResponse.ok(deliveryAddressService.selectAddressList(form));
}
}
package com.esv.freight.customer.module.goodsowner.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.esv.freight.customer.module.goodsowner.entity.DeliveryAddressEntity;
import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
/**
* 货主发货地址表
*
......@@ -13,5 +16,14 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface DeliveryAddressDao extends BaseMapper<DeliveryAddressEntity> {
/**
* description 分页查询地址列表
* param [page, queryObj]
* return com.baomidou.mybatisplus.core.metadata.IPage
* author Administrator
* createTime 2020/04/22 9:20
**/
IPage selectAddressList(IPage page, Map<String, Object> queryObj);
}
......@@ -13,5 +13,7 @@ import org.apache.ibatis.annotations.Mapper;
*/
@Mapper
public interface ReceiveAddressDao extends BaseMapper<ReceiveAddressEntity> {
}
package com.esv.freight.customer.module.goodsowner.dto;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import java.util.Date;
......@@ -20,7 +19,6 @@ public class AccountInfoDto {
/**
*
*/
@TableId
private Long id;
/**
* 租户ID
......
package com.esv.freight.customer.module.goodsowner.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
/**
* 货主发货地址表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-04-21 15:27:27
*/
@Data
public class DeliveryAddressDto {
/**
*
*/
private Long id;
/**
* 货主类型:1-个人、2-企业
*/
private String ownerType;
/**
* 客户名称
*/
private String ownerFullName;
/**
* (个人或企业)联系人
*/
private String contactor;
/**
* 地址编码
*/
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;
/**
* 是否默认发货地址:0-非默认,1-默认
*/
private Boolean defaultAddress;
/**
* 0-未删除,1-已删除
*/
private Boolean deleted;
/**
* 创建者
*/
private String createUser;
/**
* 修改者
*/
private String updateUser;
/**
* 创建时间
*/
private Date createTime;
/**
* 修改时间
*/
private Date updateTime;
}
......@@ -2,12 +2,14 @@ package com.esv.freight.customer.module.goodsowner.form;
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.ValidatorList;
import com.esv.freight.customer.common.validator.groups.ValidatorUpdate;
import com.esv.freight.customer.module.goodsowner.validator.groups.AddressBrief;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
......@@ -35,11 +37,11 @@ public class DeliveryAddressForm {
@NotBlank(message = "参数addressName不能为空", groups = {ValidatorInsert.class})
private String addressName;
@Length(min = 6, max = 6, message = "参数provinceCode长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@Length(min = 6, max = 6, message = "参数provinceCode长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class, ValidatorList.class})
@NotBlank(message = "参数provinceCode不能为空", groups = {ValidatorInsert.class})
private String provinceCode;
@Length(min = 6, max = 6, message = "参数cityCode长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class})
@Length(min = 6, max = 6, message = "参数cityCode长度不合法", groups = {ValidatorInsert.class, ValidatorUpdate.class, ValidatorList.class})
@NotBlank(message = "参数cityCode不能为空", groups = {ValidatorInsert.class})
private String cityCode;
......@@ -71,6 +73,22 @@ public class DeliveryAddressForm {
@Pattern(regexp = "[01]", message = "参数addressCopy不合法", groups = {ValidatorInsert.class})
private String addressCopy;
@Length(max = 50, message = "参数keywords长度不合法", groups = {ValidatorList.class})
private String keywords;
/**
* 页码
**/
@Range(min = 1, max = 65535, message = "无效的pageNum", groups = {ValidatorList.class})
@NotNull(message = "参数pageNum不能为空", groups = {ValidatorList.class})
private Integer pageNum;
/**
* 每页记录条数
**/
@Range(min = 1, max = 100, message = "pageSize", groups = {ValidatorList.class})
@NotNull(message = "参数pageSize不能为空", groups = {ValidatorList.class})
private Integer pageSize;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
......
package com.esv.freight.customer.module.goodsowner.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.esv.freight.customer.common.vo.PageResultVO;
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.DeliveryAddressBriefVO;
import com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressListVO;
import com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressVO;
import java.util.List;
import java.util.Map;
/**
* 货主发货地址表
......@@ -72,5 +75,14 @@ public interface DeliveryAddressService extends IService<DeliveryAddressEntity>
**/
List<DeliveryAddressEntity> getAddressByName(Long ownerId, String addressName);
/**
* description 分页查询地址列表
* param [form]
* return com.esv.freight.customer.common.vo.PageResultVO
* author Administrator
* createTime 2020/04/22 9:21
**/
PageResultVO selectAddressList(DeliveryAddressForm form);
}
......@@ -2,17 +2,24 @@ package com.esv.freight.customer.module.goodsowner.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.esv.freight.customer.common.component.ErrorMessageComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.FeignUtils;
import com.esv.freight.customer.common.vo.PageResultVO;
import com.esv.freight.customer.feign.FeignBaseService;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.dao.DeliveryAddressDao;
import com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto;
import com.esv.freight.customer.module.goodsowner.dto.DeliveryAddressDto;
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.DeliveryAddressBriefVO;
import com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressListVO;
import com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
......@@ -20,9 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
@Service("deliveryAddressService")
......@@ -154,4 +159,38 @@ public class DeliveryAddressServiceImpl extends ServiceImpl<DeliveryAddressDao,
queryWrapper.eq("address_name", addressName);
return this.getBaseMapper().selectList(queryWrapper);
}
@Override
public PageResultVO selectAddressList(DeliveryAddressForm form) {
// 分页查询
Map<String, Object> queryObj = new HashMap<>(3);
if (StringUtils.isNotBlank(form.getKeywords())) {
queryObj.put("keywords", form.getKeywords());
}
if (StringUtils.isNotBlank(form.getProvinceCode())) {
queryObj.put("provinceCode", form.getProvinceCode());
}
if (StringUtils.isNotBlank(form.getCityCode())) {
queryObj.put("cityCode", form.getCityCode());
}
IPage<DeliveryAddressDto> page = new Page<>(form.getPageNum(), form.getPageSize());
this.baseMapper.selectAddressList(page, queryObj);
// 数据转换
List<DeliveryAddressDto> addressDtoList = page.getRecords();
List<DeliveryAddressListVO> addressListVOList = new ArrayList<>();
addressDtoList.forEach(entity -> {
DeliveryAddressListVO vo = new DeliveryAddressListVO();
BeanUtils.copyProperties(entity, vo);
vo.setCreateTime(entity.getCreateTime().getTime());
if (GoodsOwnerConstants.OWNER_TYPE_PERSONAL.equals(entity.getOwnerType())) {
vo.setGoodsOwnerName(entity.getContactor());
} else {
vo.setGoodsOwnerName(entity.getOwnerFullName());
}
addressListVOList.add(vo);
});
return new PageResultVO(page, addressListVOList);
}
}
\ No newline at end of file
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;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.goodsowner.vo.DeliveryAddressListVO
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/21 19:39
* @version:1.0
*/
@Data
public class DeliveryAddressListVO {
/**
*
*/
private Long id;
/**
* 地址编码
*/
private String goodsOwnerName;
/**
* 地址编码
*/
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 String createUser;
/**
*
*/
private Long createTime;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -28,5 +28,25 @@
<result property="updateTime" column="update_time"/>
</resultMap>
<!-- 分页查询地址列表 -->
<select id="selectAddressList" parameterType="java.util.Map"
resultType="com.esv.freight.customer.module.goodsowner.dto.DeliveryAddressDto">
select a.*, b.owner_type, b.owner_full_name, b.contactor
from goods_owner_delivery_address a, goods_owner_info b
where a.owner_id = b.account_id
<if test="queryObj.provinceCode != null">
and b.province_code = #{queryObj.provinceCode}
</if>
<if test="queryObj.cityCode != null">
and b.city_code = #{queryObj.cityCode}
</if>
<if test="queryObj.keywords != null">
and (a.address_name like CONCAT('%',#{queryObj.keywords},'%')
or b.owner_full_name like CONCAT('%',#{queryObj.keywords},'%')
or b.owner_brief_name like CONCAT('%',#{queryObj.keywords},'%')
or b.contactor like CONCAT('%',#{queryObj.keywords},'%'))
</if>
ORDER BY a.update_time DESC
</select>
</mapper>
\ No newline at end of file
......@@ -29,4 +29,5 @@
</resultMap>
</mapper>
\ No newline at end of file
......@@ -384,4 +384,33 @@ public class DeliveryAddressControllerTest extends BaseTestController {
Assert.assertFalse(result.getJSONArray("data").isEmpty());
}
/**
* 分页查询发货地址列表
**/
@Test
public void f1_list_success_test() throws Exception {
String url = "/goodsowner/delivery/address/list";
// 构造数据
DeliveryAddressForm form = new DeliveryAddressForm();
form.setPageNum(1);
form.setPageSize(10);
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("records"));
}
}
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