package com.shcd.scheduling;


import com.shcd.entity.dredging.DredgingImportRule;
import com.shcd.service.dredging.DredgingService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import groovy.util.logging.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
@Slf4j
public class DredgingSchedule {
    @Resource
    private DredgingService dredgingService;
    @XxlJob("Dredging")
    //@Scheduled(cron = "0 0 1 * * ?")
    public ReturnT<String> dredging(String param){
       List<DredgingImportRule> dredgingImportRules =  dredgingService.getAllProjectId();
       if (dredgingImportRules != null && dredgingImportRules.size() > 0){
           for (DredgingImportRule dredgingImportRule : dredgingImportRules) {
               try {
                   dredgingService.importData(dredgingImportRule);
               } catch (Exception e) {
                   e.printStackTrace();
                   XxlJobLogger.log(e.getMessage() + "疏浚数据导入失败");
                   return ReturnT.FAIL;
               }
           }
           System.out.println("ok");
       }
       return ReturnT.SUCCESS;
    }
}
