|
@@ -1,10 +1,24 @@
|
|
|
package com.qmth.themis.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.themis.business.cache.bean.ExamCacheBean;
|
|
|
import com.qmth.themis.business.dao.TEOrgSummaryMapper;
|
|
|
+import com.qmth.themis.business.entity.TBOrg;
|
|
|
+import com.qmth.themis.business.entity.TEExamSummary;
|
|
|
import com.qmth.themis.business.entity.TEOrgSummary;
|
|
|
+import com.qmth.themis.business.enums.OrgSummaryEnum;
|
|
|
+import com.qmth.themis.business.service.TEExamService;
|
|
|
import com.qmth.themis.business.service.TEOrgSummaryService;
|
|
|
+import com.qmth.themis.business.service.ThemisCacheService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.StringJoiner;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -17,4 +31,92 @@ import org.springframework.stereotype.Service;
|
|
|
@Service
|
|
|
public class TEOrgSummaryServiceImpl extends ServiceImpl<TEOrgSummaryMapper, TEOrgSummary> implements TEOrgSummaryService {
|
|
|
|
|
|
-}
|
|
|
+ @Resource
|
|
|
+ ThemisCacheService themisCacheService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEExamService teExamService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ TEOrgSummaryService teOrgSummaryService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存机构统计信息公用
|
|
|
+ *
|
|
|
+ * @param orgId
|
|
|
+ * @param examIdSet
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void orgSummary(Long orgId, List<Long> examIdSet) {
|
|
|
+ TEOrgSummary teOrgSummary = themisCacheService.addOrgSummaryCache(orgId);
|
|
|
+ if (Objects.isNull(teOrgSummary)) {//说明没有缓存
|
|
|
+ if (orgId.longValue() == 0) {//全局机构
|
|
|
+ Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);
|
|
|
+ Integer examCount = this.baseMapper.orgSummaryByExamCount(examIdSet);
|
|
|
+ List<Integer> finishCountList = this.baseMapper.orgSummaryByFinishCountAndFinishStudentCount(examIdSet);
|
|
|
+ teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCountList.get(0), finishCountList.get(1));
|
|
|
+ teOrgSummaryService.saveOrgSummaryCommon(teOrgSummary);
|
|
|
+ } else {
|
|
|
+ LinkedMultiValueMap<Long, Long> orgExamIdMap = new LinkedMultiValueMap<>();
|
|
|
+ boolean reloadDb = false;
|
|
|
+ //先查询考试批次统计缓存
|
|
|
+ for (Long l : examIdSet) {
|
|
|
+ List<TEExamSummary> teExamSummaryList = themisCacheService.addExamSummaryCache(l);
|
|
|
+ if (!CollectionUtils.isEmpty(teExamSummaryList)) {//如果没有该批次的考试统计缓存信息,则自己从数据库取
|
|
|
+ ExamCacheBean examCacheBean = teExamService.getExamCacheBean(l);
|
|
|
+ TBOrg tbOrg = themisCacheService.addOrgCache(examCacheBean.getOrgId());
|
|
|
+ orgExamIdMap.add(tbOrg.getId(), l);
|
|
|
+ } else {
|
|
|
+ reloadDb = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (reloadDb) {//没有该批次的考试统计缓存信息,则从数据库取数据
|
|
|
+ Integer onlineCount = this.baseMapper.orgSummaryByOnlineCount(examIdSet);
|
|
|
+ Integer examCount = this.baseMapper.orgSummaryByExamCount(examIdSet);
|
|
|
+ List<Integer> finishCountList = this.baseMapper.orgSummaryByFinishCountAndFinishStudentCount(examIdSet);
|
|
|
+ teOrgSummary = new TEOrgSummary(orgId, onlineCount, examCount, finishCountList.get(0), finishCountList.get(1));
|
|
|
+ teOrgSummaryService.saveOrgSummaryCommon(teOrgSummary);
|
|
|
+ } else {
|
|
|
+ orgExamIdMap.forEach((k, v) -> {//从考试批次缓存信息里拿取在线人数、考试人数、完成考生数
|
|
|
+ Integer onlineCount = 0, examCount = 0, finishStudentCount = 0;
|
|
|
+ for (Long l : v) {
|
|
|
+ List<TEExamSummary> teExamSummaryList = themisCacheService.addExamSummaryCache(l);
|
|
|
+ for (TEExamSummary t : teExamSummaryList) {
|
|
|
+ onlineCount = onlineCount + t.getOnlineCount();
|
|
|
+ examCount = examCount + t.getExamCount();
|
|
|
+ finishStudentCount = finishStudentCount + t.getFinishCount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Integer finishCount = this.baseMapper.orgSummaryByFinishCount(v);
|
|
|
+ TEOrgSummary teOrgSummaryNotZero = new TEOrgSummary(orgId, onlineCount, examCount, finishCount, finishStudentCount);
|
|
|
+ teOrgSummaryService.saveOrgSummaryCommon(teOrgSummaryNotZero);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存机构统计信息
|
|
|
+ *
|
|
|
+ * @param teOrgSummary
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void saveOrgSummaryCommon(TEOrgSummary teOrgSummary) {
|
|
|
+ StringJoiner stringJoinerFieldName = new StringJoiner(",");
|
|
|
+ StringJoiner stringJoinerFieldValue = new StringJoiner(",");
|
|
|
+ OrgSummaryEnum[] orgSummaryEnums = OrgSummaryEnum.values();
|
|
|
+ for (int i = 0; i < orgSummaryEnums.length; i++) {
|
|
|
+ stringJoinerFieldName.add(orgSummaryEnums[i].getCode());
|
|
|
+ }
|
|
|
+ stringJoinerFieldValue.add("'" + teOrgSummary.getOrgId() + "'")
|
|
|
+ .add(teOrgSummary.getOnlineCount() + "")
|
|
|
+ .add(teOrgSummary.getExamCount() + "")
|
|
|
+ .add(teOrgSummary.getFinishCount() + "")
|
|
|
+ .add(teOrgSummary.getFinishStudentCount() + "");
|
|
|
+ this.baseMapper.saveOrgSummary(stringJoinerFieldName.toString(), stringJoinerFieldValue.toString());
|
|
|
+ }
|
|
|
+}
|