Procházet zdrojové kódy

Merge branch 'Dev' into 'Test'

Dev

See merge request crowd-2019/crowd-test-service-backend!111
郭超 před 5 roky
rodič
revize
21728aaa4c

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

@@ -135,14 +135,6 @@ public class CommonRepo {
         }
     }
 
-    public Field getFieldByFieldCode(String code) {
-        Optional<FieldPO> fieldPO = fieldDao.findByCode(code);
-        if (!fieldPO.isPresent()) {
-            throw new FieldNoExistException();
-        } else {
-            return Converter.convert(Field.class, fieldPO.get());
-        }
-    }
 
     public List<ApplicationTypeToTestType> getAppToTypeByAppCode(String appCode) {
         List<ApplicationTypeToTestTypePO> appToTypeList = applicationTypeToTestTypeDao.findByApplicationTypeCode(appCode);
@@ -236,7 +228,7 @@ public class CommonRepo {
         // 测试类型的转换
         Optional<TestTypePO> testTypePO = testTypeDao.findByCode(code);
         if (!testTypePO.isPresent()) {
-            throw new HttpBadRequestException("请选择测试类型");
+            throw new HttpBadRequestException("测试类型有误");
         }
         return testTypePO.get().getName();
     }
@@ -244,9 +236,35 @@ public class CommonRepo {
     public String getApplicationNameByCode(String code) {
         Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByCode(code);
         if (!applicationTypePO.isPresent()) {
-            throw new HttpBadRequestException("请选择应用类型");
+            throw new HttpBadRequestException("应用类型有误");
         }
         return applicationTypePO.get().getName();
     }
 
+    public String getFieldCodeByFieldName(String name) {
+        Optional<FieldPO> fieldPO = fieldDao.findByName(name);
+        if (!fieldPO.isPresent()) {
+            throw new HttpBadRequestException("领域类型有误");
+        } else {
+            return fieldPO.get().getCode();
+        }
+    }
+
+    public String getApplicationCodeByName(String name) {
+        Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByName(name);
+        if (!applicationTypePO.isPresent()) {
+            throw new HttpBadRequestException("应用类型有误");
+        }
+        return applicationTypePO.get().getCode();
+    }
+
+
+    public String getTypeCodeByName(String name) {
+        // 测试类型的转换
+        Optional<TestTypePO> testTypePO = testTypeDao.findByName(name);
+        if (!testTypePO.isPresent()) {
+            throw new HttpBadRequestException("测试类型有误");
+        }
+        return testTypePO.get().getCode();
+    }
 }

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/command/CrowdTestProjectCommand.java

@@ -31,7 +31,7 @@ public class CrowdTestProjectCommand {
     @NotNull(message = "项目应用类型不可为空")
     private String platform;
 
-    @NotNull(message = "项目服务类型不可为空")
+//    @NotNull(message = "项目服务类型不可为空")
     private ArrayList<String> type;
 
 //    @NotNull(message = "项目描述不可为空")

+ 13 - 2
site/src/main/java/com/mooctest/crowd/site/mediator/impl/OperationMediatorImpl.java

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.site.mediator.impl;
 
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
+import com.mooctest.crowd.domain.repository.CommonRepo;
 import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
 import com.mooctest.crowd.site.command.CrowdTestProjectCommand;
 import com.mooctest.crowd.site.data.dto.ProjectDetailsDTO;
@@ -11,6 +12,9 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author: Diors.Po
@@ -22,6 +26,9 @@ public class OperationMediatorImpl implements OperationMediator {
 
     @Autowired
     private CrowdTestProjectRepo projectRepo;
+    
+    @Autowired
+    private CommonRepo commonRepo;
 
     @Autowired
     private ThemeSchedulerService themeSchedulerService;
@@ -36,9 +43,13 @@ public class OperationMediatorImpl implements OperationMediator {
     }
 
     @Override
-    public CrowdTestProject updateProject(CrowdTestProject project, CrowdTestProjectCommand crowdTestProjectCommand) {
+    public CrowdTestProject updateProject(CrowdTestProject project, CrowdTestProjectCommand command) {
+        command.setField(commonRepo.getFieldCodeByFieldName(command.getField()));
+        command.setPlatform(commonRepo.getApplicationCodeByName(command.getPlatform()));
+        List<String> typeCodeList = command.getType().stream().map(s -> commonRepo.getTypeCodeByName(s)).collect(Collectors.toList());
+        command.setType((ArrayList<String>) typeCodeList);
         themeSchedulerService.cancelThemeScheduler(project);
-        CrowdTestProject updateProject = crowdTestProjectCommand.toCrowdProject();
+        CrowdTestProject updateProject = command.toCrowdProject();
         updateProject.setId(project.getId());
         updateProject.setCode(project.getCode());
         updateProject.setStatus(project.getStatus());

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

@@ -347,11 +347,19 @@ public class WebMediatorImpl implements ViewMediator {
 
         // 获取入驻品牌机构
         List<ResidentAgency> allResidentAgency = commonRepo.getAllResidentAgency();
-        List<EvaluationAgencyVO> agencyVOS = allResidentAgency.stream().map(residentAgency -> {
+        List<EvaluationAgencyVO> agencyVOS = new ArrayList<>();
+        List<EvaluationAgencyVO> agencyVOList = allResidentAgency.stream().map(residentAgency -> {
             EvaluationAgency agency = evaluationAgencyRepo.findAgencyById(residentAgency.getAgencyId());
             EvaluationAgencyVO evalutionAgencyVO = new EvaluationAgencyVO(agency);
             return evalutionAgencyVO;
         }).collect(Collectors.toList());
+        if (agencyVOList.size() > 12) {
+            for (int i = 0; i < 12; i++) {
+                agencyVOS.add(agencyVOList.get(i));
+            }
+        } else {
+            agencyVOS = agencyVOList;
+        }
 
         // 获取合作机构
 //        List<Partner> partnerList = commonRepo.getAllPartner();
@@ -454,10 +462,18 @@ public class WebMediatorImpl implements ViewMediator {
 
         // 获取资源和工具
         List<Resource> resourceList = commonRepo.getAllResource();
-        List<ResourceVO> resourceVOS = resourceList.stream().map(resource -> {
+        List<ResourceVO> resourceVOS = new ArrayList<>();
+        List<ResourceVO> resourceVOList = resourceList.stream().map(resource -> {
             ResourceVO resourceVO = new ResourceVO(resource);
             return resourceVO;
         }).collect(Collectors.toList());
+        if (resourceVOList.size() > 12) {
+            for (int i = 0; i < 12; i++) {
+                resourceVOS.add(resourceVOList.get(i));
+            }
+        } else {
+            resourceVOS = resourceVOList;
+        }
 
         indexInfoDTO.setApplicationTypeRank(applicationTypeRanks);
         indexInfoDTO.setAgencyRank(agencyRanks);
@@ -779,7 +795,7 @@ public class WebMediatorImpl implements ViewMediator {
         if (fieldPO.isPresent()) {
             projectVO.setField(fieldPO.get().getName());
         } else {
-            throw new HttpBadRequestException("请选择领域类型");
+            throw new HttpBadRequestException("领域类型有误");
         }
 
         // 测试类型的转换
@@ -1107,7 +1123,7 @@ public class WebMediatorImpl implements ViewMediator {
             if (applicationTypePO.isPresent()) {
                 crowdTestProject.setApplicationType(applicationTypePO.get().getName());
             } else {
-                throw new HttpBadRequestException("请选择应用类型");
+                throw new HttpBadRequestException("应用类型有误");
             }
             return new CrowdTestProjectVO(crowdTestProject);
 
@@ -1127,7 +1143,7 @@ public class WebMediatorImpl implements ViewMediator {
             if (applicationTypePO.isPresent()) {
                 crowdTestProject.setApplicationType(applicationTypePO.get().getName());
             } else {
-                throw new HttpBadRequestException("请选择应用类型");
+                throw new HttpBadRequestException("应用类型有误");
             }
             return new CrowdTestProjectVO(crowdTestProject);
 

+ 1 - 2
site/src/main/java/com/mooctest/crowd/site/service/impl/CommonServiceImpl.java

@@ -21,7 +21,6 @@ import com.mooctest.crowd.site.service.CommonService;
 import com.mooctest.crowd.site.util.DataUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.cache.annotation.Cacheable;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
@@ -90,7 +89,7 @@ public class CommonServiceImpl implements CommonService {
     }
 
     @Override
-    @Cacheable(value = "userCache",key = "#userId")
+//    @Cacheable(value = "userCache",key = "#userId")
     public IndexInfoDTO getIndexInfosCache(Long userId){
         IndexInfoDTO indexInfoDTO = viewMediator.renderIndexInfosCache();
         return indexInfoDTO;

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/service/impl/CrowdTaskServiceImpl.java

@@ -119,7 +119,7 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
             throw new CrowdTestTaskNotExistException();
         if (task.get().getStatus() == CrowdTestTaskStatus.HAS_FINISHED)
             throw new BaseException("禁止修改已结束的任务!");
-
+        command.setType(commonRepo.getTypeCodeByName(command.getType()));
         CrowdTestTask updateTask = command.toCrowdTask(projectCode);
         // 定向任务被拒绝,更新时需要删除任务中的taskToUser  acceptedUserList
         if (task.get().getDistributionType().equals(DistributeType.DIRECT.getId())) {