package com.steering.jobface.cld;

import com.steering.jobface.cld.entity.CldDataEntity;
import com.steering.jobface.cld.service.CldDataService;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;
import java.util.TimerTask;

public class CldDataTask extends TimerTask {
    Logger logger = Logger.getLogger(CldDataTask.class);



    @Override
    public synchronized void run() {
        try {
            CldDataService CldDataService = new CldDataService();
            CldActualSync(CldDataService);
        } catch (Exception e) {
            logger.error("天淮测量点同步失败！  :" + e.getMessage());
            e.printStackTrace();
        }
    }

    private void CldActualSync(CldDataService cldDataService) throws Exception {
        CldDataEntity entity = new CldDataEntity();
        ArrayList<CldDataEntity> list = cldDataService.queryData(entity);
        for (CldDataEntity cldDataEntity : list) {
            try {
                cldDataService.insertData(cldDataEntity);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error("天淮测量点同步失败！ "+ cldDataEntity.getJudgeStoveNo() +" :" + e.getMessage());
            }
        }
        cldDataService.updateData(list);
    }

}
