Răsfoiți Sursa

修改bug:
私有应收 跟单结算报表-保险公司报表未结算是0,这里显示有数据,这个应该是回款差额,负数

jiakai 2 luni în urmă
părinte
comite
31a3b548a0

+ 42 - 0
commons/src/main/java/com/jzg/commons/constants/SettlementIdentificationEnum.java

@@ -0,0 +1,42 @@
+package com.jzg.commons.constants;
+
+/**
+ * 费用类型枚举
+ */
+public enum SettlementIdentificationEnum {
+
+    /** 1、手续费 */
+    UNSETTLED("0", "未结算"),
+    /** 2、跟单费 */
+    SETTLED("1", "已结算");
+
+    // 编码(String类型)
+    private final String code;
+    // 名称(String类型)
+    private final String desc;
+
+    SettlementIdentificationEnum(String code, String desc) {
+        this.code = code;
+        this.desc = desc;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public String getDesc() {
+        return desc;
+    }
+
+    /**
+     * 根据code获取枚举
+     */
+    public static SettlementIdentificationEnum getByCode(String code) {
+        for (SettlementIdentificationEnum value : values()) {
+            if (value.getCode().equals(code)) {
+                return value;
+            }
+        }
+        return null;
+    }
+}

+ 3 - 0
commons/src/main/java/com/jzg/commons/entity/finance/dto/InsFeeFollowOrderDto.java

@@ -45,6 +45,9 @@ public class InsFeeFollowOrderDto extends PageRequest {
     @Schema(description = "本次开票金额")
     private BigDecimal invoicedAmountTime;
 
+    @Schema(description = "是否结算完成 0:未结算 1:已结算")
+    private String settlementIdentification;
+
     @Schema(description = "系统编码")
     private String systemCode;
 }

+ 3 - 0
commons/src/main/java/com/jzg/commons/entity/finance/po/InsFeeFollowOrder.java

@@ -54,6 +54,9 @@ public class InsFeeFollowOrder extends BaseModel {
     @Schema(description = "虚增差额")
     private BigDecimal falselyIncreasedDifference;
 
+    @Schema(description = "是否结算完成 0:未结算 1:已结算")
+    private String settlementIdentification;
+
     @Schema(description = "虚增原因")
     private String falselyIncreasedReason;
 

+ 6 - 0
commons/src/main/java/com/jzg/commons/entity/finance/vo/FollowCompanyFeeVO.java

@@ -74,4 +74,10 @@ public class FollowCompanyFeeVO {
      */
     private String invoiceType;
 
+    /**
+     * 是否结算完成 0:未结算 1:已结算
+     */
+    @Schema(description = "是否结算完成 0:未结算 1:已结算")
+    private String settlementIdentification;
+
 }

+ 3 - 0
commons/src/main/java/com/jzg/commons/entity/finance/vo/InsFeeFollowOrderVo.java

@@ -56,6 +56,9 @@ public class InsFeeFollowOrderVo implements Serializable {
     @Schema(description = "虚增原因")
     private String falselyIncreasedReason;
 
+    @Schema(description = "是否结算完成 0:未结算 1:已结算")
+    private String settlementIdentification;
+
     @Schema(description = "本次开票金额")
     private BigDecimal invoicedAmountTime;
 

+ 48 - 8
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -18,6 +18,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jzg.commons.constants.InvoiceTypeEnum;
 import com.jzg.commons.constants.ProductsType;
+import com.jzg.commons.constants.SettlementIdentificationEnum;
 import com.jzg.commons.constants.dict.InsOrderStatusEnum;
 import com.jzg.commons.core.base.BaseController;
 import com.jzg.commons.core.page.HttpResult;
@@ -864,8 +865,8 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             List<String> followIds = voList.stream().map(FollowCompanyFeeVO::getFollowId).distinct().toList();
             List<String> settlementIds = voList.stream().map(FollowCompanyFeeVO::getSettlementId).distinct().toList();
 
-            // 应收金额(取第一条)
-            InsFeeFollowOrder firstFollow = followOrderMap.get(followIds.get(0));
+            // 应收金额(取第任意一条就行了)
+            InsFeeFollowOrder firstFollow = followOrderMap.getOrDefault(followIds.get(0), new InsFeeFollowOrder());
             BigDecimal receivablePremium = Optional.ofNullable(firstFollow)
                     .map(InsFeeFollowOrder::getReceivablePremium)
                     .orElse(BigDecimal.ZERO);
@@ -893,7 +894,13 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                     .map(InsPlyIncomeInvoiceSettlement::getActualReceivedAmount)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
             vo.setTotalSettlementAmount(totalSettlementAmount);
-            vo.setTotalUnSettlementAmount(totalInvoiced.subtract(totalSettlementAmount));
+            // 设置未结算总金额,获取所有ins_fee_follow_order数据,只有所以的都结算了,才能算已结算
+            List<InsFeeFollowOrder> insFeeFollowOrderList = followOrderMap.values().stream().filter(insFeeFollowOrder -> insFeeFollowOrder.getYear().toString().equals(year) && insFeeFollowOrder.getMonth().toString().equals(month) && insFeeFollowOrder.getPartnerCompanyId().equals(partnerCompanyId) && insFeeFollowOrder.getInvoiceType().equals(invoiceType)).toList();
+            if (insFeeFollowOrderList.size() == insFeeFollowOrderList.stream().filter(insFeeFollowOrder -> SettlementIdentificationEnum.SETTLED.getCode().equals(insFeeFollowOrder.getSettlementIdentification())).count()){
+                vo.setTotalUnSettlementAmount(BigDecimal.ZERO);
+            }else{
+                vo.setTotalUnSettlementAmount(totalInvoiced.subtract(totalSettlementAmount));
+            }
 
             aggResult.add(vo);
         }
@@ -1690,9 +1697,9 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             return false;
         }
         long result;
-        final String number = "1";
+        final String number = SettlementIdentificationEnum.SETTLED.getCode();
         result = switch (invoiceType) {
-            case number -> baseMapper.update(new LambdaUpdateWrapper<InsPlyIncome>()
+            case "1" -> baseMapper.update(new LambdaUpdateWrapper<InsPlyIncome>()
                     .in(InsPlyIncome::getId, incomeIds)
                     .set(InsPlyIncome::getSuperviseSettlement, number)
                     .set(InsPlyIncome::getSettlementTime,settlementTime)
@@ -1762,7 +1769,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                                                 String systemCode, String companyId) {
         log.info("更新结算状态: invoiceType=[{}], incomeIds=[{}], settlementTime=[{}], systemCode=[{}], companyId=[{}]",
                 invoiceType, JSONUtil.toJsonStr(incomeIds), settlementTime, systemCode, companyId);
-        final String number = "1";
+        final String number = SettlementIdentificationEnum.SETTLED.getCode();
         long result = 0;
         // 针对 invoiceType 为 2 或 4 的特殊逻辑:按签约年月、系统编码、公司ID进行批量更新
         if ("2".equals(invoiceType) || "4".equals(invoiceType)) {
@@ -2662,7 +2669,7 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             if (surplusPremium.compareTo(settlementVo.getActualReceivedAmount()) <= 0) {
                 log.info("序号为[{}]的发票已经结算完成",insPlyIncomeInvoice.getId());
                 // 更新发票状态
-                insPlyIncomeInvoice.setStatus("1");
+                insPlyIncomeInvoice.setStatus(SettlementIdentificationEnum.SETTLED.getCode());
                 insPlyIncomeInvoiceMapper.updateById(insPlyIncomeInvoice);
                 // 将所有订单进行标记
                 List<String> incomeIds = new ArrayList<>();
@@ -4424,11 +4431,14 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             if (surplusPremium.compareTo(settlementVo.getActualReceivedAmount()) <= 0) {
                 log.info("序号为[{}]的发票已经结算完成",insPlyIncomeInvoice.getId());
                 // 更新发票状态
-                insPlyIncomeInvoice.setStatus("1");
+                insPlyIncomeInvoice.setStatus(SettlementIdentificationEnum.SETTLED.getCode());
                 insPlyIncomeInvoiceMapper.updateById(insPlyIncomeInvoice);
                 // 判断是需要更新哪个字段
                 this.updateIncomeSettlementStatus(insPlyIncomeInvoice.getInvoiceType(), null, LocalDateTime.now(),
                         baseController.getSystemCode(), insPlyIncomeInvoice.getCompanyId());
+
+                // 更新 ins_fee_follow_order的结算状态
+                updateFollowSettlementIdentification(settlementVo.getInvoicingId());
             }else{
                 log.info("invoiceId=[{}], 还剩[{}]钱没有结算",settlementVo.getInvoicingId(), surplusPremium.subtract(settlementVo.getActualReceivedAmount()));
             }
@@ -6160,6 +6170,9 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
             insPlyIncomeInvoiceSettlement.setSettlementPaymentReason(settlementPaymentReason);
             insPlyIncomeInvoiceSettlementMapper.insert(insPlyIncomeInvoiceSettlement);
         }
+        // 更新 ins_fee_follow_order的结算状态
+        updateFollowSettlementIdentification(invoiceId);
+
         return insPlyIncomeInvoiceMapper.update(null, new LambdaUpdateWrapper<InsPlyIncomeInvoice>()
                 .set(InsPlyIncomeInvoice::getStatus,"1")
                 .set(InsPlyIncomeInvoice::getUpdateBy,userName)
@@ -6167,6 +6180,33 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
                 .eq(InsPlyIncomeInvoice::getId, invoiceId));
     }
 
+    /**
+     * 根据发票ID更新发票的结算完成标识
+     * <p>
+     * 该方法用于根据指定的发票ID更新发票的结算完成标识,包括以下处理逻辑:
+     * 1. 获取当前操作用户信息和租户代码
+     * 2. 查询指定发票ID的关联的应收订单列表
+     */
+    private void updateFollowSettlementIdentification(String invoiceId) {
+        // 更新 ins_fee_follow_order的结算状态
+        LambdaQueryWrapper<InsPlyFollowInvoiceLink> insPlyFollowInvoiceLinkLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        insPlyFollowInvoiceLinkLambdaQueryWrapper.eq(InsPlyFollowInvoiceLink::getInvoiceId, invoiceId);
+        List<InsPlyFollowInvoiceLink> insPlyFollowInvoiceLinks = insPlyFollowInvoiceLinkMapper.selectList(insPlyFollowInvoiceLinkLambdaQueryWrapper);
+        if (CollUtil.isNotEmpty(insPlyFollowInvoiceLinks)){
+            // 根据link表的follow_id查询follow表
+            LambdaQueryWrapper<InsFeeFollowOrder> insFeeFollowOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            insFeeFollowOrderLambdaQueryWrapper.in(InsFeeFollowOrder::getId, insPlyFollowInvoiceLinks.stream().map(InsPlyFollowInvoiceLink::getFollowId).toList());
+            List<InsFeeFollowOrder> insFeeFollowOrders = insFeeFollowOrderMapper.selectList(insFeeFollowOrderLambdaQueryWrapper);
+            if (CollUtil.isNotEmpty(insFeeFollowOrders)){
+                // 批量修改:是否结算完成
+                for (InsFeeFollowOrder insFeeFollowOrder : insFeeFollowOrders) {
+                    insFeeFollowOrder.setSettlementIdentification(SettlementIdentificationEnum.SETTLED.getCode());
+                }
+                insFeeFollowOrderMapper.updateById(insFeeFollowOrders);
+            }
+        }
+    }
+
     /**
      * yyyy-MM-dd 转当天起始 LocalDateTime
      */

+ 1 - 0
tenant/organization/src/main/resources/mapper/InsFeeFollowOrderMapper.xml

@@ -52,6 +52,7 @@
         ffo.year,
         ffo.month,
         ffo.invoice_type,
+        ffo.settlement_identification,
         inv.id AS invoiceId,
         sett.id AS settlementId
         FROM ins_fee_follow_order ffo