品牌热度定时任务

简介: 品牌热度定时任务

1 设置定时任务

/**
 * @description: 品牌热度定时任务
  * @create: 2021-06-23 18:06
 **/
@Slf4j
@RestController
@RequestMapping("/v1/api/brand/task")
@EnableScheduling
public class BrandHotTask {
    @Resource
    private IBrandHotTaskService brandHotTaskService;
    /**
     *  @ Scheduled(cron = "0 0 1 * * ?")
     *  每日一点开始分析品牌热度数据
     */
    @Scheduled(cron = "0 0 1 * * ?")
    public void execute() {
        log.info("品牌热度定时任务start");
        Date date = DateUtils.getNow();
        Date time = DateUtils.getDayTimeAtFirst(DateUtils.diffDate(date, 1));
        brandHotTaskService.handlerBrandHotData(time);
        log.info("品牌热度定时任务end ");
    }
}

2 进入定时任务接口

public interface IBrandHotTaskService {
    /**
     *  处理品牌热度数据
     * @param executeDate
     */
    void handlerBrandHotData(Date executeDate);
}

3 具体实现

/**
 * @description: 品牌热度定时任务实现接口
 * @create: 2021-06-23 18:12
 **/
@SuppressWarnings("PMD")
@Slf4j
@Service
public class BrandHotTaskServiceImpl implements IBrandHotTaskService {
    @Autowired
    private JoinBrandHotMapper joinBrandHotMapper;
    @Resource
    private IUserVisitRecordRemoteService userVisitRecordRemoteService;
    /**
     *  1. lego_analysis库分析埋点数据,查询品牌详情页面的pageId数据,进行汇总统计
     *  2. 插入hot表及hot_record表
     * @param executeDate
     */
    @SneakyThrows
    @Override
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public void handlerBrandHotData(Date executeDate) {
        log.info("品牌热度定时任务 start executeDate:{}", executeDate);
        BaseResponse<List<UserVisitRecordHitNumber>> response = getUserVisitPageRecord(executeDate);
        if (response == null || CollectionUtil.isEmpty(response.getData())) {
            return;
        }
        List<UserVisitRecordHitNumber> data = response.getData();
        // TODO 后续需要考虑集合过大 循环执行事务时间过长
        for (UserVisitRecordHitNumber datum : data) {
            String brandCode = datum.getRefId();
            String clickCount = datum.getU();
            String realClick = datum.getDu();
            JoinBrandHot joinBrandHot = getJoinBrandHot(brandCode, clickCount, realClick);
            joinBrandHot.setStatus(1);
            JoinBrandHot brandHot = joinBrandHotMapper.getByBrandCode(brandCode);
            if (brandHot == null) {
                joinBrandHotMapper.saveBrandHotTask(joinBrandHot);
            } else {
                joinBrandHot.setId(brandHot.getId());
                joinBrandHotMapper.updateBrandHotTask(joinBrandHot);
            }
            /**
             * 插入到hot_record,直接插入,只作为记录就好
             */
            JoinBrandHotRecord joinBrandHotRecord = getJoinBrandHotRecord(brandCode, clickCount, realClick);
            joinBrandHotMapper.deleteByBrandCodeAndDate(brandCode, DateUtils.getDate());
            joinBrandHotMapper.saveBrandHotTaskToRecord(joinBrandHotRecord);
        }
    }
    private BaseResponse<List<UserVisitRecordHitNumber>> getUserVisitPageRecord(Date executeDate) {
        Date startTime = DateUtils.getDayTimeAtFirst(executeDate);
        Date endTime = DateUtils.getDayTimeAtLast(executeDate);
        String pageId = "10014";
        UserVisitPageReq visitPageReq = new UserVisitPageReq();
        visitPageReq.setPageId(pageId);
        visitPageReq.setStartTime(startTime);
        visitPageReq.setEndTime(endTime);
        BaseResponse<List<UserVisitRecordHitNumber>> response = userVisitRecordRemoteService
                .userVisitRecordByYest(visitPageReq);
        log.info("品牌数据查询pageId:{}, startTime:{},endTime:{}, 结果 response:{}", pageId, startTime,
                endTime, response);
        return response;
    }
    private JoinBrandHot getJoinBrandHot(String brandCode, String clickCount, String realClick) {
        JoinBrandHot joinBrandHot = new JoinBrandHot();
        joinBrandHot.setBrandCode(brandCode);
        joinBrandHot.setClickCount(clickCount);
        joinBrandHot.setRealClick(realClick);
        joinBrandHot.setGmtCreate(DateUtils.getNow());
        joinBrandHot.setGmtModified(DateUtils.getNow());
        return joinBrandHot;
    }
    private JoinBrandHotRecord getJoinBrandHotRecord(String brandCode, String clickCount, String realClick) {
        JoinBrandHotRecord joinBrandHotRecord = new JoinBrandHotRecord();
        joinBrandHotRecord.setBrandCode(brandCode);
        joinBrandHotRecord.setClickCount(clickCount);
        joinBrandHotRecord.setRealClick(realClick);
        joinBrandHotRecord.setGmtCreate(DateUtils.getNow());
        return joinBrandHotRecord;
    }
}
目录
打赏
0
0
0
0
8
分享
相关文章
如何解读过去的一段时间的涨粉图表分析
在涨粉赚钱平台首页,选择“涨粉统计”时,图表区域默认显示所有涨粉号过去7天的涨粉情况统计,你也可以选择过去30天的统计情况或选择自己想查看的具体时间段的涨粉数据。
1186 0
淘宝商品数据洞察:解锁精准营销新策略
在快速变化的商业环境中,高效的营销策略对企业至关重要。通过API获取淘宝APP的商品细节数据,企业可以精准分析产品特性、强化卖点,并制定灵活的价格策略。利用用户画像实现个性化营销,选择最佳渠道并优化内容,从而提升品牌影响力。这一方法不仅帮助企业抓住目标消费者,还能增强市场竞争力,促进长期发展。
消费典型族群特征分析及营销策略方法
全国消费群体差异性大,根据不同年龄、不同阶层、不同性别、不同区域等特征都可以细分出不同的消费群体。其中,最具市场潜力的典型消费群体是80后族群、90后族群。了解他们的特征是企业开展品牌营销的基础。
2024 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等