From 55aac55195dc2bd404042ec099045fee8ac73e81 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期三, 02 七月 2025 21:48:53 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java |  289 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 283 insertions(+), 6 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 afcc2ca..5717177 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,18 +1,28 @@
 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.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;
@@ -21,6 +31,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涓氬姟灞傚鐞�
@@ -28,14 +39,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;
 
 
     /**
@@ -77,6 +92,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);
     }
 
@@ -96,7 +129,7 @@
     }
 
     /**
-     * 鏍规嵁鍙楃泭浜虹紪鍙疯幏鍙栫◣璐归噾棰�
+     * 鏍规嵁鍙楃泭浜鸿韩浠借瘉缂栧彿鑾峰彇绋庤垂閲戦
      *
      * @param taxMoneyVo
      * @return
@@ -216,5 +249,249 @@
         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;
+    }
 
+    /**
+     * 鎵归噺绠楃◣涓绘柟娉�
+     * 1. 鏍¢獙鍙傛暟
+     * 2. 鎺掑簭鏄庣粏锛屼繚璇佺◣鏃堕棿涓虹┖鐨勬帓鍦ㄥ悗闈�
+     * 3. 閬嶅巻姣忔潯鏄庣粏锛屽垎韬唤璇佸彿涓虹┖鍜屼笉涓虹┖涓ょ鎯呭喌鍒嗗埆澶勭悊
+     * - 韬唤璇佸彿涓虹┖锛氱洿鎺ユ寜瑙勫垯璧嬪�肩◣鍚庨噾棰濄�佺◣閲�
+     * - 韬唤璇佸彿涓嶄负绌猴細
+     * a. 鏌ヨ鏈湀绗竴澶╋紝鑾峰彇鏈�澶у簭鍙�
+     * b. 鏌ヨ鏈湀绱绋庡墠銆佺◣閲戙�佺◣鍚庨噾棰�
+     * c. 鏍规嵁"绋庡墠/绋庡悗"绫诲瀷鍒嗗埆璁$畻绋庨噾銆佺◣鍚庨噾棰�
+     * d. 璁剧疆绠楃◣鏃堕棿銆佸簭鍙风瓑
+     * 4. 绱鏈壒娆℃�荤◣鍓嶃�佺◣鍚庨噾棰�
+     * 5. 鎵归噺鏇存柊鎵�鏈夋槑缁�
+     * 6. 鏇存柊涓昏〃ServiceFund鐨勬�婚噾棰濄�佺畻绋庢椂闂淬�佺姸鎬�
+     *
+     * @param serviceFunddetails 璐圭敤鏄庣粏鍒楄〃
+     * @return 鏄惁绠楃◣鎴愬姛
+     */
+    @Override
+    public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails, Map<String, TaxMoneySumEO> tempTaxSumMap) {
+        // 1. 鏍¢獙鍙傛暟
+        if (CollectionUtils.isEmpty(serviceFunddetails)) {
+            throw new BaseException("绠楃◣鏉′欢涓虹┖锛岃妫�鏌ュ悗锛屽啀杩涜璁$畻");
+        }
+        // 2. 鎺掑簭锛岀◣鏃堕棿涓虹┖鐨勬帓鍚庨潰
+        serviceFunddetails.sort(Comparator.comparing(obj -> ObjectUtils.isEmpty(obj.getTaxTime()) ? 1 : 0));
+
+        // 3. 鑾峰彇鏈壒娆undid鍙婁富琛ㄤ俊鎭�
+        Long fundid = serviceFunddetails.get(0).getFundid();
+        log.info("绠楃◣鐨刦undid鐨勫�间负锛歿}", fundid);
+        ServiceFund serviceFund1 = serviceFundMapper.selectById(fundid);
+        log.info("fund琛ㄧ殑fundtextime鍊间负锛歿}", serviceFund1.getFundtaxtime());
+        // 4. 鍒濆鍖栫疮璁¢噾棰濄�佸緟鏇存柊鏄庣粏鍒楄〃銆佸簭鍙风紦瀛樸�佺疮璁¢噾棰濈紦瀛�
+        BigDecimal pretaxcost = BigDecimal.ZERO;
+        BigDecimal taxedcost = BigDecimal.ZERO;
+
+        //鍒涘缓涓�涓敤浜庡瓨鏀锯�滈渶瑕佹洿鏂板埌鏁版嵁搴撶殑ServiceFunddetail瀵硅薄鈥濈殑鍒楄〃
+        List<ServiceFunddetail> updateList = new ArrayList<>();
+
+        // 5. 閬嶅巻姣忔潯鏄庣粏锛屽垎鎯呭喌澶勭悊
+        for (ServiceFunddetail detail : serviceFunddetails) {
+            // 5.1 韬唤璇佸彿涓虹┖锛岀洿鎺ヨ祴鍊硷紙涓�浜涗汉鎴栧叕鍙革紝涓嶉渶瑕佺畻绋庯級
+            if (StringUtils.isEmpty(detail.getIdcardno())) {
+                if (StringUtils.isEmpty(detail.getServicesscopename()) || !detail.getServicesscopename().contains("绋庡悗")) {
+                    // 鏅�氭槑缁嗭紝绋庡悗閲戦=鐢宠閲戦
+                    detail.setTaxedamount(detail.getAmount());
+                } else {
+                    // 绋庡悗鏄庣粏锛岀敵璇烽噾棰�=绋庡悗閲戦
+                    detail.setAmount(detail.getTaxedamount());
+                }
+                // 绱鏈壒娆℃�婚噾棰�
+                pretaxcost = pretaxcost.add(BigDecimal.valueOf(detail.getAmount()));
+                taxedcost = taxedcost.add(BigDecimal.valueOf(detail.getTaxedamount()));
+                detail.setTaxamount(0.0);
+                updateList.add(detail);
+                continue;
+            }
+
+            // 5.2 韬唤璇佸彿涓嶄负绌猴紝闇�鏌ュ巻鍙茬疮璁¢噾棰濄�佸簭鍙�
+            String idcard = detail.getIdcardno().trim();
+
+            // 5.2.1 鏌ヨ鏈湀绱閲戦锛堢紦瀛橀伩鍏嶉噸澶嶆煡搴擄級
+            TaxMoneySumEO taxSum = tempTaxSumMap.getOrDefault(idcard, null);
+            if (taxSum == null) {
+                taxSum = new TaxMoneySumEO();
+                taxSum.setXh(1L);
+                detail.setXh(1L);
+                tempTaxSumMap.put(idcard, taxSum);
+                detail.setAllAmount(taxSum.getAmounts());
+            } else {
+                long xh = taxSum.getXh() + 1;
+                taxSum.setXh(xh);
+                tempTaxSumMap.put(idcard, taxSum);
+                detail.setXh(xh);
+                detail.setAllAmount(taxSum.getAmounts());
+            }
+
+            // 5.2.3 绠楃◣閫昏緫
+            if (detail.getServicesscopename().contains("绋庡悗")) {
+                // 绋庡悗鏄庣粏锛氱疮璁$◣鍚庨噾棰濓紝鍙嶆帹绋庡墠閲戦鍜岀◣閲�
+                if (idcard.equals("330103196704060019")) {
+                    log.info("330103196704060019");
+                }
+                BigDecimal newTaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(BigDecimal.valueOf(detail.getTaxedamount()));
+                String taxationBefore = TaxtUtils.getTaxationBefore(newTaxedAmounts);
+                BigDecimal amountNow = new BigDecimal(taxationBefore).subtract(BigDecimal.valueOf(taxSum.getAmounts()));
+                BigDecimal tax = amountNow.subtract(BigDecimal.valueOf(detail.getTaxedamount()));
+                detail.setAmount(amountNow.doubleValue());
+                detail.setTaxamount(tax.doubleValue());
+                if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
+                    detail.setTaxTime(new Date());
+                } else {
+                    detail.setTaxTime(serviceFund1.getFundtaxtime());
+                }
+                if (tax.doubleValue() < 0) {
+                    log.info("灏忎簬0浜�");
+                }
+                taxSum.setAmounts((BigDecimal.valueOf(taxSum.getAmounts()).add(amountNow)).doubleValue());
+                taxSum.setTaxAmounts((BigDecimal.valueOf(taxSum.getTaxAmounts()).add(tax)).doubleValue());
+                taxSum.setTaxedAmounts(newTaxedAmounts.doubleValue());
+            } else {
+                // 绋庡墠鏄庣粏锛氱疮璁$◣鍓嶉噾棰濓紝绠楁�荤◣閲戯紝鍐嶇畻鏈绋庨噾鍜岀◣鍚庨噾棰�
+                BigDecimal newAmounts = BigDecimal.valueOf(taxSum.getAmounts()).add(BigDecimal.valueOf(detail.getAmount()));
+                if (idcard.equals("330103196704060019")) {
+                    log.info("330103196704060019");
+                }
+                String taxation = TaxtUtils.getTaxation(newAmounts);
+                BigDecimal taxAmountNow = new BigDecimal(taxation).subtract(new BigDecimal(String.valueOf(taxSum.getTaxAmounts())));
+                BigDecimal texdAfterNow = BigDecimal.valueOf(detail.getAmount()).subtract(taxAmountNow);
+                detail.setTaxamount(taxAmountNow.doubleValue());
+                detail.setTaxedamount(texdAfterNow.doubleValue());
+                if (taxAmountNow.doubleValue() < 0) {
+                    log.info("灏忎簬0浜�");
+                }
+
+                if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
+                    detail.setTaxTime(new Date());
+                } else {
+                    detail.setTaxTime(serviceFund1.getFundtaxtime());
+                }
+                taxSum.setAmounts(newAmounts.doubleValue());
+                taxSum.setTaxAmounts((BigDecimal.valueOf(taxSum.getTaxAmounts()).add(taxAmountNow).doubleValue()));
+                taxSum.setTaxedAmounts((BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(texdAfterNow)).doubleValue());
+            }
+
+            updateList.add(detail);
+
+            pretaxcost = pretaxcost.add(BigDecimal.valueOf(detail.getAmount()));
+            taxedcost = taxedcost.add(BigDecimal.valueOf(detail.getTaxedamount()));
+
+        }
+        // 6. 鎵归噺鏇存柊鎵�鏈夋槑缁�
+        for (ServiceFunddetail d : updateList) {
+            this.updateById(d);
+        }
+        // 7. 鏇存柊涓昏〃ServiceFund
+        ServiceFund serviceFund = new ServiceFund();
+        serviceFund.setPretaxcost(pretaxcost.doubleValue());
+        serviceFund.setTaxedcost(taxedcost.doubleValue());
+        serviceFund.setId(serviceFunddetails.get(0).getFundid());
+        serviceFund.setFundtaxtime(new Date());
+
+        serviceFund.setIstax(1);
+        serviceFundMapper.updateById(serviceFund);
+        return true;
+    }
+
+//    @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.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(), spStatBonusReq.getPabonustype());
+    }
 }

--
Gitblit v1.9.3