90 lines
2.9 KiB
90 lines
2.9 KiB
package com.yingji.quartz;
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.http.HttpRequest;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.yingji.entity.Fire;
|
|
import com.yingji.entity.QuartzLog;
|
|
import com.yingji.service.FireService;
|
|
import com.yingji.service.QuartzLogService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.context.annotation.Configuration;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.time.LocalDateTime;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* 119数据保存定时任务
|
|
*
|
|
* @author wu
|
|
* @since 2024/05/06 10:18
|
|
*/
|
|
@Configuration
|
|
public class FireQuartz {
|
|
|
|
public static final Logger log = LoggerFactory.getLogger(FireQuartz.class);
|
|
|
|
@Resource
|
|
private FireService fireService;
|
|
|
|
|
|
@Resource
|
|
private QuartzLogService quartzLogService;
|
|
|
|
/**
|
|
* 保存所有数据
|
|
*/
|
|
@Async
|
|
@Scheduled(cron = "0 */5 * * * ? ")
|
|
public void savaData() {
|
|
log.info("119接口开始" + LocalDateTime.now());
|
|
QuartzLog quartzLog = new QuartzLog();
|
|
quartzLog.setInterfaceName(2);
|
|
quartzLog.setCreateTime(LocalDateTime.now());
|
|
try {
|
|
// 获取token
|
|
String token = fireService.getToken();
|
|
if (StrUtil.isNotEmpty(token)) {
|
|
// 根据id查询数据保存
|
|
List<Fire> list = fireService.findDataList(token);
|
|
// 110算法接口
|
|
if (CollectionUtil.isNotEmpty(list)) {
|
|
fireService.saveAll(list);
|
|
for (Fire fire : list) {
|
|
link119Algorithm(fire.getId());
|
|
}
|
|
}
|
|
quartzLog.setStatus(1);
|
|
log.info("119接口结束" + LocalDateTime.now());
|
|
} else {
|
|
quartzLog.setStatus(2);
|
|
log.error("============119算法接口获取token失败119接口结束=============");
|
|
}
|
|
} catch (Exception e) {
|
|
quartzLog.setStatus(2);
|
|
} finally {
|
|
quartzLogService.save(quartzLog);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 120算法接口
|
|
*/
|
|
public void link119Algorithm(String id) {
|
|
log.info("============119和110对比算法接口开始" + LocalDateTime.now() + "=============");
|
|
Map<String, String> map = new HashMap<>();
|
|
map.put("id", id);
|
|
String body = JSONUtil.toJsonStr(map);
|
|
String response = HttpRequest.post("http://localhost:9002/link119_algorithm").body(body).execute().body();
|
|
log.info("++++++119和110对比算法响应数据++++++" + response);
|
|
log.info("============119和110对比算法接口结束" + LocalDateTime.now() + "=============");
|
|
}
|
|
}
|