|
|
@@ -15,14 +15,15 @@ import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
-import org.springframework.data.mongodb.core.FindAndModifyOptions;
|
|
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
import org.springframework.data.mongodb.core.query.Criteria;
|
|
|
import org.springframework.data.mongodb.core.query.Query;
|
|
|
-import org.springframework.data.mongodb.core.query.Update;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
-import java.util.*;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -78,17 +79,15 @@ public class SimpleTaskTimerDao {
|
|
|
}).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 通过id找到这条数据
|
|
|
- *
|
|
|
- * @param id
|
|
|
- * @return
|
|
|
- */
|
|
|
public <T> T findById(String id) {
|
|
|
return (T) this.mongoTemplate.findById(id, this.taskTimerTableCls);
|
|
|
}
|
|
|
|
|
|
+ public boolean existsById(String id) {
|
|
|
+ return this.mongoTemplate.exists(Query.query(Criteria.where("_id").is(id)), this.taskTimerTableCls);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 查询并转换为任务调度器对象
|
|
|
*
|
|
|
@@ -112,36 +111,36 @@ public class SimpleTaskTimerDao {
|
|
|
}
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 执行锁定时间
|
|
|
- */
|
|
|
- public boolean lockTime(String id) {
|
|
|
- final String lockSession = UUID.randomUUID().toString();
|
|
|
- Query query = Query.query(
|
|
|
- Criteria.where("_id").is(id).and("executeLockTIme").lt(this.dbHelper.getTime())
|
|
|
- );
|
|
|
- Update update = new Update();
|
|
|
- update.set("executeLockTIme", (this.dbHelper.getTime() + this.taskTimerConf.getExecuteLockTIme()));
|
|
|
- update.set("lockSession", lockSession);
|
|
|
- this.dbHelper.updateTime(update);
|
|
|
-
|
|
|
- //取出数据实体
|
|
|
- final SimpleTaskTimerTable simpleTaskTimerTable = (SimpleTaskTimerTable) this.mongoTemplate.findAndModify(query, update, FindAndModifyOptions.options().returnNew(true), getTaskTimerTableCls());
|
|
|
- return simpleTaskTimerTable != null && lockSession.equals(simpleTaskTimerTable.getLockSession());
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 解除锁定时间
|
|
|
- *
|
|
|
- * @param id
|
|
|
- */
|
|
|
- public void unlockTime(String id) {
|
|
|
- Query query = Query.query(Criteria.where("_id").is(id));
|
|
|
- Update update = new Update();
|
|
|
- update.set("executeLockTIme", 0);
|
|
|
- this.dbHelper.updateTime(update);
|
|
|
- this.mongoTemplate.updateFirst(query, update, getTaskTimerTableCls());
|
|
|
- }
|
|
|
+// /**
|
|
|
+// * 执行锁定时间
|
|
|
+// */
|
|
|
+// public boolean lockTime(String id) {
|
|
|
+// final String lockSession = UUID.randomUUID().toString();
|
|
|
+// Query query = Query.query(
|
|
|
+// Criteria.where("_id").is(id).and("executeLockTIme").lt(this.dbHelper.getTime())
|
|
|
+// );
|
|
|
+// Update update = new Update();
|
|
|
+// update.set("executeLockTIme", (this.dbHelper.getTime() + this.taskTimerConf.getExecuteLockTIme()));
|
|
|
+// update.set("lockSession", lockSession);
|
|
|
+// this.dbHelper.updateTime(update);
|
|
|
+//
|
|
|
+// //取出数据实体
|
|
|
+// final SimpleTaskTimerTable simpleTaskTimerTable = (SimpleTaskTimerTable) this.mongoTemplate.findAndModify(query, update, FindAndModifyOptions.options().returnNew(true), getTaskTimerTableCls());
|
|
|
+// return simpleTaskTimerTable != null && lockSession.equals(simpleTaskTimerTable.getLockSession());
|
|
|
+// }
|
|
|
+//
|
|
|
+// /**
|
|
|
+// * 解除锁定时间
|
|
|
+// *
|
|
|
+// * @param id
|
|
|
+// */
|
|
|
+// public void unlockTime(String id) {
|
|
|
+// Query query = Query.query(Criteria.where("_id").is(id));
|
|
|
+// Update update = new Update();
|
|
|
+// update.set("executeLockTIme", 0);
|
|
|
+// this.dbHelper.updateTime(update);
|
|
|
+// this.mongoTemplate.updateFirst(query, update, getTaskTimerTableCls());
|
|
|
+// }
|
|
|
|
|
|
|
|
|
}
|