|
@@ -18,6 +18,8 @@ import com.payment.platform.module.payment.account.mapper.TransferMapper;
|
|
|
import com.payment.platform.module.payment.account.mapper.WithdrawMapper;
|
|
import com.payment.platform.module.payment.account.mapper.WithdrawMapper;
|
|
|
import com.payment.platform.module.payment.notification.entity.PayBillEntity;
|
|
import com.payment.platform.module.payment.notification.entity.PayBillEntity;
|
|
|
import com.payment.platform.module.payment.notification.mapper.PayBillMapper;
|
|
import com.payment.platform.module.payment.notification.mapper.PayBillMapper;
|
|
|
|
|
+import com.payment.platform.module.payment.facetoface.entity.F2fTradeRecordEntity;
|
|
|
|
|
+import com.payment.platform.module.payment.facetoface.mapper.F2fTradeRecordMapper;
|
|
|
import com.payment.platform.common.exception.BusinessException;
|
|
import com.payment.platform.common.exception.BusinessException;
|
|
|
import com.payment.platform.core.alipay.AlipayClientFactory;
|
|
import com.payment.platform.core.alipay.AlipayClientFactory;
|
|
|
import com.alipay.api.AlipayApiException;
|
|
import com.alipay.api.AlipayApiException;
|
|
@@ -63,6 +65,7 @@ public class AccountService {
|
|
|
private final AlipayClientFactory alipayClientFactory;
|
|
private final AlipayClientFactory alipayClientFactory;
|
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
private final RedisTemplate<String, Object> redisTemplate;
|
|
|
private final PayBillMapper payBillMapper;
|
|
private final PayBillMapper payBillMapper;
|
|
|
|
|
+ private final F2fTradeRecordMapper f2fTradeRecordMapper;
|
|
|
private final AlipayTransferService alipayTransferService;
|
|
private final AlipayTransferService alipayTransferService;
|
|
|
|
|
|
|
|
public List<AccountVO> queryAccounts(String enterpriseId) {
|
|
public List<AccountVO> queryAccounts(String enterpriseId) {
|
|
@@ -90,16 +93,56 @@ public class AccountService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
- * 汇总统计金额 — 转账 + 消费
|
|
|
|
|
|
|
+ * 统计当面付收款金额 — 仅统计 TRADE_SUCCESS 状态的记录
|
|
|
|
|
+ */
|
|
|
|
|
+ public Map<String, String> statF2fTradeAmount(Long tenantId, String enterpriseId) {
|
|
|
|
|
+ OffsetDateTime today = LocalDate.now().atStartOfDay(ZoneOffset.ofHours(8)).toOffsetDateTime();
|
|
|
|
|
+ OffsetDateTime weekAgo = today.minusDays(7);
|
|
|
|
|
+
|
|
|
|
|
+ LambdaQueryWrapper<F2fTradeRecordEntity> base = new LambdaQueryWrapper<>();
|
|
|
|
|
+ base.eq(F2fTradeRecordEntity::getTradeStatus, "TRADE_SUCCESS");
|
|
|
|
|
+ if (tenantId != null) base.eq(F2fTradeRecordEntity::getTenantId, tenantId);
|
|
|
|
|
+ if (enterpriseId != null && !enterpriseId.isBlank())
|
|
|
|
|
+ base.eq(F2fTradeRecordEntity::getEnterpriseId, enterpriseId);
|
|
|
|
|
+
|
|
|
|
|
+ // 分三次查询简单清晰,当面付收款量不会太大
|
|
|
|
|
+ BigDecimal todayAmount = sumF2fTradeAmount(
|
|
|
|
|
+ base.clone().ge(F2fTradeRecordEntity::getGmtPayment, today));
|
|
|
|
|
+ BigDecimal weekAmount = sumF2fTradeAmount(
|
|
|
|
|
+ base.clone().ge(F2fTradeRecordEntity::getGmtPayment, weekAgo));
|
|
|
|
|
+ BigDecimal allAmount = sumF2fTradeAmount(base);
|
|
|
|
|
+
|
|
|
|
|
+ return Map.of(
|
|
|
|
|
+ "amount_of_today", todayAmount.toPlainString(),
|
|
|
|
|
+ "amount_of_7days", weekAmount.toPlainString(),
|
|
|
|
|
+ "amount_of_all", allAmount.toPlainString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private BigDecimal sumF2fTradeAmount(LambdaQueryWrapper<F2fTradeRecordEntity> w) {
|
|
|
|
|
+ List<F2fTradeRecordEntity> records = f2fTradeRecordMapper.selectList(w);
|
|
|
|
|
+ return records.stream()
|
|
|
|
|
+ .map(r -> {
|
|
|
|
|
+ try { return new BigDecimal(r.getTotalAmount()); }
|
|
|
|
|
+ catch (Exception e) { return BigDecimal.ZERO; }
|
|
|
|
|
+ })
|
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 汇总统计金额 — 转账 + 消费 + 当面付收款
|
|
|
*/
|
|
*/
|
|
|
public Map<String, String> statSummaryAmount(Long tenantId, String enterpriseId, String payeeType) {
|
|
public Map<String, String> statSummaryAmount(Long tenantId, String enterpriseId, String payeeType) {
|
|
|
Map<String, String> transfer = statTransferAmount(tenantId, enterpriseId, payeeType);
|
|
Map<String, String> transfer = statTransferAmount(tenantId, enterpriseId, payeeType);
|
|
|
Map<String, String> consume = statConsumeAmount(tenantId, enterpriseId, payeeType);
|
|
Map<String, String> consume = statConsumeAmount(tenantId, enterpriseId, payeeType);
|
|
|
|
|
+ Map<String, String> f2f = statF2fTradeAmount(tenantId, enterpriseId);
|
|
|
|
|
|
|
|
return Map.of(
|
|
return Map.of(
|
|
|
- "amount_of_today", add(transfer.get("amount_of_today"), consume.get("amount_of_today")),
|
|
|
|
|
- "amount_of_7days", add(transfer.get("amount_of_7days"), consume.get("amount_of_7days")),
|
|
|
|
|
- "amount_of_all", add(transfer.get("amount_of_all"), consume.get("amount_of_all")));
|
|
|
|
|
|
|
+ "amount_of_today", add(add(transfer.get("amount_of_today"), consume.get("amount_of_today")),
|
|
|
|
|
+ f2f.get("amount_of_today")),
|
|
|
|
|
+ "amount_of_7days", add(add(transfer.get("amount_of_7days"), consume.get("amount_of_7days")),
|
|
|
|
|
+ f2f.get("amount_of_7days")),
|
|
|
|
|
+ "amount_of_all", add(add(transfer.get("amount_of_all"), consume.get("amount_of_all")),
|
|
|
|
|
+ f2f.get("amount_of_all")));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String add(String a, String b) {
|
|
private String add(String a, String b) {
|