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 | 261 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 158 insertions(+), 103 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 bf6a358..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,6 +1,7 @@ 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; @@ -9,13 +10,16 @@ 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.*; 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; @@ -35,6 +39,7 @@ * @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()); @@ -43,6 +48,9 @@ @Autowired ServiceFundMapper serviceFundMapper; + + @Autowired + SpStatBonusMapper spStatBonusMapper; /** @@ -95,6 +103,12 @@ } 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); } @@ -253,134 +267,170 @@ } /** - * 鏍规嵁鏉′欢绠楃◣ + * 鎵归噺绠楃◣涓绘柟娉� + * 1. 鏍¢獙鍙傛暟 + * 2. 鎺掑簭鏄庣粏锛屼繚璇佺◣鏃堕棿涓虹┖鐨勬帓鍦ㄥ悗闈� + * 3. 閬嶅巻姣忔潯鏄庣粏锛屽垎韬唤璇佸彿涓虹┖鍜屼笉涓虹┖涓ょ鎯呭喌鍒嗗埆澶勭悊 + * - 韬唤璇佸彿涓虹┖锛氱洿鎺ユ寜瑙勫垯璧嬪�肩◣鍚庨噾棰濄�佺◣閲� + * - 韬唤璇佸彿涓嶄负绌猴細 + * a. 鏌ヨ鏈湀绗竴澶╋紝鑾峰彇鏈�澶у簭鍙� + * b. 鏌ヨ鏈湀绱绋庡墠銆佺◣閲戙�佺◣鍚庨噾棰� + * c. 鏍规嵁"绋庡墠/绋庡悗"绫诲瀷鍒嗗埆璁$畻绋庨噾銆佺◣鍚庨噾棰� + * d. 璁剧疆绠楃◣鏃堕棿銆佸簭鍙风瓑 + * 4. 绱鏈壒娆℃�荤◣鍓嶃�佺◣鍚庨噾棰� + * 5. 鎵归噺鏇存柊鎵�鏈夋槑缁� + * 6. 鏇存柊涓昏〃ServiceFund鐨勬�婚噾棰濄�佺畻绋庢椂闂淬�佺姸鎬� * - * @param serviceFunddetails + * @param serviceFunddetails 璐圭敤鏄庣粏鍒楄〃 + * @return 鏄惁绠楃◣鎴愬姛 */ @Override - @Transactional(rollbackFor = Exception.class) - public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails) { - //鐢ㄤ簬涓存椂淇濆瓨宸茬粡绠楀ソ鐨�"璐圭敤璇︽儏鏁版嵁" - List<ServiceFunddetail> temporarySave = new ArrayList<>(); + 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)); - //淇濆瓨鎬荤◣鍓嶉噾棰濓紙鐢ㄤ簬鏇存柊fund琛ㄩ噷鐨勶級 - BigDecimal pretaxcost = BigDecimal.valueOf(0.00); - for (ServiceFunddetail serviceFunddetail : serviceFunddetails) { - if (StringUtils.isEmpty(serviceFunddetail.getIdcardno())) { - logger.info("serviceFunddetail鏁版嵁鍏ュ弬 锛� {}", serviceFunddetail); - //濡傛灉韬唤璇佸彿涓虹┖锛屽氨涓嶇敤鏌ヤ簡锛屽彲鑳芥槸鍖婚櫌鐨勮褰� - if (StringUtils.isEmpty(serviceFunddetail.getServicesscopename()) || !serviceFunddetail.getServicesscopename().contains("绋庡悗")) { - serviceFunddetail.setTaxedamount(serviceFunddetail.getAmount()); + // 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 { - serviceFunddetail.setAmount(serviceFunddetail.getTaxedamount()); + // 绋庡悗鏄庣粏锛岀敵璇烽噾棰�=绋庡悗閲戦 + detail.setAmount(detail.getTaxedamount()); } - serviceFunddetail.setTaxamount(0.0); - logger.info("serviceFunddetail鏇存柊鍚庣殑鏁版嵁 锛� {}", serviceFunddetail); - boolean b = this.updateById(serviceFunddetail); - logger.info("serviceFunddetail淇敼缁撴灉 锛� {}", b); + // 绱鏈壒娆℃�婚噾棰� + pretaxcost = pretaxcost.add(BigDecimal.valueOf(detail.getAmount())); + taxedcost = taxedcost.add(BigDecimal.valueOf(detail.getTaxedamount())); + detail.setTaxamount(0.0); + updateList.add(detail); continue; } - //鑾峰彇褰撴湀鐨勭涓�澶� - 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(); + // 5.2 韬唤璇佸彿涓嶄负绌猴紝闇�鏌ュ巻鍙茬疮璁¢噾棰濄�佸簭鍙� + String idcard = detail.getIdcardno().trim(); - 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); - logger.info("鏌ヨ鐨則axSum鐨勫�� 锛� {}", taxSum); - if (ObjectUtils.isEmpty(taxSum)) { + // 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()); } - //鍒ゆ柇涓存椂闆嗗悎temporarySave涓紝鏈夋病鏈夊凡缁忕畻杩囩殑鏁版嵁 - if (CollectionUtils.isNotEmpty(temporarySave)) { - for (ServiceFunddetail serviceFunddetail1 : temporarySave) { - //濡傛灉鏈鐨勨�濅汉鍛樼被鍨嬧�溿�佲�濊韩浠借瘉鍙封�滃湪涓存椂闆嗗悎涓瓨鍦紝鍒欏皢闆嗗悎鏁版嵁涓殑璇ュ彈鐩婁汉鐨勶紝绋庡墠銆佺◣閲戙�佺◣鍚庯紝鍜屾�荤殑鐩稿姞锛屽苟灏嗚�佺殑瑕嗙洊 - // if (serviceFunddetail1.getApplytype().equals(serviceFunddetail.getApplytype()) && serviceFunddetail1.getBeneficiaryno().equals(serviceFunddetail.getBeneficiaryno())) { - if (serviceFunddetail1.getIdcardno().trim().equals(serviceFunddetail.getIdcardno().trim())) { - //灏嗛泦鍚堟暟鎹腑鐨勮鍙楃泭浜虹殑锛岀◣鍓嶃�佺◣閲戙�佺◣鍚庯紝鍜屾�荤殑鐩稿姞 - 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; + // 5.2.3 绠楃◣閫昏緫 + if (detail.getServicesscopename().contains("绋庡悗")) { + // 绋庡悗鏄庣粏锛氱疮璁$◣鍚庨噾棰濓紝鍙嶆帹绋庡墠閲戦鍜岀◣閲� + if (idcard.equals("330103196704060019")) { + log.info("330103196704060019"); } - } - - if (StringUtils.isEmpty(serviceFunddetail.getServicesscopename()) || !serviceFunddetail.getServicesscopename().contains("绋庡悗")) { - logger.info("璁$畻绋庡墠淇℃伅寮�濮嬶細{}", serviceFunddetail); - logger.info("taxSum鍏ュ弬鏁版嵁锛歿}", taxSum); - // 濡備綍绋庡墠閲戦涓嶄负绌猴紝鐢ㄤ箣鍓嶇殑鈥濇�荤◣鍓嶉噾棰濃�滐紝鍔犱笂褰撳墠鈥濈◣鍓嶉噾棰濃�� - 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); - logger.info("鎵撳嵃newAmounts锛歿},taxation:{},taxAmountNow:{},texdAfterNow:{}", newAmounts, taxation, taxAmountNow, texdAfterNow); - - //灏嗗惊鐜殑鏁版嵁閲嶆柊鏀惧埌涓�涓柊瀵硅薄涓� - ServiceFunddetail serviceFunddetail3 = DtoConversionUtils.sourceToTarget(serviceFunddetail, ServiceFunddetail.class); - serviceFunddetail3.setTaxamount(taxAmountNow.doubleValue()); - serviceFunddetail3.setTaxedamount(texdAfterNow.doubleValue()); - serviceFunddetail3.setTaxTime(new Date()); - logger.info("鎵撳嵃绋庡墠serviceFunddetail3鏁版嵁 :{}", serviceFunddetail3); - - // 灏嗚鏉℃暟鎹洿鏂� - boolean b = this.updateById(serviceFunddetail3); - pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail.getAmount())); - // 鎶婅鏁版嵁锛屾斁鍒颁复鏃剁殑闆嗗悎涓� - temporarySave.add(serviceFunddetail3); - } else if (serviceFunddetail.getServicesscopename().contains("绋庡悗")) { - logger.info("璁$畻绋庡悗淇℃伅寮�濮嬶細{}", serviceFunddetail); - logger.info("taxSum鍏ュ弬鏁版嵁锛歿}", taxSum); - //绋庡悗涓嶄负绌�, 鐢ㄤ箣鍓嶇殑鈥濇�荤◣鍚庨噾棰濃�滐紝鍔犱笂褰撳墠鈥濈◣鍚庨噾棰濃�� - BigDecimal newTaxedAmounts = BigDecimal.valueOf(taxSum.getTaxedAmounts()).add(BigDecimal.valueOf(serviceFunddetail.getTaxedamount())); - - //閫氳繃鎬荤◣鍚庯紙鍖呭惈鏈锛夌畻鍑烘�荤◣鍓� + 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浜�"); + } - //绠楀嚭鏈绋庨噾(鏈绋庡墠 - 鏈绋庡悗) - BigDecimal tax = amountNow.subtract(BigDecimal.valueOf(serviceFunddetail.getTaxedamount())); - logger.info("鎵撳嵃newTaxedAmounts锛歿},taxationBefore:{},amountNow:{},tax:{}", newTaxedAmounts, taxationBefore, amountNow, tax); - - //灏嗗惊鐜殑鏁版嵁閲嶆柊鏀惧埌涓�涓柊瀵硅薄涓� - ServiceFunddetail serviceFunddetail3 = DtoConversionUtils.sourceToTarget(serviceFunddetail, ServiceFunddetail.class); - serviceFunddetail3.setAmount(amountNow.doubleValue()); - serviceFunddetail3.setTaxamount(tax.doubleValue()); - serviceFunddetail3.setTaxTime(new Date()); - logger.info("鎵撳嵃serviceFunddetail3:{}", serviceFunddetail3); - // 灏嗚鏉℃暟鎹洿鏂� - updateById(serviceFunddetail3); - pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail3.getAmount())); - // 鎶婅鏁版嵁锛屾斁鍒颁复鏃剁殑闆嗗悎涓� - temporarySave.add(serviceFunddetail3); + 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()); - serviceFundMapper.updateById(serviceFund); + 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) { @@ -439,4 +489,9 @@ 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