「已注销」 2021-12-16 10:43 采纳率: 0%
浏览 36
已结题

数据入库时遇到的定时任务调度问题

问题遇到的现象和发生背景
入库时不会定时调度
问题相关代码,请勿粘贴截图
@EnableScheduling
@Component
public class PrecipitationCsvDataScheduler {
private Logger logger = LoggerFactory.getLogger(PrecipitationCsvDataScheduler.class);

@Autowired
TLiveDataService tLiveDataService;

@Scheduled(cron="*/30 * * * * ?")
public void startScheduler()  {
    logger.info("----文件数据入库任务开始----");
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);
    Date startDate = cal.getTime();
    try {
        getPrecipitationForMusic(startDate);
    } catch (IOException ioException) {
        logger.error("----文件数据入库任务失败:{}----",startDate);
        ioException.printStackTrace();
    }
}
public void getPrecipitationForMusic(Date startDate) throws IOException {
    Date  endDate = new Date(startDate.getTime());
    System.out.println(endDate);
    String path = "E:\\需要入库的路径";
    File file = new File(path);
    File[] fileList = file.listFiles();
    Pattern p = Pattern.compile("obs-\\d{10}-\\d{10}.nc");
    TLiveDataDTO tLiveDataDTO =null;
    List<TLiveDataDTO> list = tLiveDataService.findTest();
    Map<String, TLiveDataDTO> maps = new HashMap<>();
    for (TLiveDataDTO tlo : list) {
        maps.put(tlo.getAbsolutePath(), tlo);
    }
    for (File file1:fileList){
        if (maps.get(file1.getAbsolutePath())!=null){
            logger.info("文件已经存在"+file1.getAbsolutePath());
            continue;
        }
        Matcher matcher = p.matcher(file1.getName());
        while(matcher.find()){
            System.out.println(path+File.separator+matcher.group());
            tLiveDataDTO = new TLiveDataDTO();
            String[] filetime = file1.getName().split("-");
            tLiveDataDTO.setType(filetime[0]);
            tLiveDataDTO.setTime(filetime[1].replace(".nc",""));
            tLiveDataDTO.setAbsolutePath(file1.getAbsolutePath());
            tLiveDataService.save(tLiveDataDTO);
        }
    }
}

}
运行结果及报错内容
结果就是入库用正则指定这个类型,不是则无法入库,判断入库文件名,如果库中有该文件,则执行下一次for

  • 写回答

1条回答 默认 最新

  • CSDN专家-sinJack 2021-12-16 10:53
    关注

    不会定时调度指的是没有定时执行还是没触发?

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 12月16日
  • 创建了问题 12月16日

悬赏问题

  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥50 如何将脑的图像投影到颅骨上
  • ¥15 提问一个关于vscode相关的环境配置问题,就是输入中文但是显示不出来,代码在idea可以显示中文,但在vscode不行,不知道怎么配置环境
  • ¥15 netcore使用PuppeteerSharp截图
  • ¥20 这张图页头,页脚具体代码该怎么写?
  • ¥15 关于#sql#的问题,请各位专家解答!
  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
  • ¥15 数字信号处理考试111