liusheng
2024-03-11 7a1a246539b16c7e81006fb79dd2885d94aa8c01
ruoyi-project/src/main/java/com/ruoyi/project/service/impl/ServiceFunddetailServiceImpl.java
@@ -9,13 +9,18 @@
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 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;
@@ -32,9 +37,10 @@
 * @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;
@@ -93,6 +99,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);
    }
@@ -112,7 +124,7 @@
    }
    /**
     * 根据受益人编号获取税费金额
     * 根据受益人身份证编号获取税费金额
     *
     * @param taxMoneyVo
     * @return
@@ -241,6 +253,10 @@
                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;
    }
@@ -253,26 +269,54 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean calculateTax(List<ServiceFunddetail> serviceFunddetails) {
        if (CollectionUtils.isEmpty(serviceFunddetails)) {
            throw new BaseException("算税条件为空,请检查后,再进行计算");
        }
        //这个是为了获取fund_tax_time
        Long fundid = serviceFunddetails.get(0).getFundid();
        log.info("算税的fundid的值为:{}", fundid);
        ServiceFund serviceFund1 = serviceFundMapper.selectById(fundid);
        log.info("fund表的fundtextime值为:{}", serviceFund1.getFundtaxtime());
        //用于临时保存已经算好的"费用详情数据"
        List<ServiceFunddetail> temporarySave = new ArrayList<>();
        //保存总税前金额(用于更新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());
                } else {
                    serviceFunddetail.setAmount(serviceFunddetail.getTaxedamount());
                }
                //公司的申请金额也要加进去
                pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail.getAmount()));
                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());
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String firstDatStr = dateFormat.format(firstDay);
//            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            String firstDatStr = dateFormat.format(firstDay);
            TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO();
            taxMoneyVO.setTaxTime(new Date());
            if (serviceFund1.getFundtaxtime() != null) {
                taxMoneyVO.setTaxTime(serviceFund1.getFundtaxtime());
            } else {
                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("查询的taxSum的值 : {}", taxSum);
            if (ObjectUtils.isEmpty(taxSum)) {
                taxSum = new TaxMoneySumEO();
            }
@@ -282,7 +326,7 @@
                for (ServiceFunddetail serviceFunddetail1 : temporarySave) {
                    //如果本次的”人员类型“、”身份证号“在临时集合中存在,则将集合数据中的该受益人的,税前、税金、税后,和总的相加,并将老的覆盖
                    // if (serviceFunddetail1.getApplytype().equals(serviceFunddetail.getApplytype()) && serviceFunddetail1.getBeneficiaryno().equals(serviceFunddetail.getBeneficiaryno())) {
                    if (serviceFunddetail1.getIdcardno().equals(serviceFunddetail.getIdcardno())) {
                    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())));
@@ -296,7 +340,9 @@
                }
            }
            if (!serviceFunddetail.getServicesscopename().contains("税后")) {
            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()));
@@ -307,18 +353,27 @@
                //计算本次的税后金额(本次的税前金额 - 税金)
                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());
                if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
                    serviceFunddetail3.setTaxTime(new Date());
                } else {
                    serviceFunddetail3.setTaxTime(serviceFund1.getFundtaxtime());
                }
                logger.info("打印税前serviceFunddetail3数据 :{}", serviceFunddetail3);
                // 将该条数据更新
                updateById(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()));
@@ -329,12 +384,18 @@
                //算出本次税金(本次税前 - 本次税后)
                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());
                if (ObjectUtils.isEmpty(serviceFund1.getFundtaxtime())) {
                    serviceFunddetail3.setTaxTime(new Date());
                } else {
                    serviceFunddetail3.setTaxTime(serviceFund1.getFundtaxtime());
                }
                logger.info("打印serviceFunddetail3:{}", serviceFunddetail3);
                // 将该条数据更新
                updateById(serviceFunddetail3);
                pretaxcost = pretaxcost.add(BigDecimal.valueOf(serviceFunddetail3.getAmount()));
@@ -345,6 +406,11 @@
        ServiceFund serviceFund = new ServiceFund();
        serviceFund.setPretaxcost(pretaxcost.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;
@@ -407,4 +473,9 @@
        return map;
    }
    @Override
    public List<SpStatBonus> getListBySpStatBonus(SpStatBonusReq spStatBonusReq) {
        return serviceFunddetailMapper.getListBySpStatBonus(spStatBonusReq.getPabegtime(), spStatBonusReq.getPaendtime(), spStatBonusReq.getPadeptno(), spStatBonusReq.getPauserno(), spStatBonusReq.getPabonustype());
    }
}