1、定时获取热搜榜数据

pull/254/head
xjs 4 years ago
parent 075d505b80
commit 9c8a8c81ef

@ -1,53 +0,0 @@
package com.xjs.common.task;
import com.xjs.copywriting.service.CopyWritingService;
import com.xjs.topsearch.service.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* @author xiejs
* @desc
* @create 2022-01-06
*/
@Component
@Log4j2
public class DeleteRepeatTask {
@Autowired
private CopyWritingService copyWritingService;
@Autowired
private ApiTopsearchAllnetworkService apiTopsearchAllnetworkService;
@Autowired
private ApiTopsearchWechatService apiTopsearchWechatService;
@Autowired
private ApiTopsearchBaiduService apiTopsearchBaiduService;
@Autowired
private ApiTopsearchDouyinService apiTopsearchDouyinService;
@Autowired
private ApiTopsearchWeiboService apiTopsearchWeiboService;
/**
* 2022-01-07 07:00:00<br>
* 2022-01-07 08:00:00<br>
* 2022-01-07 09:00:00<br>
* 2022-01-07 10:00:00<br>
*/
@Scheduled(cron = "0 0 10,14,20 * * ? ")
public void execute() {
int copyWritingCount = copyWritingService.deleteRepeatData();
log.info("thread id:{},定时清除文案重复数据,重复数:{}", Thread.currentThread().getId(),copyWritingCount);
Integer allNetworkCount = apiTopsearchAllnetworkService.deleteRepeatData();
log.info("thread id:{},定时清除全网热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),allNetworkCount);
Integer wechatCount = apiTopsearchWechatService.deleteRepeatData();
log.info("thread id:{},定时清除微信热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),wechatCount);
Integer baiduCount = apiTopsearchBaiduService.deleteRepeatData();
log.info("thread id:{},定时清除百度热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),baiduCount);
Integer douyinCount = apiTopsearchDouyinService.deleteRepeatData();
log.info("thread id:{},定时清除抖音热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),douyinCount);
Integer weiboCount = apiTopsearchWeiboService.deleteRepeatData();
log.info("thread id:{},定时清除微博热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),weiboCount);
}
}

@ -0,0 +1,54 @@
package com.xjs.common.task;
import com.xjs.copywriting.service.CopyWritingService;
import com.xjs.topsearch.service.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* openapi
* @author xiejs
* @since 2022-01-06
*/
@Component
@Log4j2
public class OpenApiTask {
@Autowired
private CopyWritingService copyWritingService;
@Autowired
private TopSearchService topSearchService;
/**
* <br>
* 2022-01-07 07:00:00<br>
* 2022-01-07 08:00:00<br>
* 2022-01-07 09:00:00<br>
* 2022-01-07 10:00:00<br>
*/
@Scheduled(cron = "0 0 10,14,20 * * ? ")
public void deleteRepeat() {
int copyWritingCount = copyWritingService.deleteRepeatData();
log.info("thread id:{},定时清除文案重复数据,重复数:{}", Thread.currentThread().getId(),copyWritingCount);
Integer integer = topSearchService.deleteRepeat();
log.info("thread id:{},定时清除重复数据总数,重复数:{}", Thread.currentThread().getId(),integer);
}
/**
* <br>
* 2022-01-22 11:11:00<br>
* 2022-01-22 11:22:00<br>
* 2022-01-22 11:33:00<br>
* 2022-01-22 11:44:00<br>
* 2022-01-22 11:55:00<br>
*/
@Scheduled(cron = "0 0/11 * * * ? ")
public void getTopSearch() {
log.info("thread id:{},定时获取热搜榜数据", Thread.currentThread().getId());
topSearchService.getAllTopSearch();
}
}

@ -4,8 +4,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.xjs.topsearch.domain.*;
import com.xjs.topsearch.factory.TopserachFactory;
import com.xjs.topsearch.service.TopSearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@ -34,15 +32,8 @@ import static com.xjs.consts.RedisConst.HOT_EXPIRE;
public class ApiTopSearchController {
@Autowired
private TopserachFactory<ApiTopsearchAllnetwork> tianXingTopsearchAllnetworkFactory;
@Autowired
private TopserachFactory<ApiTopsearchWechat> tianXingTopsearchWechatFactory;
@Autowired
private TopserachFactory<ApiTopsearchBaidu> tianXingTopsearchBaiduFactory;
@Autowired
private TopserachFactory<ApiTopsearchWeibo> tianXingTopsearchWeiboFactory;
@Autowired
private TopserachFactory<ApiTopsearchDouyin> tianXingTopsearchDouyinFactory;
private TopSearchService topSearchService;
@Autowired
private RedisService redisService;
@ -56,25 +47,7 @@ public class ApiTopSearchController {
Map<String, List> cacheObject = redisService.getCacheObject(HOT);
return AjaxResult.success(cacheObject);
}
//获取全网热搜
List<ApiTopsearchAllnetwork> allnetworkList = tianXingTopsearchAllnetworkFactory.topSearchApi();
//获取微博热搜
List<ApiTopsearchWeibo> weiboList = tianXingTopsearchWeiboFactory.topSearchApi();
//获取抖音热搜
List<ApiTopsearchDouyin> douyinList = tianXingTopsearchDouyinFactory.topSearchApi();
//获取微信热搜
List<ApiTopsearchWechat> wechatList = tianXingTopsearchWechatFactory.topSearchApi();
//获取百度热搜
List<ApiTopsearchBaidu> baiduList = tianXingTopsearchBaiduFactory.topSearchApi();
Map<String, List> listHashMap = new HashMap<>();
listHashMap.put("allnetworkList", allnetworkList);
listHashMap.put("wechatList", wechatList);
listHashMap.put("baiduList", baiduList);
listHashMap.put("weiboList", weiboList);
listHashMap.put("douyinList", douyinList);
Map<String, List> listHashMap = topSearchService.getAllTopSearch();
//把数据存入redis十分钟过期
redisService.setCacheObject(HOT,listHashMap,HOT_EXPIRE, TimeUnit.MINUTES);
return AjaxResult.success(listHashMap);

@ -0,0 +1,27 @@
package com.xjs.topsearch.service;
import java.util.List;
import java.util.Map;
/**
*
* @author xiejs
* @since 2022-01-22
*/
public interface TopSearchService {
/**
*
* @return
*/
Map<String, List> getAllTopSearch();
/**
*
* @return
*/
Integer deleteRepeat();
}

@ -0,0 +1,81 @@
package com.xjs.topsearch.service.impl;
import com.xjs.topsearch.domain.*;
import com.xjs.topsearch.factory.TopserachFactory;
import com.xjs.topsearch.service.*;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
* @author xiejs
* @since 2022-01-22
*/
@Service
@Log4j2
public class TopSearchServiceImpl implements TopSearchService {
@Autowired
private TopserachFactory<ApiTopsearchAllnetwork> tianXingTopsearchAllnetworkFactory;
@Autowired
private TopserachFactory<ApiTopsearchWechat> tianXingTopsearchWechatFactory;
@Autowired
private TopserachFactory<ApiTopsearchBaidu> tianXingTopsearchBaiduFactory;
@Autowired
private TopserachFactory<ApiTopsearchWeibo> tianXingTopsearchWeiboFactory;
@Autowired
private TopserachFactory<ApiTopsearchDouyin> tianXingTopsearchDouyinFactory;
@Autowired
private ApiTopsearchAllnetworkService apiTopsearchAllnetworkService;
@Autowired
private ApiTopsearchWechatService apiTopsearchWechatService;
@Autowired
private ApiTopsearchBaiduService apiTopsearchBaiduService;
@Autowired
private ApiTopsearchDouyinService apiTopsearchDouyinService;
@Autowired
private ApiTopsearchWeiboService apiTopsearchWeiboService;
@Override
public Map<String, List> getAllTopSearch() {
//获取全网热搜
List<ApiTopsearchAllnetwork> allnetworkList = tianXingTopsearchAllnetworkFactory.topSearchApi();
//获取微博热搜
List<ApiTopsearchWeibo> weiboList = tianXingTopsearchWeiboFactory.topSearchApi();
//获取抖音热搜
List<ApiTopsearchDouyin> douyinList = tianXingTopsearchDouyinFactory.topSearchApi();
//获取微信热搜
List<ApiTopsearchWechat> wechatList = tianXingTopsearchWechatFactory.topSearchApi();
//获取百度热搜
List<ApiTopsearchBaidu> baiduList = tianXingTopsearchBaiduFactory.topSearchApi();
Map<String, List> listHashMap = new HashMap<>();
listHashMap.put("allnetworkList", allnetworkList);
listHashMap.put("wechatList", wechatList);
listHashMap.put("baiduList", baiduList);
listHashMap.put("weiboList", weiboList);
listHashMap.put("douyinList", douyinList);
return listHashMap;
}
@Override
public Integer deleteRepeat() {
Integer allNetworkCount = apiTopsearchAllnetworkService.deleteRepeatData();
log.info("thread id:{},清除全网热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),allNetworkCount);
Integer wechatCount = apiTopsearchWechatService.deleteRepeatData();
log.info("thread id:{},清除微信热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),wechatCount);
Integer baiduCount = apiTopsearchBaiduService.deleteRepeatData();
log.info("thread id:{},清除百度热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),baiduCount);
Integer douyinCount = apiTopsearchDouyinService.deleteRepeatData();
log.info("thread id:{},清除抖音热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),douyinCount);
Integer weiboCount = apiTopsearchWeiboService.deleteRepeatData();
log.info("thread id:{},清除微博热搜榜重复数据,重复数:{}", Thread.currentThread().getId(),weiboCount);
return allNetworkCount+wechatCount+baiduCount+douyinCount+weiboCount;
}
}

@ -5,19 +5,17 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author xiejs
* @since 2022-01-12
*/
@SpringBootTest(classes = XjsOpenApiApp.class)
class DeleteRepeatTaskTest {
class OpenApiTaskTest {
@Autowired
private DeleteRepeatTask deleteRepeatTask;
private OpenApiTask openApiTask;
@Test
void execute() {
deleteRepeatTask.execute();
openApiTask.deleteRepeat();
}
}
Loading…
Cancel
Save