|
|
@@ -775,6 +775,24 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -916,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获取公司名称
|
|
|
*/
|
|
|
@@ -947,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();
|
|
|
@@ -1036,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();
|
|
|
@@ -1053,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)) {
|
|
|
@@ -1070,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);
|
|
|
@@ -6116,11 +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()));
|
|
|
+ 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.updateById(insPlyIncomeInvoiceSettlement);
|
|
|
+ insPlyIncomeInvoiceSettlementMapper.insert(insPlyIncomeInvoiceSettlement);
|
|
|
}
|
|
|
return insPlyIncomeInvoiceMapper.update(null, new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
|
|
|
.set(InsPlyIncomeInvoice::getStatus,"1")
|