品牌热度定时任务

简介: 品牌热度定时任务

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;
    }
}
相关文章
|
18天前
|
人工智能 自然语言处理 文字识别
阿里云百炼Qwen3.7-Max简介:能力、优势、支持订阅计划参考
Qwen3.7-Max是阿里云百炼面向智能体时代推出的新一代旗舰模型,对标GPT-5.5、Claude Opus 4.7等闭源旗舰。该模型支持百万级token上下文窗口,具备顶级推理能力、多模态搜索与视觉理解增强、流式输出低延迟响应等核心优势,覆盖编程、办公、长周期自主执行等复杂场景。同时支持OpenAI接口兼容,便于系统快速迁移。用户可通过Token Plan团队或节省计划等订阅方式灵活调用,适合企业级高要求场景使用。
6835 30
阿里云百炼Qwen3.7-Max简介:能力、优势、支持订阅计划参考
|
3天前
|
数据采集 人工智能 前端开发
让 Coding Agent 从黑盒到透明:阿里云 Agent 观测审计数据采集实践
AI Agent 规模化落地带来执行黑盒、行为难追溯、成本难度量三大难题。阿里云基于 OTel 标准,面向 Coding Agent、个人通用助理和框架型 Agent,推出 LoongSuite Pilot、插件及探针等无侵入采集方案,让 Agent 实现可看见、可分析、可审计、可治理。
605 138
|
3天前
|
人工智能 弹性计算 运维
阿里云发布堡垒机智能运维Agent,运维交互进入自然语言新时代
支持自然语言运维,提升效率与安全双保障。
1145 0
|
10天前
|
人工智能 安全 定位技术
CodeGraph深度解析 让Claude Code工具调用直降七成的核心原理与实操教程
如今以Claude Code为代表的AI编程智能体已经成为开发者日常编码、项目重构、漏洞修复的必备工具。但在长期使用过程中,几乎所有开发者都会遇到同一个明显痛点:AI虽然具备强大的代码生成与分析能力,却常常陷入盲目探索的循环中。
1171 1
|
13天前
|
存储 定位技术 数据库
CodeGraph 如何让 Claude Code减少 7 成工具调用?
CodeGraph 为 Coding Agent 提供本地代码知识图谱,把函数、类、调用链和框架路由提前整理成“项目地图”,减少盲目搜索和文件读取。它不是新 Agent,而是上下文基础设施,让 Agent 更快找到正确代码路径,平均减少 7 成工具调用。
1272 3
|
11天前
|
人工智能 弹性计算 安全
阿里云618活动时间、活动入口、优惠活动详细解读
2026年阿里云618创新加速季已全面开启,作为年度力度最大的云产品促销活动,本次大促覆盖轻量应用服务器、ECS云服务器、GPU云服务器、数据库、AI算力、安全服务、CDN等全品类产品,推出5亿元算力补贴、新用户限时秒杀、普惠满减、企业专享、免费试用、云大使返佣等多重福利,个人开发者、中小企业、AI团队均可享受专属低价。本文将系统梳理2026年阿里云618活动的完整时间节点、官方参与入口、各类优惠细则、使用规则、热门产品推荐及实操代码,帮助用户精准参与、高效省钱,以最低成本完成上云部署。
982 5
|
9天前
|
人工智能 自然语言处理 安全
Vibe Coding 实战:别盲目跟风,先分清 vibe coding 适合什么场景
本文系统总结vibe coding实战经验:明确其适用场景(原型、小工具、标准化模块),剖析5步落地流程(场景判定→结构化提示词→目录初始化→分模块生成→自动化校验),指出四大常见误区,并推荐适配工具Trae。强调“场景匹配+规则前置”是提效关键,避免盲目套用。
805 1