| | |
| | | import com.ruoyi.project.domain.ServiceFunddetail; |
| | | import com.ruoyi.project.domain.ServiceFundtax; |
| | | import com.ruoyi.project.domain.vo.FundTaxVO; |
| | | import com.ruoyi.project.domain.vo.TaxMoneyByItemEO; |
| | | import com.ruoyi.project.domain.vo.TaxMoneySumEO; |
| | | import com.ruoyi.project.mapper.ServiceFundMapper; |
| | | import com.ruoyi.project.mapper.ServiceFunddetailMapper; |
| | | import com.ruoyi.project.mapper.ServiceFundtaxMapper; |
| | | import com.ruoyi.project.service.IServiceFundService; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.List; |
| | | import java.time.LocalDate; |
| | | import java.time.ZoneId; |
| | | import java.time.temporal.TemporalAdjusters; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * 专家费用算税申请主Service业务层处理 |
| | |
| | | private IServiceFundService serviceFundService; |
| | | @Autowired |
| | | private ServiceFundtaxMapper serviceFundtaxMapper; |
| | | |
| | | @Autowired |
| | | private ServiceFundMapper serviceFundMapper; |
| | | |
| | | |
| | | /** |
| | |
| | | return serviceFundtaxMapper.getMaxFundTaxId(); |
| | | } |
| | | |
| | | /** |
| | | * 批量算税主入口 |
| | | * 1. 校验参数 |
| | | * 2. 校验批次合法性(如有必要) |
| | | * 3. 查询本批次所有ServiceFund(按id升序) |
| | | * 4. 预查询本月所有身份证号的累计金额,缓存到Map,提升后续算税效率 |
| | | * 5. 遍历每个ServiceFund,批量算税 |
| | | * |
| | | * @param fundTaxVO 批次算税参数 |
| | | * @return 是否算税成功 |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Boolean batchFundTax(FundTaxVO fundTaxVO) { |
| | | log.info("批量算税的fundTaxVO入参为:{}", fundTaxVO); |
| | | // 1. 校验参数 |
| | | if (fundTaxVO.getFundTaxId() == null) { |
| | | throw new BaseException("分批算税出问题了,请检查后再进行计算"); |
| | | } |
| | | // 2. 校验批次合法性(仅限修改操作) |
| | | if (fundTaxVO.getAddOrupdate() == 1) { |
| | | Integer maxFundTaxId = serviceFundtaxMapper.getMaxFundTaxId(); |
| | | log.info("批量算税的maxFundTaxId为:{}", maxFundTaxId); |
| | | if (fundTaxVO.getFundTaxId() != maxFundTaxId.longValue()) { |
| | | if (!fundTaxVO.getFundTaxId().equals(Long.valueOf(maxFundTaxId))) { |
| | | throw new BaseException("该批数据不能算税"); |
| | | } |
| | | } |
| | | |
| | | // 3. 查询本批次所有ServiceFund(按id升序) |
| | | ServiceFund serviceFund = new ServiceFund(); |
| | | serviceFund.setFundTaxId(fundTaxVO.getFundTaxId()); |
| | | serviceFund.setDel_flag(0); |
| | | List<ServiceFund> serviceFunds = serviceFundService.selectServiceFundList(serviceFund); |
| | | if (CollectionUtils.isEmpty(serviceFunds)) { |
| | | //根据id排序(升序) |
| | | serviceFunds.sort(Comparator.comparing(ServiceFund::getId)); |
| | | for (ServiceFund serviceFund1 : serviceFunds) { |
| | | serviceFundMapper.updateFundIsTexById(serviceFund1.getId(), 0L); |
| | | } |
| | | |
| | | // 按id升序排序,保证处理顺序一致 |
| | | serviceFunds.sort(Comparator.comparing(ServiceFund::getId)); |
| | | if (CollectionUtils.isEmpty(serviceFunds)) { |
| | | log.warn("未查询到相关ServiceFund,fundTaxId={}", fundTaxVO.getFundTaxId()); |
| | | return false; |
| | | } |
| | | |
| | | // 4. 预查询本月所有身份证号的累计金额,缓存到Map,提升后续算税效率 |
| | | TaxMoneyByItemEO taxMoneyVO = new TaxMoneyByItemEO(); |
| | | Date firstDay = Date.from(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay(ZoneId.systemDefault()).toInstant()); |
| | | taxMoneyVO.setFirstDay(firstDay); |
| | | taxMoneyVO.setTaxTime(new Date()); |
| | | Map<String, TaxMoneySumEO> tempTaxSumMap = new HashMap<>(); |
| | | List<TaxMoneySumEO> taxSum = serviceFunddetailMapper.getTaxSum(taxMoneyVO); |
| | | for (TaxMoneySumEO taxMoneySumEO : taxSum) { |
| | | tempTaxSumMap.put(taxMoneySumEO.getIDCardNo(), taxMoneySumEO); |
| | | } |
| | | |
| | | // 5. 遍历每个ServiceFund,批量算税 |
| | | for (ServiceFund serviceFund1 : serviceFunds) { |
| | | ServiceFunddetail serviceFunddetail = new ServiceFunddetail(); |
| | | serviceFunddetail.setFundid(serviceFund1.getId()); |
| | | List<ServiceFunddetail> serviceFunddetails = serviceFunddetailMapper.selectServiceFunddetailList(serviceFunddetail); |
| | | serviceFunddetailService.calculateTax(serviceFunddetails); |
| | | // 传入累计金额缓存,提升算税效率 |
| | | serviceFunddetailService.calculateTax(serviceFunddetails, tempTaxSumMap); |
| | | } |
| | | return true; |
| | | } |