|
|
@@ -71,6 +71,12 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
|
|
|
private static final DateTimeFormatter DTF = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void test(LocalDate date) {
|
|
|
+ doGeneratePlatformBill(date);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void generatePlatformBill(LocalDate date, boolean cover) {
|
|
|
RLock lock = redissonClient.getLock(RedisKey.PLATFORM_BILL_LOCK);
|
|
|
@@ -92,27 +98,10 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 查询前一天账单
|
|
|
- LambdaQueryWrapper<PlatformBill> queryWrapper = Wrappers.lambdaQuery();
|
|
|
- queryWrapper.eq(PlatformBill::getDayId, date.minusDays(1));
|
|
|
- queryWrapper.eq(PlatformBill::getType, "1");
|
|
|
- List<PlatformBill> prePlatformBillDataS = list(queryWrapper);
|
|
|
- Map<Long, PlatformBill> platformBillMap = prePlatformBillDataS.stream().collect(Collectors.toMap(PlatformBill::getUserId, Function.identity()));
|
|
|
-
|
|
|
- // 查询商户数据
|
|
|
- List<PlatformBill> shopPlatformBills = queryShopBill(date, platformBillMap);
|
|
|
-
|
|
|
- // 查询骑手数据
|
|
|
- List<PlatformBill> riderPlatformBills = queryRiderBill(date, platformBillMap);
|
|
|
-
|
|
|
- // 计算平台账单数据
|
|
|
- PlatformBill platformBills = calcPlatformBill(date, shopPlatformBills, riderPlatformBills, prePlatformBillDataS);
|
|
|
-
|
|
|
- // 合并商户、骑手账单数据
|
|
|
- Collection<PlatformBill> allPlatformBills = CollUtil.union(shopPlatformBills, riderPlatformBills, Arrays.asList(platformBills));
|
|
|
+ Collection<PlatformBill> platformBills = doGeneratePlatformBill(date);
|
|
|
|
|
|
// 保存最终结果
|
|
|
- saveBatch(allPlatformBills);
|
|
|
+ saveBatch(platformBills);
|
|
|
|
|
|
transactionManager.commit(status);
|
|
|
} catch (Exception e) {
|
|
|
@@ -339,6 +328,35 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 生成指定日期的平台账单集合
|
|
|
+ * @param date 需要生成账单的目标日期(日级账单)
|
|
|
+ * @return 包含三种类型账单的集合:商户账单、骑手账单、平台汇总账单
|
|
|
+ * 集合结构:[商户账单列表] + [骑手账单列表] + [平台汇总账单]
|
|
|
+ */
|
|
|
+ private Collection<PlatformBill> doGeneratePlatformBill(LocalDate date) {
|
|
|
+ // 查询前一天账单
|
|
|
+ LambdaQueryWrapper<PlatformBill> queryWrapper = Wrappers.lambdaQuery();
|
|
|
+ queryWrapper.eq(PlatformBill::getDayId, date.minusDays(1));
|
|
|
+ queryWrapper.eq(PlatformBill::getType, "1");
|
|
|
+ List<PlatformBill> prePlatformBillDataS = list(queryWrapper);
|
|
|
+ Map<String, PlatformBill> platformBillMap = prePlatformBillDataS.stream().collect(Collectors.toMap(e -> (e.getUserId() + "-" + e.getType()), Function.identity()));
|
|
|
+
|
|
|
+ // 查询商户数据
|
|
|
+ List<PlatformBill> shopPlatformBills = queryShopBill(date, platformBillMap);
|
|
|
+
|
|
|
+ // 查询骑手数据
|
|
|
+ List<PlatformBill> riderPlatformBills = queryRiderBill(date, platformBillMap);
|
|
|
+
|
|
|
+ // 计算平台账单数据
|
|
|
+ PlatformBill platformBills = calcPlatformBill(date, shopPlatformBills, riderPlatformBills, prePlatformBillDataS);
|
|
|
+
|
|
|
+ // 合并商户、骑手账单数据
|
|
|
+ Collection<PlatformBill> allPlatformBills = CollUtil.union(shopPlatformBills, riderPlatformBills, Arrays.asList(platformBills));
|
|
|
+
|
|
|
+ return allPlatformBills;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 计算平台账单数据
|
|
|
*
|
|
|
* @param date 账期
|
|
|
@@ -395,26 +413,26 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
|
|
|
/**
|
|
|
* 查询骑手指定日期账单数据
|
|
|
- * 从跑腿订单中获取:
|
|
|
- * 收入
|
|
|
- * 收入笔数
|
|
|
- * 从提现表中获取
|
|
|
- * 提现金额
|
|
|
- * 提现手续费
|
|
|
- * 提现笔数
|
|
|
- * 从对账表中获取:
|
|
|
- * 期初金额:前一天的期末金额
|
|
|
- * 从用户钱包明细中获取:
|
|
|
- * 赠送骑手余额
|
|
|
- * 从用户信息表中获取:
|
|
|
- * 总收益
|
|
|
- * 期末金额:等于总收益
|
|
|
+ * 从跑腿订单中获取:
|
|
|
+ * 收入
|
|
|
+ * 收入笔数
|
|
|
+ * 总收益:等于当天收入
|
|
|
+ * 从提现表中获取:
|
|
|
+ * 提现金额
|
|
|
+ * 提现手续费
|
|
|
+ * 提现笔数
|
|
|
+ * 从对账表中获取:
|
|
|
+ * 期初金额:前一天的期末金额
|
|
|
+ * 从用户钱包明细中获取:
|
|
|
+ * 赠送骑手余额
|
|
|
+ * 从用户信息表中获取:
|
|
|
+ * 期末金额:用户余额
|
|
|
*
|
|
|
* @param date 账单日期
|
|
|
* @param platformBillMap 前一天对账数据
|
|
|
* @return 骑手对账信息
|
|
|
*/
|
|
|
- private List<PlatformBill> queryRiderBill(LocalDate date, Map<Long, PlatformBill> platformBillMap) {
|
|
|
+ private List<PlatformBill> queryRiderBill(LocalDate date, Map<String, PlatformBill> platformBillMap) {
|
|
|
// 账期
|
|
|
String accountPeriod = date.toString();
|
|
|
// 账期开始-截止时间
|
|
|
@@ -430,7 +448,7 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
Map<Long, IndentOrderDataBO> indentOrderDataMap = indentOrderDataBOS.stream().collect(Collectors.toMap(IndentOrderDataBO::getUserId, Function.identity()));
|
|
|
|
|
|
// 查询提现数据
|
|
|
- List<CashOutRecordBO> riderCashOutRecords = baseMapper.getCashOutRecord(startTime, endTime, userIds);
|
|
|
+ List<CashOutRecordBO> riderCashOutRecords = baseMapper.getRiderCashOutRecord(startTime, endTime);
|
|
|
Map<Long, CashOutRecordBO> riderCashOutRecordMap = riderCashOutRecords.stream().collect(Collectors.toMap(CashOutRecordBO::getUserId, Function.identity()));
|
|
|
|
|
|
// 查询订单赠送金额数据
|
|
|
@@ -471,7 +489,7 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
platformBill.setSysGiftAmount(BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
- PlatformBill preBill = platformBillMap.get(riderInfo.getUserId());
|
|
|
+ PlatformBill preBill = platformBillMap.get(riderInfo.getUserId() + "-" + "2");
|
|
|
if (ObjectUtil.isNotNull(preBill)) {
|
|
|
platformBill.setStartMoney(preBill.getEndMoney());
|
|
|
} else {
|
|
|
@@ -488,32 +506,33 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
|
|
|
/**
|
|
|
* 查询商家指定日期账单数据
|
|
|
- * 从订单表中获取(当天数据):
|
|
|
- * 用户实际付款:当天用户实际付款金额
|
|
|
- * 退款金额:当天退款金额
|
|
|
- * 退款笔数:当天退款笔数
|
|
|
- * 收入:当天商家收入
|
|
|
- * 收入笔数:当天商家收入笔数
|
|
|
- * 从商家钱包明细表中获取:
|
|
|
- * 总收益:当天的入账金额(等于订单表里的商家收入)
|
|
|
- * 平台抽成手续费:当天平台抽成金额
|
|
|
- * 从提现表中获取(当天数据):
|
|
|
- * 提现金额:当天提现金额
|
|
|
- * 提现手续费:当天提现手续费
|
|
|
- * 提现笔数:当天提现笔数
|
|
|
- * 从用户信息表中获取:
|
|
|
- * 账户余额:截止统计时的用户账户余额
|
|
|
- * 从平台对账表中获取:
|
|
|
- * 期初金额:前一天的期末金额
|
|
|
- * 直接复用:
|
|
|
- * 期末金额:总收益
|
|
|
+ * 从订单表中获取(当天数据):
|
|
|
+ * 用户实际付款:当天用户实际付款金额
|
|
|
+ * 退款金额:当天退款金额
|
|
|
+ * 退款笔数:当天退款笔数
|
|
|
+ * 收入:当天商家收入
|
|
|
+ * 收入笔数:当天商家收入笔数
|
|
|
+ * 从商家钱包明细表中获取:
|
|
|
+ * 总收益:当天的入账金额(等于订单表里的商家收入)
|
|
|
+ * 平台抽成手续费:当天平台抽成金额
|
|
|
+ * 从提现表中获取(当天数据):
|
|
|
+ * 提现金额:当天提现金额
|
|
|
+ * 提现手续费:当天提现手续费
|
|
|
+ * 提现笔数:当天提现笔数
|
|
|
+ * 从用户信息表中获取:
|
|
|
+ * 账户余额:截止统计时的用户账户余额
|
|
|
+ * 从平台对账表中获取:
|
|
|
+ * 期初金额:前一天的期末金额
|
|
|
+ * 直接复用:
|
|
|
+ * 期末金额:总收益
|
|
|
*
|
|
|
* @param date 账单日期
|
|
|
* @param platformBillMap 前一天账单数据
|
|
|
* @return 商家对账单信息
|
|
|
*/
|
|
|
- private List<PlatformBill> queryShopBill(LocalDate date, Map<Long, PlatformBill> platformBillMap) {
|
|
|
+ private List<PlatformBill> queryShopBill(LocalDate date, Map<String, PlatformBill> platformBillMap) {
|
|
|
// 账期
|
|
|
+
|
|
|
String accountPeriod = date.toString();
|
|
|
// 账期开始-截止时间
|
|
|
String startTime = DTF.format(date.atTime(0, 0, 0));
|
|
|
@@ -532,7 +551,7 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
Map<Long, ShopMoneyRecordBO> shopMoneryRecordMap = shopMoneyRecords.stream().collect(Collectors.toMap(ShopMoneyRecordBO::getShopId, Function.identity()));
|
|
|
|
|
|
// 查询所有商家提现记录
|
|
|
- List<CashOutRecordBO> shopCashOutRecords = baseMapper.getCashOutRecord(startTime, endTime, userIds);
|
|
|
+ List<CashOutRecordBO> shopCashOutRecords = baseMapper.getShopCashOutRecord(startTime, endTime);
|
|
|
Map<Long, CashOutRecordBO> cashOutRecordMap = shopCashOutRecords.stream().collect(Collectors.toMap(CashOutRecordBO::getUserId, Function.identity()));
|
|
|
|
|
|
// 查询商户余额
|
|
|
@@ -589,7 +608,7 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
platformBill.setShopBalance(BigDecimal.ZERO);
|
|
|
}
|
|
|
|
|
|
- PlatformBill preBill = platformBillMap.get(goodsShop.getUserId());
|
|
|
+ PlatformBill preBill = platformBillMap.get(goodsShop.getUserId() + "1");
|
|
|
if (ObjectUtil.isNotNull(preBill)) {
|
|
|
platformBill.setStartMoney(preBill.getEndMoney());
|
|
|
} else {
|
|
|
@@ -598,8 +617,8 @@ public class PlatformBillServiceImpl extends ServiceImpl<PlatformBillMapper, Pla
|
|
|
|
|
|
// 总收益等于完成订单收入
|
|
|
platformBill.setTotalIncome(platformBill.getRevenue());
|
|
|
- // 期末金额等于总收益
|
|
|
- platformBill.setEndMoney(platformBill.getRevenue());
|
|
|
+ // 期末金额等于商家余额
|
|
|
+ platformBill.setEndMoney(platformBill.getShopBalance());
|
|
|
|
|
|
return platformBill;
|
|
|
}).collect(Collectors.toList());
|