RankLogService.java 2.42 KB
package com.tanpu.community.service;

import com.tanpu.common.util.JsonUtil;
import com.tanpu.community.api.beans.qo.ThemeAnalysDO;
import com.tanpu.community.api.beans.qo.TopicRankQo;
import com.tanpu.community.api.enums.RankLogTypeEnum;
import com.tanpu.community.dao.entity.community.RankLogEntity;
import com.tanpu.community.dao.mapper.community.RankLogMapper;
import com.tanpu.community.util.BizUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class RankLogService {


    @Resource
    private RankLogMapper rankLogMapper;

    private Integer pageSize = 50;


    //话题排序日志
    public void logTopicRank(List<TopicRankQo> rankList, LocalDateTime logTime, Long cost) {
        if (CollectionUtils.isEmpty(rankList)) {
            return;
        }
        //分页插入
        for (int i = 0; i * pageSize < rankList.size(); i++) {
            int pageStart = i * pageSize;
            List<TopicRankQo> sublist = BizUtils.subList(rankList, pageStart, pageSize);
            RankLogEntity entity = RankLogEntity.builder().rankTime(logTime)
                    .type(RankLogTypeEnum.TOPIC.getCode())
                    .totalCount(rankList.size())
                    .rankCost(cost)
                    .content(JsonUtil.toJson(sublist))
                    .pageNumber(i + 1)
                    .pageSize(sublist.size())
                    .build();
            rankLogMapper.insert(entity);
        }
    }

    //主题排序日志
    public void logThemeRank(List<ThemeAnalysDO> themeList, LocalDateTime logTime, Long cost) {
        if (CollectionUtils.isEmpty(themeList)) {
            return;
        }
        //分页插入
        for (int i = 0; i * pageSize < themeList.size(); i++) {
            int pageStart = i * pageSize;
            List<ThemeAnalysDO> sublist = BizUtils.subList(themeList, pageStart, pageSize);
            RankLogEntity entity = RankLogEntity.builder().rankTime(logTime)
                    .type(RankLogTypeEnum.THEME.getCode())
                    .totalCount(themeList.size())
                    .rankCost(cost)
                    .content(JsonUtil.toJson(sublist))
                    .pageNumber(i + 1)
                    .pageSize(sublist.size())
                    .build();
            rankLogMapper.insert(entity);
        }
    }
}