Commit 3eca0503 authored by 杨钧's avatar 杨钧

订单信息查询接口

parent cbb4062e
package cn.quantgroup.customer.enums;
import java.util.Arrays;
import java.util.Optional;
/**
* Created by Administrator on 2019/12/17.
*/
public enum OrderStatusEnums {
CREDIT_SUCC("CREDIT_SUCC","授信成功"),
APPROVE_ING("APPROVE_ING","审批中"),
FUAD_ASSIFN_SUCC("FUAD_ASSIFN_SUCC","分配资金方成功"),
REJECT("REJECT","风控审核不通过"),
WITHDRAW("WITHDRAW","用户提现申请成功"),
WITHDRAW_APPROVING("WITHDRAW_APPROVING","提现审批中"), // 对应loan状态50等待二次审核
PAY_ING("PAY_ING","放款中"),
FUND_SUCC("FUND_SUCC","放款成功"),
FUND_WAITING_WITHDRAW("FUND_WAITING_WITHDRAW","放款成功,等待二次提现"),
FUND_WITHDRAW_SUCC("FUND_WITHDRAW_SUCC","放款提现成功,存管提现成功"),
FUND_FAIL("FUND_FAIL","放款失败"),
ALL_REPAID("ALL_REPAID","结清"),
CANCEL_LOAN("CANCEL_LOAN","贷前关闭订单"),
CANCEL_AFTER_LOAN("CANCEL_AFTER_LOAN","贷后关闭订单");
private String key;
private String value;
OrderStatusEnums(String key, String value) {
this.key = key;
this.value = value;
}
public String getKey() {
return key;
}
public String getValue() {
return value;
}
public static String getValue(String key){
Optional<OrderStatusEnums> optional =Arrays.asList(OrderStatusEnums.values()).stream().filter(coreStatus -> key.equalsIgnoreCase(coreStatus.getKey())).findFirst();
if(optional.isPresent()){
return optional.get().getValue();
}
return OrderStatusEnums.APPROVE_ING.getValue();
}
public static boolean finalStatus (OrderStatusEnums enums) {
switch (enums) {
case REJECT:
case FUND_FAIL:
case ALL_REPAID:
case CANCEL_LOAN:
case CANCEL_AFTER_LOAN: return true;
default:return false;
}
}
}
package cn.quantgroup.customer.model.order;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import java.util.Objects;
/**
* @author yangjun
* @Date 2020/3/20 14:13
* @Desc
* @Update
*/
@Data
public class CallbackRecord {
/**
* 通知类型
*/
private String noticeType;
/**
* 通知成功或者失败
*/
private String noticeStatus;
/**
* 期数
*/
private Long termNo;
/**
* 通知时间
*/
private Long dateTime;
/**
* 通知时间 YYYY-MM-dd HH:mm:ss
*/
private String createAt;
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (Objects.isNull(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
CallbackRecord other = (CallbackRecord) obj;
if (StringUtils.isBlank(other.getNoticeType())) {
return false;
} else {
if(!this.getNoticeType().equals(other.getNoticeType())){
return false;
}else {
if(Objects.isNull(other.getTermNo())){
return true;
}else{
if(!this.getTermNo().equals(other.getTermNo())){
return false;
}
return true;
}
}
}
}
}
package cn.quantgroup.customer.model.order;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Jony
* @Date 2020/3/20 16:28
* @Desc
* @Update
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OrderInfo {
private String channelOrderNo;
private Long channelId;
private String status;
private String remark;
private String applyNo;
private Long loanId;
}
package cn.quantgroup.customer.model.order;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
/**
* @author yangjun
* @Date 2020/3/20 16:27
* @Desc
* @Update
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class OrderInfoVo {
private List<CallbackRecord> noticeList;
private OrderInfo orderInfo;
}
package cn.quantgroup.customer.model.order;
import cn.quantgroup.customer.enums.OrderStatusEnums;
import lombok.Data;
/**
* @author yangjun
* @Date 2020/3/20 13:52
* @Desc
* @Update
*/
@Data
public class OrderStatus {
/**
* 订单状态
*/
private OrderStatusEnums status;
/**
* 状态更新时间
*/
private Long updateTime;
}
package cn.quantgroup.customer.model.order;
import lombok.Data;
@Data
public class OrderStatusXyqb {
private OrderStatus currentStatus;
}
package cn.quantgroup.customer.rest; package cn.quantgroup.customer.rest;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.param.repay.RepayOrderInfoQuery;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IOrderService; import cn.quantgroup.customer.service.IOrderService;
import cn.quantgroup.customer.service.IXyqbService; import cn.quantgroup.customer.service.IXyqbService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import javax.validation.Valid;
import org.springframework.web.bind.annotation.RestController;
/** /**
* @author Wang Xiangwei * @author Wang Xiangwei
...@@ -35,4 +36,14 @@ public class OrderRest { ...@@ -35,4 +36,14 @@ public class OrderRest {
return orderService.findFlowChart(orderNo); return orderService.findFlowChart(orderNo);
} }
/**
* 订单信息查询
* @param orderQuery
* @return
*/
@GetMapping("/info")
public JsonResult queryRepayInfo(OrderQueryParam orderQuery) {
log.info("[查询订单信息],请求参数:orderQuery={}", orderQuery);
return orderService.queryOrderInfo(orderQuery);
}
} }
...@@ -2,6 +2,7 @@ package cn.quantgroup.customer.service; ...@@ -2,6 +2,7 @@ package cn.quantgroup.customer.service;
import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult; import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping; import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.order.CallbackRecord;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
...@@ -26,4 +27,12 @@ public interface IKaService { ...@@ -26,4 +27,12 @@ public interface IKaService {
JsonResult<List<ChannelConfigurationResult>> getAllChannelConfiguration(); JsonResult<List<ChannelConfigurationResult>> getAllChannelConfiguration();
/**
* 查询发送通知记录
* @param applyNo 申请单号
* @param channelId 渠道号
* @param aTrue true 成功 false 失败
* @return
*/
JsonResult<List<CallbackRecord>> querySendRecords(String applyNo, Long channelId, Boolean aTrue);
} }
...@@ -2,6 +2,7 @@ package cn.quantgroup.customer.service; ...@@ -2,6 +2,7 @@ package cn.quantgroup.customer.service;
import cn.quantgroup.customer.model.order.FlowNode; import cn.quantgroup.customer.model.order.FlowNode;
import cn.quantgroup.customer.model.order.LoanOrderDetail; import cn.quantgroup.customer.model.order.LoanOrderDetail;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import java.util.List; import java.util.List;
...@@ -21,4 +22,11 @@ public interface IOrderService{ ...@@ -21,4 +22,11 @@ public interface IOrderService{
JsonResult<LoanOrderDetail> getLoanOrderDetail(Long loanId); JsonResult<LoanOrderDetail> getLoanOrderDetail(Long loanId);
/**
* 查询订单信息
* @param orderQuery
* @return
*/
JsonResult queryOrderInfo(OrderQueryParam orderQuery);
} }
package cn.quantgroup.customer.service; package cn.quantgroup.customer.service;
import cn.quantgroup.customer.model.order.ApplyOrder; import cn.quantgroup.customer.model.order.*;
import cn.quantgroup.customer.model.order.FlowNode;
import cn.quantgroup.customer.model.order.LoanOrder;
import cn.quantgroup.customer.model.order.OrderRepayment;
import cn.quantgroup.customer.rest.param.card.ModifyReservePhone; import cn.quantgroup.customer.rest.param.card.ModifyReservePhone;
import cn.quantgroup.customer.rest.param.card.UnBindCardModel; import cn.quantgroup.customer.rest.param.card.UnBindCardModel;
import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery; import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.param.repay.RepayOrderInfoQuery; import cn.quantgroup.customer.rest.param.repay.RepayOrderInfoQuery;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery; import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
...@@ -57,4 +55,11 @@ public interface IXyqbService { ...@@ -57,4 +55,11 @@ public interface IXyqbService {
String queryRepayInfo(RepayOrderInfoQuery repayOrderQuery); String queryRepayInfo(RepayOrderInfoQuery repayOrderQuery);
String queryRepayOptRecords(String businessFlowNo); String queryRepayOptRecords(String businessFlowNo);
/**
* 订单状态查询
* @param orderQuery
* @return
*/
JsonResult<OrderStatus> orderStatusQuery(OrderQueryParam orderQuery);
} }
...@@ -4,6 +4,7 @@ import cn.quantgroup.customer.enums.ErrorCodeEnum; ...@@ -4,6 +4,7 @@ import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.exception.BusinessException; import cn.quantgroup.customer.exception.BusinessException;
import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult; import cn.quantgroup.customer.model.kaordermapping.ChannelConfigurationResult;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping; import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.order.CallbackRecord;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IKaService; import cn.quantgroup.customer.service.IKaService;
...@@ -33,7 +34,7 @@ import java.util.StringJoiner; ...@@ -33,7 +34,7 @@ import java.util.StringJoiner;
public class KaServiceImpl implements IKaService { public class KaServiceImpl implements IKaService {
@Value("${qapi.http}") @Value("http://localhost:7037")
private String kaSysUrl; private String kaSysUrl;
@Autowired @Autowired
...@@ -138,7 +139,7 @@ public class KaServiceImpl implements IKaService { ...@@ -138,7 +139,7 @@ public class KaServiceImpl implements IKaService {
log.info("{},获得所有渠道", logPre); log.info("{},获得所有渠道", logPre);
String url = kaSysUrl + "/external//query/all/channelConfiguration"; String url = kaSysUrl + "/external/query/all/channelConfiguration";
String result; String result;
...@@ -158,4 +159,46 @@ public class KaServiceImpl implements IKaService { ...@@ -158,4 +159,46 @@ public class KaServiceImpl implements IKaService {
JsonResult<List<ChannelConfigurationResult>> jsonResult = JSONTools.deserialize(result, typeToken); JsonResult<List<ChannelConfigurationResult>> jsonResult = JSONTools.deserialize(result, typeToken);
return jsonResult; return jsonResult;
} }
@Override
public JsonResult<List<CallbackRecord>> querySendRecords(String applyNo, Long channelId, Boolean isSucc) {
String logPre = "[KaServiceImpl.querySendRecords] 查询发送通知记录";
log.info("{}, applyNo={},channelId={},isSucc={}", logPre, applyNo,channelId,isSucc);
String url = kaSysUrl + "/external/query/orderCallBack";
try {
Map<String, Object> param = Maps.newHashMap();
if (Objects.nonNull(applyNo)) {
param.put("applyNo", applyNo);
}
if (Objects.nonNull(channelId)) {
param.put("channelId", String.valueOf(channelId));
}
param.put("isSucc",isSucc);
String result = null;
try {
result = httpService.get(url, param);
} catch (Exception e) {
log.error(" {} http请求异常 url={},param={}", logPre, url, param, e);
return JsonResult.buildErrorStateResult("通讯异常", null);
}
log.info("{} 请求ka系统返回值:{}", logPre, result);
if (StringUtils.isBlank(result)) {
log.error("{} 返回结果为空,查询失败 jsonResult={}", logPre, result);
return JsonResult.buildErrorStateResult("查询数据异常", null);
}
TypeReference<JsonResult<List<CallbackRecord>>> typeToken = new TypeReference<JsonResult<List<CallbackRecord>>>() {
};
JsonResult<List<CallbackRecord>> jsonResult = JSONTools.deserialize(result, typeToken);
return jsonResult;
} catch (Exception e) {
log.error("{} 网络通讯异常,applyNo={},channelId={},isSucc={},ex:{}", applyNo,channelId,isSucc, ExceptionUtils.getStackTrace(e));
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
}
} }
package cn.quantgroup.customer.service.impl; package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.enums.OrderStatusEnums;
import cn.quantgroup.customer.model.Tuple;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping; import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.order.*; import cn.quantgroup.customer.model.order.*;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
...@@ -7,13 +10,15 @@ import cn.quantgroup.customer.rest.vo.JsonResult; ...@@ -7,13 +10,15 @@ import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IKaService; import cn.quantgroup.customer.service.IKaService;
import cn.quantgroup.customer.service.IOrderService; import cn.quantgroup.customer.service.IOrderService;
import cn.quantgroup.customer.service.IXyqbService; import cn.quantgroup.customer.service.IXyqbService;
import cn.quantgroup.customer.util.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
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.ArrayList; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
import java.util.Objects;
/** /**
* @author Wang Xiangwei * @author Wang Xiangwei
...@@ -79,9 +84,9 @@ public class OrderServiceImpl implements IOrderService { ...@@ -79,9 +84,9 @@ public class OrderServiceImpl implements IOrderService {
loanOrderDetail.setLoanOrder(loanOrderData); loanOrderDetail.setLoanOrder(loanOrderData);
loanOrderDetail.setRepaymentList(repaymentList); loanOrderDetail.setRepaymentList(repaymentList);
if(Objects.isNull(loanOrderData) || !loanOrderData.getShowPlans()){ if (Objects.isNull(loanOrderData) || !loanOrderData.getShowPlans()) {
log.info("{} 不需查询还款计划",logPre); log.info("{} 不需查询还款计划", logPre);
return JsonResult.buildSuccessResult("查询成功",loanOrderDetail); return JsonResult.buildSuccessResult("查询成功", loanOrderDetail);
} }
//还款计划查询 //还款计划查询
...@@ -96,4 +101,183 @@ public class OrderServiceImpl implements IOrderService { ...@@ -96,4 +101,183 @@ public class OrderServiceImpl implements IOrderService {
return JsonResult.buildSuccessResult("查询成功", loanOrderDetail); return JsonResult.buildSuccessResult("查询成功", loanOrderDetail);
} }
@Override
public JsonResult queryOrderInfo(OrderQueryParam orderQuery) {
String logPre = "OrderServiceImpl.queryOrderInfo";
Tuple<Boolean, String> tuple = validate(orderQuery);
if (!tuple.getKey()) {
log.error("{},参数验证失败,{}", logPre, tuple.getValue());
return JsonResult.buildErrorStateResult(tuple.getValue(), null);
}
// 查询订单信息 查询ka
JsonResult<LoanOrderMapping> orderMappingResult = kaService.findOrderMapping(orderQuery);
LoanOrderMapping loanOrderMapping;
if (!orderMappingResult.isSuccess() || Objects.isNull(loanOrderMapping = orderMappingResult.getData())) {
log.error("{} 查询订单信息orderMapping失败 result={} orderQuery={}", logPre, orderMappingResult, orderQuery);
return JsonResult.buildErrorStateResult(ErrorCodeEnum.RETURN_ERROR.getMessage(), ErrorCodeEnum.RETURN_ERROR.getCode());
}
// 查询订单状态 xyqb
orderQuery.setApplyOrderNo(loanOrderMapping.getApplyNo());
orderQuery.setLoanId(loanOrderMapping.getLoanId());
orderQuery.setChannelId(loanOrderMapping.getRegisteredFrom());
JsonResult<OrderStatus> orderStatusResult = xyqbService.orderStatusQuery(orderQuery);
OrderStatus orderStatus;
if (!orderStatusResult.isSuccess() || Objects.isNull(orderStatus = orderStatusResult.getData())) {
log.error("{} 查询订单状态 orderStatus 失败 result={} orderQuery={}", logPre, orderStatusResult, orderQuery);
return JsonResult.buildErrorStateResult(ErrorCodeEnum.RETURN_ERROR.getMessage(), ErrorCodeEnum.RETURN_ERROR.getCode());
}
// 查询通知记录 查询ka
JsonResult<List<CallbackRecord>> callbackListResult = queryOrderCallback(orderQuery);
if (!callbackListResult.isSuccess()) {
log.error("{} 查询发送记录失败 result={} orderQuery={}", logPre, callbackListResult, orderQuery);
return JsonResult.buildErrorStateResult(ErrorCodeEnum.RETURN_ERROR.getMessage(), ErrorCodeEnum.RETURN_ERROR.getCode());
}
OrderInfo orderInfo = OrderInfo.builder()
.channelOrderNo(loanOrderMapping.getChannelOrderNo())
.applyNo(loanOrderMapping.getApplyNo())
.channelId(loanOrderMapping.getRegisteredFrom())
.loanId(loanOrderMapping.getLoanId())
.status(orderStatus.getStatus().getValue())
.build();
OrderInfoVo orderInfoVo = OrderInfoVo.builder()
.orderInfo(orderInfo)
.noticeList(callbackListResult.getData())
.build();
log.info("{} 查询订单信息,返回信息 orderInfoVo={}", logPre, orderInfoVo);
return JsonResult.buildSuccessResult("处理成功", orderInfoVo);
}
private Tuple<Boolean, String> validate(OrderQueryParam orderQuery) {
Tuple<Boolean, String> result = new Tuple<>();
result.setKey(false);
int orderParam = 0;
if (Objects.isNull(orderQuery)) {
result.setValue("请求参数为空");
return result;
}
if (StringUtils.isNotBlank(orderQuery.getChannelOrderNo())) {
if (Objects.isNull(orderQuery.getChannelId())) {
result.setValue("查询参数渠道订单号和渠道号要同时存在");
return result;
}
orderParam++;
}
if (StringUtils.isNotBlank(orderQuery.getApplyOrderNo())) {
orderParam++;
}
if (Objects.nonNull(orderQuery.getLoanId())) {
orderParam++;
}
if (orderParam == 0) {
result.setValue("请求参数为空");
return result;
} else if (orderParam > 1) {
result.setValue("只能选择一个参数进行查询");
return result;
}
result.setKey(true);
return result;
}
/**
* 处理Ka通知记录
*
* @param orderQuery
* @return
*/
private JsonResult<List<CallbackRecord>> queryOrderCallback(OrderQueryParam orderQuery) {
String logPre = "OrderServiceImpl.queryOrderCallback 处理Ka通知记录 ";
log.info("{} 请求信息 orderQuery :{}", logPre, orderQuery);
String applyNo = orderQuery.getApplyOrderNo();
Long channelId = orderQuery.getChannelId();
//查询发送成功记录
JsonResult<List<CallbackRecord>> sendSuccRecordResult = kaService.querySendRecords(applyNo, channelId, Boolean.TRUE);
if (!sendSuccRecordResult.isSuccess()) {
log.error("{} 查询发送成功记录失败 orderQuery :{},sendSuccRecordResult:{}", logPre, orderQuery, sendSuccRecordResult);
return sendSuccRecordResult;
}
//查询发送失败记录
JsonResult<List<CallbackRecord>> sendFailRecordResult = kaService.querySendRecords(applyNo, channelId, Boolean.FALSE);
if (!sendFailRecordResult.isSuccess()) {
log.error("{} 查询发送失败记录失败 orderQuery :{},sendFailRecordResult:{}", logPre, orderQuery, sendFailRecordResult);
return sendSuccRecordResult;
}
//聚合信息
List<CallbackRecord> callbackRecords = doMergeLists(sendSuccRecordResult.getData(), sendFailRecordResult.getData());
return JsonResult.buildSuccessResult("查询成功", callbackRecords);
}
private List<CallbackRecord> doMergeLists(List<CallbackRecord> data, List<CallbackRecord> data1) {
data1.forEach(callbackRecord -> {
if(!data.contains(callbackRecord)){
data.add(callbackRecord);
}
});
// Map<String, List<CallbackRecord>> groupedMap = data.stream().collect(Collectors.groupingBy(CallbackRecord::getNoticeType));
// List<CallbackRecord> callbackRecords = new ArrayList<>(groupedMap.size());
// groupedMap.values().forEach(records -> {
// if (records.size() == 1) {
// callbackRecords.addAll(records);
// } else {
// callbackRecords.addAll(selectAllRecord(records));
// }
// });
List<CallbackRecord> callbackRecords1 = data.stream().sorted(Comparator.comparing(CallbackRecord::getDateTime)).collect(Collectors.toList());
callbackRecords1.forEach(callbackRecord ->
{
callbackRecord.setCreateAt(DateUtil.format(DateUtil.getByLongTimes(callbackRecord.getDateTime()), DateUtil.DATE_FORMAT_1));
callbackRecord.setDateTime(null);
}
);
return callbackRecords1;
}
private List<CallbackRecord> selectAllRecord(List<CallbackRecord> records) {
List<CallbackRecord> existTermNoRecords = records.stream().filter(callbackRecord -> Objects.nonNull(callbackRecord.getTermNo())).collect(Collectors.toList());
// 不为空代表是还款或者还款结果通知,此时还需要根据期数分组
if (CollectionUtils.isNotEmpty(existTermNoRecords)) {
Map<Long, List<CallbackRecord>> groupedMap = existTermNoRecords.stream().collect(Collectors.groupingBy(CallbackRecord::getTermNo));
List<CallbackRecord> callbackRecords = new ArrayList<>(groupedMap.size());
groupedMap.values().forEach(termNoRecord -> {
if (termNoRecord.size() == 1) {
callbackRecords.addAll(termNoRecord);
}
callbackRecords.addAll(findOneRecord(termNoRecord));
});
return callbackRecords;
} else {
return findOneRecord(records);
}
}
private List<CallbackRecord> findOneRecord(List<CallbackRecord> termNoRecord) {
// 除还款和还款结果通知以外的其他
CallbackRecord sendSuccRecord = null;
final String succNoticeStatus = "成功";
for (CallbackRecord callbackRecord : termNoRecord) {
if (succNoticeStatus.equals(callbackRecord.getNoticeStatus())) {
sendSuccRecord = callbackRecord;
break;
}
}
if (Objects.isNull(sendSuccRecord)) {
sendSuccRecord = termNoRecord.stream().sorted(Comparator.comparing(CallbackRecord::getDateTime).reversed()).findFirst().get();
}
return Collections.singletonList(sendSuccRecord);
}
} }
package cn.quantgroup.customer.service.impl; package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.model.order.ApplyOrder; import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.model.order.FlowNode; import cn.quantgroup.customer.model.order.*;
import cn.quantgroup.customer.model.order.LoanOrder;
import cn.quantgroup.customer.model.order.OrderRepayment;
import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery; import cn.quantgroup.customer.rest.param.applyorder.ApplyOrderQuery;
import cn.quantgroup.customer.rest.param.card.ModifyReservePhone; import cn.quantgroup.customer.rest.param.card.ModifyReservePhone;
import cn.quantgroup.customer.rest.param.card.UnBindCardModel; import cn.quantgroup.customer.rest.param.card.UnBindCardModel;
import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.param.repay.RepayOrderInfoQuery; import cn.quantgroup.customer.rest.param.repay.RepayOrderInfoQuery;
import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery; import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IXyqbService; import cn.quantgroup.customer.service.IXyqbService;
import cn.quantgroup.customer.service.http.IHttpService; import cn.quantgroup.customer.service.http.IHttpService;
import cn.quantgroup.customer.util.JSONTools; import cn.quantgroup.customer.util.JSONTools;
import cn.quantgroup.customer.util.SignUtil;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -30,7 +30,7 @@ import java.util.Objects; ...@@ -30,7 +30,7 @@ import java.util.Objects;
@Service("xyqbService") @Service("xyqbService")
public class XyqbServiceImpl implements IXyqbService { public class XyqbServiceImpl implements IXyqbService {
@Value("${api.http}") @Value("http://api-ka1.liangkebang.net") //${api.http}
private String xyqbSysUrl; private String xyqbSysUrl;
...@@ -317,4 +317,40 @@ public class XyqbServiceImpl implements IXyqbService { ...@@ -317,4 +317,40 @@ public class XyqbServiceImpl implements IXyqbService {
} }
return response; return response;
} }
/**
* 查询订单状态
* @param orderQuery
* @return
*/
@Override
public JsonResult<OrderStatus> orderStatusQuery(OrderQueryParam orderQuery) {
String logPre = "[XyqbServiceImpl.orderStatusQuery] 查询订单状态";
String url = xyqbSysUrl + "/ex/ka/order/status";
Map<String, String> queryParam = new HashMap<>(4);
queryParam.put("orderNo", orderQuery.getApplyOrderNo());
if (Objects.nonNull(orderQuery.getLoanId())) {
queryParam.put("loanId", String.valueOf(orderQuery.getLoanId()));
}
log.info("{} 请求参数 orderQuery={},queryParam={}", logPre, orderQuery,queryParam);
Map param = SignUtil.sign(SignUtil.KA_API_KEY, queryParam);
Map<String,String> header = new HashMap<>(2);
header.put("Accept","application/json");
header.put("Content-Type","application/x-www-form-urlencoded");
String result = httpService.post(url, header,param);
log.info("{} 返回结果 result:{}",logPre,result);
if (StringUtils.isBlank(result)) {
log.error("{} 处理失败 queryParam={} result={}", logPre, queryParam, result);
return JsonResult.buildErrorStateResult("查询订单状态失败,返回为空", ErrorCodeEnum.RETURN_ERROR);
} else {
TypeReference<JsonResult<OrderStatusXyqb>> typeToken = new TypeReference<JsonResult<OrderStatusXyqb>>() {
};
JsonResult<OrderStatusXyqb> jsonResult = JSONTools.deserialize(result, typeToken);
if (Objects.isNull(jsonResult) || Objects.isNull(jsonResult.getData())) {
return JsonResult.buildErrorStateResult("查询订单状态失败,反序列化失败", ErrorCodeEnum.RETURN_ERROR);
} else {
return JsonResult.buildSuccessResult("查询订单状态成功",jsonResult.getData().getCurrentStatus());
}
}
}
} }
package cn.quantgroup.customer.util;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import java.security.SignatureException;
import java.util.*;
/**
* xyqb 加签验证工具类
* @author Feng
* @version 2017.12.22
*/
public class SignUtil {
public static final String KA_API_KEY = "100011";
private static final long MAX_RATIO = 0x258;// 十分钟 10 * 60
private static Map<String, String> apiKeys = new HashMap<>();
static {
apiKeys.put(KA_API_KEY, "aukpaqy3za9lkjisdfaoqtdtxumrjqzm");
apiKeys.put("xyqb", "cd6yFfEgI0t67JaOYtLxTqXvumfJbsZi");
}
public static void addKeys(String appid, String key) {
apiKeys.put(appid, key);
}
/**
* 参数签名
*
* @return map 所有参数 以及 sign
*/
public static Map<String, ?> sign(String appid, Map<String, ?> params) {
Map<String, Object> map = new HashMap<String, Object>();
map.putAll(params);
map.put("app_id", appid);
map.put("timestamp", String.valueOf(System.currentTimeMillis() / 1000));
map.put("noncestr", RandomStringUtils.randomAlphanumeric(8));
String sign = signParams(map, appid);
map.put("sign", sign);
return map;
}
/**
* 签名
*
* @param map
* @return
*/
private static String signParams(Map<String, ?> map, String appid) {
List<String> names = new ArrayList<String>(map.keySet());
Collections.sort(names);
StringBuffer buffer = new StringBuffer();
for (String key : names) {
buffer.append(key).append("=").append(map.get(key)).append("&");
}
buffer.append("security_code=").append(apiKeys.get(appid));
String sign = DigestUtils.md5Hex(buffer.toString());
return sign;
}
/**
* 验证签名
*
* @param params
* 1、参数中必须包含 app_id 、timestamp、noncestr,sign
* @return
* @throws IllegalAccessException
*/
public static boolean checkSign(Map<String, ?> params) throws SignatureException {
String pid = Objects.toString(params.get("app_id"), null);
String noncestr = Objects.toString(params.get("noncestr"), null);
String timestamp = Objects.toString(params.get("timestamp"), null);
String sign = Objects.toString(params.get("sign"), null);
if (StringUtils.isBlank(pid) || StringUtils.isBlank(noncestr) || StringUtils.isBlank(timestamp)
|| StringUtils.isBlank(sign)) {
throw new SignatureException("参数中必须包含 app_id 、timestamp、noncestr 、sign");
}
// 验证时间
int int13Line83 = 13;
if (timestamp.length() == int13Line83) {
long ratio = System.currentTimeMillis() - Long.valueOf(timestamp);
int int1000Line86 = 1000;
if (ratio > (MAX_RATIO * int1000Line86)) {
throw new SignatureException("request overdue ....");
}
} else {
long ratio = (System.currentTimeMillis() / 1000) - Long.valueOf(timestamp);
if (ratio > MAX_RATIO) {
throw new SignatureException("request overdue ....");
}
}
params.remove("sign");
String signVal = signParams(params, pid);// 签名
return StringUtils.equalsIgnoreCase(signVal,sign);
}
}
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