From b1f41c066b0b7c38faffddbfe73b9be8d0bd508e Mon Sep 17 00:00:00 2001
From: yxh <172933527@qq.com>
Date: 星期日, 08 十一月 2026 23:42:09 +0800
Subject: [PATCH] 修改了增值税城建税

---
 ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java |  452 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 419 insertions(+), 33 deletions(-)

diff --git a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
index f7add24..6bf6c64 100644
--- a/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
+++ b/ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
@@ -1,17 +1,29 @@
 package com.ruoyi.project.service.impl;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
 import java.time.LocalDate;
+import java.time.ZoneId;
 import java.time.temporal.TemporalAdjusters;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
 
+import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.tax.PerformanceTaxtUtils;
 import com.ruoyi.common.tax.TaxtUtils;
+import com.ruoyi.common.tax.VatTaxUtils;
+import com.ruoyi.common.utils.bean.DtoConversionUtils;
 import com.ruoyi.project.domain.*;
-import com.ruoyi.project.domain.vo.TaxMoneyVO;
-import com.ruoyi.project.domain.vo.TaxedMoneyVO;
+import com.ruoyi.project.domain.vo.*;
 import com.ruoyi.project.mapper.ServiceFundMapper;
+import com.ruoyi.project.mapper.SpStatBonusMapper;
+import lombok.extern.flogger.Flogger;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@@ -20,6 +32,7 @@
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.project.mapper.ServiceFunddetailMapper;
 import com.ruoyi.project.service.IServiceFunddetailService;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * 璐圭敤鐢宠鏄庣粏Service涓氬姟灞傚鐞�
@@ -27,14 +40,18 @@
  * @author ruoyi
  * @date 2022-01-25
  */
+@Slf4j
 @Service
 public class ServiceFunddetailServiceImpl extends ServiceImpl<ServiceFunddetailMapper, ServiceFunddetail> implements IServiceFunddetailService {
-
+    protected final Logger logger = LoggerFactory.getLogger(this.getClass());
     @Autowired
     ServiceFunddetailMapper serviceFunddetailMapper;
 
     @Autowired
     ServiceFundMapper serviceFundMapper;
+
+    @Autowired
+    SpStatBonusMapper spStatBonusMapper;
 
 
     /**
@@ -76,6 +93,24 @@
         if (serviceFunddetail.getUploadtime() != null) {
             wrappers.eq(ServiceFunddetail::getUploadtime, serviceFunddetail.getUploadtime());
         }
+        if (serviceFunddetail.getJxrq() != null) {
+            wrappers.like(ServiceFunddetail::getJxrq, serviceFunddetail.getJxrq());
+        }
+        if (StringUtils.isNotBlank(serviceFunddetail.getIdcardno())) {
+            wrappers.eq(ServiceFunddetail::getIdcardno, serviceFunddetail.getIdcardno());
+        }
+        if (StringUtils.isNotBlank(serviceFunddetail.getApplytype())) {
+            wrappers.eq(ServiceFunddetail::getApplytype, serviceFunddetail.getApplytype());
+        }
+        if (serviceFunddetail.getDel_flag() != null) {
+            wrappers.eq(ServiceFunddetail::getDel_flag, serviceFunddetail.getDel_flag());
+        }
+        if (serviceFunddetail.getDeptId() != null) {
+            wrappers.eq(ServiceFunddetail::getDeptId, serviceFunddetail.getDeptId());
+        }
+        if (serviceFunddetail.getDeptName() != null) {
+            wrappers.eq(ServiceFunddetail::getDeptName, serviceFunddetail.getDeptName());
+        }
         return this.list(wrappers);
     }
 
@@ -95,55 +130,73 @@
     }
 
     /**
-     * 鏍规嵁鍙楃泭浜虹紪鍙疯幏鍙栫◣璐归噾棰�
+     * 鏍规嵁鍙楃泭浜鸿韩浠借瘉缂栧彿鑾峰彇绋庤垂閲戦
      *
      * @param taxMoneyVo
      * @return
      */
     @Override
-    public Double getTaxBeforeByBeneFiciaryNo(TaxMoneyVO taxMoneyVo) {
-        Double sum = 0.00;
-        Double totalScore = 0.00;
+    public Double getTaxByBeneFiciaryNo(TaxMoneyVO taxMoneyVo) {
+        // 閲戦绱姞蹇呴』鐢� BigDecimal锛歞ouble 绱姞浼氬紩鍏ユ诞鐐瑰熬宸紝瀵艰嚧绠楀嚭鐨勪釜绋庡嚭鐜板垎浠ヤ笅璇樊
+        BigDecimal sum = BigDecimal.ZERO;
+        BigDecimal totalScore = BigDecimal.ZERO;
         List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo);
         if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) {
             //璁$畻鐢宠閲戦鎬诲拰锛屼笉鍖呮嫭褰撳墠浼犺繘鏉ョ殑
-            sum = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getAmount).sum();
+            sum = taxationByBeneFiciaryNo.stream()
+                    .map(ServiceFunddetail::getAmount)
+                    .filter(java.util.Objects::nonNull)
+                    .map(BigDecimal::valueOf)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
             //涓嶅姞鏈钖叕鐨勪釜绋�
-            totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum();
+            totalScore = taxationByBeneFiciaryNo.stream()
+                    .map(ServiceFunddetail::getTaxamount)
+                    .filter(java.util.Objects::nonNull)
+                    .map(BigDecimal::valueOf)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
         }
 
