From 8b8ca4fb9791a5b79107e354cde500ed6f278219 Mon Sep 17 00:00:00 2001
From: liusheng <337615773@qq.com>
Date: 星期日, 08 十月 2023 18:27:53 +0800
Subject: [PATCH] 代码提交

---
 ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java |  175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 171 insertions(+), 4 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 698d830..d9524a6 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,19 @@
 package com.ruoyi.project.service.impl;
 
 import java.math.BigDecimal;
+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.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 org.apache.commons.collections4.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -23,6 +24,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涓氬姟灞傚鐞�
@@ -78,6 +80,18 @@
         }
         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());
         }
         return this.list(wrappers);
     }
@@ -231,4 +245,157 @@
         return serviceFunddetailVOS;
     }
 
+    /**
+     * 鏍规嵁鏉′欢绠楃◣
+     *
+     * @param serviceFunddetails
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails) {
+        //鐢ㄤ簬涓存椂淇濆瓨宸茬粡绠楀ソ鐨�"璐圭敤璇︽儏鏁版嵁"
+        List<ServiceFunddetail> temporarySave = new ArrayList<>();
+
+        for (ServiceFunddetail serviceFunddetail : serviceFunddetails) {
+            //鑾峰彇褰撴湀鐨勭涓�澶�
+            Date firstDay = Date.from(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant());
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            String firstDatStr = dateFormat.format(firstDay);
+            TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO();
+
+            taxMoneyVO.setTaxTime(new Date());
+            taxMoneyVO.setFirstDay(firstDay);
+//            taxMoneyVO.setApplyType(Long.valueOf(serviceFunddetail.getApplytype()));
+            taxMoneyVO.setFundID(serviceFunddetail.getFundid());
+//            taxMoneyVO.setBeneficiaryNo(serviceFunddetail.getBeneficiaryno());
+            taxMoneyVO.setIDCard(serviceFunddetail.getIdcardno());
+            //鏌ュ嚭绋庡墠銆佺◣銆佺◣鍚庣殑鎬婚锛堜笉鍖呭惈鏈锛�
+            TaxMoneySumEO taxSum = serviceFunddetailMapper.getTaxSum(taxMoneyVO);
+            if (ObjectUtils.isEmpty(taxSum)) {
+                taxSum = new TaxMoneySumEO();
+            }
+
+            //鍒ゆ柇涓存椂闆嗗悎temporarySave涓紝鏈夋病鏈夊凡缁忕畻杩囩殑鏁版嵁
+            if (CollectionUtils.isNotEmpty(temporarySave)) {
+                for (ServiceFunddetail serviceFunddetail1 : temporarySave) {
+                    //濡傛灉鏈鐨勨�濅汉鍛樼被鍨嬧�溿�佲�濆彈鐩婁汉缂栧彿鈥滃湪涓存椂闆嗗悎涓瓨鍦紝鍒欏皢闆嗗悎鏁版嵁涓殑璇ュ彈鐩婁汉鐨勶紝绋庡墠銆佺◣閲戙�佺◣鍚庯紝鍜屾�荤殑鐩稿姞锛屽苟灏嗚�佺殑瑕嗙洊
+                    // if (serviceFunddetail1.getApplytype().equals(serviceFunddetail.getApplytype()) && serviceFunddetail1.getBeneficiaryno().equals(serviceFunddetail.getBeneficiaryno())) {
+                    if (serviceFunddetail1.getBeneficiaryno().equals(serviceFunddetail.getBeneficiaryno())) {
+                        //灏嗛泦鍚堟暟鎹腑鐨勮鍙楃泭浜虹殑锛岀◣鍓嶃�佺◣閲戙�佺◣鍚庯紝鍜屾�荤殑鐩稿姞
+                        BigDecimal amounts = BigDecimal.valueOf(taxSum.getAmounts()).add(new BigDecimal(String.valueOf(serviceFunddetail1.getAmount())));
+                        BigDecimal taxAmounts = BigDecimal.valueOf(taxSum.getTaxAmounts()).add(new BigDecimal(String.valueOf(serviceFunddetail1.getTaxamount())));
+                        BigDecimal TaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(new BigDecimal(String.valueOf(serviceFunddetail1.getTaxedamount())));
+                        //灏嗚�佺殑瑕嗙洊
+                        taxSum.setAmounts(amounts.doubleValue());
+                        taxSum.setTaxAmounts(taxAmounts.doubleValue());
+                        taxSum.setTaxedAmounts(TaxedAmounts.doubleValue());
+                    }
+                    continue;
+                }
+            }
+
+            if (!serviceFunddetail.getServicesscopename().contains("绋庡悗")) {
+                // 濡備綍绋庡墠閲戦涓嶄负绌猴紝鐢ㄤ箣鍓嶇殑鈥濇�荤◣鍓嶉噾棰濃�滐紝鍔犱笂褰撳墠鈥濈◣鍓嶉噾棰濃��
+                BigDecimal newAmounts = BigDecimal.valueOf(taxSum.getAmounts()).add(BigDecimal.valueOf(serviceFunddetail.getAmount()));
+
+                // 璁$畻鎬荤◣閲戯紙鍖呭惈鏈锛�
+                String taxation = TaxtUtils.getTaxation(newAmounts);
+                //璁$畻鏈绋庨噾锛堟�荤◣閲戯紙鍖呭惈鏈锛� - 鎬荤◣閲戯紙涓嶅寘鍚湰娆★級锛�
+                BigDecimal taxAmountNow = new BigDecimal(taxation).subtract(new BigDecimal(String.valueOf(taxSum.getTaxAmounts())));
+
+                //璁$畻鏈鐨勭◣鍚庨噾棰�(鏈鐨勭◣鍓嶉噾棰� - 绋庨噾)
+                BigDecimal texdAfterNow = BigDecimal.valueOf(serviceFunddetail.getAmount()).subtract(taxAmountNow);
+
+                //灏嗗惊鐜殑鏁版嵁閲嶆柊鏀惧埌涓�涓柊瀵硅薄涓�
+                ServiceFunddetail serviceFunddetail3 = DtoConversionUtils.sourceToTarget(serviceFunddetail, ServiceFunddetail.class);
+                serviceFunddetail3.setTaxamount(taxAmountNow.doubleValue());
+                serviceFunddetail3.setTaxedamount(texdAfterNow.doubleValue());
+                serviceFunddetail3.setTaxTime(new Date());
+                // 灏嗚鏉℃暟鎹洿鏂�
+                updateById(serviceFunddetail3);
+                // 鎶婅鏁版嵁锛屾斁鍒颁复鏃剁殑闆嗗悎涓�
+                temporarySave.add(serviceFunddetail3);
+            } else if (serviceFunddetail.getServicesscopename().contains("绋庡悗")) {
+                //绋庡悗涓嶄负绌�, 鐢ㄤ箣鍓嶇殑鈥濇�荤◣鍚庨噾棰濃�滐紝鍔犱笂褰撳墠鈥濈◣鍚庨噾棰濃��
+                BigDecimal newTaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(BigDecimal.valueOf(serviceFunddetail.getTaxedamount()));
+
+                //閫氳繃鎬荤◣鍚庯紙鍖呭惈鏈锛夌畻鍑烘�荤◣鍓�
+                String taxationBefore = TaxtUtils.getTaxationBefore(newTaxedAmounts);
+                //绠楀嚭鏈绋庡墠锛堟�荤◣鍓嶏紙鍖呭惈鏈锛� - 鎬荤◣鍓嶏紙涓嶅寘鍚湰娆★級锛�
+                BigDecimal amountNow = new BigDecimal(taxationBefore).subtract(BigDecimal.valueOf(taxSum.getAmounts()));
+
+                //绠楀嚭鏈绋庨噾(鏈绋庡墠 - 鏈绋庡悗)
+                BigDecimal tax = amountNow.subtract(BigDecimal.valueOf(serviceFunddetail.getTaxedamount()));
+
+                //灏嗗惊鐜殑鏁版嵁閲嶆柊鏀惧埌涓�涓柊瀵硅薄涓�
+                ServiceFunddetail serviceFunddetail3 = DtoConversionUtils.sourceToTarget(serviceFunddetail, ServiceFunddetail.class);
+                serviceFunddetail3.setAmount(amountNow.doubleValue());
+                serviceFunddetail3.setTaxamount(tax.doubleValue());
+                serviceFunddetail3.setTaxTime(new Date());
+                // 灏嗚鏉℃暟鎹洿鏂�
+                updateById(serviceFunddetail3);
+                // 鎶婅鏁版嵁锛屾斁鍒颁复鏃剁殑闆嗗悎涓�
+                temporarySave.add(serviceFunddetail3);
+            }
+        }
+        return true;
+    }
+
+    @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;
+    }
+
 }

--
Gitblit v1.9.3