|
|
@@ -9,6 +9,7 @@ import com.github.microservice.types.common.CommonEnum;
|
|
|
import com.mongodb.client.result.UpdateResult;
|
|
|
import com.zhongshu.card.client.type.OrganizationState;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
+import com.zhongshu.card.server.core.domain.base.SuperMain;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.paySetting.ProjectMainPaySetting;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
@@ -191,34 +192,31 @@ public class CommonService {
|
|
|
return base64;
|
|
|
}
|
|
|
|
|
|
- public String acquire(String key, Long expiration) {
|
|
|
- Query query = Query.query(Criteria.where("_id").is(key).and("token").isNull());
|
|
|
+ public String acquire(String id, Long expiration, SuperMain superMain) {
|
|
|
+ Query query = Query.query(Criteria.where("_id").is(id).and("token").isNull());
|
|
|
String token = TokenUtil.create();
|
|
|
Update update = new Update().set("expireAt", System.currentTimeMillis() + expiration).set("token", token);
|
|
|
|
|
|
FindAndModifyOptions options = new FindAndModifyOptions().upsert(false).returnNew(true);
|
|
|
-
|
|
|
- ProjectMainPaySetting doc = mongoTemplate.findAndModify(query, update, options, ProjectMainPaySetting.class);
|
|
|
+ SuperMain doc = mongoTemplate.findAndModify(query, update, options, superMain.getClass());
|
|
|
if (doc == null) {
|
|
|
- ProjectMainPaySetting lockObj = mongoTemplate.findOne(Query.query(Criteria.where("_id").is(key)), ProjectMainPaySetting.class);
|
|
|
+ SuperMain lockObj = mongoTemplate.findOne(Query.query(Criteria.where("_id").is(id)), ProjectMainPaySetting.class);
|
|
|
doc = lockObj;
|
|
|
}
|
|
|
boolean locked = doc != null && doc.getToken() != null && doc.getToken().equals(token);
|
|
|
|
|
|
- // 如果已过期
|
|
|
if (!locked && doc != null && doc.getExpireAt() < System.currentTimeMillis()) {
|
|
|
- release(key);
|
|
|
- // 成功释放锁, 再次尝试获取锁
|
|
|
- return this.acquire(key, expiration);
|
|
|
+ release(id, superMain);
|
|
|
+ return this.acquire(id, expiration, superMain);
|
|
|
}
|
|
|
return locked ? token : null;
|
|
|
}
|
|
|
|
|
|
- public boolean release(String key) {
|
|
|
- Query releaseQuery = Query.query(Criteria.where("_id").is(key));
|
|
|
+ public boolean release(String id, SuperMain superMain) {
|
|
|
+ Query releaseQuery = Query.query(Criteria.where("_id").is(id));
|
|
|
Update releaseUpdate = new Update().set("expireAt", null).set("token", null);
|
|
|
FindAndModifyOptions releaseOptions = new FindAndModifyOptions().upsert(true).returnNew(true);
|
|
|
- ProjectMainPaySetting flowDisposition = mongoTemplate.findAndModify(releaseQuery, releaseUpdate, releaseOptions, ProjectMainPaySetting.class);
|
|
|
+ SuperMain flowDisposition = mongoTemplate.findAndModify(releaseQuery, releaseUpdate, releaseOptions, superMain.getClass());
|
|
|
return StringUtils.isEmpty(flowDisposition.getToken());
|
|
|
}
|
|
|
|