-        sum = sum + new Double(taxMoneyVo.getMoney());
+        sum = sum.add(new BigDecimal(taxMoneyVo.getMoney()));
         //鍔犱笂鏈钖叕鐨勬�讳釜绋�
-        String taxation = TaxtUtils.getTaxation(new BigDecimal(sum));
+        String taxation = TaxtUtils.getTaxation(sum);
 
-        Double tax = Double.valueOf(taxation) - totalScore;
+        Double tax = new BigDecimal(taxation).subtract(totalScore).doubleValue();
         return tax;
     }
 
     /**
      * 鏍规嵁绋庡悗宸ヨ祫锛岀畻鍑虹◣鍓嶅伐璧�
      *
-     * @param money
+     * @param taxMoneyVo
      * @return
      */
     @Override
     public TaxedMoneyVO getTaxBeforeByAfterMoney(TaxMoneyVO taxMoneyVo) {
         TaxedMoneyVO taxedMoneyVO = new TaxedMoneyVO();
-        Double sum = 0.00;
-        Double totalScore = 0.00;
+        // 閲戦绱姞蹇呴』鐢� BigDecimal锛岄伩鍏嶆诞鐐瑰熬宸奖鍝嶇◣鍓�/绋庨缁撴灉
+        BigDecimal sum = BigDecimal.ZERO;
+        BigDecimal totalScore = BigDecimal.ZERO;
         List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo);
         if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) {
             //璁$畻鍑虹◣鍚庢�婚噾棰濓紙涓嶅寘鍚湰娆★級
-            sum = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxedamount).sum();
+            sum = taxationByBeneFiciaryNo.stream()
+                    .map(ServiceFunddetail::getTaxedamount)
+                    .filter(java.util.Objects::nonNull)
+                    .map(BigDecimal::valueOf)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
             //姹傚嚭涔嬪墠鐨勬�荤殑涓◣
-            totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum();
+            totalScore = taxationByBeneFiciaryNo.stream()
+                    .map(ServiceFunddetail::getTaxamount)
+                    .filter(java.util.Objects::nonNull)
+                    .map(BigDecimal::valueOf)
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
         }
         //璁$畻鍑烘�荤殑绋庡悗钖叕锛堝寘鍚湰娆★級
-        sum = sum + taxMoneyVo.getMoney();
+        sum = sum.add(new BigDecimal(taxMoneyVo.getMoney()));
         //绋庡墠鎬婚噾棰�
-        String taxationBefore = TaxtUtils.getTaxationBefore(new BigDecimal(sum));
+        String taxationBefore = TaxtUtils.getTaxationBefore(sum);
         //鎬讳釜绋�
