|
@@ -0,0 +1,56 @@
|
|
|
+package com.jpsoft.bus.scheduled;
|
|
|
+
|
|
|
+import com.jpsoft.bus.modules.bus.entity.VehicleInfo;
|
|
|
+import com.jpsoft.bus.modules.bus.service.VehicleInfoService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.joda.time.DateTime;
|
|
|
+import org.joda.time.Minutes;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 检查车辆是否有gps传回
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class CheckVehicleTask {
|
|
|
+ @Autowired
|
|
|
+ private VehicleInfoService vehicleInfoService;
|
|
|
+
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ?")
|
|
|
+ public void run() {
|
|
|
+ List<VehicleInfo> vehicleInfoList = vehicleInfoService.getRunningList();
|
|
|
+
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+
|
|
|
+ for (VehicleInfo vehicleInfo : vehicleInfoList) {
|
|
|
+ boolean running = false;
|
|
|
+
|
|
|
+ if (vehicleInfo.getUpdateTime()!=null) {
|
|
|
+ int minutes = Minutes.minutesBetween(new DateTime(vehicleInfo.getUpdateTime()), now).getMinutes();
|
|
|
+
|
|
|
+ if (minutes > 5) {
|
|
|
+ //5分钟未更新
|
|
|
+ running = false;
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ running = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ running = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!running) {
|
|
|
+ vehicleInfo.setRunning(false);
|
|
|
+ vehicleInfo.setUpdateTime(new Date());
|
|
|
+
|
|
|
+ vehicleInfoService.update(vehicleInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|