Эх сурвалжийг харах

Merge remote-tracking branch 'origin/dev_jzg_lipf_v20260622' into dev_jzg_lipf_v20260622

jiakai 2 сар өмнө
parent
commit
fa8ad4d286

+ 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;
 

+ 1 - 1
tenant/insurance/quotation-summary/src/main/java/com/jzg/quotation/summary/service/impl/InsFeeOrdersServiceImpl.java

@@ -202,7 +202,7 @@ public class InsFeeOrdersServiceImpl extends ServiceImpl<InsFeeOrdersMapper, Ins
         // 加投直接乘
         BigDecimal addThrow = premium.multiply(addThrowRatio).setScale(scale, RoundingMode.HALF_EVEN);
         // 出口直接乘
-        BigDecimal export = premium.multiply(exportRatio).setScale(scale, RoundingMode.DOWN);
+        BigDecimal export = premium.multiply(exportRatio).setScale(2, RoundingMode.DOWN);
         BigDecimal exportKeepPoint = premium.multiply(exportKeepPointRatio).setScale(scale, RoundingMode.DOWN);
         // 留点比例直接乘, modify by lipf ,留点比例在infFeeOrder中计算得到。这里直接使用 2026年6月16日17:32:09, 为了保持金额一致,留点比例不适用百分比乘积,而是使用金额相减
         // BigDecimal keepPoint = premium.multiply(keepPointRatio).setScale(scale, RoundingMode.HALF_EVEN);

+ 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);
+
 }

+ 26 - 6
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -328,7 +328,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
         List<InsPlyIncomeOrder> res = page.getRecords().stream()
                 .map(action -> new InsPlyIncomeOrder(action.getId(), action.getOrderNo())).toList();
         BigDecimal totalAmount = page.getRecords().stream()
-                .map(action -> new BigDecimal(Objects.toString(action.getJyReceivablePremium(), "0"))).reduce(BigDecimal.ZERO, BigDecimal::add);
+                .map(action -> new BigDecimal(Objects.toString(action.getReceivableAmount(), "0"))).reduce(BigDecimal.ZERO, BigDecimal::add);
 
         InsPlyIncomeVO vo = new InsPlyIncomeVO(null, res,Objects.toString(totalAmount,"0"));
         log.info("获取私有/平台协议手续费应收列表的id集合。receivableQueryVo=[{}]. ids.size=[{}]", JSONUtil.toJsonStr(receivableQueryVo), CollUtil.size(res));
@@ -1482,7 +1482,8 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             default -> null;
         };
         // 四舍五入
-        return result.setScale(2, BigDecimal.ROUND_HALF_UP);
+//        return result.setScale(2, BigDecimal.ROUND_HALF_UP);
+        return result;
     }
 
     /**
@@ -4445,7 +4446,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);
                 // 设置待结算金额
@@ -5389,7 +5390,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()) {
@@ -5406,16 +5411,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());
@@ -5574,6 +5580,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;
@@ -5971,6 +5978,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)

+ 3 - 2
tenant/organization/src/main/resources/mapper/ReceivableMapper.xml

@@ -2002,12 +2002,13 @@
     <select id="querySettledAmount" resultType="com.jzg.organization.entity.dto.CalRes">
         select
         a.company_id ,
-        sum(COALESCE(a.actual_received_amount, 0)) as settlement
+        sum(COALESCE(a.actual_received_amount, 0)) as settlement,sum(a.overinflatedAmount) overinflatedAmount
         from
         (
         select distinct ins.id,
         ipi.company_id ,
-        COALESCE(ins.actual_received_amount, 0) as actual_received_amount
+        COALESCE(ins.actual_received_amount, 0) as actual_received_amount,
+        COALESCE(ins.settlement_payment_difference,0) as overinflatedAmount
         from ins_ply_income_invoice_settlement ins
         inner join ins_ply_income_invoice inc
         on ins.invoice_id = inc.id