liusheng
2025-01-02 b6dd47b05107fc36d8ff4f7f29a4446521f95503
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
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.*;
 
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;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
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业务层处理
 *
 * @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;
 
 
    /**
     * 查询费用申请明细列表
     *
     * @param serviceFunddetail 费用申请明细
     * @return 费用申请明细
     */
    @Override
    public List<ServiceFunddetail> queryList(ServiceFunddetail serviceFunddetail) {
        LambdaQueryWrapper<ServiceFunddetail> wrappers = Wrappers.lambdaQuery();
        if (StringUtils.isNotBlank(serviceFunddetail.getBeneficiaryname())) {
            wrappers.like(ServiceFunddetail::getBeneficiaryname, serviceFunddetail.getBeneficiaryname());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getUnitname())) {
            wrappers.like(ServiceFunddetail::getUnitname, serviceFunddetail.getUnitname());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getApplytype())) {
            wrappers.eq(ServiceFunddetail::getApplytype, serviceFunddetail.getApplytype());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getItemname())) {
            wrappers.like(ServiceFunddetail::getItemname, serviceFunddetail.getItemname());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getItemtype())) {
            wrappers.eq(ServiceFunddetail::getItemtype, serviceFunddetail.getItemtype());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getRecordstatus())) {
            wrappers.eq(ServiceFunddetail::getRecordstatus, serviceFunddetail.getRecordstatus());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getCreateBy())) {
            wrappers.eq(ServiceFunddetail::getCreateBy, serviceFunddetail.getCreateBy());
        }
        if (serviceFunddetail.getCreateTime() != null) {
            wrappers.eq(ServiceFunddetail::getCreateTime, serviceFunddetail.getCreateTime());
        }
        if (StringUtils.isNotBlank(serviceFunddetail.getUploadflag())) {
            wrappers.eq(ServiceFunddetail::getUploadflag, serviceFunddetail.getUploadflag());
        }
        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);
    }
 
    @Override
    public List<ServiceFunddetail> getDataBybeneficiaryNo(FunddetailReqVo funddetailReqVo) {
        if (StringUtils.isEmpty(funddetailReqVo.getStarttime())) {
            // 获取当月第一天日期
            funddetailReqVo.setStarttime(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).toString());
        }
        if (StringUtils.isEmpty(funddetailReqVo.getEndtime())) {
            // 获取当月最后一天日期
            funddetailReqVo.setEndtime(LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()).toString());
        }
        List<ServiceFunddetail> dataBybeneficiaryNo = serviceFunddetailMapper.getDataBybeneficiaryNo(funddetailReqVo);
 
        return dataBybeneficiaryNo;
    }
 
    /**
     * 根据受益人身份证编号获取税费金额
     *
     * @param taxMoneyVo
     * @return
     */
    @Override
    public Double getTaxByBeneFiciaryNo(TaxMoneyVO taxMoneyVo) {
        Double sum = 0.00;
        Double totalScore = 0.00;
        List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo);
        if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) {
            //计算申请金额总和,不包括当前传进来的
            sum = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getAmount).sum();
            //不加本次薪酬的个税
            totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum();
        }
 
        sum = sum + new Double(taxMoneyVo.getMoney());
        //加上本次薪酬的总个税
        String taxation = TaxtUtils.getTaxation(new BigDecimal(sum));
 
        Double tax = Double.valueOf(taxation) - totalScore;
        return tax;
    }
 
    /**
     * 根据税后工资,算出税前工资
     *
     * @param taxMoneyVo
     * @return
     */
    @Override
    public TaxedMoneyVO getTaxBeforeByAfterMoney(TaxMoneyVO taxMoneyVo) {
        TaxedMoneyVO taxedMoneyVO = new TaxedMoneyVO();
        Double sum = 0.00;
        Double totalScore = 0.00;
        List<ServiceFunddetail> taxationByBeneFiciaryNo = serviceFunddetailMapper.getTaxBeforeByBeneFiciaryNo(taxMoneyVo);
        if (CollectionUtils.isNotEmpty(taxationByBeneFiciaryNo)) {
            //计算出税后总金额(不包含本次)
            sum = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxedamount).sum();
            //求出之前的总的个税
            totalScore = taxationByBeneFiciaryNo.stream().mapToDouble(ServiceFunddetail::getTaxamount).sum();
        }
        //计算出总的税后薪酬(包含本次)
        sum = sum + Double.valueOf(taxMoneyVo.getMoney());
        //税前总金额
        String taxationBefore = TaxtUtils.getTaxationBefore(new BigDecimal(sum));
        //总个税
        BigDecimal tax = new BigDecimal(taxationBefore).subtract(new BigDecimal(sum));
 
        //本次的税前金额
        String nowTaxMoney = TaxtUtils.getTaxationBefore(new BigDecimal(taxMoneyVo.getMoney()));
        //本次的税费
        BigDecimal subtract = new BigDecimal(nowTaxMoney).subtract(new BigDecimal(taxMoneyVo.getMoney()));
 
        taxedMoneyVO.setAllTax(tax.toString());
        taxedMoneyVO.setAllTaxbeforeMoney(taxationBefore);
        taxedMoneyVO.setAllAaxAfterMoney(sum.toString());
        taxedMoneyVO.setNowTaxBeforeMoney(nowTaxMoney);
        taxedMoneyVO.setNowTax(subtract.toString());
 
        return taxedMoneyVO;
    }
 
 
    @Override
    public List<ServiceFunddetail> getAllDetailsByFDIDLW(Long id) {
        return serviceFunddetailMapper.getAllDetailsByFDIDLW(id);
    }
 
    @Override
    public List<ServiceFunddetail> getAllDetailsByFDIDSH(Long id) {
        return serviceFunddetailMapper.getAllDetailsByFDIDSH(id);
    }
 
    @Override
    public List<ServiceFunddetail> getAllDetailsByFDIDSS(Long id) {
        return serviceFunddetailMapper.getAllDetailsByFDIDSS(id);
    }
 
    @Override
    public List<ServiceFunddetail> getAllDetailsByFDIDYX(Long id) {
        return serviceFunddetailMapper.getAllDetailsByFDIDYX(id);
    }
 
    @Override
    public List<ServiceFunddetail> getAllDetailsByFDIDHZ(Long id) {
        return serviceFunddetailMapper.getAllDetailsByFDIDHZ(id);
    }
 
    @Override
    public List<ServiceFunddetail> getAllDetailsByFDIDLWF(Long id) {
        return serviceFunddetailMapper.getAllDetailsByFDIDLWF(id);
    }
 
    @Override
    public List<ServiceFunddetail> selectServiceFunddetailList(ServiceFunddetail serviceFunddetail) {
        return serviceFunddetailMapper.selectServiceFunddetailList(serviceFunddetail);
    }
 
    @Override
    public int deleteDetail(Long id) {
        ServiceFunddetail serviceFunddetail = serviceFunddetailMapper.selectById(id);
        Long fundid = serviceFunddetail.getFundid();
        ServiceFund serviceFund = serviceFundMapper.selectById(fundid);
        if (ObjectUtils.isNotEmpty(serviceFund)) {
            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);
        }
        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;
    }
 
    /**
     * 根据条件算税
     *
     * @param serviceFunddetails
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails) {
        if (CollectionUtils.isEmpty(serviceFunddetails)) {
            throw new BaseException("算税条件为空,请检查后,再进行计算");
        }
        // 用于临时保存已经算好的"费用详情数据"
        List<ServiceFunddetail> temporarySave = new ArrayList<>();
        // 用于记录序号
        Map<String, Long> xhMap = new HashMap<>();
 
        // 先对serviceFunddetails排序
        Comparator<ServiceFunddetail> customComparator = Comparator.comparing(obj -> {
            if (ObjectUtils.isEmpty(obj.getTaxTime())) {
                return 1; // 返回1表示字段为空的对象排在后面
            } else {
                return 0; // 返回0表示字段不为空的对象保持原顺序
            }
        });
        Collections.sort(serviceFunddetails, customComparator);
 
        //这个是为了获取fund_tax_time
        Long fundid = serviceFunddetails.get(0).getFundid();
        log.info("算税的fundid的值为:{}", fundid);
        ServiceFund serviceFund1 = serviceFundMapper.selectById(fundid);
        log.info("fund表的fundtextime值为:{}", serviceFund1.getFundtaxtime());
        //保存总税前金额(用于更新fund表里的)
        BigDecimal pretaxcost = BigDecimal.valueOf(0.00);
        BigDecimal taxedcost = BigDecimal.valueOf(0.00);
        for (ServiceFunddetail serviceFunddetail : serviceFunddetails) {
            if (serviceFunddetail.getBeneficiaryname().equals("吴康松")) {
                System.out.println(serviceFunddetail);
            }
            if (StringUtils.isEmpty(serviceFunddetail.getIdcardno())) {
                logger.info("serviceFunddetail数据入参 : {}", serviceFunddetail);
                //如果身份证号为空,就不用查了,可能是医院的记录
                if (StringUtils.isEmpty(serviceFunddetail.getServicesscopename()) || !serviceFunddetail.getServicesscopename().contains("税后")) {
                    serviceFunddetail.setTaxedamount(serviceFunddetail.getAmount());
                } else {
                    serviceFunddetail.setAmount(serviceFunddetail.getTaxedamount());
                }
                //公司的申请金额也要加进去
                pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail.getAmount()));
                taxedcost = taxedcost.add(BigDecimal.valueOf(serviceFunddetail.getTaxedamount()));
 
                serviceFunddetail.setTaxamount(0.0);
                logger.info("serviceFunddetail更新后的数据 : {}", serviceFunddetail);
                boolean b = this.updateById(serviceFunddetail);
                logger.info("serviceFunddetail修改结果 : {}", b);
                continue;
            }
 
            //获取当月的第一天
            Date firstDay = Date.from(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant());
            //获取到当前人的本月算税序号最大值
            TaxMoneyByItemEO taxMoneyByItemEO = new TaxMoneyByItemEO();
            taxMoneyByItemEO.setFirstDay(firstDay);
            taxMoneyByItemEO.setIDCard(serviceFunddetail.getIdcardno());
            taxMoneyByItemEO.setTaxTime(new Date());
            //根据条件获取表中该条数据的”序号“最大值
            Long maxXH = serviceFunddetailMapper.getMaxXH(taxMoneyByItemEO);
            if (maxXH == null) {
                maxXH = 1L;
            } else {
                maxXH = maxXH + 1;
            }
            //序号Map与数据库表里的xh同时不为空,那就以map里的为准
            if (ObjectUtils.isNotEmpty(xhMap)) {
                Long xhValue = xhMap.get(serviceFunddetail.getIdcardno());
                if (xhValue != null) maxXH = xhValue + 1;
            }
 
            TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO();
            if (serviceFund1.getFundtaxtime() != null) {
                taxMoneyVO.setTaxTime(serviceFund1.getFundtaxtime());
            } else {
                taxMoneyVO.setTaxTime(new Date());
            }
            taxMoneyVO.setFirstDay(firstDay);
            taxMoneyVO.setFundID(serviceFunddetail.getFundid());
            taxMoneyVO.setIDCard(serviceFunddetail.getIdcardno());
            if (serviceFunddetail.getXh() != null) {
//                taxMoneyVO.setXh(serviceFunddetail.getXh());
                //这个序号,有可能是之前版税的序号,在这里不能再用了
                serviceFunddetail.setXh(null);
                taxMoneyVO.setXh(maxXH);
                xhMap.put(serviceFunddetail.getIdcardno(), maxXH);
            } else {
                taxMoneyVO.setXh(maxXH);
                xhMap.put(serviceFunddetail.getIdcardno(), maxXH);
            }
            //查出税前、税、税后的总额(不包含本次)
            TaxMoneySumEO taxSum = serviceFunddetailMapper.getTaxSum(taxMoneyVO);
            logger.info("查询的taxSum的值 : {}", taxSum);
            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.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;
                }
            }
            if (serviceFunddetail.getXh() == null) {
                serviceFunddetail.setXh(maxXH);
            }
 
            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());
                if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
                    serviceFunddetail3.setTaxTime(new Date());
                } else {
                    serviceFunddetail3.setTaxTime(serviceFund1.getFundtaxtime());
                }
                logger.info("打印税前serviceFunddetail3数据 :{}", serviceFunddetail3);
 
                // 将该条数据更新
 
                boolean b = this.updateById(serviceFunddetail3);
                pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail.getAmount()));
                taxedcost = taxedcost.add(BigDecimal.valueOf(serviceFunddetail.getTaxedamount()));
//                // 把该数据,放到临时的集合中
                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()));
 
                //通过总税后(包含本次)算出总税前
                String taxationBefore = TaxtUtils.getTaxationBefore(newTaxedAmounts);
                //算出本次税前(总税前(包含本次) - 总税前(不包含本次))
                BigDecimal amountNow = new BigDecimal(taxationBefore).subtract(BigDecimal.valueOf(taxSum.getAmounts()));
 
                //算出本次税金(本次税前 - 本次税后)
                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());
                if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
                    serviceFunddetail3.setTaxTime(new Date());
                } else {
                    serviceFunddetail3.setTaxTime(serviceFund1.getFundtaxtime());
                }
                logger.info("打印serviceFunddetail3:{}", serviceFunddetail3);
                //获取到当前人的本月算税序号最大值
                TaxMoneyByItemEO byItemEO = new TaxMoneyByItemEO();
                byItemEO.setFirstDay(firstDay);
                byItemEO.setIDCard(serviceFunddetail.getIdcardno());
                byItemEO.setTaxTime(new Date());
                // 将该条数据更新
                updateById(serviceFunddetail3);
                pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail3.getAmount()));
                taxedcost = taxedcost.add(BigDecimal.valueOf(serviceFunddetail3.getTaxedamount()));
//                // 把该数据,放到临时的集合中
                temporarySave.add(serviceFunddetail3);
            }
        }
        ServiceFund serviceFund = new ServiceFund();
        serviceFund.setPretaxcost(pretaxcost.doubleValue());
        serviceFund.setTaxedcost(taxedcost.doubleValue());
        serviceFund.setId(serviceFunddetails.get(0).getFundid());
        if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
            serviceFund.setFundtaxtime(new Date());
        }
        // 1 已算税
        serviceFund.setIstax(1);
        serviceFundMapper.updateById(serviceFund);
 
        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);
        //计算扣去每月5000的历史税前金额
        BigDecimal historyTaxBefore = BigDecimal.valueOf(0.00);
        //本月是否已经算过绩效(下面扣除5000需要用到这个,如果本月已经扣过5000,就不再扣了)
        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());
    }
}