|
@@ -2,25 +2,26 @@ package com.ywt.mg.services;
|
|
|
|
|
|
import com.ywt.mg.core.PagedList;
|
|
|
import com.ywt.mg.core.SqlHelper;
|
|
|
-import com.ywt.mg.core.utils.*;
|
|
|
+import com.ywt.mg.core.utils.Checker;
|
|
|
+import com.ywt.mg.core.utils.DateUtil;
|
|
|
+import com.ywt.mg.core.utils.FormatUtil;
|
|
|
+import com.ywt.mg.core.utils.PaymentChannelUtil;
|
|
|
import com.ywt.mg.domain.entities.OrderPayment;
|
|
|
import com.ywt.mg.domain.models.ConstantDef;
|
|
|
import com.ywt.mg.domain.models.ExcelDataMap;
|
|
|
+import com.ywt.mg.domain.models.enums.PaymentChannelEnum;
|
|
|
import com.ywt.mg.domain.models.enums.PaymentStatusEnum;
|
|
|
import com.ywt.mg.domain.models.enums.TerminalEnum;
|
|
|
import com.ywt.mg.domain.models.pojo.ExcelCollectPojo;
|
|
|
import com.ywt.mg.params.deposit.DepositOrderInfo;
|
|
|
import com.ywt.mg.params.deposit.QueryDepositListRequest;
|
|
|
-import com.ywt.mg.params.offline.DownloadOfflineListNewRequest;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.text.ParseException;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
public class DepositService {
|
|
@@ -152,6 +153,7 @@ public class DepositService {
|
|
|
col11};
|
|
|
}
|
|
|
PagedList<DepositOrderInfo> list = queryDepositPageList(request);
|
|
|
+ Map<String, Integer> statisticalDataMap = new HashMap<>();
|
|
|
ExcelDataMap map = new ExcelDataMap(columns);
|
|
|
if (!Checker.isNone(list.getItems())) {
|
|
|
// 得到支付的记录日志(需要从 order_payment 获取 transaction_id 字段)
|
|
@@ -203,7 +205,7 @@ public class DepositService {
|
|
|
//// p.getPatientMobile(), p.getCardNo(), amount, paymentChannel, paymentStatus, paymentTime};
|
|
|
// }
|
|
|
// }
|
|
|
- map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request,
|
|
|
+ map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request, statisticalDataMap,
|
|
|
col0,
|
|
|
col1,
|
|
|
col2,
|
|
@@ -222,7 +224,7 @@ public class DepositService {
|
|
|
request.setPageIndex(i);
|
|
|
list = queryDepositPageList(request);
|
|
|
orderPaymentList = orderPaymentService.getOrderPaymentListByDepositList(list.getItems());
|
|
|
- map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request,
|
|
|
+ map = setExcelDataMap(orderPaymentList, list, map, hospitalId, hosp, request, statisticalDataMap,
|
|
|
col0,
|
|
|
col1,
|
|
|
col2,
|
|
@@ -241,7 +243,7 @@ public class DepositService {
|
|
|
|
|
|
}
|
|
|
int total = list.getTotal();
|
|
|
- List<ExcelCollectPojo> itemList = new ArrayList<>();
|
|
|
+ List<ExcelCollectPojo> itemList = getStatisticsData(total, statisticalDataMap);
|
|
|
downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, total);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("/deposit/downloadDepositList(): {}", e.getMessage(), e);
|
|
@@ -266,7 +268,7 @@ public class DepositService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private ExcelDataMap setExcelDataMap(List<OrderPayment> orderPaymentList, PagedList<DepositOrderInfo> list, ExcelDataMap map, int hospitalId, int hosp, QueryDepositListRequest request,
|
|
|
+ private ExcelDataMap setExcelDataMap(List<OrderPayment> orderPaymentList, PagedList<DepositOrderInfo> list, ExcelDataMap map, int hospitalId, int hosp, QueryDepositListRequest request, Map<String, Integer> statisticalDataMap,
|
|
|
String col0,
|
|
|
String col1,
|
|
|
String col2,
|
|
@@ -325,6 +327,34 @@ public class DepositService {
|
|
|
// String[] bodyStr = new String[]{p.getOrderNo(), p.getPaymentNo(), transactionId, hospitalName, terminal, p.getPatientName(),
|
|
|
// p.getPatientMobile(), p.getCardNo(), amount, paymentChannel, paymentStatus, paymentTime};
|
|
|
}
|
|
|
+ OrderPayment orderPayment = orderPaymentList.stream().filter(o -> o.getOrderId().intValue() == p.getOrderId().intValue()).findFirst().orElse(null);
|
|
|
+ int paymentChannelInt = orderPaymentService.getPaymentChannelIntByOrderPayment(orderPayment);
|
|
|
+// int payTotal = statisticalDataMap.getOrDefault(),
|
|
|
+// refundTotal = 0;
|
|
|
+ String payKeyPrefix = "payTotal_", refundKeyPrefix = "refundTotal_";
|
|
|
+ String payKey = payKeyPrefix + paymentChannelInt;
|
|
|
+ String totalKey = "payTotal_" + 0;
|
|
|
+ String refundKey = refundKeyPrefix + paymentChannelInt;
|
|
|
+ int payValue = statisticalDataMap.getOrDefault(payKey, 0);
|
|
|
+ int payTotal = statisticalDataMap.getOrDefault(totalKey, 0);
|
|
|
+ int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
|
|
|
+ int amountInt = Checker.getIntegerValue(p.getAmount());
|
|
|
+ if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
|
|
|
+ payTotal += amountInt;
|
|
|
+ payValue += amountInt;
|
|
|
+ statisticalDataMap.put(payKey, payValue);
|
|
|
+ statisticalDataMap.put(totalKey, payTotal);
|
|
|
+ }
|
|
|
+
|
|
|
+ //押金没有退款功能
|
|
|
+// refundTotal += 0;
|
|
|
+ refundValue += 0;
|
|
|
+ statisticalDataMap.put(refundKey, refundValue);
|
|
|
+// if ((Checker.getIntegerValue(p.getS) & ConsultStatusEnum.Refund.getValue()) == ConsultStatusEnum.Refund.getValue()) {
|
|
|
+// refundTotal += amountInt;
|
|
|
+// refundValue += amountInt;
|
|
|
+// statisticalDataMap.put(refundKey, refundValue);
|
|
|
+// }
|
|
|
}
|
|
|
return map;
|
|
|
}
|
|
@@ -342,23 +372,26 @@ public class DepositService {
|
|
|
|
|
|
PagedList<DepositOrderInfo> depositPageList = queryDepositPageList(request);
|
|
|
ExcelDataMap map = new ExcelDataMap(columns);
|
|
|
+
|
|
|
+ Map<String, Integer> statisticalDataMap = new HashMap<>();
|
|
|
if (!Checker.isNone(depositPageList)) {
|
|
|
// 得到支付的记录日志(需要从 order_payment 获取 transaction_id 字段)
|
|
|
List<OrderPayment> orderPaymentList = orderPaymentService.getOrderPaymentListByDepositOrderInfoList(depositPageList.getItems());
|
|
|
int size = depositPageList.getTotalPage();
|
|
|
- map = setBillDeposit(request, depositPageList, orderPaymentList, map,
|
|
|
+ map = setBillDeposit(request, depositPageList, orderPaymentList, map, statisticalDataMap,
|
|
|
col0,
|
|
|
col1,
|
|
|
col2,
|
|
|
col3,
|
|
|
col4,
|
|
|
col5);
|
|
|
+
|
|
|
if (size > 1) {
|
|
|
for (int i = 2; i <= size; i++) {
|
|
|
request.setPageIndex(i);
|
|
|
depositPageList = queryDepositPageList(request);
|
|
|
orderPaymentList = orderPaymentService.getOrderPaymentListByDepositList(depositPageList.getItems());
|
|
|
- map = setBillDeposit(request, depositPageList, orderPaymentList, map,
|
|
|
+ map = setBillDeposit(request, depositPageList, orderPaymentList, map, statisticalDataMap,
|
|
|
col0,
|
|
|
col1,
|
|
|
col2,
|
|
@@ -370,7 +403,7 @@ public class DepositService {
|
|
|
|
|
|
}
|
|
|
int total = depositPageList.getTotal();
|
|
|
- List<ExcelCollectPojo> itemList = new ArrayList<>();
|
|
|
+ List<ExcelCollectPojo> itemList = getStatisticsData(total, statisticalDataMap);
|
|
|
downloadRecordService.createFileAndUploadOssAndSaveToDataBase(fileName, downloadRecordId, map, itemList, total);
|
|
|
} catch (Exception e) {
|
|
|
logger.error("/deposit/downloadDepositBillList(): {}", e.getMessage(), e);
|
|
@@ -381,7 +414,7 @@ public class DepositService {
|
|
|
|
|
|
private ExcelDataMap setBillDeposit (QueryDepositListRequest
|
|
|
request, PagedList < DepositOrderInfo > depositPageList, List < OrderPayment > orderPaymentList, ExcelDataMap
|
|
|
- map,
|
|
|
+ map, Map<String, Integer> statisticalDataMap,
|
|
|
String col0,
|
|
|
String col1,
|
|
|
String col2,
|
|
@@ -420,6 +453,29 @@ public class DepositService {
|
|
|
map.getStringListSafely(col4).add(orderNo);
|
|
|
map.getStringListSafely(col5).add(typeStr);
|
|
|
|
|
|
+// OrderPayment orderPayment = orderPaymentList.stream().filter(o -> o.getOrderId().intValue() == p.getOrderId().intValue()).findFirst().orElse(null);
|
|
|
+ int paymentChannelInt = orderPaymentService.getPaymentChannelIntByOrderPayment(orderPayment);
|
|
|
+// int payTotal = statisticalDataMap.getOrDefault(),
|
|
|
+// refundTotal = 0;
|
|
|
+ String payKeyPrefix = "payTotal_", refundKeyPrefix = "refundTotal_";
|
|
|
+ String payKey = payKeyPrefix + paymentChannelInt;
|
|
|
+ String totalKey = "payTotal_" + 0;
|
|
|
+ String refundKey = refundKeyPrefix + paymentChannelInt;
|
|
|
+ int payValue = statisticalDataMap.getOrDefault(payKey, 0);
|
|
|
+ int payTotal = statisticalDataMap.getOrDefault(totalKey, 0);
|
|
|
+ int refundValue = statisticalDataMap.getOrDefault(refundKey, 0);
|
|
|
+ int amountInt = Checker.getIntegerValue(p.getAmount());
|
|
|
+ if (Checker.getIntegerValue(p.getPaymentStatus()) == PaymentStatusEnum.Success.getValue()) {
|
|
|
+ payTotal += amountInt;
|
|
|
+ payValue += amountInt;
|
|
|
+ statisticalDataMap.put(payKey, payValue);
|
|
|
+ statisticalDataMap.put(totalKey, payTotal);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ refundValue += 0;
|
|
|
+ statisticalDataMap.put(refundKey, refundValue);
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -427,4 +483,41 @@ public class DepositService {
|
|
|
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private List<ExcelCollectPojo> getStatisticsData(int size, Map<String, Integer> statisticalDataMap) {
|
|
|
+
|
|
|
+ int startRows = size + 3;
|
|
|
+ int startColumn = 3;
|
|
|
+
|
|
|
+
|
|
|
+ List<ExcelCollectPojo> customExcelItemList = new ArrayList<>();
|
|
|
+
|
|
|
+ String totalKey = "payTotal_" + 0;
|
|
|
+ String payKeyPrefix = "payTotal_";
|
|
|
+ int payTotal = statisticalDataMap.getOrDefault(totalKey, 0);
|
|
|
+ int refundTotal = 0;
|
|
|
+ customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{"支付总额", FormatUtil.intShrink100ToStr(payTotal)}));
|
|
|
+ customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{"退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
|
|
|
+ customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{"实际支付金额", FormatUtil.intShrink100ToStr(payTotal - refundTotal)}));
|
|
|
+ startRows += 1;
|
|
|
+
|
|
|
+
|
|
|
+ for (PaymentChannelEnum enumValue : PaymentChannelEnum.values()) {
|
|
|
+ int enumValueValue = enumValue.getValue();
|
|
|
+ if (enumValueValue < 0) continue;
|
|
|
+ int payValue = Checker.getIntegerValue(statisticalDataMap.get(payKeyPrefix + enumValueValue));
|
|
|
+ if (payValue != 0 && enumValueValue != 0) {
|
|
|
+ String payChannelStr = enumValue.getDisplayName();
|
|
|
+
|
|
|
+ customExcelItemList.add(new ExcelCollectPojo(startColumn + 1, startRows, new String[]{payChannelStr + "支付总额", FormatUtil.intShrink100ToStr(payValue)}));
|
|
|
+ customExcelItemList.add(new ExcelCollectPojo(startColumn + 3, startRows, new String[]{payChannelStr + "退款总额", FormatUtil.intShrink100ToStr(refundTotal)}));
|
|
|
+ customExcelItemList.add(new ExcelCollectPojo(startColumn + 5, startRows, new String[]{payChannelStr + "实际支付金额", FormatUtil.intShrink100ToStr(payValue - refundTotal)}));
|
|
|
+ startRows += 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return customExcelItemList;
|
|
|
}
|
|
|
+
|
|
|
+}
|