|
@@ -1,6 +1,15 @@
|
|
|
package com.huimv.eartag2.manage2.schedule;
|
|
|
|
|
|
+import cn.hutool.core.date.DateTime;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.huimv.eartag2.manage2.pojo.EartagDeviceRegister;
|
|
|
+import com.huimv.eartag2.manage2.pojo.SysBaseConfig;
|
|
|
+import com.huimv.eartag2.manage2.service.EartagDeviceRegisterService;
|
|
|
import com.huimv.eartag2.manage2.service.IEartagService;
|
|
|
+import com.huimv.eartag2.manage2.service.SysBaseConfigService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
@@ -8,6 +17,7 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.sql.Timestamp;
|
|
|
+import java.util.Date;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
@@ -26,17 +36,55 @@ public class EartagTask {
|
|
|
@Autowired
|
|
|
private IEartagService eartagService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private SysBaseConfigService baseConfigService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private EartagDeviceRegisterService deviceRegisterService;
|
|
|
+
|
|
|
// 10分钟
|
|
|
- @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
- private void countEartagOnlineTimes() throws IOException {
|
|
|
- Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
- System.out.println("时间戳="+nowTimestamp);
|
|
|
-
|
|
|
-// ExecutorService service = Executors.newFixedThreadPool(5);
|
|
|
-// ExecutorService service = Executors.newSingleThreadExecutor();
|
|
|
-// RunnableTaskEartagOnlineStatus task1 = new RunnableTaskEartagOnlineStatus();
|
|
|
-// service.execute(task1);
|
|
|
- //更新耳标在线状态
|
|
|
- eartagService.updateEartagLiveStatusAndCount();
|
|
|
+// @Scheduled(cron = "0 0/10 * * * ? ")
|
|
|
+// private void countEartagOnlineTimes() throws IOException {
|
|
|
+// Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
|
|
|
+// System.out.println("时间戳="+nowTimestamp);
|
|
|
+//
|
|
|
+//// ExecutorService service = Executors.newFixedThreadPool(5);
|
|
|
+//// ExecutorService service = Executors.newSingleThreadExecutor();
|
|
|
+//// RunnableTaskEartagOnlineStatus task1 = new RunnableTaskEartagOnlineStatus();
|
|
|
+//// service.execute(task1);
|
|
|
+// //更新耳标在线状态
|
|
|
+// eartagService.updateEartagLiveStatusAndCount();
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ // 5分钟
|
|
|
+ @Scheduled(cron = "0 0/5 * * * ? ")
|
|
|
+ private void updateDevice() {
|
|
|
+ SysBaseConfig baseConfig = baseConfigService.getById(60);
|
|
|
+
|
|
|
+ String configValueStr = baseConfig.getConfigValue();
|
|
|
+ if (StringUtils.isNotBlank(configValueStr)){
|
|
|
+ int configValueInt = Integer.parseInt(configValueStr);
|
|
|
+ DateTime dateTime = DateUtil.offsetMinute(new Date(), -configValueInt);
|
|
|
+
|
|
|
+ UpdateWrapper<EartagDeviceRegister> wrapper = new UpdateWrapper<>();
|
|
|
+ wrapper.ge("last_time",dateTime);
|
|
|
+ EartagDeviceRegister deviceRegister = new EartagDeviceRegister();
|
|
|
+ //未离线
|
|
|
+ deviceRegister.setActiveStatus(1);
|
|
|
+ deviceRegister.setDeviceStatus(1);
|
|
|
+ deviceRegisterService.update(deviceRegister,wrapper);
|
|
|
+
|
|
|
+ //离线
|
|
|
+ deviceRegister.setActiveStatus(2);
|
|
|
+ deviceRegister.setDeviceStatus(0);
|
|
|
+ wrapper.clear();
|
|
|
+ wrapper.le("last_time",dateTime);
|
|
|
+ deviceRegisterService.update(deviceRegister,wrapper);
|
|
|
+ }else {
|
|
|
+ System.out.println("未设置定时时长");
|
|
|
+ }
|
|
|
+
|
|
|
+ System.out.println("测试数据");
|
|
|
}
|
|
|
}
|