소스 검색

优化首页获取各种类型

郭超 4 년 전
부모
커밋
a972d370a4

+ 22 - 10
core/src/main/java/com/mooctest/crowd/domain/repository/CommonRepo.java

@@ -253,10 +253,6 @@ public class CommonRepo {
         return testTypePO.get().getName();
     }
 
-    public Map<String, String> getTypeCodeNameMap() {
-        return testTypeDao.findAll().stream()
-                .collect(Collectors.toMap(testTypePO -> testTypePO.getCode(), testTypePO -> testTypePO.getName()));
-    }
 
     public String getApplicationNameByCode(String code) {
         Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByCode(code);
@@ -272,12 +268,6 @@ public class CommonRepo {
     }
 
 
-    public Map<String, String> getApplicationCodeNameMap() {
-        return applicationTypeDao.findAll().stream()
-                .collect(Collectors.toMap(applicationTypePO -> applicationTypePO.getCode(), applicationTypePO -> applicationTypePO.getName()));
-
-    }
-
     public String getFieldCodeByFieldName(String name) {
         Optional<FieldPO> fieldPO = fieldDao.findByName(name);
         if (!fieldPO.isPresent()) {
@@ -296,11 +286,33 @@ public class CommonRepo {
         }
     }
 
+    public List<Field> getFieldList() {
+        return fieldDao.findAll().stream().map(fieldPO -> Converter.convert(Field.class, fieldPO)).collect(Collectors.toList());
+    }
+
+    public List<ApplicationType> getApplicationList() {
+        return applicationTypeDao.findAll().stream().map(applicationTypePO -> Converter.convert(ApplicationType.class, applicationTypePO)).collect(Collectors.toList());
+    }
+
+    public List<TestType> getTypeList() {
+        return testTypeDao.findAll().stream().map(testTypePO -> Converter.convert(TestType.class, testTypePO)).collect(Collectors.toList());
+    }
+
     public Map<String, String> getFieldCodeNameMap() {
         return fieldDao.findAll().stream()
                 .collect(Collectors.toMap(fieldPO -> fieldPO.getCode(), fieldPO -> fieldPO.getName()));
     }
 
+    public Map<String, String> getApplicationCodeNameMap() {
+        return applicationTypeDao.findAll().stream()
+                .collect(Collectors.toMap(applicationTypePO -> applicationTypePO.getCode(), applicationTypePO -> applicationTypePO.getName()));
+    }
+
+    public Map<String, String> getTypeCodeNameMap() {
+        return testTypeDao.findAll().stream()
+                .collect(Collectors.toMap(testTypePO -> testTypePO.getCode(), testTypePO -> testTypePO.getName()));
+    }
+
     public String getApplicationCodeByName(String name) {
         Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByName(name);
         if (!applicationTypePO.isPresent()) {

+ 29 - 3
site/src/main/java/com/mooctest/crowd/site/configuration/DataCache.java

@@ -1,5 +1,8 @@
 package com.mooctest.crowd.site.configuration;
 
+import com.mooctest.crowd.domain.domainobject.ApplicationType;
+import com.mooctest.crowd.domain.domainobject.Field;
+import com.mooctest.crowd.domain.domainobject.TestType;
 import com.mooctest.crowd.domain.repository.CommonRepo;
 import lombok.Data;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -11,6 +14,7 @@ import javax.annotation.PreDestroy;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.stream.Collectors;
 
 /**
  * @author guochao
@@ -19,6 +23,9 @@ import java.util.Map;
 @Data
 @Component
 public class DataCache {
+    private List<Field> fieldList;
+    private List<ApplicationType> applicationList;
+    private List<TestType> typeList;
     private Map<String, String> fieldMap;
     private Map<String, String> applicationTypeMap;
     private Map<String, String> testTypeMap;
@@ -33,13 +40,32 @@ public class DataCache {
     public void init() {
         // 系统启动时加载Map,每次运行初始化
         // 获取领域、应用、测试类型code 和 name 的map
-        Map<String, String> fieldMapTemp = commonRepo.getFieldCodeNameMap();
-        Map<String, String> applicationTypeMapTemp = commonRepo.getApplicationCodeNameMap();
-        Map<String, String> testTypeMapTemp = commonRepo.getTypeCodeNameMap();
+        List<Field> fieldList = commonRepo.getFieldList();
+        List<ApplicationType> applicationList = commonRepo.getApplicationList();
+        List<TestType> typeList = commonRepo.getTypeList();
+        Map<String, String> fieldMapTemp = fieldList.stream().collect(Collectors.toMap(field -> field.getCode(), field -> field.getName()));
+        Map<String, String> applicationTypeMapTemp = applicationList.stream().collect(Collectors.toMap(applicationType -> applicationType.getCode(), applicationType -> applicationType.getName()));
+        Map<String, String> testTypeMapTemp = typeList.stream().collect(Collectors.toMap(testType -> testType.getCode(), testType -> testType.getName()));
+
         Map<String, List<String>> fieldToAppMapTemp = new HashMap();
         Map<String, List<String>> appToTestTypeMapTemp = new HashMap();
         Map<String, String> testTypeCodeToNameMapTemp = new HashMap();
 
+        if(this.fieldList != null) {
+            this.fieldList.clear();
+        }
+        this.fieldList = fieldList;
+
+        if(this.applicationList != null) {
+            this.applicationList.clear();
+        }
+        this.applicationList = applicationList;
+
+        if(this.typeList != null) {
+            this.typeList.clear();
+        }
+        this.typeList = typeList;
+
         // 获取所有领域类型信息
         if(this.fieldMap != null) {
             this.fieldMap.clear();

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/data/dto/IndexInfoDTO.java

@@ -12,12 +12,12 @@ import java.util.List;
  */
 @Data
 public class IndexInfoDTO implements Serializable {
+    private List<FieldVO> fieldList;
     private List<TestTypeVO> testTypeList;
     private List<ApplicationTypeVO> applicationTypeList;
     private List<ApplicationTypeVO> applicationTypeRank;
     private List<EvaluationAgencyVO> agencyRank;
     private List<UserVO> userRank;
-    private List<FieldVO> fieldList;
     private List<CompetitionVO> competitionList;
     private List<ResourceVO> resourceList;
     private List<ToolVO> toolList;

+ 3 - 3
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -236,11 +236,11 @@ public class WebMediatorImpl implements ViewMediator {
         // 获取大赛信息
         List<CompetitionVO> competitionVOS = commonRepo.getAllCompetition(Integer.parseInt(indexCompetitionCount)).stream().map(CompetitionVO::new).collect(Collectors.toList());
         // 获取领域划分
-        List<FieldVO> fieldVOS = commonRepo.getAllFieldType().stream().map(FieldVO::new).collect(Collectors.toList());
+        List<FieldVO> fieldVOS = dataCache.getFieldList().stream().map(FieldVO::new).collect(Collectors.toList());
         // 获取服务类型
-        List<TestTypeVO> testTypeVOS = commonRepo.getAllTestType().stream().map(TestTypeVO::new).collect(Collectors.toList());
+        List<TestTypeVO> testTypeVOS = dataCache.getTypeList().stream().map(TestTypeVO::new).collect(Collectors.toList());
         // 获取应用类型
-        List<ApplicationTypeVO> applicationTypeVOS = commonRepo.getAllApplicationType().stream().map(ApplicationTypeVO::new).collect(Collectors.toList());
+        List<ApplicationTypeVO> applicationTypeVOS = dataCache.getApplicationList().stream().map(ApplicationTypeVO::new).collect(Collectors.toList());
         // 获取入驻品牌机构
         List<ResidentAgency> allResidentAgency = commonRepo.getAllResidentAgency(Integer.parseInt(indexResidentAgencyCount));
         List<EvaluationAgencyVO> agencyVOS = allResidentAgency.stream().map(residentAgency -> {