|
@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
import static com.rongwei.zhsw.system.utils.SaveConstans.billInfo.*;
|
|
|
import static com.rongwei.zhsw.system.utils.SaveConstans.billReccord.DATASOURCEBALANCEDEDUCTION;
|
|
@@ -146,6 +147,7 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
|
|
|
*/
|
|
|
@Override
|
|
|
public R transferAccount(Map<String, Object> map) throws Exception {
|
|
|
+ try {
|
|
|
|
|
|
//获取账单数据 已根据户号 分组 创建时间正序
|
|
|
Map<String, List<SwBillManagementUnpaidDo>> billGroups = getGroupedBills(map);
|
|
@@ -159,7 +161,7 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
|
|
|
billGroups.keySet().forEach(key -> processUserBills(billGroups.get(key), userGroups.get(key).get(0), transferAccountDo));
|
|
|
|
|
|
// 保存处理结果
|
|
|
- try {
|
|
|
+
|
|
|
swBillManagementUnpaidService.saveProcessedData(transferAccountDo);
|
|
|
}catch (Exception e){
|
|
|
log.error("转正式账单数据保存失败 {}",e.getMessage());
|
|
@@ -232,25 +234,40 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
|
|
|
private void processUserBills(List<SwBillManagementUnpaidDo> swBillManagementUnpaidDos, SwUserManagementDo user,
|
|
|
TransferAccountDo transferAccountDo ) {
|
|
|
|
|
|
+ // 初始化变量
|
|
|
+ BigDecimal accumulatedAmount = BigDecimal.ZERO;
|
|
|
+ List<SwBillManagementUnpaidDo> processedBills = new ArrayList<>();
|
|
|
+ //是否累加值超出余额
|
|
|
+ boolean isBalanceExceeded = false;
|
|
|
+
|
|
|
BigDecimal billAmount =BigDecimal.ZERO;
|
|
|
List<SwBillManagementUnpaidDo> unpaidDos = new ArrayList<>();
|
|
|
SwBillManagementPaidDo paid;
|
|
|
- String paymentBatchId = SecurityUtil.getUUID(); // 批次唯一ID
|
|
|
+
|
|
|
+
|
|
|
+ // 获取当前用户和批次信息
|
|
|
SysUserVo currentUser = ZHSWCommonUtils.getCurrentUser();
|
|
|
- HashMap<String, BigDecimal> map = new HashMap<>();
|
|
|
- //是否累加值超出余额
|
|
|
- Boolean excessBalance =false;
|
|
|
+ String paymentBatchId = SecurityUtil.getUUID();
|
|
|
|
|
|
|
|
|
- for (SwBillManagementUnpaidDo unpaidDo:swBillManagementUnpaidDos){
|
|
|
- //当累计的账单的 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 <= 账户余额,生成计费记录
|
|
|
- billAmount = billAmount.add(unpaidDo.getOughttohavepaid()).subtract(unpaidDo.getFeewaiver()).add(unpaidDo.getLatefees());
|
|
|
+ //合并并排序账单
|
|
|
+ List<SwBillManagementUnpaidDo> sortedBills = mergeAndSortBills(swBillManagementUnpaidDos);
|
|
|
+
|
|
|
+ for (SwBillManagementUnpaidDo unpaidDo:sortedBills){
|
|
|
+
|
|
|
+ if (unpaidDo ==null ){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- if (excessBalance){
|
|
|
+
|
|
|
+ if (isBalanceExceeded ){
|
|
|
transferAccountDo.getOfficeIds().add(unpaidDo.getId());
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ //当累计的账单的 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 <= 账户余额,生成计费记录
|
|
|
+ billAmount = billAmount.add(unpaidDo.getOughttohavepaid()).subtract(unpaidDo.getFeewaiver()).add(unpaidDo.getLatefees());
|
|
|
+
|
|
|
if (billAmount.compareTo(user.getAccountbalance()) <= 0){
|
|
|
//转正式账单后 生成缴费记录,生成 已缴费账单,删除待缴费记录,更新用户余额
|
|
|
|
|
@@ -268,9 +285,8 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
|
|
|
//整合要生成缴费记录的预收账单
|
|
|
unpaidDos.add(unpaidDo);
|
|
|
|
|
|
-
|
|
|
}else{
|
|
|
- excessBalance =true;
|
|
|
+ isBalanceExceeded =true;
|
|
|
// 超出余额部分标记为正式账单
|
|
|
transferAccountDo.getOfficeIds().add(unpaidDo.getId());
|
|
|
}
|
|
@@ -297,6 +313,33 @@ public class SwBillManagementUnpaidServiceImpl extends ServiceImpl<SwBillManagem
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 是否小于等于 0 的数据先处理
|
|
|
+ * @param swBillManagementUnpaidDos
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<SwBillManagementUnpaidDo> mergeAndSortBills(List<SwBillManagementUnpaidDo> swBillManagementUnpaidDos) {
|
|
|
+ //【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 是否小于等于 0 分成两列
|
|
|
+ Map<Boolean, List<SwBillManagementUnpaidDo>> partitioned = swBillManagementUnpaidDos.stream()
|
|
|
+ .collect(Collectors.partitioningBy(unpaidDo ->
|
|
|
+ unpaidDo.getOughttohavepaid()
|
|
|
+ .subtract(unpaidDo.getFeewaiver())
|
|
|
+ .add(unpaidDo.getLatefees())
|
|
|
+ .compareTo(BigDecimal.ZERO) <= 0
|
|
|
+ ));
|
|
|
+
|
|
|
+ //将 【原应缴(元)】-【总减免(元)】 +【滞纳金(元)】 是否小于等于 0 先处理 后面的数据还是按照原来的 创建时间排序
|
|
|
+
|
|
|
+ // 合并并保持原始顺序
|
|
|
+ List<SwBillManagementUnpaidDo> result = new ArrayList<>();
|
|
|
+
|
|
|
+ result.addAll(partitioned.getOrDefault(true, Collections.emptyList()));
|
|
|
+
|
|
|
+ result.addAll(partitioned.getOrDefault(false, Collections.emptyList()));
|
|
|
+ return result;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存数据
|
|
|
* @param transferAccountDo
|