|
|
@@ -768,10 +768,32 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
resultList.addAll(followAggVoList);
|
|
|
}
|
|
|
|
|
|
- // 3. 查询额外其他费用收入数据,补充到结果集
|
|
|
- List<InsPlyIncomeDto> incomeDtoList = queryFollowIncomeData(settlementReportQueryVo);
|
|
|
- if (CollUtil.isEmpty(incomeDtoList)) {
|
|
|
- return resultList;
|
|
|
+ // 应收项为空时才去补充数据,不为空时不补充数据,补充数据是因为联查了invoice和settlement表,所以没开票和结算的数据会被过滤掉,才需要补充数据
|
|
|
+ List<InsPlyIncomeDto> incomeDtoList = CollUtil.newArrayList();
|
|
|
+ if (StrUtil.isBlank(settlementReportQueryVo.getInvoiceType())){
|
|
|
+ // 3. 查询额外其他费用收入数据,补充到结果集
|
|
|
+ incomeDtoList = queryFollowIncomeData(settlementReportQueryVo);
|
|
|
+ if (CollUtil.isEmpty(incomeDtoList)) {
|
|
|
+ return resultList;
|
|
|
+ }else{
|
|
|
+ // 如果JyPremium不为0,则设置发票类型为4
|
|
|
+ incomeDtoList.stream().forEach(item -> {
|
|
|
+ if (StrUtil.isNotBlank(item.getJyPremium()) && !NumberUtil.equals(BigDecimal.ZERO, new BigDecimal(item.getJyPremium()))){
|
|
|
+ item.setInvoiceType(InvoiceTypeEnum.FEE_4.getCode());
|
|
|
+ }else{
|
|
|
+ item.setInvoiceType(InvoiceTypeEnum.FEE_2.getCode());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<InsPlyIncomeDto> copyList = CollUtil.newArrayList();
|
|
|
+ // 如果有发票类型为4的,则复制一条4的数据,完全一致,但发票类型为2
|
|
|
+ incomeDtoList.stream().filter(item -> InvoiceTypeEnum.FEE_4.getCode().equals(item.getInvoiceType())).forEach(item -> {
|
|
|
+ InsPlyIncomeDto incomeDto = new InsPlyIncomeDto();
|
|
|
+ BeanUtils.copyProperties(item, incomeDto);
|
|
|
+ incomeDto.setInvoiceType(InvoiceTypeEnum.FEE_2.getCode());
|
|
|
+ copyList.add(incomeDto);
|
|
|
+ });
|
|
|
+ incomeDtoList.addAll(copyList);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 4. 根据筛选条件过滤收入数据(发票、结算时间/状态过滤)
|
|
|
@@ -912,13 +934,6 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
return StrUtil.format("{}_{}_{}_{}", vo.getPartnerCompanyId(), vo.getYear(), vo.getMonth(), vo.getInvoiceType());
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 构建分组Key:partnerCompanyId_year_month
|
|
|
- */
|
|
|
- private String buildFillGroupKey(FollowCompanyFeeVO vo) {
|
|
|
- return StrUtil.format("{}_{}_{}", vo.getPartnerCompanyId(), vo.getYear(), vo.getMonth());
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 根据合作公司ID获取公司名称
|
|
|
*/
|
|
|
@@ -943,7 +958,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
* 根据发票状态、开票时间、结算时间过滤收入数据
|
|
|
* 优化:嵌套anyMatch改为HashMapID映射匹配,O(n²) -> O(n)
|
|
|
*/
|
|
|
- private List<InsPlyIncomeDto> filterIncomeByInvoiceAndSettleCondition(List<InsPlyIncomeDto> incomeList, SettlementReportQueryVo queryVo) {
|
|
|
+ private List<InsPlyIncomeDto> filterIncomeByInvoiceAndSettleCondition(List<InsPlyIncomeDto> incomeList, SettlementReportQueryVo queryVo) {
|
|
|
String status = queryVo.getStatus();
|
|
|
String invoiceStartTime = queryVo.getInvoiceStartTime();
|
|
|
String invoiceEndTime = queryVo.getInvoiceEndTime();
|
|
|
@@ -1032,15 +1047,15 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
// 现有结果集Key缓存
|
|
|
Map<String, FollowCompanyFeeVO> existVoMap = resultList.stream()
|
|
|
.collect(Collectors.toMap(
|
|
|
- this::buildFillGroupKey,
|
|
|
+ this::buildGroupKey,
|
|
|
Function.identity(),
|
|
|
(oldVal, newVal) -> oldVal
|
|
|
));
|
|
|
|
|
|
// 收入分组
|
|
|
Map<String, List<InsPlyIncomeDto>> incomeGroupMap = incomeList.stream()
|
|
|
- .collect(Collectors.groupingBy(dto -> StrUtil.format("{}_{}_{}",
|
|
|
- dto.getPartnerCompanyId(), dto.getSignYear(), dto.getSignMonth())));
|
|
|
+ .collect(Collectors.groupingBy(dto -> StrUtil.format("{}_{}_{}_{}",
|
|
|
+ dto.getPartnerCompanyId(), dto.getSignYear(), dto.getSignMonth(), dto.getInvoiceType())));
|
|
|
|
|
|
for (Map.Entry<String, List<InsPlyIncomeDto>> entry : incomeGroupMap.entrySet()) {
|
|
|
String groupKey = entry.getKey();
|
|
|
@@ -1049,15 +1064,27 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
String partnerCompanyId = firstDto.getPartnerCompanyId();
|
|
|
String signYear = firstDto.getSignYear();
|
|
|
String signMonth = firstDto.getSignMonth();
|
|
|
-
|
|
|
- // 安全字符串转BigDecimal,兜底0
|
|
|
- BigDecimal totalOtherReceivable = dtoList.stream()
|
|
|
- .map(dto -> {
|
|
|
- BigDecimal jq = safeBigDecimal(dto.getJqOtherCostsPremiums());
|
|
|
- BigDecimal sy = safeBigDecimal(dto.getSyOtherCostsPremiums());
|
|
|
- return jq.add(sy);
|
|
|
- })
|
|
|
- .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ String invoiceType = firstDto.getInvoiceType();
|
|
|
+
|
|
|
+ BigDecimal totalOtherReceivable = BigDecimal.ZERO;
|
|
|
+ if (InvoiceTypeEnum.FEE_2.getCode().equals(invoiceType)){
|
|
|
+ // 安全字符串转BigDecimal,兜底0
|
|
|
+ totalOtherReceivable = dtoList.stream()
|
|
|
+ .map(dto -> {
|
|
|
+ BigDecimal jq = safeBigDecimal(dto.getJqOtherCostsPremiums());
|
|
|
+ BigDecimal sy = safeBigDecimal(dto.getSyOtherCostsPremiums());
|
|
|
+ return jq.add(sy);
|
|
|
+ })
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }else{
|
|
|
+ // 安全字符串转BigDecimal,兜底0
|
|
|
+ totalOtherReceivable = dtoList.stream()
|
|
|
+ .map(dto -> {
|
|
|
+ BigDecimal jy = safeBigDecimal(dto.getJyOtherCostsPremiums());
|
|
|
+ return jy;
|
|
|
+ })
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
|
|
|
// 已存在直接跳过,不存在新建VO
|
|
|
if (!existVoMap.containsKey(groupKey)) {
|
|
|
@@ -1066,6 +1093,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
newVo.setYear(signYear);
|
|
|
newVo.setMonth(signMonth);
|
|
|
newVo.setTotalReceivable(totalOtherReceivable);
|
|
|
+ newVo.setInvoiceType(invoiceType);
|
|
|
newVo.setTotalInvoiced(BigDecimal.ZERO);
|
|
|
newVo.setTotalUnInvoiced(BigDecimal.ZERO);
|
|
|
newVo.setTotalSettlementAmount(BigDecimal.ZERO);
|
|
|
@@ -4535,16 +4563,19 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
.map(InsPlyIncomeInvoiceSettlement::getActualReceivedAmount)
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
-// BigDecimal settlementPaymentDifference = insPlyIncomeInvoiceSettlements.stream()
|
|
|
-// .map(InsPlyIncomeInvoiceSettlement::getSettlementPaymentDifference)
|
|
|
-// .filter(Objects::nonNull)
|
|
|
-// .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal settlementPaymentDifference = insPlyIncomeInvoiceSettlements.stream()
|
|
|
+ .map(InsPlyIncomeInvoiceSettlement::getSettlementPaymentDifference)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
BigDecimal receivableSupervisePremium = action.getReceivableSupervisePremium() != null ? action.getReceivableSupervisePremium(): BigDecimal.ZERO;
|
|
|
|
|
|
// BigDecimal overinflatedAmount = action.getOverinflatedAmount() != null? action.getOverinflatedAmount(): BigDecimal.ZERO;
|
|
|
// 回款差计算逻辑调整 2026年7月14日09:29:08
|
|
|
- BigDecimal settlementPaymentDifference = BigDecimalUtil.subtract(settlementAmount,receivableSupervisePremium);
|
|
|
+// BigDecimal settlementPaymentDifference = BigDecimal.ZERO;
|
|
|
+// if (CollUtil.isNotEmpty(insPlyIncomeInvoiceSettlements) && settlementAmount.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+// settlementPaymentDifference = BigDecimalUtil.subtract(settlementAmount,receivableSupervisePremium);
|
|
|
+// }
|
|
|
// 待结算金额 = 开票金额 - 已收金额
|
|
|
BigDecimal remainSettlementAmount = receivableSupervisePremium.subtract(BigDecimalUtil.add(settlementAmount, settlementPaymentDifference));
|
|
|
// 设置已结算的金额
|
|
|
@@ -4554,7 +4585,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
// 特殊梳理,当待结算金额计算出来为负数时, 设置为0
|
|
|
remainSettlementAmount = BigDecimal.ZERO;
|
|
|
}
|
|
|
- action.setRemainSettlementAmount( remainSettlementAmount);
|
|
|
+ action.setRemainSettlementAmount(remainSettlementAmount);
|
|
|
action.setCompanyAllName(allCompanyHierarchyPaths.get(Objects.toString(action.getCompanyId(),"")));
|
|
|
action.setSettlementStatus(settlementStatusName);
|
|
|
|
|
|
@@ -4798,6 +4829,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
case "6" -> dto.setInvoiceType("平台协议非车险应收");
|
|
|
}
|
|
|
dto.setInvoiceTypeName(Constant.invoiceRiskTypeMap.get(Objects.toString(dto.getInvoiceType())));
|
|
|
+ dto.setInvoiceRiskTypeName(Constant.invoiceRiskTypeMap.get(Objects.toString(dto.getInvoiceRiskType())));
|
|
|
LambdaQueryWrapper<InsPlyIncomeInvoiceSettlementFile> wrapper = new LambdaQueryWrapper<InsPlyIncomeInvoiceSettlementFile>();
|
|
|
List<InsPlyIncomeInvoiceSettlementFile> insPlyIncomeInvoiceSettlementFiles = insPlyIncomeInvoiceSettlementFileMapper.selectList(wrapper.eq(InsPlyIncomeInvoiceSettlementFile::getSettlementId, dto.getSettlementId()));
|
|
|
if(CollUtil.isNotEmpty(insPlyIncomeInvoiceSettlementFiles)){
|
|
|
@@ -5339,30 +5371,29 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
List<CompanySuperviseSettlementReportDto> allCompaniesIncomeDatas = baseMapper.queryCumulativeAccountsReceivable(systemCode, queryVo);
|
|
|
// 结算状态在上面的sql进行过筛选了,后面就不再筛选了
|
|
|
queryVo.setStatus(null);
|
|
|
- if("20".equals(queryVo.getAccountsReceivable())){
|
|
|
- allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
|
|
|
- // 统计非车的手续费
|
|
|
- action.setSuperviseFee(action.getSuperviseFee4Other());
|
|
|
- }).toList();
|
|
|
- }
|
|
|
-
|
|
|
- // 车险
|
|
|
-// if("10".equals(queryVo.getAccountsReceivable())){
|
|
|
-// // 默认情况下,superviseFee 得到的就是车险的手续费
|
|
|
-// allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().toList();
|
|
|
-// }else if("20".equals(queryVo.getAccountsReceivable())){
|
|
|
+// if("20".equals(queryVo.getAccountsReceivable())){
|
|
|
// allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
|
|
|
// // 统计非车的手续费
|
|
|
-// action.setSuperviseFee(action.getSuperviseFee4Other());
|
|
|
+// action.setSuperviseFee(action.getSuperviseFee4Other());
|
|
|
// }).toList();
|
|
|
-// }else if(StrUtil.isEmpty(queryVo.getAccountsReceivable())){
|
|
|
-// // 统计总的手续费
|
|
|
-//// allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
|
|
|
-//// // 统计非车的手续费
|
|
|
-//// action.setSuperviseFee(action.getTotalReceivable());
|
|
|
-//// }).toList();
|
|
|
// }
|
|
|
|
|
|
+ // 车险
|
|
|
+ if("10".equals(queryVo.getAccountsReceivable())){
|
|
|
+ // 默认情况下,superviseFee 得到的就是车险的手续费
|
|
|
+ allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().toList();
|
|
|
+ }else if("20".equals(queryVo.getAccountsReceivable())){
|
|
|
+ allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
|
|
|
+ // 统计非车的手续费
|
|
|
+ action.setSuperviseFee(action.getSuperviseFee4Other());
|
|
|
+ }).toList();
|
|
|
+ }else if(StrUtil.isEmpty(queryVo.getAccountsReceivable())){
|
|
|
+ // 统计总的手续费(车险+非车险)
|
|
|
+ allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().peek(action->{
|
|
|
+ action.setSuperviseFee(BigDecimalUtil.add(action.getSuperviseFee(), action.getSuperviseFee4Other()));
|
|
|
+ }).toList();
|
|
|
+ }
|
|
|
+
|
|
|
// for test, 查看一家公司的数据,将不可变对象变成 可变对象
|
|
|
// allCompaniesIncomeDatas = allCompaniesIncomeDatas.stream().filter(action-> "1738811735599338932".equals(action.getCompanyId())).toList();
|
|
|
// allCompaniesIncomeDatas = new ArrayList<>(allCompaniesIncomeDatas);
|
|
|
@@ -6090,11 +6121,14 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
* 3. 记录更新人和更新时间
|
|
|
* </p>
|
|
|
*
|
|
|
- * @param invoiceId 发票序号,用于定位需要更新的发票记录
|
|
|
+ * @param updateSettlementStatusVo 发票序号,用于定位需要更新的发票记录
|
|
|
* @return int 返回受影响的记录数,通常为1表示更新成功,0表示更新失败或记录不存在
|
|
|
*/
|
|
|
@Override
|
|
|
- public int updateSettlementStatus(String invoiceId) {
|
|
|
+ public int updateSettlementStatus(UpdateSettlementStatusVo updateSettlementStatusVo) {
|
|
|
+ String invoiceId = updateSettlementStatusVo.getInvoiceId();
|
|
|
+ String settlementPaymentReason = updateSettlementStatusVo.getSettlementPaymentReason();
|
|
|
+
|
|
|
String userName = baseController.getUserName();
|
|
|
String systemCode = baseController.getSystemCode();
|
|
|
log.info("租户[{}]下的用户[{}]标识发票[{}]为结算完成", systemCode, userName, invoiceId);
|
|
|
@@ -6106,10 +6140,21 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
BigDecimal settlementAmount = insPlyIncomeInvoiceSettlements.stream().map(action-> BigDecimalUtil.add(action.getSettlementPaymentDifference(), action.getActualReceivedAmount()))
|
|
|
.reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
BigDecimal subtract = BigDecimalUtil.subtract(insPlyIncomeInvoice.getReceivableSupervisePremium(), settlementAmount);
|
|
|
- if(subtract.compareTo(BigDecimal.ZERO) != 0){
|
|
|
- InsPlyIncomeInvoiceSettlement insPlyIncomeInvoiceSettlement = insPlyIncomeInvoiceSettlements.get(0);
|
|
|
- insPlyIncomeInvoiceSettlement.setSettlementPaymentDifference(BigDecimalUtil.add(subtract,insPlyIncomeInvoiceSettlement.getSettlementPaymentDifference()));
|
|
|
- insPlyIncomeInvoiceSettlementMapper.updateById(insPlyIncomeInvoiceSettlement);
|
|
|
+ if (CollUtil.isNotEmpty(insPlyIncomeInvoiceSettlements)){
|
|
|
+ if(subtract.compareTo(BigDecimal.ZERO) != 0){
|
|
|
+ InsPlyIncomeInvoiceSettlement insPlyIncomeInvoiceSettlement = insPlyIncomeInvoiceSettlements.get(0);
|
|
|
+ insPlyIncomeInvoiceSettlement.setSettlementPaymentDifference(BigDecimalUtil.add(subtract,insPlyIncomeInvoiceSettlement.getSettlementPaymentDifference()));
|
|
|
+ insPlyIncomeInvoiceSettlement.setSettlementPaymentReason(settlementPaymentReason);
|
|
|
+ insPlyIncomeInvoiceSettlementMapper.updateById(insPlyIncomeInvoiceSettlement);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ InsPlyIncomeInvoiceSettlement insPlyIncomeInvoiceSettlement = new InsPlyIncomeInvoiceSettlement();
|
|
|
+ insPlyIncomeInvoiceSettlement.setInvoiceId(invoiceId);
|
|
|
+ insPlyIncomeInvoiceSettlement.setReceivePaymentDate(new DateTime());
|
|
|
+ insPlyIncomeInvoiceSettlement.setActualReceivedAmount(BigDecimal.ZERO);
|
|
|
+ insPlyIncomeInvoiceSettlement.setSettlementPaymentDifference(BigDecimal.ZERO.subtract(insPlyIncomeInvoice.getReceivableSupervisePremium()));
|
|
|
+ insPlyIncomeInvoiceSettlement.setSettlementPaymentReason(settlementPaymentReason);
|
|
|
+ insPlyIncomeInvoiceSettlementMapper.insert(insPlyIncomeInvoiceSettlement);
|
|
|
}
|
|
|
return insPlyIncomeInvoiceMapper.update(null, new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
|
|
|
.set(InsPlyIncomeInvoice::getStatus,"1")
|