导出文件加字段

This commit is contained in:
2023-11-06 17:38:22 +08:00
parent 8978c56ef9
commit 12c7cb7927
3 changed files with 43 additions and 26 deletions

View File

@@ -2,6 +2,8 @@ package com.jsowell.pile.service;
import com.jsowell.pile.domain.ClearingBillDetail; import com.jsowell.pile.domain.ClearingBillDetail;
import java.util.List; import java.util.List;
import java.util.Map;
public interface ClearingBillDetailService{ public interface ClearingBillDetailService{
@@ -27,6 +29,5 @@ public interface ClearingBillDetailService{
int batchInsert(List<ClearingBillDetail> list); int batchInsert(List<ClearingBillDetail> list);
ClearingBillDetail selectByOrderCode(String orderCode); Map<String, ClearingBillDetail> selectByOrderCodeList(List<String> orderCodeList);
} }

View File

@@ -1,6 +1,7 @@
package com.jsowell.pile.service.impl; package com.jsowell.pile.service.impl;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.constant.CacheConstants; import com.jsowell.common.constant.CacheConstants;
import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.core.redis.RedisCache;
import com.jsowell.pile.domain.ClearingBillDetail; import com.jsowell.pile.domain.ClearingBillDetail;
@@ -9,11 +10,12 @@ import com.jsowell.pile.service.ClearingBillDetailService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
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 javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@@ -80,40 +82,49 @@ public class ClearingBillDetailServiceImpl implements ClearingBillDetailService{
return clearingBillDetailMapper.batchInsert(list); return clearingBillDetailMapper.batchInsert(list);
} }
@Override
public ClearingBillDetail selectByOrderCode(String orderCode) {
String redisKey = CacheConstants.CLEARING_BILL_DETAIL_BY_ORDER_CODE + orderCode;
ClearingBillDetail clearingBillDetail = redisCache.getCacheObject(redisKey);
if (clearingBillDetail == null) {
clearingBillDetail = clearingBillDetailMapper.selectByOrderCode(orderCode);
if (Objects.nonNull(clearingBillDetail)) {
redisCache.setCacheObject(redisKey, clearingBillDetail, CacheConstants.cache_expire_time_10d);
}
}
return clearingBillDetail;
}
/** /**
* 根据订单编号list查询分账记录 * 根据订单编号批量查询
* @param orderCodes * @param orderCodeList
* @return * @return
*/ */
public List<ClearingBillDetail> selectByOrderCodes(List<String> orderCodes) { @Override
if (CollectionUtils.isEmpty(orderCodes)) { public Map<String, ClearingBillDetail> selectByOrderCodeList(List<String> orderCodeList) {
return Lists.newArrayList(); Map<String, ClearingBillDetail> resultMap = Maps.newHashMap();
if (CollectionUtils.isEmpty(orderCodeList)) {
return resultMap;
} }
List<String> redisKeyList = Lists.newArrayList(); List<String> redisKeyList = Lists.newArrayList();
for (String orderCode : orderCodes) { for (String orderCode : orderCodeList) {
redisKeyList.add(CacheConstants.CLEARING_BILL_DETAIL_BY_ORDER_CODE + orderCode); redisKeyList.add(CacheConstants.CLEARING_BILL_DETAIL_BY_ORDER_CODE + orderCode);
} }
// 批量从redis获取 // 批量从redis获取
List<ClearingBillDetail> resultList = redisCache.multiGet(redisKeyList); List<ClearingBillDetail> resultList = redisCache.multiGet(redisKeyList);
resultList = resultList.stream().filter(Objects::nonNull).collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(resultList)) { if (CollectionUtils.isNotEmpty(resultList)) {
for (ClearingBillDetail clearingBillDetail : resultList) {
resultMap.put(clearingBillDetail.getOrderCode(), clearingBillDetail);
} }
List<ClearingBillDetail> billDetailList = clearingBillDetailMapper.selectByOrderCodes(orderCodes);
return billDetailList; // 剔除已经从缓存中获取到的数据
Iterator<String> iterator = orderCodeList.iterator();
while (iterator.hasNext()) {
String orderCode = iterator.next();
ClearingBillDetail detail = resultMap.get(orderCode);
if (detail != null) {
iterator.remove();
}
}
}
if (CollectionUtils.isNotEmpty(orderCodeList)) {
List<ClearingBillDetail> detailList = clearingBillDetailMapper.selectByOrderCodes(orderCodeList);
if (CollectionUtils.isNotEmpty(detailList)) {
for (ClearingBillDetail clearingBillDetail : detailList) {
resultMap.put(clearingBillDetail.getOrderCode(), clearingBillDetail);
}
}
}
return resultMap;
} }
} }

View File

@@ -219,6 +219,11 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
if (CollectionUtils.isEmpty(orderListVOS)) { if (CollectionUtils.isEmpty(orderListVOS)) {
return orderListVOS; return orderListVOS;
} }
// 批量查手续费
List<String> orderCodeList = orderListVOS.stream().map(OrderListVO::getOrderCode).collect(Collectors.toList());
Map<String, ClearingBillDetail> billDetailMap = clearingBillDetailService.selectByOrderCodeList(orderCodeList);
for (OrderListVO orderListVO : orderListVOS) { for (OrderListVO orderListVO : orderListVOS) {
// 如果是微信支付,通过订单号查询微信支付单号 // 如果是微信支付,通过订单号查询微信支付单号
// logger.info("如果是微信支付,通过订单号查询微信支付单号 orderListVO:{}", JSON.toJSONString(orderListVO)); // logger.info("如果是微信支付,通过订单号查询微信支付单号 orderListVO:{}", JSON.toJSONString(orderListVO));
@@ -248,7 +253,7 @@ public class OrderBasicInfoServiceImpl implements IOrderBasicInfoService {
} }
// 交易手续费 // 交易手续费
ClearingBillDetail clearingBillDetail = clearingBillDetailService.selectByOrderCode(orderListVO.getOrderCode()); ClearingBillDetail clearingBillDetail = billDetailMap.get(orderListVO.getOrderCode());
if (Objects.nonNull(clearingBillDetail)) { if (Objects.nonNull(clearingBillDetail)) {
orderListVO.setFeeAmount(clearingBillDetail.getFeeAmt() + ""); orderListVO.setFeeAmount(clearingBillDetail.getFeeAmt() + "");
} }