Browse Source

私有协议-手续费-保险公司报表功能完善

lipf 2 months ago
parent
commit
2854146ea0

+ 4 - 0
commons/src/main/java/com/jzg/commons/entity/finance/dto/CompanySuperviseSettlementReportDto.java

@@ -43,6 +43,7 @@ public class CompanySuperviseSettlementReportDto implements Serializable {
     @Schema(description = "应收手续费")
     private String superviseFee;
 
+
     @Schema(description = "应收跟单费")
     private String followFee;
 
@@ -76,6 +77,9 @@ public class CompanySuperviseSettlementReportDto implements Serializable {
     @Schema(description = "虚增金额合计")
     private String totalOverinflatedAmount;
 
+    @Schema(description = "回款差额合计")
+    private String settlementPaymentDifference;
+
     @Schema(description = "子保险公司数据")
     private List<CompanySuperviseSettlementReportDto> children;
 

+ 5 - 0
tenant/organization/src/main/java/com/jzg/organization/mapper/InsPlyIncomeInvoiceSettlementMapper.java

@@ -5,6 +5,7 @@ import com.jzg.commons.entity.finance.po.InsPlyIncomeInvoiceSettlement;
 import com.jzg.commons.entity.finance.vo.SettlementVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
 
 import java.util.List;
 
@@ -18,4 +19,8 @@ public interface InsPlyIncomeInvoiceSettlementMapper extends BaseMapper<InsPlyIn
      * @date 2026/6/30 15:39
      */
     SettlementVo querySettlementAndDiff(@Param("settlementIds") List<String> settlementIds);
+
+    @Select("select * from ins_ply_income_invoice_settlement ipiis where ipiis.invoice_id = #{invoiceId,jdbcType=VARCHAR} order by ipiis.create_time desc ")
+    List<InsPlyIncomeInvoiceSettlement> querySettlementRecent(@Param("invoiceId") String invoiceId);
+
 }

+ 23 - 4
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -4423,7 +4423,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 BigDecimal receivableSupervisePremium = action.getReceivableSupervisePremium()  != null ? action.getReceivableSupervisePremium(): BigDecimal.ZERO;
 //                BigDecimal overinflatedAmount = action.getOverinflatedAmount() != null? action.getOverinflatedAmount(): BigDecimal.ZERO;
                 // 待结算金额 = 开票金额 - 已收金额
-                BigDecimal remainSettlementAmount = receivableSupervisePremium.subtract(settlementAmount);
+                BigDecimal remainSettlementAmount = receivableSupervisePremium.subtract(BigDecimalUtil.add(settlementAmount, settlementPaymentDifference));
                 // 设置已结算的金额
                 action.setSettlementAmount(settlementAmount);
                 // 设置待结算金额
@@ -5367,7 +5367,11 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         List<CalRes> sxfList = baseMapper.querySettledAmount(systemCode, queryVo.getInvoiceStartTime(), queryVo.getInvoiceEndTime(), queryVo.getAgreementType(), CollUtil.newArrayList("1", "3"));
         List<CalRes> gdfList = baseMapper.querySettledAmount(systemCode, queryVo.getInvoiceStartTime(), queryVo.getInvoiceEndTime(), queryVo.getAgreementType(), CollUtil.newArrayList("2", "4"));
         Map<String, BigDecimal> sxfSettledAmountMap = CollUtil.isNotEmpty(sxfList) ? sxfList.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getSettlement, (o1,o2)->o1)) : new HashMap<>();
+        // 手续费的回款差额汇总
+        Map<String, BigDecimal> sxfSettledDiffAmountMap = CollUtil.isNotEmpty(sxfList) ? sxfList.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getOverinflatedAmount, (o1,o2)->o1)) : new HashMap<>();
         Map<String, BigDecimal> gdfSettledAmountMap = CollUtil.isNotEmpty(gdfList) ? gdfList.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getSettlement, (o1,o2)->o1)) : new HashMap<>();
