Commit 465d8a61 authored by huangcb's avatar huangcb

新增接口:分页查询帐号列表

parent 42f72662
package com.esv.freight.customer.config;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.gateway.common.GatewayHeaders;
import feign.RequestInterceptor;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
......@@ -8,6 +10,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
import java.lang.reflect.Field;
/**
* @description: Feign接口配置
* @project: freight-customer-service
......@@ -34,6 +38,15 @@ public class FeignConfigure {
RequestInterceptor requestInterceptor = ((requestTemplate -> {
requestTemplate.header("trace_id", MDC.get("traceId"));
requestTemplate.header("application_name", applicationName);
GatewayHeaders gatewayHeaders = new GatewayHeaders();
Class cls = gatewayHeaders.getClass();
Field[] fields = cls.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
f.setAccessible(true);
requestTemplate.header(f.getName(), ReqUtils.getRequestHeader(f.getName()));
}
}));
return requestInterceptor;
}
......
......@@ -10,12 +10,15 @@ import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.freight.customer.common.util.VerifyUtils;
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.common.vo.PageResultVO;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto;
import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.form.AccountQueryForm;
import com.esv.freight.customer.module.goodsowner.service.AccountService;
import com.esv.freight.customer.module.goodsowner.validator.groups.*;
import com.esv.freight.customer.module.goodsowner.vo.AccountInfoVO;
......@@ -61,12 +64,6 @@ public class GoodsOwnerController {
this.passwordComponent = passwordComponent;
}
@PostMapping("/list")
public EResponse getAccountList() {
String account = "test";
return EResponse.ok(accountService.getAccountRecordByAccount(account));
}
/**
* description 平台用户创建帐号
* param [form]
......@@ -253,4 +250,17 @@ public class GoodsOwnerController {
data.put("id", id);
return EResponse.ok(data);
}
/**
* description 分页查询帐号列表
* param [form]
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/20 20:03
**/
@PostMapping("/list")
public EResponse getAccountList(@RequestBody @Validated(ValidatorList.class) AccountQueryForm form) throws EException {
PageResultVO pageResult = accountService.selectAccountInfoList(form);
return EResponse.ok(pageResult);
}
}
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.dto.AccountInfoDto;
import com.esv.freight.customer.module.goodsowner.entity.AccountEntity;
import com.esv.freight.customer.module.goodsowner.form.AccountQueryForm;
import org.apache.ibatis.annotations.Mapper;
import java.util.Map;
/**
* 货主基础信息表
*
......@@ -33,4 +37,13 @@ public interface AccountDao extends BaseMapper<AccountEntity> {
**/
AccountInfoDto getAccountInfoByAccount(String account);
/**
* description 分页查询帐号列表
* param [page, queryObj]
* return com.baomidou.mybatisplus.core.metadata.IPage
* author Administrator
* createTime 2020/04/20 19:51
**/
IPage selectAccountInfoList(IPage page, AccountQueryForm queryObj);
}
package com.esv.freight.customer.module.goodsowner.form;
import com.esv.freight.customer.common.validator.groups.ValidatorList;
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.NotNull;
import javax.validation.constraints.Pattern;
/**
* @description:
* @project: freight-customer-service
* @name: com.esv.freight.customer.module.goodsowner.form.AccountQueryForm
* @author: 黄朝斌
* @email: huangchaobin@esvtek.com
* @createTime: 2020/04/17 16:11
* @version:1.0
*/
@Data
public class AccountQueryForm {
/**
* 货主类型:1-个人、2-企业
*/
@Pattern(regexp = "[12]", message = "参数ownerType不合法", groups = {ValidatorList.class})
private String ownerType;
/**
* 货主编码
*/
@Length( max = 20, message = "参数ownerNumber长度不合法", groups = {ValidatorList.class})
private String ownerNumber;
/**
* 货主帐号审核状态(字典表):0-待审核、1-审核成功,2-审核失败
*/
@Pattern(regexp = "[012]", message = "参数auditStatus不合法", groups = {ValidatorList.class})
private String auditStatus;
/**
* 帐号状态:1-正常、2-停用
*/
@Pattern(regexp = "[12]", message = "参数accountStatus不合法", groups = {ValidatorList.class})
private String accountStatus;
/**
* (个人或企业联系人手机号)帐号
*/
@Length(max = 11, message = "参数account长度不合法", groups = {ValidatorList.class})
private String account;
/**
* 客户名称/客户简称/联系人
*/
@Length(max = 50, message = "参数name长度不合法", groups = {ValidatorList.class})
private String name;
/**
* 页码
**/
@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.dto.AccountInfoDto;
import com.esv.freight.customer.module.goodsowner.entity.AccountEntity;
import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.form.AccountQueryForm;
import java.util.List;
......@@ -108,5 +110,14 @@ public interface AccountService extends IService<AccountEntity> {
**/
Long registerAccount(String account);
/**
* description 分页查询帐号列表
* param [queryForm]
* return com.esv.freight.customer.common.vo.PageResultVO
* author Administrator
* createTime 2020/04/20 19:52
**/
PageResultVO selectAccountInfoList(AccountQueryForm queryForm);
}
......@@ -4,12 +4,15 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
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.component.PasswordComponent;
import com.esv.freight.customer.common.exception.EException;
import com.esv.freight.customer.common.util.FeignUtils;
import com.esv.freight.customer.common.util.ReqUtils;
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.AccountDao;
......@@ -19,9 +22,11 @@ import com.esv.freight.customer.module.goodsowner.entity.AuditHistoryEntity;
import com.esv.freight.customer.module.goodsowner.entity.InfoEntity;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.form.AccountQueryForm;
import com.esv.freight.customer.module.goodsowner.service.AccountService;
import com.esv.freight.customer.module.goodsowner.service.AuditHistoryService;
import com.esv.freight.customer.module.goodsowner.service.InfoService;
import com.esv.freight.customer.module.goodsowner.vo.AccountListVO;
import com.esv.gateway.common.GatewayHeaders;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.StringUtils;
......@@ -30,8 +35,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Service("accountService")
......@@ -291,4 +296,27 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
return accountId;
}
@Override
public PageResultVO selectAccountInfoList(AccountQueryForm queryForm) {
IPage<AccountInfoDto> page = new Page<>(queryForm.getPageNum(), queryForm.getPageSize());
this.baseMapper.selectAccountInfoList(page, queryForm);
// 数据转换
List<AccountInfoDto> dtoList = page.getRecords();
List<AccountListVO> targetRecordList = new ArrayList<>();
for (AccountInfoDto dto : dtoList) {
AccountListVO vo = new AccountListVO();
BeanUtils.copyProperties(dto, vo);
if (GoodsOwnerConstants.OWNER_TYPE_PERSONAL.equals(dto.getOwnerType())) {
vo.setOwnerName(dto.getContactor());
} else {
vo.setOwnerName(dto.getOwnerFullName());
}
vo.setCreateTime(dto.getCreateTime().getTime());
targetRecordList.add(vo);
}
return new PageResultVO(page, targetRecordList);
}
}
\ 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;
import java.io.Serializable;
/**
* 货主信息表
*
* @author 黄朝斌
* @email huangchaobin@esvtek.com
* @date 2020-04-17 13:54:57
*/
@Data
public class AccountListVO implements Serializable {
private static final long serialVersionUID = -2559918457110278351L;
/**
*
*/
private Long id;
/**
* 创建来源:1-平台创建、2-自行注册
*/
private String sourceType;
/**
* 货主名称(企业时为全称、个人时为联系人姓名)
*/
private String ownerName;
/**
* 客户编码
*/
private String ownerNumber;
/**
* 货主类型:1-个人、2-企业
*/
private String ownerType;
/**
* 登录帐号,货主手机号
*/
private String account;
/**
* 帐号状态:1-正常、2-停用
*/
private String accountStatus;
/**
*
*/
private String createUser;
/**
*
*/
private Long createTime;
/**
* 货主帐号审核状态:0-待审核、1-审核成功,2-审核失败,APP自行注册需要平台审核
*/
private Integer auditStatus;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -22,6 +22,39 @@
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="selectAccountInfoList" parameterType="com.esv.freight.customer.module.goodsowner.form.AccountQueryForm"
resultType="com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto">
select a.*,
b.owner_type, b.owner_number, b.owner_full_name, b.owner_brief_name, b.uni_credit_code, b.credit_expire_date, b.credit_original_url,
b.credit_copy_url, b.legal_person, b.legal_phone, b.province_code, b.city_code, b.district_code, b.detail_address, b.contactor,
b.id_card, b.id_card_expire_date, b.id_card_front_url, b.id_card_back_url
from goods_owner_account a
left join goods_owner_info b
on a.id = b.account_id
where 1 = 1
<if test="queryObj.ownerType != null">
and b.owner_type = #{queryObj.ownerType}
</if>
<if test="queryObj.ownerNumber != null">
and b.owner_number = #{queryObj.ownerNumber}
</if>
<if test="queryObj.auditStatus != null">
and a.audit_status = #{queryObj.auditStatus}
</if>
<if test="queryObj.accountStatus != null">
and a.account_status = #{queryObj.accountStatus}
</if>
<if test="queryObj.account != null">
and a.account = #{queryObj.account}
</if>
<if test="queryObj.name != null">
and (b.owner_full_name like CONCAT('%',#{queryObj.name},'%')
or b.owner_brief_name like CONCAT('%',#{queryObj.name},'%')
or b.contactor like CONCAT('%',#{queryObj.name},'%'))
</if>
ORDER BY a.update_time DESC, a.account ASC
</select>
<select id="getAccountInfoById" parameterType="java.lang.Long" resultType="com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto">
select a.*,
b.owner_type, b.owner_number, b.owner_full_name, b.owner_brief_name, b.uni_credit_code, b.credit_expire_date, b.credit_original_url,
......
......@@ -6,6 +6,7 @@ import com.esv.freight.customer.common.response.ECode;
import com.esv.freight.customer.module.goodsowner.GoodsOwnerConstants;
import com.esv.freight.customer.module.goodsowner.form.AccountForm;
import com.esv.freight.customer.module.goodsowner.form.AccountInfoForm;
import com.esv.freight.customer.module.goodsowner.form.AccountQueryForm;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;
import org.junit.FixMethodOrder;
......@@ -704,4 +705,65 @@ public class GoodsOwnerControllerTest extends BaseTestController {
JSONObject result = JSONObject.parseObject(responseStr);
Assert.assertEquals(1001, result.getIntValue("code"));
}
/**
* 分页查询帐号列表
**/
@Test
@Rollback
public void j1_getAccountList_success_test() throws Exception {
String url = "/goodsowner/account/list";
// 构造数据
AccountQueryForm form = new AccountQueryForm();
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"));
}
/**
* 分页查询帐号列表
**/
@Test
@Rollback
public void j1_getAccountList_with_param_success_test() throws Exception {
String url = "/goodsowner/account/list";
// 构造数据
AccountQueryForm form = new AccountQueryForm();
form.setName("黄");
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