parent
b9d1be9cb4
commit
7863f11ef7
@ -0,0 +1,26 @@
|
||||
package com.xjs.business.api;
|
||||
|
||||
import com.ruoyi.common.core.constant.ServiceNameConstants;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.api.factory.RemoteTopSearchFactory;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 获取热搜榜内部远程调用feign
|
||||
*
|
||||
* @author xiejs
|
||||
* @since 2022-01-26
|
||||
*/
|
||||
@FeignClient(contextId = "remoteTopSearchFeign",
|
||||
value = ServiceNameConstants.BUSINESS_OPENAPI_SERVICE,
|
||||
fallbackFactory = RemoteTopSearchFactory.class)
|
||||
public interface RemoteTopSearchFeign {
|
||||
|
||||
|
||||
@GetMapping("/topsearch/getTopsearchForRPC")
|
||||
R<Map<String, List>> topSearchForRPC();
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.xjs.business.api.factory;
|
||||
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.api.RemoteTopSearchFeign;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-26
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class RemoteTopSearchFactory implements FallbackFactory<RemoteTopSearchFeign> {
|
||||
|
||||
@Override
|
||||
public RemoteTopSearchFeign create(Throwable cause) {
|
||||
return new RemoteTopSearchFeign() {
|
||||
@Override
|
||||
public R<Map<String, List>> topSearchForRPC() {
|
||||
log.error("api模块获取热搜服务调用失败:{}", cause.getMessage());
|
||||
return R.fail("文案服务调用失败" + cause.getMessage());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.xjs.job.task;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.xjs.business.api.RemoteTopSearchFeign;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 热搜榜定时任务
|
||||
* @author xiejs
|
||||
* @since 2022-01-26
|
||||
*/
|
||||
@Component("TopSearchTask")
|
||||
@Log4j2
|
||||
public class TopSearchTask {
|
||||
|
||||
@Resource
|
||||
private RemoteTopSearchFeign remoteTopSearchFeign;
|
||||
|
||||
/**
|
||||
* 定时获取热搜榜
|
||||
*/
|
||||
public void getTopSearch() {
|
||||
log.info("---------------热搜榜定时任务Start-------------------");
|
||||
LocalDateTime localDateTime1 = DateUtil.date().toLocalDateTime();
|
||||
|
||||
R<Map<String, List>> mapR = remoteTopSearchFeign.topSearchForRPC();
|
||||
log.info("热搜榜定时任务结果:code={},msg={}",mapR.getCode(),mapR.getMsg());
|
||||
|
||||
LocalDateTime localDateTime2 = DateUtil.date().toLocalDateTime();
|
||||
long between = ChronoUnit.MILLIS.between(localDateTime1, localDateTime2);
|
||||
log.info("热搜榜定时任务Job耗费时间:{}ms", between);
|
||||
log.info("---------------热搜榜定时任务end---------------------");
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +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;
|
||||
|
||||
/**
|
||||
* 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.deleteRepeatData();
|
||||
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();
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package com.xjs.common.task;
|
||||
|
||||
import com.xjs.XjsOpenApiApp;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
/**
|
||||
* @author xiejs
|
||||
* @since 2022-01-12
|
||||
*/
|
||||
@SpringBootTest(classes = XjsOpenApiApp.class)
|
||||
class OpenApiTaskTest {
|
||||
@Autowired
|
||||
private OpenApiTask openApiTask;
|
||||
|
||||
@Test
|
||||
void execute() {
|
||||
openApiTask.deleteRepeat();
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
package com.xjs.task;
|
||||
|
||||
import com.xjs.domain.ApiRecord;
|
||||
import com.xjs.handler.RecordDateHandler;
|
||||
import com.xjs.service.ApiWarningService;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 预警相关定时任务
|
||||
* @author xiejs
|
||||
* @since 2022-01-21
|
||||
*/
|
||||
@Component
|
||||
@Log4j2
|
||||
public class WarningTask extends RecordDateHandler {
|
||||
|
||||
@Autowired
|
||||
private ApiWarningService apiWarningService;
|
||||
|
||||
/**
|
||||
* 处理预警api信息的每天调用次数<br>
|
||||
* 最近10次运行:<br>
|
||||
* 2022-01-22 00:00:10<br>
|
||||
* 2022-01-23 00:00:10<br>
|
||||
* 2022-01-24 00:00:10<br>
|
||||
* 2022-01-25 00:00:10<br>
|
||||
* 2022-01-26 00:00:10<br>
|
||||
* 2022-01-27 00:00:10<br>
|
||||
* 2022-01-28 00:00:10<br>
|
||||
* 2022-01-29 00:00:10<br>
|
||||
* 2022-01-30 00:00:10<br>
|
||||
* 2022-01-31 00:00:10<br>
|
||||
*/
|
||||
@Scheduled(cron = "10 0 0 * * ? ")
|
||||
public void handleRecordDate() {
|
||||
List<ApiRecord> apiRecordList = apiWarningService.selectApiRecordList(new ApiRecord());
|
||||
List<ApiRecord> handleDate = super.handleDate(apiRecordList);
|
||||
handleDate.forEach(data ->{
|
||||
apiWarningService.updateApiRecordByUrl(data);
|
||||
});
|
||||
log.info("定时任务处理预警api信息的每天调用次数完毕");
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue