From 0bc118d74a03685d1b4685a0b7d38468f307b537 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期三, 02 八月 2023 17:51:34 +0800
Subject: [PATCH] 修改代码

---
 ruoyi-project/src/main/java/com/ruoyi/project/service/IServiceFundService.java         |   14 ++--
 ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java |   74 ++++++++++++++++++++++++
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java  |   61 --------------------
 3 files changed, 83 insertions(+), 66 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java
index 0595f39..58204bf 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/project/ServiceFundController.java
@@ -434,67 +434,8 @@
     @RepeatSubmit
     @Options(useGeneratedKeys = true, keyProperty = "id")
     public AjaxResult addOrUpdateNew(@RequestBody ServiceFundVO serviceFundVO) {
-        Long id = null;
-        if (serviceFundVO.getId() == null) {
-            boolean b = serviceFundService.save(serviceFundVO);
-            id = serviceFundVO.getId();
-        } else {
-            serviceFundService.updateById(serviceFundVO);
-            id = serviceFundVO.getId();
-        }
-        List<ServiceFunddetail> serviceFunddetails = serviceFundVO.getServiceFunddetails();
 
-        double taxBefore = 0.0;
-        double taxAfter = 0.0;
-        for (ServiceFunddetail serviceFunddetail : serviceFunddetails) {
-            serviceFunddetail.setFundid(id);
-            log.info("serviceFunddetail鐨勫�间负 : {}", serviceFunddetail);
-            if (serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getAmount() != null && serviceFunddetail.getTaxedamount() != 0.0 && serviceFunddetail.getAmount() != 0.0) {
-                // 绋庡墠绋庡悗閮戒笉涓虹┖
-                if (serviceFunddetail.getId() == null) {
-                    serviceFunddetailService.save(serviceFunddetail);
-                } else {
-                    serviceFunddetailService.updateById(serviceFunddetail);
-                }
-                continue;
-            } else if (serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getTaxedamount() != 0.0) {
-                // 绋庡悗姹傜◣鍓�,濡傛灉鏄笓瀹惰垂鐢宠  鎴� 浼︾悊涓撳璐圭敵璇�   鎵嶄細璁$畻绋庡墠绋庡悗
-                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
-                    Double taxationBefore = Double.valueOf(TaxtUtils.getTaxationBefore(BigDecimal.valueOf(serviceFunddetail.getTaxedamount())));
-                    // 绋庨噾
-                    String taxation = TaxtUtils.getTaxation(BigDecimal.valueOf(taxationBefore));
-                    serviceFunddetail.setAmount(Double.valueOf(taxationBefore));
-                    serviceFunddetail.setTaxamount(Double.parseDouble(taxation));
-                }
-            } else if (serviceFunddetail.getAmount() != null && serviceFunddetail.getAmount() != 0.0) {
-                // 绋庡墠姹傜◣鍚�,濡傛灉鏄笓瀹惰垂鐢宠  鎴� 浼︾悊涓撳璐圭敵璇�   鎵嶄細璁$畻绋庡墠绋庡悗
-                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
-                    double tax = Double.parseDouble(TaxtUtils.getTaxation(BigDecimal.valueOf(serviceFunddetail.getAmount())));
-                    BigDecimal taxAfterMoney = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(BigDecimal.valueOf(tax));
-                    serviceFunddetail.setTaxamount(tax);
-                    serviceFunddetail.setTaxedamount(taxAfterMoney.doubleValue());
-                }
-            }
-
-            //鏍规嵁id鍒ゆ柇鏄柊澧炶繕鏄慨鏀�
-            if (serviceFunddetail.getId() == null) {
-                serviceFunddetailService.save(serviceFunddetail);
-            } else {
-                serviceFunddetailService.updateById(serviceFunddetail);
-            }
-            if (serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
-                //濡傛灉鏄笓瀹惰垂鐢宠  鎴� 浼︾悊涓撳璐圭敵璇�   鎵嶄細璁$畻绋庡墠绋庡悗
-                taxBefore = taxBefore + serviceFunddetail.getAmount();
-                taxAfter = taxAfter + serviceFunddetail.getTaxedamount();
-            }
-        }
-        //灏嗙◣鍓嶃�佺◣鍚庨噾棰濇洿鏂板埌fund琛ㄤ腑
-        serviceFundVO.setPretaxcost(taxBefore);
-        serviceFundVO.setTaxedcost(taxAfter);
-        serviceFundService.updateById(serviceFundVO);
-//        //灏嗚绠楀ソ鐨勬暟鎹紝淇濆瓨鍒癲etail琛ㄤ腑
-//        serviceFunddetailService.saveBatch(serviceFunddetails);
-        return AjaxResult.success(id);
+        return AjaxResult.success(serviceFundService.addOrUpdateNew(serviceFundVO));
     }
 
 
diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/IServiceFundService.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/IServiceFundService.java
index 2cb77c7..ea57e34 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/IServiceFundService.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/IServiceFundService.java
@@ -1,6 +1,7 @@
 package com.ruoyi.project.service;
 
 import java.util.List;
+
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.project.domain.ServiceFund;
 import com.ruoyi.project.domain.ServiceFunddetail;
@@ -9,16 +10,15 @@
 
 /**
  * 璐圭敤鐢宠涓籗ervice鎺ュ彛
- * 
+ *
  * @author ruoyi
  * @date 2022-01-24
  */
-public interface IServiceFundService extends IService<ServiceFund>
-{
+public interface IServiceFundService extends IService<ServiceFund> {
 
     /**
      * 鏌ヨ璐圭敤鐢宠涓诲垪琛�
-     * 
+     *
      * @param serviceFund 璐圭敤鐢宠涓�
      * @return 璐圭敤鐢宠涓婚泦鍚�
      */
@@ -29,11 +29,11 @@
     List<ServiceFund> getInfoByInfoId(Long infoid);
 
 
-
     Long getFundId(Long infoid);
 
     /**
      * 寰�鍒嗕韩琛ㄤ腑娣诲姞鏁版嵁
+     *
      * @param id
      * @return
      */
@@ -52,7 +52,9 @@
 
     String returnId(Long id);
 
-    List<SpFinancialExpensesFundOut> getListBypower(String PAUSERNO, Integer PAFUNDTYPE, String PAAPPLICANT, String PAAPPLICATIONBEGTIME, String PAAPPLICATIONENDTIME, String PADEPARTMENT,Integer CHECKFLAG,Integer APPLYTYPE);
+    List<SpFinancialExpensesFundOut> getListBypower(String PAUSERNO, Integer PAFUNDTYPE, String PAAPPLICANT, String PAAPPLICATIONBEGTIME, String PAAPPLICATIONENDTIME, String PADEPARTMENT, Integer CHECKFLAG, Integer APPLYTYPE);
 
     int countItem(Long infoid, Long itemid);
+
+    Long addOrUpdateNew(ServiceFundVO serviceFundVO);
 }
diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
index 198c7b7..38adfd8 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFundServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ruoyi.project.service.impl;
 
 import java.io.File;
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -9,13 +10,16 @@
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.config.RuoYiConfig;
+import com.ruoyi.common.tax.TaxtUtils;
 import com.ruoyi.common.utils.HttpClientKit;
 import com.ruoyi.common.utils.bean.DtoConversionUtils;
 import com.ruoyi.project.domain.*;
 import com.ruoyi.project.domain.vo.*;
 import com.ruoyi.project.mapper.*;
 import com.ruoyi.project.service.IServiceFundSharedService;
+import com.ruoyi.project.service.IServiceFunddetailService;
 import com.ruoyi.project.service.IServiceFunddetailSharedService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -31,6 +35,7 @@
  * @author ruoyi
  * @date 2022-01-24
  */
+@Slf4j
 @Service
 public class ServiceFundServiceImpl extends ServiceImpl<ServiceFundMapper, ServiceFund> implements IServiceFundService {
     @Autowired
@@ -56,6 +61,9 @@
 
     @Autowired
     IServiceFunddetailSharedService detailSharedService;
+
+    @Autowired
+    private IServiceFunddetailService serviceFunddetailService;
 
 
     /**
@@ -659,6 +667,72 @@
         return count;
     }
 
+    @Override
+    @Transactional
+    public Long addOrUpdateNew(ServiceFundVO serviceFundVO) {
+        Long id = null;
+        if (serviceFundVO.getId() == null) {
+            save(serviceFundVO);
+            id = serviceFundVO.getId();
+        } else {
+            updateById(serviceFundVO);
+            id = serviceFundVO.getId();
+        }
+        List<ServiceFunddetail> serviceFunddetails = serviceFundVO.getServiceFunddetails();
+
+        // 鐢ㄤ簬璁板綍绋庡墠銆佺◣鍚庣殑鎬诲拰
+        double taxBefore = 0.0;
+        double taxAfter = 0.0;
+
+        for (ServiceFunddetail serviceFunddetail : serviceFunddetails) {
+            serviceFunddetail.setFundid(id);
+            if (serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getAmount() != null && serviceFunddetail.getTaxedamount() != 0.0 && serviceFunddetail.getAmount() != 0.0) {
+                // 绋庡墠绋庡悗閮戒笉涓虹┖
+                if (serviceFunddetail.getId() == null) {
+                    serviceFunddetailService.save(serviceFunddetail);
+                } else {
+                    serviceFunddetailService.updateById(serviceFunddetail);
+                }
+                continue;
+            } else if (serviceFunddetail.getTaxedamount() != null && serviceFunddetail.getTaxedamount() != 0.0) {
+                // 绋庡悗姹傜◣鍓�,濡傛灉鏄笓瀹惰垂鐢宠  鎴� 浼︾悊涓撳璐圭敵璇�   鎵嶄細璁$畻绋庡墠绋庡悗
+                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
+                    Double taxationBefore = Double.valueOf(TaxtUtils.getTaxationBefore(BigDecimal.valueOf(serviceFunddetail.getTaxedamount())));
+                    // 绋庨噾
+                    String taxation = TaxtUtils.getTaxation(BigDecimal.valueOf(taxationBefore));
+                    serviceFunddetail.setAmount(Double.valueOf(taxationBefore));
+                    serviceFunddetail.setTaxamount(Double.parseDouble(taxation));
+                }
+            } else if (serviceFunddetail.getAmount() != null && serviceFunddetail.getAmount() != 0.0) {
+                // 绋庡墠姹傜◣鍚�,濡傛灉鏄笓瀹惰垂鐢宠  鎴� 浼︾悊涓撳璐圭敵璇�   鎵嶄細璁$畻绋庡墠绋庡悗
+                if (StringUtils.isNotEmpty(serviceFundVO.getApplytype()) && serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
+                    double tax = Double.parseDouble(TaxtUtils.getTaxation(BigDecimal.valueOf(serviceFunddetail.getAmount())));
+                    BigDecimal taxAfterMoney = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(BigDecimal.valueOf(tax));
+                    serviceFunddetail.setTaxamount(tax);
+                    serviceFunddetail.setTaxedamount(taxAfterMoney.doubleValue());
+                }
+            }
+
+            //鏍规嵁id鍒ゆ柇鏄柊澧炶繕鏄慨鏀�
+            if (serviceFunddetail.getId() == null) {
+                serviceFunddetailService.save(serviceFunddetail);
+            } else {
+                serviceFunddetailService.updateById(serviceFunddetail);
+            }
+            if (serviceFundVO.getApplytype().equals("1") || serviceFundVO.getApplytype().equals("2")) {
+                //濡傛灉鏄笓瀹惰垂鐢宠  鎴� 浼︾悊涓撳璐圭敵璇�   鎵嶄細璁$畻绋庡墠绋庡悗
+                taxBefore = taxBefore + serviceFunddetail.getAmount();
+                taxAfter = taxAfter + serviceFunddetail.getTaxedamount();
+            }
+        }
+        //灏嗙◣鍓嶃�佺◣鍚庨噾棰濇洿鏂板埌fund琛ㄤ腑
+        serviceFundVO.setPretaxcost(taxBefore);
+        serviceFundVO.setTaxedcost(taxAfter);
+        updateById(serviceFundVO);
+
+        return id;
+    }
+
     int uploadOAFileAndUpdateDb(ServiceFundShared remShare) {
         //涓婁紶OA鏂囦欢
         //String strUrl = "http://129.88.242.39:8899/seeyon/rest/token?userName=opo&password=127814f8-84e8-4304-84a5-a71573567efd&loginName=demo3";

--
Gitblit v1.9.3