+        // 跟单费的回款差额汇总
+        Map<String, BigDecimal> gdfSettledDiffAmountMap = CollUtil.isNotEmpty(gdfList) ? gdfList.stream().collect(Collectors.toMap(CalRes::getCompanyId, CalRes::getOverinflatedAmount, (o1,o2)->o1)) : new HashMap<>();
 
         // 计算已开票和未开票
         for (String companyId : companyMap.keySet()) {
@@ -5384,16 +5388,17 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
 
             CompanySuperviseSettlementReportDto dto;
             dto = companyMap.get(companyId);
-            companySuperviseSettlementReportDto.setSxfUnInvoicedAmount(BigDecimalUtil.subtract(new BigDecimal(dto.getSuperviseFee()),sxf).toString());
-            companySuperviseSettlementReportDto.setGdfUnInvoicedAmount(BigDecimalUtil.subtract(new BigDecimal(dto.getFollowFee()),gdf).toString());
+            companySuperviseSettlementReportDto.setSxfUnInvoicedAmount(BigDecimalUtil.subtract(new BigDecimal(dto.getSuperviseFee()),BigDecimalUtil.subtract(sxf, new BigDecimal(dto.getTotalOverinflatedAmount()))).toString());
+            companySuperviseSettlementReportDto.setGdfUnInvoicedAmount(BigDecimalUtil.subtract(new BigDecimal(dto.getFollowFee()),BigDecimalUtil.subtract(gdf,new BigDecimal(dto.getTotalOverinflatedAmount()))).toString());
             companySuperviseSettlementReportDto.setPtUnInvoicedAmount(BigDecimal.ZERO.toString());
 
             BigDecimal sxfS = sxfSettledAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
             BigDecimal gdfS = gdfSettledAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
             BigDecimal overinflatedAmount = sxfOverinflatedAmountMap.getOrDefault(companyId, BigDecimal.ZERO);
             companySuperviseSettlementReportDto.setSxfSettledAmount(Objects.toString(sxfS, BigDecimal.ZERO+""));
-            companySuperviseSettlementReportDto.setSxfUnSettledAmount(BigDecimalUtil.subtract(sxf,sxfS).toString());
+            companySuperviseSettlementReportDto.setSxfUnSettledAmount(BigDecimalUtil.subtract(sxf,BigDecimalUtil.add(sxfS,sxfSettledDiffAmountMap.getOrDefault(companyId, BigDecimal.ZERO))).toString());
             companySuperviseSettlementReportDto.setTotalOverinflatedAmount(Objects.toString(overinflatedAmount, BigDecimal.ZERO+""));
+            companySuperviseSettlementReportDto.setSettlementPaymentDifference(Objects.toString(sxfSettledDiffAmountMap.getOrDefault(companyId, BigDecimal.ZERO)) );
 
             companySuperviseSettlementReportDto.setGdfSettledAmount(Objects.toString(gdfS, BigDecimal.ZERO+""));
             companySuperviseSettlementReportDto.setGdfUnSettledAmount(BigDecimalUtil.subtract(gdf,gdfS).toString());
@@ -5552,6 +5557,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             tree.putExtra("gdfSettledAmount",dto.getGdfSettledAmount());
             tree.putExtra("gdfUnSettledAmount",dto.getGdfUnSettledAmount());
             tree.putExtra("totalOverinflatedAmount",dto.getTotalOverinflatedAmount());
+            tree.putExtra("settlementPaymentDifference",dto.getSettlementPaymentDifference());
         });
         log.info("树形结构构建:一级数据[{}]个", CollUtil.size(build));
         return build;
@@ -5949,6 +5955,19 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         String userName = baseController.getUserName();
         String systemCode = baseController.getSystemCode();
         log.info("租户[{}]下的用户[{}]标识发票[{}]为结算完成", systemCode, userName, invoiceId);
+
+        List<InsPlyIncomeInvoiceSettlement> insPlyIncomeInvoiceSettlements =  insPlyIncomeInvoiceSettlementMapper.querySettlementRecent(invoiceId);
+        InsPlyIncomeInvoice insPlyIncomeInvoice = insPlyIncomeInvoiceMapper.selectById(invoiceId);
+
+        // 标记结算完成的时候,将未结算金额汇总 到最后一次结算的回款差额里面  lipf 2026年7月7日10:53:47
+        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);
+        }
         return insPlyIncomeInvoiceMapper.update(null, new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
                 .set(InsPlyIncomeInvoice::getStatus,"1")
                 .set(InsPlyIncomeInvoice::getUpdateBy,userName)