فهرست منبع

批改后的应收数据修改

Qchen 11 ماه پیش
والد
کامیت
ae1f5d55dc

+ 4 - 0
tenant/insurance/quotation-commons/src/main/java/com/jzg/quotation/commons/client/OrgClient.java

@@ -4,6 +4,7 @@ import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.dto.CostAgreementParam;
 import com.jzg.commons.entity.dto.MessageAddParam;
 import com.jzg.commons.entity.enums.MessageCodeEnum;
+import com.jzg.commons.entity.orders.po.InsOrderAdjust;
 import com.jzg.commons.entity.po.*;
 import com.jzg.commons.entity.vo.*;
 import org.springframework.cloud.openfeign.FeignClient;
@@ -121,4 +122,7 @@ public interface OrgClient {
 
     @GetMapping(value = "userInfo/getUserInfoById")
     public HttpResult<SysUserJzgInfo> getUserInfoById(String id);
+
+    @PostMapping(value = "receivable/restockInsPlyIncome")
+    public void restockInsPlyIncome(@RequestBody InsOrderAdjust insOrderAdjust);
 }

+ 1 - 1
tenant/organization/src/main/java/com/jzg/organization/client/QuoteClient.java

@@ -7,7 +7,7 @@ import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 
-@FeignClient(name="jzg-insurance",url = "http://192.168.0.106:9898/")
+@FeignClient(name="jzg-insurance",url = "http://localhost:9898/")
 public interface QuoteClient {
     @PostMapping(value = "/insFeeOrder/getInsFeeOrdersList")
     public List<InsFeeOrders> getInsFeeOrdersList(@RequestBody InsFeeOrdersParam param);

+ 7 - 0
tenant/organization/src/main/java/com/jzg/organization/controller/ReceivableController.java

@@ -6,6 +6,7 @@ import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.finance.po.InsPlyIncome;
 import com.jzg.commons.entity.finance.po.InsPlyIncomeInvoiceSettlement;
 import com.jzg.commons.entity.finance.vo.*;
+import com.jzg.commons.entity.orders.po.InsOrderAdjust;
 import com.jzg.commons.request.RequestSingleParam;
 import com.jzg.commons.util.AssertionUtils;
 import com.jzg.organization.service.ReceivableService;
@@ -334,4 +335,10 @@ public class ReceivableController {
     public HttpResult getInvoiceRecordDetail(@RequestSingleParam("id") String id){
         return HttpResult.ok(receivableService.getInvoiceRecordDetail(id));
     }
+
+    @PostMapping("/restockInsPlyIncome")
+    @Operation(summary = "批改订单后应收重新添加")
+    public void restockInsPlyIncome(@RequestBody InsOrderAdjust insOrderAdjust){
+        receivableService.restockInsPlyIncome(insOrderAdjust);
+    }
 }

+ 2 - 1
tenant/organization/src/main/java/com/jzg/organization/service/ReceivableService.java

@@ -6,6 +6,7 @@ import com.jzg.commons.entity.finance.dto.*;
 import com.jzg.commons.entity.finance.po.InsPlyIncome;
 import com.jzg.commons.entity.finance.po.InsPlyIncomeInvoiceSettlement;
 import com.jzg.commons.entity.finance.vo.*;
+import com.jzg.commons.entity.orders.po.InsOrderAdjust;
 import com.jzg.commons.entity.orders.po.InsOrders;
 import com.jzg.commons.entity.orders.po.InsOrdersPolicy;
 import com.jzg.commons.entity.po.EsmInsCompany;
@@ -252,6 +253,6 @@ public interface ReceivableService extends IService<InsPlyIncome> {
     /**
      * 批改订单后应收重新添加
      */
-    void restockInsPlyIncome(String orderNo,String companyId);
+    void restockInsPlyIncome(InsOrderAdjust insOrderAdjust);
 
 }

+ 130 - 5
tenant/organization/src/main/java/com/jzg/organization/service/impl/ReceivableServiceImpl.java

@@ -12,6 +12,7 @@ import com.jzg.commons.core.page.HttpResult;
 import com.jzg.commons.entity.finance.dto.*;
 import com.jzg.commons.entity.finance.po.*;
 import com.jzg.commons.entity.finance.vo.*;
+import com.jzg.commons.entity.orders.po.InsOrderAdjust;
 import com.jzg.commons.entity.po.EsmInsCompany;
 import com.jzg.commons.entity.po.PtlAgreement;
 import com.jzg.commons.entity.po.SysUploadFiles;
@@ -50,6 +51,8 @@ import java.time.format.DateTimeFormatter;
 import java.time.format.DateTimeParseException;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
+import java.util.function.BiConsumer;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 /**
  * @author tz
@@ -1218,16 +1221,138 @@ public class ReceivableServiceImpl extends ServiceImpl<ReceivableMapper, InsPlyI
     }
 
     @Override
-    public void restockInsPlyIncome(String orderNo, String companyId) {
+    public void restockInsPlyIncome(InsOrderAdjust insOrderAdjust) {
+        final String AGREEMENT_TYPE_PLATFORM = "1";
+        final BigDecimal RATIO_1_06 = new BigDecimal("1.06");
         List<InsPlyIncome> insPlyIncomeList = baseMapper
-                .selectList(new LambdaQueryWrapper<InsPlyIncome>().eq(InsPlyIncome::getOrderNo, orderNo).eq(InsPlyIncome::getCompanyId, companyId));
+                .selectList(new LambdaQueryWrapper<InsPlyIncome>().eq(InsPlyIncome::getOrderNo, insOrderAdjust.getOrderNo()).eq(InsPlyIncome::getCompanyId, insOrderAdjust.getCompanyId()));
         if (insPlyIncomeList.isEmpty()) {
             throw new SystemException("未找到该应收订单");
         }
         InsPlyIncome insPlyIncome = insPlyIncomeList.get(0);
-        InsPlyIncome restockInsPlyIncome = new InsPlyIncome();
-        BeanUtils.copyProperties(insPlyIncome, restockInsPlyIncome);
-        this.save(restockInsPlyIncome);
+        InsPlyIncome restockIncome = new InsPlyIncome();
+        BeanUtils.copyProperties(insPlyIncome, restockIncome);
+        // 获取批改后的保费
+        BigDecimal adjustJqPremium = insOrderAdjust.getAfterJqPremium();
+        BigDecimal adjustSyPremium = insOrderAdjust.getAfterSyPremium();
+        BigDecimal adjustJyPremium = insOrderAdjust.getAfterJyPremium();
+        restockIncome.setJqPremium(adjustJqPremium.toPlainString());
+        restockIncome.setSyPremium(adjustSyPremium.toPlainString());
+        restockIncome.setJyPremium(adjustJyPremium.toPlainString());
+        // 计算手续费
+        calculateAndSetCosts(restockIncome, adjustJqPremium,
+                InsPlyIncome::getJqSuperviseCostsProportion,
+                InsPlyIncome::setJqSuperviseCostsPremiums);
+
+        calculateAndSetCosts(restockIncome, adjustSyPremium,
+                InsPlyIncome::getSySuperviseCostsProportion,
+                InsPlyIncome::setSySuperviseCostsPremiums);
+
+        calculateAndSetCosts(restockIncome, adjustJyPremium,
+                InsPlyIncome::getJySuperviseCostsProportion,
+                InsPlyIncome::setJySuperviseCostsPremiums);
+
+        // 计算并设置跟单费
+        calculateAndSetCosts(restockIncome, adjustJqPremium,
+                InsPlyIncome::getJqOtherCostsProportion,
+                InsPlyIncome::setJqOtherCostsPremiums);
+
+        calculateAndSetCosts(restockIncome, adjustSyPremium,
+                InsPlyIncome::getSyOtherCostsProportion,
+                InsPlyIncome::setSyOtherCostsPremiums);
+
+        calculateAndSetCosts(restockIncome, adjustJyPremium,
+                InsPlyIncome::getJyOtherCostsProportion,
+                InsPlyIncome::setJyOtherCostsPremiums);
+
+        // 计算并设置应收保费(按协议类型处理)
+        calculateAndSetReceivable(restockIncome, adjustJqPremium, adjustSyPremium, adjustJyPremium,
+                AGREEMENT_TYPE_PLATFORM, RATIO_1_06);
+        this.save(restockIncome);
+    }
+    /**
+     * 通用计算费用(手续费/跟单费)并设置到对象
+     * @param income 目标对象
+     * @param premium 保费
+     * @param proportionGetter 比例获取器
+     * @param costSetter 费用设置器
+     */
+    private void calculateAndSetCosts(InsPlyIncome income, BigDecimal premium,
+                                      Function<InsPlyIncome, String> proportionGetter,
+                                      BiConsumer<InsPlyIncome, String> costSetter) {
+        // 转换比例字符串为BigDecimal(处理可能的空值或异常)
+        BigDecimal proportion = new BigDecimal(proportionGetter.apply(income));
+        // 计算费用并设置(使用toPlainString避免科学计数法)
+        BigDecimal cost = premium.multiply(proportion);
+        costSetter.accept(income, cost.toPlainString());
+    }
+
+    /**
+     * 计算并设置应收保费
+     */
+    private void calculateAndSetReceivable(InsPlyIncome income, BigDecimal jqPremium, BigDecimal syPremium, BigDecimal jyPremium,
+                                           String platformAgreementType, BigDecimal ratio106) {
+        // 平台协议逻辑
+        if (platformAgreementType.equals(income.getAgreementType())) {
+            setReceivableForPlatform(income, jqPremium, syPremium, jyPremium);
+        } else {
+            // 私有协议逻辑
+            setReceivableForPrivate(income, jqPremium, syPremium, jyPremium, ratio106);
+        }
+    }
+
+    /**
+     * 平台协议应收保费计算
+     */
+    private void setReceivableForPlatform(InsPlyIncome income, BigDecimal jqPremium, BigDecimal syPremium, BigDecimal jyPremium) {
+        // 从已计算的手续费和跟单费中获取值(避免重复计算)
+        BigDecimal jqTotal = new BigDecimal(income.getJqSuperviseCostsPremiums())
+                .add(new BigDecimal(income.getJqOtherCostsPremiums()));
+
+        BigDecimal syTotal = new BigDecimal(income.getSySuperviseCostsPremiums())
+                .add(new BigDecimal(income.getSyOtherCostsPremiums()));
+
+        BigDecimal jyTotal = new BigDecimal(income.getJySuperviseCostsPremiums())
+                .add(new BigDecimal(income.getJyOtherCostsPremiums()));
+
+        income.setJqReceivablePremium(jqTotal.toPlainString());
+        income.setSyReceivablePremium(syTotal.toPlainString());
+        income.setJyReceivablePremium(jyTotal.toPlainString());
+    }
+
+    /**
+     * 私有协议应收保费计算
+     */
+    private void setReceivableForPrivate(InsPlyIncome income, BigDecimal jqPremium, BigDecimal syPremium, BigDecimal jyPremium,
+                                         BigDecimal ratio106) {
+        // 计算私有协议下的应收保费
+        calculatePrivateReceivable(income, jqPremium, ratio106,
+                InsPlyIncome::getJqSuperviseCostsProportion,
+                InsPlyIncome::getJqOtherCostsProportion,
+                InsPlyIncome::setJqReceivablePremium);
+
+        calculatePrivateReceivable(income, syPremium, ratio106,
+                InsPlyIncome::getSySuperviseCostsProportion,
+                InsPlyIncome::getSyOtherCostsProportion,
+                InsPlyIncome::setSyReceivablePremium);
+
+        calculatePrivateReceivable(income, jyPremium, ratio106,
+                InsPlyIncome::getJySuperviseCostsProportion,
+                InsPlyIncome::getJyOtherCostsProportion,
+                InsPlyIncome::setJyReceivablePremium);
+    }
+
+    /**
+     * 私有协议下单个类型的应收保费计算
+     */
+    private void calculatePrivateReceivable(InsPlyIncome income, BigDecimal premium, BigDecimal ratio106,
+                                            Function<InsPlyIncome, String> superviseProportionGetter,
+                                            Function<InsPlyIncome, String> otherProportionGetter,
+                                            BiConsumer<InsPlyIncome, String> receivableSetter) {
+        BigDecimal base = premium.multiply(ratio106);
+        BigDecimal superviseCost = base.multiply(new BigDecimal(superviseProportionGetter.apply(income)));
+        BigDecimal otherCost = base.multiply(new BigDecimal(otherProportionGetter.apply(income)));
+        receivableSetter.accept(income, superviseCost.add(otherCost).toPlainString());
     }
 }