You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.5 KiB
82 lines
2.5 KiB
package com.yingji.quartz;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.yingji.entity.Alarm;
|
|
import com.yingji.entity.dto.request.AlarmRequest;
|
|
import com.yingji.service.AlarmService;
|
|
import com.yingji.service.SourceService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* 110数据保存定时任务
|
|
*
|
|
* @author wu
|
|
* @since 2024/05/06 10:18
|
|
*/
|
|
@Configuration
|
|
@EnableScheduling
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public class SaveAlarmQuartz {
|
|
|
|
public static final Logger log = LoggerFactory.getLogger(SaveAlarmQuartz.class);
|
|
|
|
@Resource
|
|
private AlarmService alarmService;
|
|
|
|
@Resource
|
|
private SourceService sourceService;
|
|
|
|
@Scheduled(cron = "0 */1 * * * ? ")
|
|
private void savaData() {
|
|
// 查询所有id
|
|
List<String> data = sourceService.findSourceAll();
|
|
// 查询数据条件
|
|
AlarmRequest alarmRequest = new AlarmRequest();
|
|
alarmRequest.setType("getValue");
|
|
alarmRequest.setPageIndex(1);
|
|
alarmRequest.setPageSize(10);
|
|
// 定义成功条数
|
|
int successNum = 0;
|
|
// 定义失败条数
|
|
int failuresNum = 0;
|
|
List<Alarm> list = new ArrayList<>();
|
|
if (data == null) {
|
|
return;
|
|
}
|
|
// 获取token
|
|
String token = alarmService.getToken();
|
|
if (StrUtil.isEmpty(token)) {
|
|
return;
|
|
}
|
|
for (String x : data) {
|
|
try {
|
|
alarmRequest.setValue(x);
|
|
Alarm alarm = alarmService.findDataList(alarmRequest, token);
|
|
if (alarm != null) {
|
|
alarm.setSourceId(x);
|
|
list.add(alarm);
|
|
sourceService.delBySourceId(x);
|
|
successNum++;
|
|
Thread.sleep(2000);
|
|
}
|
|
} catch (Exception e) {
|
|
failuresNum++;
|
|
log.info("==========================" + "id:" + x, "更新数据失败");
|
|
log.info("失败更新=========================" + failuresNum + "条数据");
|
|
}
|
|
}
|
|
alarmService.saveBatch(list);
|
|
log.info("成功更新=========================" + successNum + "条数据");
|
|
|
|
}
|
|
}
|