|
@@ -0,0 +1,70 @@
|
|
|
|
+package cn.com.qmth.examcloud.core.basic.service.cache;
|
|
|
|
+
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+
|
|
|
|
+import com.google.common.collect.Lists;
|
|
|
|
+
|
|
|
|
+import cn.com.qmth.examcloud.commons.helpers.ObjectHolder;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.AppRepo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.AppEntity;
|
|
|
|
+import cn.com.qmth.examcloud.support.cache.bean.AppCacheBean;
|
|
|
|
+import cn.com.qmth.examcloud.web.cache.FullObjectRedisCache;
|
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
+
|
|
|
|
+@Service
|
|
|
|
+public class AppCache extends FullObjectRedisCache<AppCacheBean> {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ AppRepo appRepo;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public AppCacheBean loadFromResource(Object... keys) {
|
|
|
|
+ Long appId = (Long) keys[0];
|
|
|
|
+ AppEntity a = GlobalHelper.getPresentEntity(appRepo, appId, AppEntity.class);
|
|
|
|
+
|
|
|
|
+ AppCacheBean b = new AppCacheBean();
|
|
|
|
+ b.setCode(a.getCode());
|
|
|
|
+ b.setId(a.getId());
|
|
|
|
+ b.setName(a.getName());
|
|
|
|
+ b.setSecretKey(a.getSecretKey());
|
|
|
|
+ b.setTimeRange(a.getTimeRange());
|
|
|
|
+
|
|
|
|
+ return b;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected String getKeyPrefix() {
|
|
|
|
+ return "$_APP:";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ protected List<Object[]> getKeys(ObjectHolder<Long> beginIndex, ObjectHolder<Boolean> empty) {
|
|
|
|
+ if (beginIndex.isNull()) {
|
|
|
|
+ beginIndex.set(0L);
|
|
|
|
+ }
|
|
|
|
+ Long begin = beginIndex.get();
|
|
|
|
+ Long end = begin + 500;
|
|
|
|
+
|
|
|
|
+ List<Object[]> list = appRepo.findIdList(begin, end);
|
|
|
|
+
|
|
|
|
+ List<Object[]> ret = Lists.newArrayList();
|
|
|
|
+
|
|
|
|
+ empty.set(CollectionUtils.isEmpty(list));
|
|
|
|
+ if (empty.get()) {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (Object[] cur : list) {
|
|
|
|
+ Long id = (Long) cur[0];
|
|
|
|
+ Object[] e = new Object[]{id};
|
|
|
|
+ ret.add(e);
|
|
|
|
+ beginIndex.set(id + 1);
|
|
|
|
+ }
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|