DownloadPdfService.java 3.58 KB
Newer Older
刘基明's avatar
刘基明 committed
1 2 3
package com.tanpu.fund.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
王亚雷's avatar
王亚雷 committed
4 5
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanpu.common.model.fund.req.IncReportDownloadTimesReq;
刘基明's avatar
刘基明 committed
6 7 8 9 10 11
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;

刘基明's avatar
刘基明 committed
12
import javax.annotation.Resource;
刘基明's avatar
刘基明 committed
13 14 15 16 17
import java.util.List;

@Service
public class DownloadPdfService {

刘基明's avatar
刘基明 committed
18
    @Resource
刘基明's avatar
刘基明 committed
19 20 21 22 23 24
    private ReportDownloadSummaryMapper reportDownloadSummaryMapper;

    private static final Integer onceAddTimes = 200;

    @Transactional(rollbackFor = Exception.class)
    public void emptyStandardVipCount(String userId) {
刘基明's avatar
刘基明 committed
25 26
        LambdaQueryWrapper<ReportDownloadSummary> qw = new LambdaQueryWrapper<>();
        List<ReportDownloadSummary> reportDownloadSummaries = reportDownloadSummaryMapper.selectList(qw.eq(ReportDownloadSummary::getUserId, userId));
刘基明's avatar
刘基明 committed
27 28 29 30 31 32
        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);
刘基明's avatar
刘基明 committed
33 34 35
            entity.setDeepReportStd(0);
            entity.setHoldFundReportStd(0);
            entity.setCumulativeProfitReportStd(0);
刘基明's avatar
刘基明 committed
36 37 38 39 40 41
            reportDownloadSummaryMapper.updateById(entity);
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public void addStandardVipCount(String userId) {
刘基明's avatar
刘基明 committed
42 43
        LambdaQueryWrapper<ReportDownloadSummary> qw = new LambdaQueryWrapper<>();
        List<ReportDownloadSummary> reportDownloadSummaries = reportDownloadSummaryMapper.selectList(qw.eq(ReportDownloadSummary::getUserId, userId));
刘基明's avatar
刘基明 committed
44 45 46 47 48 49 50 51
        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);
        }
王亚雷's avatar
王亚雷 committed
52
    }
刘基明's avatar
刘基明 committed
53

王亚雷's avatar
王亚雷 committed
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
    /**
     * 增加报告下载次数
     *
     * @param req 请求参数
     * @return 总次数
     */
    @Transactional(rollbackFor = Exception.class)
    public int incReportDownloadTimes(IncReportDownloadTimesReq req) {
        ReportDownloadSummary record = reportDownloadSummaryMapper.selectOne(
                Wrappers.<ReportDownloadSummary>lambdaQuery().eq(ReportDownloadSummary::getUserId, req.getUserId()));
        if (record == null) {
            reportDownloadSummaryMapper.insert(
                    ReportDownloadSummary.builder()
                            .userId(req.getUserId())
                            .reportTimesBuy(req.getIncTimes())
                            .build()
            );
        } else {
            reportDownloadSummaryMapper.updateById(
                    ReportDownloadSummary.builder()
                            .id(record.getId())
                            .reportTimesBuy(record.getReportTimesBuy() + req.getIncTimes())
                            .build()
            );
        }
        return record == null ? req.getIncTimes() :  record.getReportTimesBuy() + req.getIncTimes();
刘基明's avatar
刘基明 committed
80 81
    }
}