package com.tanpu.fund.service; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.tanpu.fund.entity.generator.ReportDownloadSummary; import com.tanpu.fund.mapper.generator.ReportDownloadSummaryMapper; import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; @Service public class DownloadPdfService { private ReportDownloadSummaryMapper reportDownloadSummaryMapper; private static final Integer onceAddTimes = 200; @Transactional(rollbackFor = Exception.class) public void emptyStandardVipCount(String userId) { List<ReportDownloadSummary> reportDownloadSummaries = reportDownloadSummaryMapper.selectList(new LambdaQueryWrapper<ReportDownloadSummary>().eq(ReportDownloadSummary::getUserId, userId)); if (CollectionUtils.isEmpty(reportDownloadSummaries)){ ReportDownloadSummary entity = ReportDownloadSummary.builder().userId(userId).stdVipLimit(0).build(); reportDownloadSummaryMapper.insert(entity); }else { ReportDownloadSummary entity = reportDownloadSummaries.get(0); entity.setStdVipLimit(0); reportDownloadSummaryMapper.updateById(entity); } } @Transactional(rollbackFor = Exception.class) public void addStandardVipCount(String userId) { List<ReportDownloadSummary> reportDownloadSummaries = reportDownloadSummaryMapper.selectList(new LambdaQueryWrapper<ReportDownloadSummary>().eq(ReportDownloadSummary::getUserId, userId)); if (CollectionUtils.isEmpty(reportDownloadSummaries)){ ReportDownloadSummary entity = ReportDownloadSummary.builder().userId(userId).stdVipLimit(onceAddTimes).build(); reportDownloadSummaryMapper.insert(entity); }else { ReportDownloadSummary entity = reportDownloadSummaries.get(0); entity.setStdVipLimit(entity.getStdVipLimit() + onceAddTimes); reportDownloadSummaryMapper.updateById(entity); } } }