RevertLineThread.java 1.3 KB
package com.bsth.vehicle.directive.thread;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.bsth.entity.realcontrol.DeviceRevertLine;
import com.bsth.repository.realcontrol.DeviceRevertLineRepository;
import com.bsth.vehicle.directive.service.DirectiveService;

/**
 * 
 * @ClassName: DeviceRevertLineThread 
 * @Description: TODO(设备线路还原线程, 将借出的车还原到原线路) 
 * @author PanZhao
 * @date 2016年7月7日 上午11:30:38 
 *
 */
@Component
public class RevertLineThread extends Thread{
	
	@Autowired
	DeviceRevertLineRepository deviceRevertLineRepository;
	
	@Autowired
	DirectiveService directiveService;
	
	@Override
	public void run() {
		Long et = System.currentTimeMillis()
			,st = et - (1000 * 60 * 5);
		
		List<DeviceRevertLine> list = deviceRevertLineRepository.findByDateAndStatus(st, et, 0);
		
		if(list.size() == 0)
			return;
		
		int code;
		for(DeviceRevertLine revertLine : list){
			//还车
			code = directiveService.lineChange(revertLine.getNbbm(), Integer.parseInt(revertLine.getRevertLine()));
			
			if(code == 0){
				//改变状态
				revertLine.setStatus(1);
				deviceRevertLineRepository.save(revertLine);
			}
		}
	}
}