-        BigDecimal tax = new BigDecimal(taxationBefore).subtract(new BigDecimal(sum));
+        BigDecimal tax = new BigDecimal(taxationBefore).subtract(sum);
 
         //鏈鐨勭◣鍓嶉噾棰�
         String nowTaxMoney = TaxtUtils.getTaxationBefore(new BigDecimal(taxMoneyVo.getMoney()));
@@ -200,20 +253,353 @@
         ServiceFunddetail serviceFunddetail = serviceFunddetailMapper.selectById(id);
         Long fundid = serviceFunddetail.getFundid();
         ServiceFund serviceFund = serviceFundMapper.selectById(fundid);
+        if (ObjectUtils.isNotEmpty(serviceFund)) {
+            // 閲戦涓�寰嬬敤 BigDecimal 绱姞/鎵e噺锛岄伩鍏嶆诞鐐瑰熬宸�
+            BigDecimal pretax = toMoney(serviceFund.getPretaxcost()).subtract(toMoney(serviceFunddetail.getAmount()));
+            BigDecimal aftertax = toMoney(serviceFund.getTaxedcost()).subtract(toMoney(serviceFunddetail.getTaxedamount()));
+            BigDecimal vat = toMoney(serviceFund.getVatCost()).subtract(toMoney(serviceFunddetail.getVatAmount()));
+            BigDecimal cityTax = toMoney(serviceFund.getCityTaxCost()).subtract(toMoney(serviceFunddetail.getCityTaxAmount()));
+            BigDecimal laborPretax = toMoney(serviceFund.getLaborPretaxCost()).subtract(toMoney(serviceFunddetail.getLaborPretaxAmount()));
+            BigDecimal tax = toMoney(serviceFund.getTaxcost()).subtract(toMoney(serviceFunddetail.getTaxamount()));
+            BigDecimal amount = pretax.add(aftertax);
 
-        Double pretax = serviceFund.getPretaxcost();
-        Double aftertax = serviceFund.getTaxedcost();
-        pretax = pretax - serviceFunddetail.getAmount();
-        aftertax = aftertax - serviceFunddetail.getTaxedamount();
-        Double amount = pretax + aftertax;
-
-        serviceFund.setPretaxcost(pretax);
-        serviceFund.setTaxedcost(aftertax);
-        serviceFund.setAmountrequested(amount);
-        int updateAmount = serviceFundMapper.updateById(serviceFund);
-
+            serviceFund.setPretaxcost(pretax.doubleValue());
+            serviceFund.setTaxedcost(aftertax.doubleValue());
+            serviceFund.setVatCost(vat.doubleValue());
+            serviceFund.setCityTaxCost(cityTax.doubleValue());
+            serviceFund.setLaborPretaxCost(laborPretax.doubleValue());
+            serviceFund.setTaxcost(tax.doubleValue());
+            serviceFund.setAmountrequested(amount.doubleValue());
+            int updateAmount = serviceFundMapper.updateById(serviceFund);
+        }
         return serviceFunddetailMapper.deleteById(id);
     }
 
+    @Override
+    public List<ServiceFunddetailVO> getFundDetail(Long id) {
+        List<ServiceFunddetail> serviceFunddetails = serviceFunddetailMapper.selectFundDetailListById(id);
+        List<ServiceFunddetailVO> serviceFunddetailVOS = DtoConversionUtils.sourceToTarget(serviceFunddetails, ServiceFunddetailVO.class);
+        for (ServiceFunddetailVO serviceFunddetailVO : serviceFunddetailVOS) {
+            if (!StringUtils.isEmpty(serviceFunddetailVO.getAnnexfiles())) {
+                List<RbDetailFile> rbDetailFiles = JSONArray.parseArray(serviceFunddetailVO.getAnnexfiles(), RbDetailFile.class);
+                serviceFunddetailVO.setAnnexfilesList(rbDetailFiles);
+            }
+            if (!StringUtils.isEmpty(serviceFunddetailVO.getInvoicefiles())) {
+                List<RbDetailFile> rbDetailFiles = JSONArray.parseArray(serviceFunddetailVO.getInvoicefiles(), RbDetailFile.class);
+                serviceFunddetailVO.setInvoicefilesList(rbDetailFiles);
+            }
+        }
+        return serviceFunddetailVOS;
+    }
 
