|
@@ -2,11 +2,10 @@ package com.mooctest.crowd.site.service.impl;
|
|
|
|
|
|
import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
|
|
import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
|
|
import com.mooctest.crowd.domain.dao.ResourceTypeDao;
|
|
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.User;
|
|
|
|
|
|
+import com.mooctest.crowd.domain.domainobject.*;
|
|
import com.mooctest.crowd.domain.exception.HaveNotAgencyAuthException;
|
|
import com.mooctest.crowd.domain.exception.HaveNotAgencyAuthException;
|
|
import com.mooctest.crowd.domain.exception.HaveNotPartAuthException;
|
|
import com.mooctest.crowd.domain.exception.HaveNotPartAuthException;
|
|
|
|
+import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
|
|
import com.mooctest.crowd.domain.model.ResourceTypePO;
|
|
import com.mooctest.crowd.domain.model.ResourceTypePO;
|
|
import com.mooctest.crowd.domain.repository.*;
|
|
import com.mooctest.crowd.domain.repository.*;
|
|
import com.mooctest.crowd.site.constants.CommonConstant;
|
|
import com.mooctest.crowd.site.constants.CommonConstant;
|
|
@@ -28,9 +27,7 @@ import org.springframework.data.domain.Pageable;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.stereotype.Service;
|
|
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;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -226,6 +223,93 @@ public class CommonServiceImpl implements CommonService {
|
|
return isAgency;
|
|
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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public List<Map.Entry<String, Long>> getAgencyProjectCount() {
|
|
|
|
+ HashMap<String, Long> agencyProjectCountMap = new HashMap<>();
|
|
|
|
+ List<EvaluationAgency> evaluationAgencyList = agencyRepo.findAll();
|
|
|
|
+ for (EvaluationAgency evaluationAgency : evaluationAgencyList){
|
|
|
|
+ //获取我创建的项目列表
|
|
|
|
+ List<CrowdTestProjectPO> myProjects = projectDao.findByUserIdAndIsDeleted(evaluationAgency.getUserId(), DeletedStatus.isNotDeleted);
|
|
|
|
+ agencyProjectCountMap.put(evaluationAgency.getEvaluationAgencyName(), (long) myProjects.size());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //////借助list实现hashMap排序//////
|
|
|
|
+ //注意 ArrayList<>() 括号里要传入map.entrySet()
|
|
|
|
+ List<Map.Entry<String, Long>> resultList = new ArrayList<>(agencyProjectCountMap.entrySet());
|
|
|
|
+ Collections.sort(resultList, new Comparator<Map.Entry<String, Long>>()
|
|
|
|
+ {
|
|
|
|
+ @Override
|
|
|
|
+ public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2)
|
|
|
|
+ {
|
|
|
|
+ //按照value值,重小到大排序
|
|
|
|
+// return o1.getValue() - o2.getValue();
|
|
|
|
+ //按照value值,从大到小排序
|
|
|
|
+ return (int) (o2.getValue() - o1.getValue());
|
|
|
|
+ //按照value值,用compareTo()方法默认是从小到大排序
|
|
|
|
+// return o1.getValue().compareTo(o2.getValue());
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ return resultList.stream().filter(result -> !result.getValue().equals(0L)).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+
|
|
Pageable getPageable(SearchConditionVO searchConditionVO) {
|
|
Pageable getPageable(SearchConditionVO searchConditionVO) {
|
|
int activePage = searchConditionVO.getActivePage() == 0 ? 1 : searchConditionVO.getActivePage();
|
|
int activePage = searchConditionVO.getActivePage() == 0 ? 1 : searchConditionVO.getActivePage();
|
|
Sort sort = new Sort(Sort.Direction.DESC, "id");
|
|
Sort sort = new Sort(Sort.Direction.DESC, "id");
|