|
@@ -2,6 +2,7 @@ package cn.com.qmth.scancentral.service.impl;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Collections;
|
|
|
+import java.util.Comparator;
|
|
|
import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
@@ -17,8 +18,11 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import cn.com.qmth.scancentral.bean.student.ExamProvinceInfo;
|
|
|
+import cn.com.qmth.scancentral.bean.student.ExamRoomInfo;
|
|
|
import cn.com.qmth.scancentral.service.DataCacheService;
|
|
|
import cn.com.qmth.scancentral.service.StudentService;
|
|
|
+import cn.com.qmth.scancentral.vo.CampusVo;
|
|
|
+import cn.com.qmth.scancentral.vo.ExamSiteVo;
|
|
|
|
|
|
@Service
|
|
|
public class DataCacheServiceImpl implements DataCacheService {
|
|
@@ -29,20 +33,35 @@ public class DataCacheServiceImpl implements DataCacheService {
|
|
|
|
|
|
private Lock provinceLock = new ReentrantLock();
|
|
|
|
|
|
+ private Map<Long, Set<ExamSiteVo>> examSiteCache = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ private Lock examSiteLock = new ReentrantLock();
|
|
|
+
|
|
|
+ private Map<Long, Set<CampusVo>> campusCache = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ private Lock campusLock = new ReentrantLock();
|
|
|
+
|
|
|
+ private Map<Long, Set<String>> examRoomCache = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ private Lock examRoomLock = new ReentrantLock();
|
|
|
+
|
|
|
@Autowired
|
|
|
private StudentService studentService;
|
|
|
|
|
|
@Override
|
|
|
public void loadCache() {
|
|
|
loadProvince();
|
|
|
+ loadExamSite();
|
|
|
+ loadCampus();
|
|
|
+ loadExamRoom();
|
|
|
}
|
|
|
|
|
|
private void loadProvince() {
|
|
|
provinceCache.clear();
|
|
|
- List<ExamProvinceInfo> provinces = studentService.listProvince();
|
|
|
- for (ExamProvinceInfo province : provinces) {
|
|
|
- if (StringUtils.isNotBlank(province.getProvince())) {
|
|
|
- addProvinceCache(province.getExamId(), province.getProvince());
|
|
|
+ List<ExamProvinceInfo> list = studentService.listProvince();
|
|
|
+ for (ExamProvinceInfo info : list) {
|
|
|
+ if (StringUtils.isNotBlank(info.getProvince())) {
|
|
|
+ addProvinceCache(info.getExamId(), info.getProvince());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -73,4 +92,112 @@ public class DataCacheServiceImpl implements DataCacheService {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
+ private void loadExamSite() {
|
|
|
+ examSiteCache.clear();
|
|
|
+ List<ExamSiteVo> list = studentService.listExamSite();
|
|
|
+ for (ExamSiteVo info : list) {
|
|
|
+ if (StringUtils.isNotBlank(info.getCode())) {
|
|
|
+ addExamSiteCache(info.getExamId(), info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addExamSiteCache(Long examId, ExamSiteVo info) {
|
|
|
+ examSiteLock.lock();
|
|
|
+ try {
|
|
|
+ Set<ExamSiteVo> cache = examSiteCache.get(examId);
|
|
|
+ if (cache == null) {
|
|
|
+ cache = new HashSet<>();
|
|
|
+ examSiteCache.put(examId, cache);
|
|
|
+ }
|
|
|
+ cache.add(info);
|
|
|
+ } finally {
|
|
|
+ examSiteLock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<ExamSiteVo> listExamSiteByExamId(Long examId) {
|
|
|
+ Set<ExamSiteVo> cache = examSiteCache.get(examId);
|
|
|
+ List<ExamSiteVo> ret = new ArrayList<>();
|
|
|
+ if (cache == null) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ ret.addAll(cache);
|
|
|
+ ret.sort(Comparator.comparing(ExamSiteVo::getCode));
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadCampus() {
|
|
|
+ campusCache.clear();
|
|
|
+ List<CampusVo> list = studentService.listCampus();
|
|
|
+ for (CampusVo info : list) {
|
|
|
+ if (StringUtils.isNotBlank(info.getCode())) {
|
|
|
+ addCampusCache(info.getExamId(), info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addCampusCache(Long examId, CampusVo info) {
|
|
|
+ campusLock.lock();
|
|
|
+ try {
|
|
|
+ Set<CampusVo> cache = campusCache.get(examId);
|
|
|
+ if (cache == null) {
|
|
|
+ cache = new HashSet<>();
|
|
|
+ campusCache.put(examId, cache);
|
|
|
+ }
|
|
|
+ cache.add(info);
|
|
|
+ } finally {
|
|
|
+ campusLock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<CampusVo> listCampusByExamId(Long examId) {
|
|
|
+ Set<CampusVo> cache = campusCache.get(examId);
|
|
|
+ List<CampusVo> ret = new ArrayList<>();
|
|
|
+ if (cache == null) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ ret.addAll(cache);
|
|
|
+ ret.sort(Comparator.comparing(CampusVo::getCode));
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void loadExamRoom() {
|
|
|
+ examRoomCache.clear();
|
|
|
+ List<ExamRoomInfo> list = studentService.listExamRoom();
|
|
|
+ for (ExamRoomInfo info : list) {
|
|
|
+ if (StringUtils.isNotBlank(info.getExamRoom())) {
|
|
|
+ addExamRoomCache(info.getExamId(), info.getExamRoom());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addExamRoomCache(Long examId, String examRoom) {
|
|
|
+ examRoomLock.lock();
|
|
|
+ try {
|
|
|
+ Set<String> cache = examRoomCache.get(examId);
|
|
|
+ if (cache == null) {
|
|
|
+ cache = new HashSet<>();
|
|
|
+ examRoomCache.put(examId, cache);
|
|
|
+ }
|
|
|
+ cache.add(examRoom);
|
|
|
+ } finally {
|
|
|
+ examRoomLock.unlock();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> listExamRoomByExamId(Long examId) {
|
|
|
+ Set<String> cache = examRoomCache.get(examId);
|
|
|
+ List<String> ret = new ArrayList<>();
|
|
|
+ if (cache == null) {
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ ret.addAll(cache);
|
|
|
+ Collections.sort(ret);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
}
|