+    /**
+     * 鎵归噺绠楃◣涓绘柟娉曪紙鍔冲姟涓◣ + 澧炲�肩◣ + 鍩庡缓绋庯紝v2 鍙e緞锛�
+     * <p>
+     * 閲戦妯″瀷锛�
+     * <pre>
+     * 绋庡墠褰曞叆锛歏 = ceil(P 脳 1%)銆丆 = ceil(V 脳 3.5%)銆丩 = P - V - C銆�
+     *          T = 鍔冲姟涓◣(褰撴湀绱 L) - 鍘熺疮璁� T銆丯 = L - T
+     * 绋庡悗褰曞叆锛歂绱 = 鍘熺疮璁� N + N銆丩绱 = getTaxationBefore(N绱)銆�
+     *          L = L绱 - 鍘熺疮璁� L銆乀 = L - N銆丳/V/C = solveGross(L)
+     * 鏃犺韩浠借瘉锛歏 = C = T = 0锛孡 = N = P
+     * </pre>
+     *
+     * @param serviceFunddetails 璐圭敤鏄庣粏鍒楄〃
+     * @param tempTaxSumMap      鏈湀绱閲戦缂撳瓨锛堟寜韬唤璇佸彿锛�
+     * @return 鏄惁绠楃◣鎴愬姛
+     */
+    @Override
+    public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails, Map<String, TaxMoneySumEO> tempTaxSumMap) {
+        return calculateTax(serviceFunddetails, tempTaxSumMap, new Date());
+    }
+
+    /**
+     * 鎵归噺绠楃◣锛堟寚瀹氭湰鎵圭畻绋庢椂闂达紝淇濊瘉鍚屾壒鏄庣粏 tax_time 涓�鑷达級
+     *
+     * @param serviceFunddetails 璐圭敤鏄庣粏鍒楄〃
+     * @param tempTaxSumMap      鏈湀绱閲戦缂撳瓨锛堟寜韬唤璇佸彿锛�
+     * @param taxTime            鏈绠楃◣鏃堕棿
+     * @return 鏄惁绠楃◣鎴愬姛
+     */
+    @Override
+    public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails, Map<String, TaxMoneySumEO> tempTaxSumMap, Date taxTime) {
+        // 1. 鏍¢獙鍙傛暟
+        if (CollectionUtils.isEmpty(serviceFunddetails)) {
+            throw new BaseException("绠楃◣鏉′欢涓虹┖锛岃妫�鏌ュ悗锛屽啀杩涜璁$畻");
+        }
+        // 2. 鎺掑簭锛氱◣鏃堕棿涓虹┖鐨勬帓鍚庨潰锛屽啀鎸� id 淇濊瘉鍚屾壒椤哄簭绋冲畾
+        serviceFunddetails.sort(Comparator
+                .comparing((ServiceFunddetail obj) -> ObjectUtils.isEmpty(obj.getTaxTime()) ? 1 : 0)
+                .thenComparing(obj -> obj.getId() == null ? Long.MAX_VALUE : obj.getId()));
+
+        // 3. 鑾峰彇鏈壒娆� fundid 鍙婁富琛ㄤ俊鎭�
+        Long fundid = serviceFunddetails.get(0).getFundid();
+        log.info("绠楃◣鐨刦undid鐨勫�间负锛歿}", fundid);
+        ServiceFund serviceFund1 = serviceFundMapper.selectById(fundid);
+        if (serviceFund1 == null) {
+            throw new BaseException("鏈壘鍒拌垂鐢ㄧ敵璇峰崟锛孖D=" + fundid);
+        }
+        // 鏄庣粏 tax_time 缁熶竴浣跨敤鏈绠楃◣鏃堕棿
+        if (taxTime == null) {
+            taxTime = new Date();
+        }
+
+        // 4. 鏈壒娆″悎璁★紙鍏ㄩ儴鐢� BigDecimal锛岀姝� double 绱姞锛�
+        BigDecimal pretaxTotal = BigDecimal.ZERO;
+        BigDecimal vatTotal = BigDecimal.ZERO;
+        BigDecimal cityTaxTotal = BigDecimal.ZERO;
+        BigDecimal laborPretaxTotal = BigDecimal.ZERO;
+        BigDecimal taxTotal = BigDecimal.ZERO;
+        BigDecimal taxedTotal = BigDecimal.ZERO;
+
+        List<ServiceFunddetail> updateList = new ArrayList<>();
+
+        // 5. 閬嶅巻姣忔潯鏄庣粏
+        for (ServiceFunddetail detail : serviceFunddetails) {
+            if (detail.getAmount() == null) {
+                detail.setAmount(0.0);
+            }
+            if (detail.getTaxedamount() == null) {
+                detail.setTaxedamount(0.0);
+            }
+            // 鏈嶅姟璇存槑涓虹┖鎸夆�滈潪绋庡悗鈥濆鐞�
+            String scopeName = detail.getServicesscopename() == null ? "" : detail.getServicesscopename().trim();
+            boolean afterTax = scopeName.contains("绋庡悗");
+
+            // 5.1 韬唤璇佸彿涓虹┖锛氫笉鎵e鍊肩◣/鍩庡缓绋�/鍔冲姟涓◣
+            if (StringUtils.isEmpty(detail.getIdcardno())) {
+                BigDecimal p = afterTax ? toMoney(detail.getTaxedamount()) : toMoney(detail.getAmount());
+                detail.setAmount(p.doubleValue());
+                detail.setVatAmount(0.0);
+                detail.setCityTaxAmount(0.0);
+                detail.setLaborPretaxAmount(p.doubleValue());
+                detail.setTaxamount(0.0);
+                detail.setTaxedamount(p.doubleValue());
+                detail.setTaxVersion(VatTaxUtils.TAX_VERSION_V2);
+                detail.setTaxTime(taxTime);
+                updateList.add(detail);
+
+                pretaxTotal = pretaxTotal.add(p);
+                laborPretaxTotal = laborPretaxTotal.add(p);
+                taxedTotal = taxedTotal.add(p);
+                continue;
+            }
+
+            // 5.2 韬唤璇佸彿涓嶄负绌猴細鏈湀绱 + 鍒嗘。绠楃◣
+            String idcard = detail.getIdcardno().trim();
+
+            // 5.2.1 鍙栨湰鏈堢疮璁★紙缂撳瓨閬垮厤閲嶅鏌ュ簱锛�
+            TaxMoneySumEO taxSum = tempTaxSumMap.get(idcard);
+            if (taxSum == null) {
+                taxSum = new TaxMoneySumEO();
+                taxSum.setXh(0L);
+                tempTaxSumMap.put(idcard, taxSum);
+            }
+            long xh = (taxSum.getXh() == null ? 0L : taxSum.getXh()) + 1;
+            taxSum.setXh(xh);
+            detail.setXh(xh);
+            // 绱绋庡墠閲戦锛堜笉鍚湰绗旓級锛岀敤浜庨〉闈㈠睍绀�
+            detail.setAllAmount(taxSum.getAmounts());
+
+            BigDecimal prevAmount = toMoney(taxSum.getAmounts());
+            BigDecimal prevLaborPretax = toMoney(taxSum.getLaborPretaxAmounts());
+            BigDecimal prevTax = toMoney(taxSum.getTaxAmounts());
+            BigDecimal prevTaxed = toMoney(taxSum.getTaxedAmounts());
+            BigDecimal prevVat = toMoney(taxSum.getVatAmounts());
+            BigDecimal prevCityTax = toMoney(taxSum.getCityTaxAmounts());
+
+            BigDecimal pretax;
+            BigDecimal vat;
+            BigDecimal cityTax;
+            BigDecimal laborPretax;
+            BigDecimal taxAmount;
+            BigDecimal taxedAmount;
+
+            if (afterTax) {
+                // 5.2.2 绋庡悗褰曞叆锛氬厛鍙嶇畻鍔冲姟绋庡墠锛屽啀寰幆鍙嶈В绋庡墠/澧炲�肩◣/鍩庡缓绋�
+                taxedAmount = toMoney(detail.getTaxedamount());
+                BigDecimal sumTaxed = prevTaxed.add(taxedAmount);
+                BigDecimal sumLaborPretax = new BigDecimal(TaxtUtils.getTaxationBefore(sumTaxed));
+                laborPretax = VatTaxUtils.roundMoney(sumLaborPretax.subtract(prevLaborPretax));
+                if (laborPretax.signum() < 0) {
+                    // 閫愮瑪鍚戜笂鍙栨暣鍙兘甯︽潵鍑犲垎閽辩殑鍙嶇畻璇樊锛屽宸唴鎸� 0 澶勭悊锛涜秴鍑哄宸鏄庢暟鎹紓甯�
+                    if (laborPretax.abs().compareTo(new BigDecimal("0.05")) <= 0) {
+                        log.warn("绋庡悗閲戦鍙嶇畻鍔冲姟绋庡墠鍑虹幇璐熷熬宸紝宸叉寜 0 澶勭悊銆備汉鍛橈細{}锛屽弽绠楀姵鍔$◣鍓�={}锛屽師绱鍔冲姟绋庡墠={}",
+                                safeName(detail), sumLaborPretax, prevLaborPretax);
+                        laborPretax = BigDecimal.ZERO;
+                    } else {
+                        throw new BaseException("绋庡悗閲戦鍙嶇畻鍔冲姟绋庡墠澶辫触锛屼汉鍛橈細" + safeName(detail));
+                    }
+                }
+                taxAmount = VatTaxUtils.roundMoney(laborPretax.subtract(taxedAmount));
+                if (taxAmount.signum() < 0) {
+                    taxAmount = BigDecimal.ZERO;
+                }
+                VatTaxUtils.GrossAmount gross = VatTaxUtils.solveGross(laborPretax);
+                pretax = gross.getPretax();
+                vat = gross.getVat();
+                cityTax = gross.getCityTax();
+            } else {
+                // 5.2.3 绋庡墠褰曞叆锛氬厛绠楀鍊肩◣/鍩庡缓绋�/鍔冲姟绋庡墠锛屽啀鎸夌疮璁″姵鍔$◣鍓嶇畻鍔冲姟涓◣
+                pretax = toMoney(detail.getAmount());
+                vat = VatTaxUtils.calcVat(pretax);
+                cityTax = VatTaxUtils.calcCityTax(vat);
+                laborPretax = VatTaxUtils.roundMoney(pretax.subtract(vat).subtract(cityTax));
+                BigDecimal sumLaborPretax = prevLaborPretax.add(laborPretax);
+                BigDecimal sumTax = new BigDecimal(TaxtUtils.getTaxation(sumLaborPretax));
+                taxAmount = VatTaxUtils.roundMoney(sumTax.subtract(prevTax));
+                if (taxAmount.signum() < 0) {
+                    taxAmount = BigDecimal.ZERO;
+                }
+                taxedAmount = VatTaxUtils.roundMoney(laborPretax.subtract(taxAmount));
+            }
+
+            detail.setAmount(pretax.doubleValue());
+            detail.setVatAmount(vat.doubleValue());
+            detail.setCityTaxAmount(cityTax.doubleValue());
+            detail.setLaborPretaxAmount(laborPretax.doubleValue());
+            detail.setTaxamount(taxAmount.doubleValue());
+            detail.setTaxedamount(taxedAmount.doubleValue());
+            detail.setTaxVersion(VatTaxUtils.TAX_VERSION_V2);
+            detail.setTaxTime(taxTime);
+            updateList.add(detail);
+
+            // 5.2.4 鏇存柊鏈湀绱
+            taxSum.setAmounts(prevAmount.add(pretax).doubleValue());
+            taxSum.setVatAmounts(prevVat.add(vat).doubleValue());
+            taxSum.setCityTaxAmounts(prevCityTax.add(cityTax).doubleValue());
+            taxSum.setLaborPretaxAmounts(prevLaborPretax.add(laborPretax).doubleValue());
+            taxSum.setTaxAmounts(prevTax.add(taxAmount).doubleValue());
+            taxSum.setTaxedAmounts(prevTaxed.add(taxedAmount).doubleValue());
+
+            pretaxTotal = pretaxTotal.add(pretax);
+            vatTotal = vatTotal.add(vat);
+            cityTaxTotal = cityTaxTotal.add(cityTax);
+            laborPretaxTotal = laborPretaxTotal.add(laborPretax);
+            taxTotal = taxTotal.add(taxAmount);
+            taxedTotal = taxedTotal.add(taxedAmount);
+        }
+
+        // 6. 鎵归噺鏇存柊鎵�鏈夋槑缁�
+        for (ServiceFunddetail d : updateList) {
+            this.updateById(d);
+        }
+
+        // 7. 鏇存柊涓昏〃 service_fund 鐨� 6 涓噾棰濄�佺畻绋庢椂闂淬�佺姸鎬併�佺増鏈�
+        ServiceFund serviceFund = new ServiceFund();
+        serviceFund.setId(fundid);
+        serviceFund.setPretaxcost(pretaxTotal.doubleValue());
+        serviceFund.setVatCost(vatTotal.doubleValue());
+        serviceFund.setCityTaxCost(cityTaxTotal.doubleValue());
+        serviceFund.setLaborPretaxCost(laborPretaxTotal.doubleValue());
+        serviceFund.setTaxcost(taxTotal.doubleValue());
+        serviceFund.setTaxedcost(taxedTotal.doubleValue());
+        serviceFund.setTaxVersion(VatTaxUtils.TAX_VERSION_V2);
+        serviceFund.setFundtaxtime(taxTime);
+        serviceFund.setIstax(1);
+        serviceFundMapper.updateById(serviceFund);
+        return true;
+    }
+
+    /**
+     * null 瀹夊叏鐨勯噾棰濊浆鎹�
+     */
+    private static BigDecimal toMoney(Double value) {
+        return value == null ? BigDecimal.ZERO : BigDecimal.valueOf(value);
+    }
+
+    /**
+     * 鎶ラ敊鏃惰兘瀹氫綅鍒板叿浣撲汉鍛�
+     */
+    private static String safeName(ServiceFunddetail detail) {
+        String name = detail.getBeneficiaryname() == null ? "" : detail.getBeneficiaryname();
+        String idcard = detail.getIdcardno() == null ? "" : detail.getIdcardno();
+        return name + "(" + idcard + ")";
+    }
+
+//    @Override
+//    public Boolean calculateTax2(List<ServiceFunddetail> serviceFunddetails) {
+//        //鐢ㄤ簬缂撳瓨姣忎釜韬唤璇佸彿锛坕dcardno锛夋湰鏈堢疮璁$殑绋庡墠銆佺◣閲戙�佺◣鍚庨噾棰濓紙TaxMoneySumEO瀵硅薄锛�
+//        Map<String, TaxMoneySumEO> tempTaxSumMap = new HashMap<>();
+//
+//        TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO();
+//        Date firstDay = Date.from(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant());
+//        taxMoneyVO.setFirstDay(firstDay);
+//        taxMoneyVO.setTaxTime(new Date());
+//
+//        List<TaxMoneySumEO> taxSum = serviceFunddetailMapper.getTaxSum(taxMoneyVO);
+//        for (TaxMoneySumEO taxMoneySumEO : taxSum) {
+//            tempTaxSumMap.put(taxMoneySumEO.getIDCardNo(), taxMoneySumEO);
+//        }
+//
+//        return calculateTax(serviceFunddetails, tempTaxSumMap);
+//    }
+
+
+    @Override
+    public Map<String, Double> performance(ServiceFunddetail serviceFunddetail) {
+        //鏍规嵁"韬唤璇佸彿"鍜�"缁╂晥鏃ユ湡(骞翠唤)"鏌ヨ涓汉鍘嗗彶缁╂晥
+        ServiceFunddetail serviceFunddetailEo = new ServiceFunddetail();
+        serviceFunddetailEo.setIdcardno(serviceFunddetail.getIdcardno());
+        serviceFunddetailEo.setApplytype("5");
+        Calendar cal = Calendar.getInstance();
+        //榛樿鏈勾搴�
+        serviceFunddetailEo.setJxrq(String.valueOf(cal.get(Calendar.YEAR)));
+        List<ServiceFunddetail> serviceFunddetails = queryList(serviceFunddetailEo);
+
+        //缁熻鍘嗗彶鐨勭◣
+        BigDecimal historyTax = BigDecimal.valueOf(0.00);
+        //璁$畻鎵e幓姣忔湀5000鐨勫巻鍙茬◣鍓嶉噾棰�
+        BigDecimal historyTaxBefore = BigDecimal.valueOf(0.00);
+        //鏈湀鏄惁宸茬粡绠楄繃缁╂晥锛堜笅闈㈡墸闄�5000闇�瑕佺敤鍒拌繖涓紝濡傛灉鏈湀宸茬粡鎵h繃5000锛屽氨涓嶅啀鎵d簡锛�
+        Boolean deduct = false;
+        //鑾峰彇褰撳墠鏈堜唤
+        Date date = new Date();
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
+        String nowMonth = sdf.format(date);
+
+        for (ServiceFunddetail serviceFunddetail1 : serviceFunddetails) {
+            historyTaxBefore = historyTaxBefore.add(BigDecimal.valueOf(serviceFunddetail1.getAmount())).subtract(BigDecimal.valueOf(5000));
+            historyTax = historyTax.add(BigDecimal.valueOf(serviceFunddetail1.getTaxamount()));
+            if (serviceFunddetail1.getJxrq().equals(nowMonth)) {
+                deduct = true;
+            }
+        }
+        BigDecimal allValue = BigDecimal.valueOf(0.00);
+        //鍏堟煡璇竴涓嬫湰鏈堟槸鍚﹀凡缁忕畻杩囩哗鏁堬紙涓�涓湀鍙噺涓�娆�5000锛屽鏋滀笂涓�娆″凡缁忓噺杩囷紝杩欎竴娆″氨涓嶅湪鍑忎簡锛�
+        if (deduct == true) {
+            //鏈湀宸茬粡鍑忚繃5000浜�
+            allValue = historyTaxBefore.add(BigDecimal.valueOf(serviceFunddetail.getAmount()));
+        } else {
+            BigDecimal subtract = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(BigDecimal.valueOf(5000));
+            allValue = historyTaxBefore.add(subtract);
+        }
+        //璁$畻鍔犱笂鏈鐨勭◣鍓嶉噾棰濈殑鎬荤◣
+        BigDecimal personTaxation = PerformanceTaxtUtils.getPersonTaxation(allValue);
+        //璁$畻鏈鐨勭◣
+        BigDecimal nowSingleTax = personTaxation.subtract(historyTax);
+        //璁$畻鏈鐨勭◣鍚�
+        BigDecimal taxAfter = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(nowSingleTax);
+
+        //灏嗚绠楀嚭鏉ョ殑鏁版嵁鏀惧埌serviceFunddetail涓�
+        serviceFunddetail.setTaxamount(nowSingleTax.doubleValue());
+        serviceFunddetail.setTaxedamount(taxAfter.doubleValue());
+        // 缁╂晥涓嶅睘浜庝笓瀹惰垂锛氫笉璁$畻澧炲�肩◣/鍩庡缓绋庯紝鍔冲姟绋庡墠 = 绋庡墠閲戦
+        serviceFunddetail.setVatAmount(0.0);
+        serviceFunddetail.setCityTaxAmount(0.0);
+        serviceFunddetail.setLaborPretaxAmount(serviceFunddetail.getAmount());
+        serviceFunddetail.setJxrq(nowMonth);
+
+        save(serviceFunddetail);
+        Map map = new HashMap();
+        map.put("amount", serviceFunddetail.getAmount());
+        map.put("taxedamount", taxAfter.doubleValue());
+        return map;
+    }
+
+
+    @Override
+    public List<SpStatBonus> getListBySpStatBonus(SpStatBonusReq spStatBonusReq) {
+        return spStatBonusMapper.getListBySpStatBonus(spStatBonusReq.getPabegtime(), spStatBonusReq.getPaendtime(), spStatBonusReq.getPadeptno(), spStatBonusReq.getPausername());
+    }
 }

--
Gitblit v1.9.3