Commit b5da5a41 authored by 王向伟's avatar 王向伟

yapi提现订单修改,修改相应代码

parent 954236df
package cn.quantgroup.customer.model.order;
import lombok.Data;
import java.math.BigDecimal;
/**
* @author Wang Xiangwei
* @version 2020/3/11
*/
@Data
public class LoanOrder {
/**
* 订单申请号
*/
private String orderNo;
/**
* 借款订单号
*/
private Long loanId;
/**
* 提现渠道号
*/
private String channelNo;
/**
* 提现时间
*/
private String loanPaidAt;
/**
* 资金方
*/
private String fund;
/**
* 合同贷款金额
*/
private String contractAmount;
/**
* 合同贷款期数
*/
private Integer contractTermNo;
/**
* 担保费
*/
private BigDecimal guaranteeFee;
/**
* 其他费用
*/
private BigDecimal otherFee;
/**
* 一次性服务费
*/
private BigDecimal onceServiceFee;
/**
* 月利率
*/
private BigDecimal monthlyInterestRate;
/**
* 当前状态
*/
private String status;
/**
* 推送资金方放款时间
*/
private String sendLoanPaidAt;
/**
* 放款银行卡号
*/
private String cardNo;
/**
* 放款银行卡户名
*/
private String cardHolderName;
/**
* 放款银行名称
*/
private String bankName;
}
...@@ -13,90 +13,8 @@ import java.util.List; ...@@ -13,90 +13,8 @@ import java.util.List;
*/ */
@Data @Data
public class LoanOrderDetail { public class LoanOrderDetail {
/**
* 订单ID
*/
private Long orderId;
/** LoanOrder loanOrder;
* 订单申请号
*/
private String orderNo;
/**
* 借款订单号
*/
private Long loanId;
/**
* 提现渠道号
*/
private String channelNo;
/**
* 提现时间
*/
private String loanPaidAt;
/**
* 资金方
*/
private String fund;
/**
* 合同贷款金额
*/
private String contractAmount;
/**
* 合同贷款期数
*/
private Integer contractTermNo;
/**
* 担保费
*/
private BigDecimal guaranteeFee;
/**
* 其他费用
*/
private BigDecimal otherFee;
/**
* 一次性服务费
*/
private BigDecimal onceServiceFee;
/**
* 月利率
*/
private BigDecimal monthlyInterestRate;
/**
* 当前状态
*/
private String status;
/**
* 推送资金方放款时间
*/
private String sendLoanPaidAt;
/**
* 放款银行卡号
*/
private String cardNo;
/**
* 放款银行卡户名
*/
private String cardHolderName;
/**
* 放款银行名称
*/
private String bankName;
List<Repayment> repaymentList; List<Repayment> repaymentList;
......
package cn.quantgroup.customer.model.order;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
/**
* @description: 还款计划相关model
* @author:tao
* @create: 2020-02-19 11:07
*/
@Data
public class OrderRepayment {
private Long loanId;
/**
* 放款总金额
*/
private BigDecimal totalLoanAmount;
/**
* 收款总金额
*/
private BigDecimal totalReceiveAmount;
/**
* 放款到账时间
*/
private Long lendTime;
/**
* 申请时间,loan的created_at就行,提现签约时间
*/
private Long applyTime;
/**
* 应还款总金额
*/
private BigDecimal totalRepaymentAmount;
/**
* 总利息
*/
private BigDecimal totalInterest;
/**
* 应还总服务费
*/
private BigDecimal totalServiceFee;
/**
* 应还总其他费用
*/
private BigDecimal totalOtherFee;
/**
* 已还 总
*/
private BigDecimal alreadyPaidAmount;
/**
* 剩余未还 总
*/
private BigDecimal notPaidAmount;
/**
* 已还n期
*/
private Integer sumPaidTerm;
/**
* 是否结清 true 结清
*/
private Boolean hasAllPaid;
/** 还款计划 */
private List<RepaymentPlanItem> repaymentPlans;
}
package cn.quantgroup.customer.model.order; package cn.quantgroup.customer.model.order;
import cn.quantgroup.customer.util.DateUtil;
import lombok.Data; import lombok.Data;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date;
/** /**
* 还款计划信息 * 还款计划信息
...@@ -16,7 +18,7 @@ public class Repayment { ...@@ -16,7 +18,7 @@ public class Repayment {
/** /**
* 还款期数 * 还款期数
*/ */
private Integer termNo; private Integer periodNo;
/** /**
* 本金 * 本金
...@@ -31,7 +33,7 @@ public class Repayment { ...@@ -31,7 +33,7 @@ public class Repayment {
/** /**
* 担保费 * 担保费
*/ */
private BigDecimal premium; private BigDecimal serviceFee;
/** /**
* 其他担保 * 其他担保
...@@ -43,28 +45,24 @@ public class Repayment { ...@@ -43,28 +45,24 @@ public class Repayment {
*/ */
private BigDecimal overdueInterest; private BigDecimal overdueInterest;
/**
* 逾期保费
*/
private BigDecimal overdueServiceFee;
/** /**
* 当前减免 * 当前减免
*/ */
private BigDecimal collectionRelief; private BigDecimal reliefAmount;
/** /**
* 还款总额 * 还款总额
*/ */
private BigDecimal actualRepayment; private BigDecimal repayAmount;
/** /**
* 应还总额 * 应还总额
*/ */
private BigDecimal shouldAmount; private BigDecimal requiredRepayment;
/** /**
* 应还时间 * 应还时间 自己转化
*/ */
private String shouldAt; private String shouldAt;
...@@ -74,12 +72,12 @@ public class Repayment { ...@@ -74,12 +72,12 @@ public class Repayment {
private String repaymentReceivedAt; private String repaymentReceivedAt;
/** /**
* 还款状态 * 还款状态 自己转化
*/ */
private String repaymentStatus; private String repaymentStatus;
/** /**
* 还款方式 * 还款方式 自己转化
*/ */
private String repayType; private String repayType;
...@@ -87,4 +85,59 @@ public class Repayment { ...@@ -87,4 +85,59 @@ public class Repayment {
* 逾期天数 * 逾期天数
*/ */
private Integer overdueDays; private Integer overdueDays;
public static Repayment valueOf(RepaymentPlanItem repaymentPlanItem) {
if (repaymentPlanItem == null) {
return null;
}
Repayment repayment = new Repayment();
repayment.setPeriodNo(repaymentPlanItem.getPeriodNo());
repayment.setPrincipal(repaymentPlanItem.getPrincipal());
repayment.setInterest(repaymentPlanItem.getInterest());
repayment.setServiceFee(repaymentPlanItem.getServiceFee());
repayment.setOtherFee(repaymentPlanItem.getOtherFee());
repayment.setOverdueInterest(repaymentPlanItem.getOverdueInterest());
repayment.setReliefAmount(repaymentPlanItem.getReliefAmount());
repayment.setRepayAmount(repaymentPlanItem.getRepayAmount());
repayment.setRequiredRepayment(repaymentPlanItem.getRequiredRepayment());
Long dueTime = repaymentPlanItem.getDueTime();
if (dueTime != null) {
//java时间戳13位
String shouldAt = DateUtil.format(new Date(dueTime * 1000), DateUtil.DATE_FORMAT_1);
repayment.setShouldAt(shouldAt);
}
Long repayTime = repaymentPlanItem.getRepayTime();
if (repayTime != null) {
//java时间戳13位
String repaymentReceivedAt = DateUtil.format(new Date(repayTime * 1000), DateUtil.DATE_FORMAT_1);
repayment.setRepaymentReceivedAt(repaymentReceivedAt);
}
Integer repaymentStatus = repaymentPlanItem.getRepaymentStatus();
String repayStatus = "";
//还款状态,0 ("未还款")、2 ("已逾期")、3 ("已还款")
switch (repaymentStatus) {
case 0:
repayStatus = "未还款";
break;
case 2:
repayStatus = "已逾期";
break;
case 3:
repayStatus = "已还款";
}
repayment.setRepaymentStatus(repayStatus);
//还款类型 待确定
repayment.setRepayType(repaymentPlanItem.getRepaymentType());
repayment.setOverdueDays(repaymentPlanItem.getOverdueDays());
return repayment;
}
} }
package cn.quantgroup.customer.model.order;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* @description: 还款计划明细
* @author:tao
* @create: 2020-02-19 11:15
*/
@Data
public class RepaymentPlanItem {
/**
* 期数
*/
private Integer periodNo;
/**
* 还款类型 COMMON(正常)或SELF_WITHHOLD(代扣)
*/
private String repaymentType;
/**
* 还款状态,0 ("未还款")、2 ("已逾期")、3 ("已还款")
*/
private Integer repaymentStatus;
/**
* 应还本金
*/
private BigDecimal principal;
/**
* 应还利息
*/
private BigDecimal interest;
/**
* 应还罚息
*/
private BigDecimal overdueInterest;
/**
* 应还服务费
*/
private BigDecimal serviceFee;
/**
* 应还其它费用
*/
private BigDecimal otherFee;
/**
* 最早可还款时间
*/
private Long repayableTime;
/**
* 还款日期(到期时间),10位时间戳
*/
private Long dueTime;
/**
* 应还金额
*/
private BigDecimal requiredRepayment;
/**
* 实还本金
*/
private BigDecimal actPrincipal;
/**
* 实还利息
*/
private BigDecimal actInterest;
/**
* 实还服务费
*/
private BigDecimal actServiceFee;
/**
* 实还罚息
*/
private BigDecimal actOverdueInterest;
/**
* 实还其它费用
*/
private BigDecimal actOtherFee;
/**
* 减免金额
*/
private BigDecimal reliefAmount;
/**
* 实还金额
*/
private BigDecimal repayAmount;
/**
* 逾期天数
*/
private Integer overdueDays;
/**
* 还款时间
*/
private Long repayTime;
}
...@@ -20,16 +20,14 @@ import org.springframework.web.bind.annotation.RestController; ...@@ -20,16 +20,14 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/order") @RequestMapping("/order")
public class OrderRest { public class OrderRest {
@Autowired
private IXyqbService xyqbService;
@Autowired @Autowired
private IOrderService orderService; private IOrderService orderService;
@GetMapping("/loan/{loanId}") @GetMapping("/loan/{loanId}")
public JsonResult getLoanOrderDetail(@PathVariable Long loanId){ public JsonResult getLoanOrderDetail(@PathVariable Long loanId){
return orderService.getLoanOrderDetail(loanId);
return xyqbService.findLoanDetail(loanId);
} }
@GetMapping("/flowchart/{orderNo}") @GetMapping("/flowchart/{orderNo}")
......
package cn.quantgroup.customer.service; 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.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
import java.util.List; import java.util.List;
...@@ -17,4 +18,7 @@ public interface IOrderService{ ...@@ -17,4 +18,7 @@ public interface IOrderService{
* @return * @return
*/ */
JsonResult<List<FlowNode>> findFlowChart(String applyOrderNo); JsonResult<List<FlowNode>> findFlowChart(String applyOrderNo);
JsonResult<LoanOrderDetail> getLoanOrderDetail(Long loanId);
} }
...@@ -2,6 +2,8 @@ package cn.quantgroup.customer.service; ...@@ -2,6 +2,8 @@ package cn.quantgroup.customer.service;
import cn.quantgroup.customer.model.order.ApplyOrder; import cn.quantgroup.customer.model.order.ApplyOrder;
import cn.quantgroup.customer.model.order.FlowNode; 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;
...@@ -35,7 +37,14 @@ public interface IXyqbService { ...@@ -35,7 +37,14 @@ public interface IXyqbService {
* @param loanId * @param loanId
* @return * @return
*/ */
JsonResult findLoanDetail(Long loanId); JsonResult<LoanOrder> findLoanOrder(Long loanId);
/**
* 还款计划
* @param loanId
* @return
*/
JsonResult<OrderRepayment> repaymentPlanQuery(Long loanId);
String queryCardLists(Long userId); String queryCardLists(Long userId);
......
package cn.quantgroup.customer.service.impl; package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping; import cn.quantgroup.customer.model.kaordermapping.LoanOrderMapping;
import cn.quantgroup.customer.model.order.FlowNode; import cn.quantgroup.customer.model.order.*;
import cn.quantgroup.customer.rest.param.ordermapping.OrderMappingQueryParam; import cn.quantgroup.customer.rest.param.ordermapping.OrderMappingQueryParam;
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;
...@@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -11,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
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.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
...@@ -56,4 +57,36 @@ public class OrderServiceImpl implements IOrderService { ...@@ -56,4 +57,36 @@ public class OrderServiceImpl implements IOrderService {
return JsonResult.buildSuccessResult("", flowNodeList); return JsonResult.buildSuccessResult("", flowNodeList);
} }
@Override
public JsonResult<LoanOrderDetail> getLoanOrderDetail(Long loanId) {
String logPre = "OrderServiceImpl.getLoanOrderDetail";
log.info("{} 提现详情 loanId={}", logPre, loanId);
JsonResult<LoanOrder> loanOrder = xyqbService.findLoanOrder(loanId);
if (!loanOrder.isSuccess()) {
log.error("{} 提现订单查询失败 loanId={}, result={}",logPre,loanId,loanOrder);
return JsonResult.buildErrorStateResult(loanOrder.getMsg(),loanOrder.getData());
}
//还款计划查询
JsonResult<OrderRepayment> orderRepaymentJsonResult = xyqbService.repaymentPlanQuery(loanId);
if (!orderRepaymentJsonResult.isSuccess()) {
log.error("{} 还款计划查询失败 result={}", logPre, orderRepaymentJsonResult);
return JsonResult.buildErrorStateResult(orderRepaymentJsonResult.getMsg(), orderRepaymentJsonResult.getData());
}
List<Repayment> repaymentList = new ArrayList<>();
List<RepaymentPlanItem> repaymentPlans = orderRepaymentJsonResult.getData().getRepaymentPlans();
repaymentPlans.forEach(e->repaymentList.add(Repayment.valueOf(e)));
LoanOrderDetail loanOrderDetail = new LoanOrderDetail();
loanOrderDetail.setLoanOrder(loanOrder.getData());
loanOrderDetail.setRepaymentList(repaymentList);
return JsonResult.buildSuccessResult("",loanOrderDetail);
}
} }
...@@ -189,7 +189,7 @@ public class UserServiceImpl implements IUserService { ...@@ -189,7 +189,7 @@ public class UserServiceImpl implements IUserService {
} }
if (!Objects.isNull(userCombinationParam.getLoanId()) || if (Objects.nonNull(userCombinationParam.getLoanId()) ||
StringUtils.isNotBlank(userCombinationParam.getChannelOrderNo()) || StringUtils.isNotBlank(userCombinationParam.getChannelOrderNo()) ||
StringUtils.isNotBlank(userCombinationParam.getOrderNo())) { StringUtils.isNotBlank(userCombinationParam.getOrderNo())) {
//通过ka获得userId然后通过userId查询 //通过ka获得userId然后通过userId查询
...@@ -208,7 +208,7 @@ public class UserServiceImpl implements IUserService { ...@@ -208,7 +208,7 @@ public class UserServiceImpl implements IUserService {
return getUserBasicInfoResult(userDetailByUserId); return getUserBasicInfoResult(userDetailByUserId);
} }
if (!Objects.isNull(userCombinationParam.getIdNo())) { if (Objects.nonNull(userCombinationParam.getIdNo())) {
//通过业务系统获得 //通过业务系统获得
log.info("{} 通过phoneNo查询 idNo={}", LOG_PRE, userCombinationParam.getIdNo()); log.info("{} 通过phoneNo查询 idNo={}", LOG_PRE, userCombinationParam.getIdNo());
return findUserDetailByIdNo(userCombinationParam.getIdNo()); return findUserDetailByIdNo(userCombinationParam.getIdNo());
......
package cn.quantgroup.customer.service.impl; package cn.quantgroup.customer.service.impl;
import cn.quantgroup.customer.model.order.ApplyOrder; import cn.quantgroup.customer.model.order.*;
import cn.quantgroup.customer.model.order.FlowNode;
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;
...@@ -10,6 +9,8 @@ import cn.quantgroup.customer.rest.param.repay.RepayOrderQuery; ...@@ -10,6 +9,8 @@ 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 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;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -120,8 +121,8 @@ public class XyqbServiceImpl implements IXyqbService { ...@@ -120,8 +121,8 @@ public class XyqbServiceImpl implements IXyqbService {
} }
@Override @Override
public JsonResult findLoanDetail(Long loanId) { public JsonResult<LoanOrder> findLoanOrder(Long loanId) {
String logPre = "XyqbServiceImpl.findLoanDetail"; String logPre = "XyqbServiceImpl.findLoanOrder";
log.info("{} 提现订单详情 loanId={}", logPre, loanId); log.info("{} 提现订单详情 loanId={}", logPre, loanId);
String url = xyqbSysUrl + "/ex/inside/customer_sys/loan/detail"; String url = xyqbSysUrl + "/ex/inside/customer_sys/loan/detail";
if (Objects.isNull(loanId)) { if (Objects.isNull(loanId)) {
...@@ -133,16 +134,44 @@ public class XyqbServiceImpl implements IXyqbService { ...@@ -133,16 +134,44 @@ public class XyqbServiceImpl implements IXyqbService {
Map<String, String> header = Maps.newHashMap(); Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/x-www-form-urlencoded"); header.put("Content-type", "application/x-www-form-urlencoded");
JsonResult jsonResult = httpService.post(url, header, param, JsonResult.class); String result = httpService.post(url, header, param);
if (Objects.isNull(jsonResult) || jsonResult.isSuccess()) { if (StringUtils.isBlank(result)) {
log.error("{} 调用信用钱包失败 url={}, header={},param={},result={}", logPre, url, header, param, jsonResult); log.error("{} 调用信用钱包失败 url={}, header={},param={},result={}", logPre, url, header, param, result);
return JsonResult.buildErrorStateResult("提现订单详情查询失败", null); return JsonResult.buildErrorStateResult("提现订单详情查询失败", null);
} }
//data数据结构 LoanOrderDetail TypeReference<JsonResult<LoanOrder>> typeToken = new TypeReference<JsonResult<LoanOrder>>() {
};
JsonResult<LoanOrder> jsonResult = JSONTools.deserialize(result, typeToken);
return jsonResult; return jsonResult;
} }
@Override
public JsonResult<OrderRepayment> repaymentPlanQuery(Long loanId) {
String logPre = "XyqbServiceImpl.findLoanOrder";
log.info("{} 查询还款计划result={}", logPre, loanId);
String url = xyqbSysUrl + "/ex/ka/loan_plan/query";
Map<String, String> queryParam = new HashMap<>(2);
queryParam.put("loanId", loanId.toString());
String result = httpService.get(url, queryParam);
if (StringUtils.isBlank(result)) {
log.error("{} 查询还款计划失败 loanId={} result={}", logPre, loanId, result);
return JsonResult.buildErrorStateResult("查询还款计划失败", null);
} else {
TypeReference<JsonResult<OrderRepayment>> typeToken = new TypeReference<JsonResult<OrderRepayment>>() {
};
JsonResult<OrderRepayment> result1 = JSONTools.deserialize(result, typeToken);
if (result1 != null && result1.isSuccess()) {
return JsonResult.buildSuccessResult("", result1);
} else {
return JsonResult.buildErrorStateResult("还款计划查询失败", null);
}
}
}
/** /**
* 查询绑定卡列表 * 查询绑定卡列表
* *
......
package cn.quantgroup.customer.util;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* JSON工具类,默认使用Jackson
* <p>
* Created by WeiWei on 2017/7/31.
*/
@Slf4j
public class JSONTools {
private static final ObjectMapper objectMapper = new ObjectMapper();
static {
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
/**
* 序列化
*
* @param data
* @return
*/
public static String serialize(Object data) {
try {
return objectMapper.writeValueAsString(data);
} catch (JsonProcessingException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
/**
* 反序列化
*
* @param dataString
* @param type
* @param <T>
* @return
*/
public static <T> T deserialize(String dataString, TypeReference type) {
try {
return objectMapper.readValue(dataString, type);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
/**
* 反序列化
*
* @param dataString
* @param type
* @param <T>
* @return
*/
public static <T> T deserialize(String dataString, Class<T> type) {
try {
return objectMapper.readValue(dataString, type);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
/**
* 转换数据类型
*
* @param data
* @param type
* @param <T>
* @return
*/
public static <T> T convert(Object data, Class<T> type) {
return deserialize(JSONTools.serialize(data), type);
}
/**
* 转换数据类型
*
* @param data
* @param type
* @param <T>
* @return
*/
public static <T> T convert(Object data, TypeReference type) {
return deserialize(JSONTools.serialize(data), type);
}
/**
* 将对象转成Map
*
* @param data
* @return
*/
public static Map toMap(Object data) {
return convert(data, Map.class);
}
/**
* 将Map对象转成URL请求参数
*
* @param data
* @return
*/
public static String toParameter(Map<String, Object> data) {
List<NameValuePair> parameters = new ArrayList<>();
data.keySet().stream().forEach(key -> parameters.add(new BasicNameValuePair(key, String.class.isInstance(data.get(key)) ? String.valueOf(data.get(key)) : JSONTools.serialize(data.get(key)))));
return URLEncodedUtils.format(parameters, "UTF-8");
}
/**
* 将Map对象转成URL请求参数
*
* @param data
* @param isEncode
* @return
*/
public static String toParameter(Map<String, Object> data, boolean isEncode) {
String parameter = toParameter(data);
try {
return !isEncode ? URLDecoder.decode(parameter, "UTF-8") : parameter;
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}
}
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