GetSchedulePlanThread.java 2.3 KB
package com.bsth.service.realcontrol;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.bsth.entity.realcontrol.ScheduleRealInfo;
import com.bsth.entity.schedule.SchedulePlanInfo;
import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
import com.bsth.repository.schedule.SchedulePlanInfoRepository;
import com.bsth.util.BatchSaveUtils;

/**
 * 
 * @ClassName: GetSchedulePlanThread 
 * @Description: TODO(从计划排班表抓取当天实际排班) 
 * @author PanZhao
 * @date 2016年6月6日 下午7:42:43 
 *
 */
@Component
public class GetSchedulePlanThread  extends Thread{
	
	Logger logger = LoggerFactory.getLogger(this.getClass());

	@Autowired
	SchedulePlanInfoRepository schedulePlanInfoRepository;
	
	@Autowired
	ScheduleRealInfoRepository scheduleRealInfoRepository;
	
	SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd")
				,sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	
	SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	
	@Override
	public void run() {
		try{
			String dateStr = /*sdf.format(new Date())*/"2016-06-01";
			List<SchedulePlanInfo> list = schedulePlanInfoRepository.findByDate(dateStr);
			logger.info("开始................." + sdf3.format(new Date(System.currentTimeMillis())));
			
			//实际排班计划
			List<ScheduleRealInfo>  realList = JSONArray.parseArray(JSON.toJSONString(list), ScheduleRealInfo.class);
			
			for(ScheduleRealInfo item : realList){
				item.setDfsj(item.getFcsj());
				//发车时间戳
				item.setFcsjT(sdf2.parse(dateStr + " " + item.getFcsj()).getTime());
			}
			
			//scheduleRealInfoRepository.save(realList);
			new BatchSaveUtils<ScheduleRealInfo>().saveListMysql(realList, ScheduleRealInfo.class);
			//写入缓存
			ScheduleBuffer.init(realList);
			logger.info("结束................." + sdf3.format(new Date(System.currentTimeMillis())));
			
			logger.info("获取当天实际排班计划数量:" + realList.size());
		}catch(Exception e){
			logger.error("",e);
		}
	}
}