Commit 92552b60 authored by huangcb's avatar huangcb

新增接口:获取所有可用货主帐号列表

parent 465d8a61
......@@ -31,6 +31,9 @@ public class LogbackFilter implements Filter {
// 获取来自上游服务的传参traceId
HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
String traceId = httpServletRequest.getHeader("gateway_traceid");
if (StringUtils.isBlank(traceId)) {
traceId = httpServletRequest.getHeader("trace_id");
}
boolean bInsertMDC = setMDC(traceId);
try {
filterChain.doFilter(servletRequest, servletResponse);
......
package com.esv.freight.customer.common.filter;
import com.alibaba.fastjson.JSONObject;
import com.esv.freight.customer.common.wrapper.RestRequestWrapper;
import com.esv.freight.customer.common.wrapper.RestResponseWrapper;
import lombok.extern.slf4j.Slf4j;
......@@ -40,12 +41,11 @@ public class RestLogFilter implements Filter {
RestResponseWrapper responseWrapper = new RestResponseWrapper((HttpServletResponse) servletResponse);
String reqContentType = StringUtils.trimToEmpty(requestWrapper.getContentType()).toLowerCase();
if (reqContentType.contains("multipart/form-data")) {
log.info("multipart/form-data request");
} else {
if (!reqContentType.contains("multipart/form-data")) {
// 日志输出请求
logReq(requestWrapper);
}
logReqHeader(requestWrapper);
filterChain.doFilter(requestWrapper, responseWrapper);
......@@ -138,6 +138,16 @@ public class RestLogFilter implements Filter {
}
}
private void logReqHeader(RestRequestWrapper request) {
JSONObject headerJson = new JSONObject();
Enumeration headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String key = (String) headerNames.nextElement();
headerJson.put(key, request.getHeader(key));
}
log.info("请求头:{}", headerJson.toJSONString());
}
private void logRes(RestRequestWrapper requestWrapper, RestResponseWrapper responseWrapper) throws Exception {
byte[] bytes = responseWrapper.getBody();
String resStr = new String(bytes,"utf-8");
......
......@@ -3,6 +3,7 @@ package com.esv.freight.customer.config;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.gateway.common.GatewayHeaders;
import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.openfeign.EnableFeignClients;
......@@ -23,6 +24,7 @@ import java.lang.reflect.Field;
*/
@EnableFeignClients(basePackages = "com.esv.freight.customer.feign")
@Configuration
@Slf4j
public class FeignConfigure {
@Value("${spring.application.name}")
......@@ -39,13 +41,18 @@ public class FeignConfigure {
requestTemplate.header("trace_id", MDC.get("traceId"));
requestTemplate.header("application_name", applicationName);
GatewayHeaders gatewayHeaders = new GatewayHeaders();
Class cls = gatewayHeaders.getClass();
Class cls = GatewayHeaders.class;
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()));
String key;
try {
key = String.valueOf(f.get(cls));
requestTemplate.header(key, ReqUtils.getRequestHeader(key));
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
}
}
}));
return requestInterceptor;
......
......@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.esv.freight.customer.common.util.ReqUtils;
import com.esv.gateway.common.GatewayHeaders;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
......@@ -37,6 +38,9 @@ public class EsvMetaObjectHandler implements MetaObjectHandler {
}
if (metaObject.hasSetter("departmentId") && metaObject.getValue("departmentId") == null) {
String departmentId = ReqUtils.getRequestHeader(GatewayHeaders.DEPARTMENT_ID);
if (StringUtils.isBlank(departmentId)) {
departmentId = "-1";
}
this.setFieldValByName("departmentId", Long.parseLong(departmentId), metaObject);
}
}
......
......@@ -228,7 +228,7 @@ public class GoodsOwnerController {
}
// 校验密码是否正确
if (!passwordComponent.checkPwd4Salt(form.getPassword(), accountInfoDto.getSalt(), accountInfoDto.getPassword())) {
throw new EException(1002, errorMessageComponent.getGoodsOwnerAccountPasswordCheck1001());
throw new EException(1002, errorMessageComponent.getGoodsOwnerAccountPasswordCheck1002());
}
AccountInfoVO accountInfoVO = new AccountInfoVO();
......@@ -263,4 +263,16 @@ public class GoodsOwnerController {
PageResultVO pageResult = accountService.selectAccountInfoList(form);
return EResponse.ok(pageResult);
}
/**
* description 获取所有可用货主帐号列表
* param []
* return com.esv.freight.customer.common.response.EResponse
* author Administrator
* createTime 2020/04/21 14:11
**/
@PostMapping("/getAllAvailable")
public EResponse getAllAvailable() throws EException {
return EResponse.ok(accountService.selectAllAvailableAccount());
}
}
......@@ -7,7 +7,7 @@ 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;
import java.util.List;
/**
* 货主基础信息表
......@@ -45,5 +45,14 @@ public interface AccountDao extends BaseMapper<AccountEntity> {
* createTime 2020/04/20 19:51
**/
IPage selectAccountInfoList(IPage page, AccountQueryForm queryObj);
/**
* description 获取所有可用货主帐号列表
* param []
* return java.util.List<com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto>
* author Administrator
* createTime 2020/04/21 9:18
**/
List<AccountInfoDto> selectAllAvailableAccount();
}
......@@ -8,6 +8,7 @@ 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.vo.AccountAvailableVO;
import java.util.List;
......@@ -119,5 +120,14 @@ public interface AccountService extends IService<AccountEntity> {
**/
PageResultVO selectAccountInfoList(AccountQueryForm queryForm);
/**
* description 获取所有可用货主帐号列表
* param []
* return java.util.List<com.esv.freight.customer.module.goodsowner.vo.AccountAvailableVO>
* author Administrator
* createTime 2020/04/21 9:19
**/
List<AccountAvailableVO> selectAllAvailableAccount();
}
......@@ -26,6 +26,7 @@ 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.AccountAvailableVO;
import com.esv.freight.customer.module.goodsowner.vo.AccountListVO;
import com.esv.gateway.common.GatewayHeaders;
import org.apache.commons.codec.digest.DigestUtils;
......@@ -319,4 +320,22 @@ public class AccountServiceImpl extends ServiceImpl<AccountDao, AccountEntity> i
return new PageResultVO(page, targetRecordList);
}
@Override
public List<AccountAvailableVO> selectAllAvailableAccount() {
List<AccountInfoDto> dtoList = this.baseMapper.selectAllAvailableAccount();
List<AccountAvailableVO> targetRecordList = new ArrayList<>();
for (AccountInfoDto dto : dtoList) {
AccountAvailableVO vo = new AccountAvailableVO();
BeanUtils.copyProperties(dto, vo);
if (GoodsOwnerConstants.OWNER_TYPE_PERSONAL.equals(dto.getOwnerType())) {
vo.setOwnerName(dto.getContactor());
} else {
vo.setOwnerName(dto.getOwnerFullName());
}
targetRecordList.add(vo);
}
return 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 AccountAvailableVO implements Serializable {
private static final long serialVersionUID = -5672242122935128064L;
/**
*
*/
private Long id;
/**
* 登录帐号,货主手机号
*/
private String account;
/**
* 客户编码
*/
private String ownerNumber;
/**
* 货主名称(企业时为全称、个人时为联系人姓名)
*/
private String ownerName;
@Override
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
......@@ -22,6 +22,7 @@
<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.*,
......@@ -55,6 +56,19 @@
ORDER BY a.update_time DESC, a.account ASC
</select>
<!-- 获取所有可用货主帐号列表 -->
<select id="selectAllAvailableAccount" parameterType="com.esv.freight.customer.module.goodsowner.form.AccountQueryForm"
resultType="com.esv.freight.customer.module.goodsowner.dto.AccountInfoDto">
select a.id, a.account,
b.owner_type, b.owner_number, b.owner_full_name, b.contactor
from goods_owner_account a
left join goods_owner_info b
on a.id = b.account_id
where a.account_status = '1'
and a.audit_status = '1'
ORDER BY b.owner_type DESC, b.owner_full_name ASC, b.contactor 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,
......
......@@ -766,4 +766,30 @@ public class GoodsOwnerControllerTest extends BaseTestController {
Assert.assertEquals(ECode.SUCCESS.code(), result.getIntValue("code"));
Assert.assertTrue(result.getJSONObject("data").containsKey("records"));
}
/**
* 获取所有可用货主帐号列表
**/
@Test
public void h1_getAllAvailable_success_test() throws Exception {
String url = "/goodsowner/account/getAllAvailable";
// 构造数据
JSONObject reqJson = new JSONObject();
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(null != result.getJSONArray("data"));
}
}
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