Browse Source

统计项目中领域类型、应用类型、测试类型的数量

guo00guo 5 years ago
parent
commit
7bad3e76dd

+ 9 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/CommonRepo.java

@@ -273,6 +273,15 @@ public class CommonRepo {
         }
     }
 
+    public String getFieldNameByFieldCode(String code) {
+        Optional<FieldPO> fieldPO = fieldDao.findByCode(code);
+        if (!fieldPO.isPresent()) {
+            throw new HttpBadRequestException("领域类型有误");
+        } else {
+            return fieldPO.get().getName();
+        }
+    }
+
     public String getApplicationCodeByName(String name) {
         Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByName(name);
         if (!applicationTypePO.isPresent()) {

File diff suppressed because it is too large
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CommonController.java


+ 4 - 1
site/src/main/java/com/mooctest/crowd/site/service/CommonService.java

@@ -6,8 +6,9 @@ import com.mooctest.crowd.site.data.vo.*;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
-import java.util.List;
 
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 @Service
@@ -51,4 +52,6 @@ public interface CommonService {
     Boolean checkCreateProject(Long userId);
 
     Boolean checkAcceptTask(Long userId);
+
+    List<HashMap<String, Long>> getStatisticsCount();
 }

+ 60 - 3
site/src/main/java/com/mooctest/crowd/site/service/impl/CommonServiceImpl.java

@@ -4,6 +4,7 @@ import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
 import com.mooctest.crowd.domain.dao.ResourceTypeDao;
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
 import com.mooctest.crowd.domain.domainobject.CrowdTestProjectStatus;
+import com.mooctest.crowd.domain.domainobject.CrowdTestTask;
 import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.domain.exception.HaveNotAgencyAuthException;
 import com.mooctest.crowd.domain.exception.HaveNotPartAuthException;
@@ -28,9 +29,7 @@ import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
@@ -226,6 +225,64 @@ public class CommonServiceImpl implements CommonService {
         return isAgency;
     }
 
+    @Override
+    public List<HashMap<String, Long>> getStatisticsCount() {
+        List<HashMap<String, Long>> statisticsList = new ArrayList<>();
+        HashMap<String, Long> fieldMap = new HashMap<>();
+        HashMap<String, Long> applicationMap = new HashMap<>();
+        HashMap<String, Long> testTypeMap = new HashMap<>();
+        List<CrowdTestProject> crowdTestProjects = projectRepo.getAllCrowdTestProject();
+        for(CrowdTestProject crowdTestProject : crowdTestProjects){
+            String fieldType = crowdTestProject.getFieldType();
+            if(!fieldMap.containsKey(fieldType)){
+                fieldMap.put(fieldType, 1L);
+            }else{
+                fieldMap.put(fieldType, fieldMap.get(fieldType) + 1);
+            }
+            String applicationType = crowdTestProject.getApplicationType();
+            if(!applicationMap.containsKey(applicationType)){
+                applicationMap.put(applicationType, 1L);
+            }else{
+                applicationMap.put(applicationType, applicationMap.get(applicationType) + 1L);
+            }
+            List<CrowdTestTask> crowdTestTaskList = crowdTestProject.getCrowdTestTaskList();
+            for(CrowdTestTask crowdTestTask : crowdTestTaskList){
+                String type = crowdTestTask.getType();
+                if(!testTypeMap.containsKey(type)){
+                    testTypeMap.put(type, 1L);
+                }else{
+                    testTypeMap.put(type, testTypeMap.get(type) + 1L);
+                }
+            }
+        }
+
+        HashMap<String, Long> fieldResultMap = new HashMap<>();
+        HashMap<String, Long> applicationResultMap = new HashMap<>();
+        HashMap<String, Long> testTypeResultMap = new HashMap<>();
+
+        Iterator<String> fieldIterator = fieldMap.keySet().iterator();
+        while(fieldIterator.hasNext()){
+            String fieldCode = fieldIterator.next();
+            String fieldName = commonRepo.getFieldNameByFieldCode(fieldCode);
+            fieldResultMap.put(fieldName, fieldMap.get(fieldCode));
+        }
+
+        for(Map.Entry<String, Long> entry : applicationMap.entrySet()){
+            String applicationName = commonRepo.getApplicationNameByCode(entry.getKey());
+            applicationResultMap.put(applicationName, entry.getValue());
+        }
+
+        for(Map.Entry<String, Long> entry : testTypeMap.entrySet()){
+            String typeName = commonRepo.getTypeNameByCode(entry.getKey());
+            testTypeResultMap.put(typeName, entry.getValue());
+        }
+
+        statisticsList.add(fieldResultMap);
+        statisticsList.add(applicationResultMap);
+        statisticsList.add(testTypeResultMap);
+        return statisticsList;
+    }
+
     Pageable getPageable(SearchConditionVO searchConditionVO) {
         int activePage = searchConditionVO.getActivePage() == 0 ? 1 : searchConditionVO.getActivePage();
         Sort sort = new Sort(Sort.Direction.DESC, "id");

+ 4 - 3
site/src/main/resources/application.yml

@@ -1,6 +1,7 @@
 spring:
   profiles:
-    active: dev-localhost
+#    active: online
+      active: dev-localhost
   cache:
     guava:
       spec: expireAfterWrite=30s
@@ -111,8 +112,8 @@ spring:
     database: 6
 user:
   service:
-#    baseUrl: http://127.0.0.1:8081
-    baseUrl: http://59.42.10.53:8081
+    baseUrl: http://127.0.0.1:8081
+#    baseUrl: http://59.42.10.53:8081
 
 website:
   domain: mooctest.net

Some files were not shown because too many files changed in this diff