|
@@ -3,15 +3,20 @@ package com.nokia.tsl_data.service;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.nokia.common.basic.DateUtil;
|
|
|
+import com.nokia.common.basic.InstantUtil;
|
|
|
+import com.nokia.common.scheduling.entity.ScheduledTask;
|
|
|
+import com.nokia.common.scheduling.entity._enum.ScheduledStatus;
|
|
|
+import com.nokia.common.scheduling.entity._enum.ScheduledType;
|
|
|
+import com.nokia.common.scheduling.entity.pojo.ScheduledParameter;
|
|
|
+import com.nokia.common.scheduling.service.SchedulingService;
|
|
|
import com.nokia.tsl_data.dao.TaskRecordRepository;
|
|
|
import com.nokia.tsl_data.dao.TslDataDao;
|
|
|
import com.nokia.tsl_data.entity.TaskRecord;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
import java.time.Instant;
|
|
|
-import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -27,38 +32,65 @@ public class TaskService {
|
|
|
private final DataWarehouseService dataWarehouseService;
|
|
|
private final MessageService messageService;
|
|
|
private final TslReportService tslReportService;
|
|
|
+ private final HighQualityDataService highQualityDataService;
|
|
|
+ private final SchedulingService schedulingService;
|
|
|
|
|
|
- public TaskService(WorkFlowService workFlowService, DataWarehouseService dataWarehouseService, MessageService messageService, TslDataDao tslDataDao, TaskRecordRepository taskRecordRepository, TslReportService tslReportService) {
|
|
|
+ public TaskService(WorkFlowService workFlowService, DataWarehouseService dataWarehouseService, MessageService messageService, TslDataDao tslDataDao, TaskRecordRepository taskRecordRepository, TslReportService tslReportService, HighQualityDataService highQualityDataService, SchedulingService schedulingService) {
|
|
|
this.workFlowService = workFlowService;
|
|
|
this.dataWarehouseService = dataWarehouseService;
|
|
|
this.messageService = messageService;
|
|
|
this.tslDataDao = tslDataDao;
|
|
|
this.taskRecordRepository = taskRecordRepository;
|
|
|
this.tslReportService = tslReportService;
|
|
|
+ this.highQualityDataService = highQualityDataService;
|
|
|
+ this.schedulingService = schedulingService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 日报表
|
|
|
+ * 每日定时任务
|
|
|
*/
|
|
|
- public void dailyReport() {
|
|
|
- // 当天时间
|
|
|
- String day = new SimpleDateFormat("yyyyMMdd")
|
|
|
- .format(new Date(System.currentTimeMillis() - 1000L * 3600 * 24));
|
|
|
- try {
|
|
|
- // 检查数据源
|
|
|
- dataWarehouseService.checkSourceAndDelayIfNotOK(day);
|
|
|
- // 入库数据
|
|
|
- dataWarehouseService.warehouseHighQualityCountDay(day);
|
|
|
- dataWarehouseService.warehouseHighQualityListDay(day);
|
|
|
- dataWarehouseService.warehouseMobileComplaintDay(day);
|
|
|
- // 生成表
|
|
|
+ public void dailyWarehouseTask() {
|
|
|
+ String day = InstantUtil.ofPattern("yyyyMMdd").format(Instant.now());
|
|
|
+ // 调度一次 taskService.wareHouseTask(day)
|
|
|
+ ScheduledTask task = new ScheduledTask()
|
|
|
+ .setRegisteredTask(schedulingService.findRegisteredTaskByBeanNameAndMethodName(
|
|
|
+ "taskService", "wareHouseTask"))
|
|
|
+ .setMethodParameter(day)
|
|
|
+ .setStatus(ScheduledStatus.ON)
|
|
|
+ // 马上调度
|
|
|
+ .setScheduledType(ScheduledType.IMMEDIATELY)
|
|
|
+ .setDescription(day + " 报表生成");
|
|
|
+ schedulingService.add(task);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 指定日期任务
|
|
|
+ */
|
|
|
+ public void wareHouseTask(String day) {
|
|
|
+ String result = dataWarehouseService.checkSource(day);
|
|
|
+ if (StringUtils.hasLength(result)) {
|
|
|
+ // 存在异常情况
|
|
|
+ messageService.error(result);
|
|
|
+ // 延时调度,间隔一段时间后再次调度
|
|
|
+ ScheduledTask task = new ScheduledTask()
|
|
|
+ .setRegisteredTask(schedulingService.findRegisteredTaskByBeanNameAndMethodName(
|
|
|
+ "taskService", "wareHouseTask"))
|
|
|
+ .setMethodParameter(day)
|
|
|
+ .setStatus(ScheduledStatus.ON)
|
|
|
+ .setScheduledType(ScheduledType.ONCE)
|
|
|
+ // 延时 1800L 调度
|
|
|
+ .setScheduledParameter(ScheduledParameter.ofDelay(1800L));
|
|
|
+ // 调度任务
|
|
|
+ schedulingService.add(task);
|
|
|
+ } else {
|
|
|
+ // 执行入库任务
|
|
|
+ dataWarehouseService.wareHouse(day);
|
|
|
+ // 生成HighQualityData
|
|
|
+ highQualityDataService.generateHighQualityData(day);
|
|
|
+ // 生成报表
|
|
|
tslReportService.generateReport(day);
|
|
|
// 截图
|
|
|
tslReportService.screenShot(day);
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("定时任务出错--{}", e.getMessage());
|
|
|
- e.printStackTrace();
|
|
|
- messageService.error("定时任务出错--" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -67,10 +99,12 @@ public class TaskService {
|
|
|
* 调度周期每小时
|
|
|
*/
|
|
|
public void updateWorkFlowBasicDataTask() {
|
|
|
+ log.info("从工单系统定时更新数据 任务开始...");
|
|
|
Instant start = taskRecordRepository.findLastSuccessUpdateWorkFlowBasicDataTaskEndInstant();
|
|
|
Instant end = Instant.now();
|
|
|
TaskRecord taskRecord = workFlowService.updateWorkFlowBasicData(start, end);
|
|
|
taskRecordRepository.save(taskRecord);
|
|
|
+ log.info("从工单系统定时更新数据 任务完成...");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -78,6 +112,7 @@ public class TaskService {
|
|
|
* 调度周期,每天
|
|
|
*/
|
|
|
public void tempTableCleanCronTask() {
|
|
|
+ log.info("定时删除过期的临时表 任务开始...");
|
|
|
TaskRecord taskRecord = new TaskRecord();
|
|
|
taskRecord.setTaskName("临时表清理");
|
|
|
taskRecord.setStartTime(Instant.now());
|
|
@@ -101,5 +136,6 @@ public class TaskService {
|
|
|
taskRecord.setEndTime(Instant.now());
|
|
|
taskRecord.setTimeCost(taskRecord.getEndTime().toEpochMilli() - taskRecord.getStartTime().toEpochMilli());
|
|
|
taskRecordRepository.save(taskRecord);
|
|
|
+ log.info("定时删除过期的临时表 任务完成...");
|
|
|
}
|
|
|
}
|