Browse Source

修改测试用例管理部分功能和新增任务仪表盘的接口

linyk 2 years ago
parent
commit
db0996858f
39 changed files with 870 additions and 66 deletions
  1. 4 0
      core/src/main/java/com/mooctest/crowd/domain/dao/DefectDao.java
  2. 2 0
      core/src/main/java/com/mooctest/crowd/domain/dao/TaskToUserDao.java
  3. 9 0
      core/src/main/java/com/mooctest/crowd/domain/dao/TestCaseDao.java
  4. 2 0
      core/src/main/java/com/mooctest/crowd/domain/dao/TestEnvDao.java
  5. 6 4
      core/src/main/java/com/mooctest/crowd/domain/dao/TestToolDao.java
  6. 2 0
      core/src/main/java/com/mooctest/crowd/domain/domainobject/Defect.java
  7. 5 0
      core/src/main/java/com/mooctest/crowd/domain/domainobject/TestCase.java
  8. 2 1
      core/src/main/java/com/mooctest/crowd/domain/domainobject/TestEnv.java
  9. 1 0
      core/src/main/java/com/mooctest/crowd/domain/domainobject/TestTool.java
  10. 6 0
      core/src/main/java/com/mooctest/crowd/domain/env/DefectType.java
  11. 6 0
      core/src/main/java/com/mooctest/crowd/domain/env/Priority.java
  12. 11 5
      core/src/main/java/com/mooctest/crowd/domain/env/Seriousness.java
  13. 6 0
      core/src/main/java/com/mooctest/crowd/domain/env/TestStatus.java
  14. 2 0
      core/src/main/java/com/mooctest/crowd/domain/model/DefectPO.java
  15. 8 1
      core/src/main/java/com/mooctest/crowd/domain/model/TestCasePO.java
  16. 12 14
      core/src/main/java/com/mooctest/crowd/domain/repository/DefectRepo.java
  17. 3 0
      core/src/main/java/com/mooctest/crowd/domain/repository/IDefectRepo.java
  18. 5 0
      core/src/main/java/com/mooctest/crowd/domain/repository/ITestCaseRepo.java
  19. 19 0
      core/src/main/java/com/mooctest/crowd/domain/repository/TestCaseRepo.java
  20. 48 0
      core/src/main/java/com/mooctest/crowd/domain/repository/TestEnvRepo.java
  21. 3 0
      core/src/main/java/com/mooctest/crowd/domain/util/Converter.java
  22. 16 1
      site/pom.xml
  23. 1 0
      site/src/main/java/com/mooctest/crowd/site/command/DefectAddedCommand.java
  24. 1 0
      site/src/main/java/com/mooctest/crowd/site/command/DefectUpdatedCommand.java
  25. 2 0
      site/src/main/java/com/mooctest/crowd/site/command/TestCaseAddedCommand.java
  26. 1 0
      site/src/main/java/com/mooctest/crowd/site/command/TestCaseUpdatedCommand.java
  27. 2 2
      site/src/main/java/com/mooctest/crowd/site/configuration/WebMvcConfiguration.java
  28. 41 4
      site/src/main/java/com/mooctest/crowd/site/controller/CrowdTaskController.java
  29. 34 0
      site/src/main/java/com/mooctest/crowd/site/controller/TestCaseController.java
  30. 6 0
      site/src/main/java/com/mooctest/crowd/site/data/TaskOperationControl.java
  31. 17 15
      site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java
  32. 5 3
      site/src/main/java/com/mooctest/crowd/site/service/CrowdTaskService.java
  33. 5 1
      site/src/main/java/com/mooctest/crowd/site/service/DefectService.java
  34. 4 0
      site/src/main/java/com/mooctest/crowd/site/service/TestCaseService.java
  35. 0 0
      site/src/main/java/com/mooctest/crowd/site/service/UserService.java
  36. 190 8
      site/src/main/java/com/mooctest/crowd/site/service/impl/CrowdTaskServiceImpl.java
  37. 193 1
      site/src/main/java/com/mooctest/crowd/site/service/impl/DefectServiceImpl.java
  38. 190 6
      site/src/main/java/com/mooctest/crowd/site/service/impl/TestCaseServiceImpl.java
  39. 0 0
      site/src/main/java/com/mooctest/crowd/site/service/impl/UserServiceImpl.java

+ 4 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/DefectDao.java

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.domain.dao;
 
 import com.mooctest.crowd.domain.model.DefectPO;
+import com.mooctest.crowd.domain.model.TestCasePO;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.CrudRepository;
@@ -14,4 +15,7 @@ public interface DefectDao extends PagingAndSortingRepository<DefectPO, Long>, C
     int countByTaskCodeAndTestCaseCode(String taskCode, String testCaseCode);
     List<DefectPO> findAllByTaskCodeAndTestCaseCode(String taskCode, String testCaseCode);
     List<DefectPO> findAllByTaskCodeAndTestCaseCodeIn(String taskCode, Collection<String> testCaseCodes);
+    DefectPO findByTaskCodeAndCommiterIdAndImportCode(String taskCode, Long commiterId, String importCode);
+    int countAllByTaskCode(String taskCode);
+    List<DefectPO> findAllByTaskCode(String taskCode);
 }

+ 2 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/TaskToUserDao.java

@@ -32,4 +32,6 @@ public interface TaskToUserDao extends CrudRepository<TaskToUserPO,Long> {
     List<RankCountInfo> findTotalCountOfUser();
 
     TaskToUserPO findByUserIdAndTaskCode(Long userId, String taskCode);
+
+    int countAllByTaskCode(String taskCode);
 }

+ 9 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/TestCaseDao.java

@@ -9,10 +9,19 @@ import org.springframework.data.repository.CrudRepository;
 import org.springframework.data.repository.PagingAndSortingRepository;
 import org.springframework.data.repository.query.Param;
 
+import java.util.List;
+
 public interface TestCaseDao extends PagingAndSortingRepository<TestCasePO, Long>, CrudRepository<TestCasePO, Long>,
         JpaRepository<TestCasePO, Long>, JpaSpecificationExecutor<TestCasePO> {
     TestCasePO findByTaskCodeAndCode(String taskCode, String code);
     @Modifying
     @Query("update TestCasePO tcp set tcp.examStatus=:examStatus, tcp.examDescr=:examDescr where tcp.id=:id")
     void exam(@Param("id") Long id, @Param("examStatus") Byte examStatus, @Param("examDescr") String examDescr);
+    @Modifying
+    @Query("update TestCasePO tcp set tcp.associatedCode=:associatedCode where tcp.id=:id")
+    void updateAssociatedCodeById(@Param("id") Long id, @Param("associatedCode") String associatedCode);
+    TestCasePO findByTaskCodeAndDesignerIdAndImportCode(String taskCode, Long designerId, String importCode);
+    int countAllByTaskCode(String taskCode);
+    int countAllByTaskCodeAndExamStatus(String taskCode, Byte examStatus);
+    List<TestCasePO> findAllByTaskCode(String taskCode);
 }

+ 2 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/TestEnvDao.java

@@ -11,4 +11,6 @@ import java.util.List;
 public interface TestEnvDao extends PagingAndSortingRepository<TestEnvPO, Long>, CrudRepository<TestEnvPO, Long>,
         JpaRepository<TestEnvPO, Long>, JpaSpecificationExecutor<TestEnvPO> {
     List<TestEnvPO> findAllByTaskCodeAndUserId(String taskCode, Long userId);
+    void deleteById(Long id);
+    List<TestEnvPO> findAllByTaskCode(String taskCode);
 }

+ 6 - 4
core/src/main/java/com/mooctest/crowd/domain/dao/TestToolDao.java

@@ -1,6 +1,6 @@
 package com.mooctest.crowd.domain.dao;
 
-import com.mooctest.crowd.domain.model.TestEnvPO;
+import com.mooctest.crowd.domain.model.TestToolPO;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.CrudRepository;
@@ -8,7 +8,9 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 
 import java.util.List;
 
-public interface TestToolDao extends PagingAndSortingRepository<TestEnvPO, Long>, CrudRepository<TestEnvPO, Long>,
-        JpaRepository<TestEnvPO, Long>, JpaSpecificationExecutor<TestEnvPO> {
-    List<TestEnvPO> findAllByTaskCodeAndUserId(String taskCode, Long userId);
+public interface TestToolDao extends PagingAndSortingRepository<TestToolPO, Long>, CrudRepository<TestToolPO, Long>,
+        JpaRepository<TestToolPO, Long>, JpaSpecificationExecutor<TestToolPO> {
+    List<TestToolPO> findAllByTaskCodeAndUserId(String taskCode, Long userId);
+    void deleteById(Long id);
+    List<TestToolPO> findAllByTaskCode(String taskCode);
 }

+ 2 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/Defect.java

@@ -8,6 +8,7 @@ import java.sql.Timestamp;
 
 import java.util.List;
 
+//缺陷
 @Data
 public class Defect {
     private Long id;
@@ -51,4 +52,5 @@ public class Defect {
     private String commiterName;
     //提交日期
     private Timestamp commitTime;
+    private String importCode;
 }

+ 5 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestCase.java

@@ -8,6 +8,7 @@ import lombok.Data;
 import java.sql.Timestamp;
 import java.util.List;
 
+//测试用例
 @Data
 public class TestCase {
     private Long id;
@@ -64,4 +65,8 @@ public class TestCase {
     //关联需求
     private String demand;
     private List<Defect> defects;
+    //从文档中导进来的原始测试用例号
+    private String importCode;
+    //关联的测试用例的code
+    private String associatedCode;
 }

+ 2 - 1
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestEnv.java

@@ -2,6 +2,7 @@ package com.mooctest.crowd.domain.domainobject;
 
 import lombok.Data;
 
+//测试环境
 @Data
 public class TestEnv {
     private Long id;
@@ -9,7 +10,7 @@ public class TestEnv {
     private Long userId;
     private String devName; //设备名称
     private String devModel; //设备型号
-    private String devCount; //设备数量
+    private Integer devCount; //设备数量
     private String devConfig; //设备硬件配置
     private String opeSys; //操作系统
     private String middleware; //中间件

+ 1 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestTool.java

@@ -2,6 +2,7 @@ package com.mooctest.crowd.domain.domainobject;
 
 import lombok.Data;
 
+//测试工具
 @Data
 public class TestTool {
     private Long id;

+ 6 - 0
core/src/main/java/com/mooctest/crowd/domain/env/DefectType.java

@@ -3,6 +3,8 @@ package com.mooctest.crowd.domain.env;
 import com.mooctest.crowd.domain.env.base.IEnum;
 import com.mooctest.crowd.domain.env.tools.EnumTools;
 
+import java.util.Arrays;
+
 public enum DefectType implements IEnum<Byte> {
     FUNCTIONALITY((byte)1, "功能性"),
     COMPATIBILITY((byte)2, "兼容性"),
@@ -33,4 +35,8 @@ public enum DefectType implements IEnum<Byte> {
     public static DefectType fromValue(byte value) {
         return EnumTools.get(values(), value);
     }
+
+    public static DefectType fromName(String name) {
+        return Arrays.stream(values()).filter(defectType -> defectType.getName().equals(name)).findFirst().get();
+    }
 }

+ 6 - 0
core/src/main/java/com/mooctest/crowd/domain/env/Priority.java

@@ -3,6 +3,8 @@ package com.mooctest.crowd.domain.env;
 import com.mooctest.crowd.domain.env.base.IEnum;
 import com.mooctest.crowd.domain.env.tools.EnumTools;
 
+import java.util.Arrays;
+
 public enum Priority implements IEnum<Byte> {
     HIGH((byte)10, "高"),
     MID((byte)20, "中"),
@@ -27,4 +29,8 @@ public enum Priority implements IEnum<Byte> {
     public static Priority fromValue(byte value) {
         return EnumTools.get(values(), value);
     }
+
+    public static Priority fromName(String name) {
+        return Arrays.stream(values()).filter(priority -> priority.getName().equals(name)).findFirst().get();
+    }
 }

+ 11 - 5
core/src/main/java/com/mooctest/crowd/domain/env/Seriousness.java

@@ -3,12 +3,14 @@ package com.mooctest.crowd.domain.env;
 import com.mooctest.crowd.domain.env.base.IEnum;
 import com.mooctest.crowd.domain.env.tools.EnumTools;
 
+import java.util.Arrays;
+
 public enum Seriousness implements IEnum<Byte> {
-    VERY_HIGH((byte)1, "极高"),
-    HIGH((byte)2, ""),
-    MID((byte)3, ""),
-    LOW((byte)4, ""),
-    VERY_LOW((byte)5, "极低");
+    VERY_HIGH((byte)1, "致命"),
+    HIGH((byte)2, "严重"),
+    MID((byte)3, "一般"),
+    LOW((byte)4, "轻微"),
+    VERY_LOW((byte)5, "建议");
 
     private byte value;
     private String name;
@@ -29,4 +31,8 @@ public enum Seriousness implements IEnum<Byte> {
     public static Seriousness fromValue(byte value) {
         return EnumTools.get(values(), value);
     }
+
+    public static Seriousness fromName(String name) {
+        return Arrays.stream(values()).filter(seriousness -> seriousness.getName().equals(name)).findFirst().get();
+    }
 }

+ 6 - 0
core/src/main/java/com/mooctest/crowd/domain/env/TestStatus.java

@@ -3,6 +3,8 @@ package com.mooctest.crowd.domain.env;
 import com.mooctest.crowd.domain.env.base.IEnum;
 import com.mooctest.crowd.domain.env.tools.EnumTools;
 
+import java.util.Arrays;
+
 public enum TestStatus implements IEnum<Byte> {
     WAIT((byte)0, "待测试"),
     PASS((byte)1, "通过"),
@@ -27,4 +29,8 @@ public enum TestStatus implements IEnum<Byte> {
     public static TestStatus fromValue(byte value) {
         return EnumTools.get(values(), value);
     }
+
+    public static TestStatus fromName(String name) {
+        return Arrays.stream(values()).filter(testStatus -> testStatus.getName().equals(name)).findFirst().get();
+    }
 }

+ 2 - 0
core/src/main/java/com/mooctest/crowd/domain/model/DefectPO.java

@@ -57,4 +57,6 @@ public class DefectPO {
     private Long commiterId;
     @Column(name = "commiter_time", nullable = false)
     private Timestamp commitTime;
+    @Column(name = "import_code", length = 9, nullable = true)
+    private String importCode;
 }

+ 8 - 1
core/src/main/java/com/mooctest/crowd/domain/model/TestCasePO.java

@@ -13,7 +13,10 @@ import java.sql.Timestamp;
 
 @Data
 @Entity
-@Table(name = "test_case", indexes = {@Index(columnList = "code,project_code", name = "code_project_code_ind", unique = true)})
+@Table(name = "test_case", indexes = {
+        @Index(columnList = "code,project_code", name = "code_project_code_ind", unique = true),
+        @Index(columnList = "task_code,designer_id,import_code", name="task_code_designer_id_import_code_ind", unique = true)
+})
 public class TestCasePO {
     @Id
     @Column(name = "id")
@@ -70,4 +73,8 @@ public class TestCasePO {
     private String examDescr;
     @Column(name = "demand", length = 400, nullable = true)
     private String demand;
+    @Column(name = "import_code", length = 9, nullable = true)
+    private String importCode;
+    @Column(name = "associated_code", length = 9, nullable = true)
+    private String associatedCode;
 }

+ 12 - 14
core/src/main/java/com/mooctest/crowd/domain/repository/DefectRepo.java

@@ -64,20 +64,7 @@ public class DefectRepo implements IDefectRepo{
             }
             return predicate;
         };
-        Page<Defect> page = defectDao.findAll(specification, pageable).map(defectPO -> {
-            Defect defect = Converter.convert(Defect.class, defectPO);
-            if (StringUtils.isNotEmpty(defectPO.getFiles())) {
-                defect.setFiles(Arrays.asList(defectPO.getFiles().split(",")));
-            } else {
-                defect.setFiles(Collections.EMPTY_LIST);
-            }
-            if (StringUtils.isNotEmpty(defectPO.getScreenshots())) {
-                defect.setScreenshots(Arrays.asList(defectPO.getScreenshots().split(",")));
-            } else {
-                defect.setScreenshots(Collections.EMPTY_LIST);
-            }
-            return defect;
-        });
+        Page<Defect> page = defectDao.findAll(specification, pageable).map(defectPO -> poToDO(defectPO));
         DOPage<Defect> doPage = new DOPage(pageNo, pageSize, page.getTotalElements(), page.getContent());
         return doPage;
     }
@@ -113,6 +100,17 @@ public class DefectRepo implements IDefectRepo{
         return defectPOs.stream().map(defectPO -> poToDO(defectPO)).collect(Collectors.toList());
     }
 
+    @Override
+    public Defect findByTaskCodeAndCommiterIdAndImportCode(String taskCode, Long commiterId, String importCode) {
+        return poToDO(defectDao.findByTaskCodeAndCommiterIdAndImportCode(taskCode, commiterId, importCode));
+    }
+
+    @Override
+    public List<Defect> findAllByTaskCode(String taskCode) {
+        List<DefectPO> defectPOs = defectDao.findAllByTaskCode(taskCode);
+        return defectPOs.stream().map(defectPO -> poToDO(defectPO)).collect(Collectors.toList());
+    }
+
     private Defect poToDO(DefectPO defectPO) {
         Defect defect = Converter.convert(Defect.class, defectPO);
         if (StringUtils.isNotEmpty(defectPO.getFiles())) {

+ 3 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/IDefectRepo.java

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.domain.repository;
 
 import com.mooctest.crowd.domain.domainobject.Defect;
+import com.mooctest.crowd.domain.domainobject.TestCase;
 import com.mooctest.crowd.domain.page.DOPage;
 
 import java.util.Collection;
@@ -14,4 +15,6 @@ public interface IDefectRepo {
     int countByTaskCodeAndTestCaseCode(String taskCode, String testCaseCode);
     List<Defect> findAllByTaskCodeAndTestCaseCode(String taskCode, String testCaseCode);
     List<Defect> findAllByTaskCodeAndTestCaseCodeIn(String taskCode, Collection<String> testCaseCodes);
+    Defect findByTaskCodeAndCommiterIdAndImportCode(String taskCode, Long commiterId, String importCode);
+    List<Defect> findAllByTaskCode(String taskCode);
 }

+ 5 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/ITestCaseRepo.java

@@ -5,6 +5,8 @@ import com.mooctest.crowd.domain.env.TestCaseExamStatus;
 import com.mooctest.crowd.domain.env.TestStatus;
 import com.mooctest.crowd.domain.page.DOPage;
 
+import java.util.List;
+
 public interface ITestCaseRepo {
     void save(TestCase testCase);
     DOPage<TestCase> find(Long designerId, String taskCode, Integer pageNo, Integer pageSize, TestStatus testStatus, TestCaseExamStatus examStatus);
@@ -12,4 +14,7 @@ public interface ITestCaseRepo {
     void deleteById(Long id);
     TestCase findByTaskCodeAndTestCaseCode(String taskCode, String testCaseCode);
     void exam(Long id, TestCaseExamStatus examStatus, String examDescr);
+    void updateAssociatedCodeById(Long id, String associatedCode);
+    TestCase findByTaskCodeAndDesignerIdAndImportCode(String taskCode, Long designerId, String importCode);
+    List<TestCase> findAllByTaskCode(String taskCode);
 }

+ 19 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/TestCaseRepo.java

@@ -21,6 +21,8 @@ import org.springframework.util.CollectionUtils;
 import javax.persistence.criteria.Predicate;
 import java.util.Arrays;
 import java.util.Collections;
+import java.util.List;
+import java.util.stream.Collectors;
 
 @Component
 public class TestCaseRepo implements ITestCaseRepo{
@@ -93,6 +95,23 @@ public class TestCaseRepo implements ITestCaseRepo{
         testCaseDao.exam(id, examStatus.getValue(), examDescr);
     }
 
+    @Override
+    public void updateAssociatedCodeById(Long id, String associatedCode) {
+        testCaseDao.updateAssociatedCodeById(id, associatedCode);
+    }
+
+    @Override
+    public TestCase findByTaskCodeAndDesignerIdAndImportCode(String taskCode, Long designerId, String importCode) {
+        TestCasePO testCasePO = testCaseDao.findByTaskCodeAndDesignerIdAndImportCode(taskCode, designerId, importCode);
+        return poToDO(testCasePO);
+    }
+
+    @Override
+    public List<TestCase> findAllByTaskCode(String taskCode) {
+        List<TestCasePO> testCasePOs = testCaseDao.findAllByTaskCode(taskCode);
+        return testCasePOs.stream().map(testCasePO -> poToDO(testCasePO)).collect(Collectors.toList());
+    }
+
     private TestCase poToDO(TestCasePO testCasePO) {
         if (testCasePO == null) {
             return null;

+ 48 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/TestEnvRepo.java

@@ -0,0 +1,48 @@
+package com.mooctest.crowd.domain.repository;
+
+import com.mooctest.crowd.domain.dao.TestEnvDao;
+import com.mooctest.crowd.domain.domainobject.TestEnv;
+import com.mooctest.crowd.domain.model.TestCasePO;
+import com.mooctest.crowd.domain.model.TestEnvPO;
+import com.mooctest.crowd.domain.util.Converter;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Component
+public class TestEnvRepo implements ITestEnvRepo {
+    @Autowired
+    private TestEnvDao testEnvDao;
+
+    @Override
+    public void save(TestEnv testEnv) {
+        TestEnvPO testEnvPO = Converter.convert(TestEnvPO.class, testEnv);
+        testEnvDao.save(testEnvPO);
+        testEnv.setId(testEnvPO.getId());
+    }
+
+    @Override
+    public List<TestEnv> findAllByTaskCodeAndUserId(String taskCode, Long userId) {
+        List<TestEnvPO> testEnvPOs = testEnvDao.findAllByTaskCodeAndUserId(taskCode, userId);
+        return testEnvPOs.stream().map(testEnvPO -> Converter.convert(TestEnv.class, testEnvPO)).collect(Collectors.toList());
+    }
+
+    @Override
+    public void deleteById(Long id) {
+        testEnvDao.deleteById(id);
+    }
+
+    @Override
+    public TestEnv findById(Long id) {
+        TestEnvPO testEnvPO = testEnvDao.findById(id).get();
+        return Converter.convert(TestEnv.class, testEnvPO);
+    }
+
+    @Override
+    public List<TestEnv> findAllByTaskCode(String taskCode) {
+        List<TestEnvPO> testEnvPOs = testEnvDao.findAllByTaskCode(taskCode);
+        return testEnvPOs.stream().map(testEnvPO -> Converter.convert(TestEnv.class, testEnvPO)).collect(Collectors.toList());
+    }
+}

+ 3 - 0
core/src/main/java/com/mooctest/crowd/domain/util/Converter.java

@@ -21,6 +21,9 @@ public class Converter {
 
     public static <T> T convert(Class<T> targetClass, Object source) {
         try {
+            if (source == null) {
+                return null;
+            }
             T target = targetClass.newInstance();
             BeanCopier copier = getCopier(source.getClass(), targetClass);
             copier.copy(source, target, primitiveConverter);

+ 16 - 1
site/pom.xml

@@ -36,7 +36,7 @@
 			<groupId>mysql</groupId>
 			<artifactId>mysql-connector-java</artifactId>
 			<scope>runtime</scope>
-			<version>5.1.6</version>
+<!--			<version>5.1.6</version>-->
 		</dependency>
 		<dependency>
 			<groupId>org.projectlombok</groupId>
@@ -131,6 +131,21 @@
 			<artifactId>easypoi-annotation</artifactId>
 			<version>3.0.3</version>
 		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi</artifactId>
+			<version>4.1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml</artifactId>
+			<version>4.1.2</version>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.poi</groupId>
+			<artifactId>poi-ooxml-schemas</artifactId>
+			<version>4.1.2</version>
+		</dependency>
 		<!-- Shiro -->
 		<dependency>
 			<groupId>org.apache.shiro</groupId>

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

@@ -51,4 +51,5 @@ public class DefectAddedCommand {
     private List<String> files;
     //截图列表
     private List<String> screenshots;
+    private String importCode;
 }

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

@@ -46,4 +46,5 @@ public class DefectUpdatedCommand {
     private List<String> files;
     //截图列表
     private List<String> screenshots;
+    private String importCode;
 }

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/command/TestCaseAddedCommand.java

@@ -49,4 +49,6 @@ public class TestCaseAddedCommand {
     private List<String> screenshots;
     //关联需求
     private String demand;
+    private String associatedCode;
+    private String importCode;
 }

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

@@ -47,4 +47,5 @@ public class TestCaseUpdatedCommand {
     private List<String> screenshots;
     //关联需求
     private String demand;
+    private String associatedCode;
 }

+ 2 - 2
site/src/main/java/com/mooctest/crowd/site/configuration/WebMvcConfiguration.java

@@ -29,10 +29,10 @@ public class WebMvcConfiguration implements WebMvcConfigurer {
     public void addInterceptors(InterceptorRegistry registry) {
         registry.addInterceptor(fileCheckInterceptor)
                 .addPathPatterns("/api/files/**");
-//        registry.addInterceptor(authCheckInterceptor)
+        registry.addInterceptor(authCheckInterceptor);
 //                .excludePathPatterns("/api/common/**")
 //                .addPathPatterns("/**");
-//        registry.addInterceptor(sysAdminCheckInterceptor)
+        registry.addInterceptor(sysAdminCheckInterceptor);
 //                .addPathPatterns("/api/user/**");
     }
     }

+ 41 - 4
site/src/main/java/com/mooctest/crowd/site/controller/CrowdTaskController.java

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.site.controller;
 
 import com.mooctest.crowd.domain.domainobject.TestCase;
+import com.mooctest.crowd.domain.domainobject.TestEnv;
 import com.mooctest.crowd.domain.env.TestStatus;
 import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.UnauthorizedException;
@@ -10,15 +11,15 @@ import com.mooctest.crowd.site.command.CrowdTestTaskCommand;
 import com.mooctest.crowd.site.command.TaskDataBoardCommand;
 import com.mooctest.crowd.site.data.dto.TaskDetailsDTO;
 import com.mooctest.crowd.site.data.dto.TaskSquareDTO;
+import com.mooctest.crowd.site.data.vo.*;
 import com.mooctest.crowd.site.data.response.ResponseVO;
 import com.mooctest.crowd.site.data.response.ServerCode;
 import com.mooctest.crowd.site.data.tfidf.JabaResult;
-import com.mooctest.crowd.site.data.vo.SimpleTaskDataVO;
-import com.mooctest.crowd.site.data.vo.SimpleUserTaskDataVO;
-import com.mooctest.crowd.site.data.vo.TaskUserSimpleData;
-import com.mooctest.crowd.site.data.vo.UserVO;
 import com.mooctest.crowd.site.service.CrowdTaskService;
 import com.mooctest.crowd.site.service.TestCaseService;
+import com.mooctest.crowd.site.service.TestEnvService;
+import com.mooctest.crowd.site.service.TestToolService;
+import com.mooctest.crowd.site.util.RedisHelper;
 import com.mooctest.crowd.site.util.RequestUtils;
 import io.swagger.annotations.Api;
 import lombok.extern.slf4j.Slf4j;
@@ -30,6 +31,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpSession;
 import java.util.List;
+import java.util.UUID;
 import java.util.stream.Collectors;
 
 /**
@@ -47,6 +49,12 @@ public class CrowdTaskController{
     private CrowdTaskService taskService;
     @Autowired
     private TestCaseService testCaseService;
+    @Autowired
+    private TestEnvService testEnvService;
+    @Autowired
+    private TestToolService testToolService;
+    @Autowired
+    private RedisHelper redisHelper;
 
     @RequestMapping(value = "/project/{projectCode}/task/{taskCode}", method = RequestMethod.GET)
     public TaskDetailsDTO getTask(@PathVariable("projectCode") String projectCode, @PathVariable("taskCode") String taskCode, HttpSession session){
@@ -218,8 +226,37 @@ public class CrowdTaskController{
         if (count > 0) {
             return new ResponseVO(ServerCode.ERROR, String.format("测试用例中存在%d条测试通过却包含缺陷的记录,请确认并删除多余的缺陷记录!", count));
         }
+        List<TestEnv> testEnvs = testEnvService.findAllByTaskCodeAndUserId(taskCode, userId, userId);
+        if (testEnvs.size() == 0) {
+            return new ResponseVO(ServerCode.ERROR, "请补充测试的环境信息");
+        }
         taskService.commitTask(page.getDatas().get(0).getProjectCode(), taskCode, userId);
         return new ResponseVO(ServerCode.SUCCESS);
     }
 
+    @LoginRequired
+    @RequestMapping(value = "/task/{taskCode}/statistics", method = RequestMethod.GET)
+    public ResponseVO<TaskStatisticsVO> getTaskStatistics(HttpServletRequest request, @PathVariable("taskCode") String taskCode) {
+        Long userId = RequestUtils.getUserId(request);
+        return new ResponseVO(ServerCode.SUCCESS, taskService.getTaskStatistics(userId, taskCode));
+    }
+
+    @LoginRequired
+    @RequestMapping(value = "/task/{taskCode}/completion", method = RequestMethod.GET)
+    public ResponseVO<Double> getTaskCompletion(HttpServletRequest request, @PathVariable("taskCode") String taskCode) {
+        Long userId = RequestUtils.getUserId(request);
+        String token = UUID.randomUUID().toString();
+        redisHelper.hset("token", token, userId, 360000);
+        System.out.println("token=======" + token);
+        return new ResponseVO(ServerCode.SUCCESS, 0.0d);
+    }
+
+    @RequestMapping(value = "/task/{taskCode}/moreinfo", method = RequestMethod.GET)
+    public ResponseVO<TaskMoreInfoVO> getTaskMoreInfo(String token, @PathVariable("taskCode") String taskCode){
+        Long userId = (Long)redisHelper.hget("token", token);
+        if (userId == null) {
+            throw new BaseException("token无效");
+        }
+        return new ResponseVO(ServerCode.SUCCESS, taskService.getTaskMoreInfo(userId, taskCode));
+    }
 }

+ 34 - 0
site/src/main/java/com/mooctest/crowd/site/controller/TestCaseController.java

@@ -22,8 +22,10 @@ import io.swagger.annotations.Api;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
 
 @RestController
 @RequestMapping("/api/testcase")
@@ -74,6 +76,22 @@ public class TestCaseController {
         return new ResponseVO<>(ServerCode.SUCCESS, page);
     }
 
+    @GetMapping(value = "/designer/defects/{taskCode}/{committerId:\\d+}/{pageNo:\\d+}/{pageSize:\\d+}")
+    @LoginRequired
+    public ResponseVO<DOPage<Defect>> defectList(HttpServletRequest request, @PathVariable String taskCode,
+                                             @PathVariable Long committerId, @PathVariable Integer pageNo,
+                                             @PathVariable Integer pageSize, String testStatus, String examStatus) {
+        if (committerId.equals(0L)) {
+            committerId = RequestUtils.getUserId(request);
+        }
+        TestCaseSearchDTO testCaseSearchDTO = new TestCaseSearchDTO();
+        testCaseSearchDTO.setTestStatus(StringUtils.isEmpty(testStatus) ? null : TestStatus.valueOf(testStatus));
+        testCaseSearchDTO.setExamStatus(StringUtils.isEmpty(examStatus) ? null : TestCaseExamStatus.valueOf(examStatus));
+
+        DOPage<Defect> page = defectService.findUserDefects(committerId, RequestUtils.getUserId(request), taskCode, pageNo, pageSize);
+        return new ResponseVO(ServerCode.SUCCESS, page);
+    }
+
     @PostMapping(value = "/defect")
     @LoginRequired
     public ResponseVO<Long> addDefect(HttpServletRequest request, @RequestBody DefectAddedCommand defectAddedCommand) {
@@ -105,4 +123,20 @@ public class TestCaseController {
         testCaseService.exam(testCaseExamCommand);
         return new ResponseVO(ServerCode.SUCCESS);
     }
+
+    @PostMapping(value = "/upload/{taskCode}")
+    @LoginRequired
+    public ResponseVO uploadTestCases(HttpServletRequest request, MultipartFile file, @PathVariable String taskCode) throws IOException {
+        Long userId = RequestUtils.getUserId(request);
+        testCaseService.importTestCases(file.getBytes(), taskCode, userId);
+        return new ResponseVO(ServerCode.SUCCESS);
+    }
+
+    @PostMapping(value = "/uploaddefects/{taskCode}")
+    @LoginRequired
+    public ResponseVO uploadDefects(HttpServletRequest request, MultipartFile file, @PathVariable String taskCode) throws IOException {
+        Long userId = RequestUtils.getUserId(request);
+        defectService.importDefects(file.getBytes(), taskCode, userId);
+        return new ResponseVO(ServerCode.SUCCESS);
+    }
 }

+ 6 - 0
site/src/main/java/com/mooctest/crowd/site/data/TaskOperationControl.java

@@ -22,6 +22,8 @@ public class TaskOperationControl {
     private boolean writeReport = false;
     private boolean taskDemonstrate = false;
     private boolean taskRecommend = false;
+    private boolean testCaseExam = false;
+    private boolean testCaseManage = false;
 
     public void hasAll(){
         this.receive = true;
@@ -32,6 +34,8 @@ public class TaskOperationControl {
         this.uploadReport = true;
         this.taskDemonstrate = true;
         this.taskRecommend = true;
+        this.testCaseExam = true;
+        this.testCaseManage = true;
     }
 
     public void noAll(){
@@ -44,5 +48,7 @@ public class TaskOperationControl {
         this.writeReport = false;
         this.taskDemonstrate = false;
         this.taskRecommend = false;
+        this.testCaseExam = false;
+        this.testCaseManage = false;
     }
 }

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

@@ -1689,12 +1689,22 @@ public class WebMediatorImpl implements ViewMediator {
         Optional<EndPointPO> endPointPOOptional = endPointDao.findByTaskCode(task.getCode());
         TaskOperationControl taskOperationControl = new TaskOperationControl();
 
-        if (user == null || task.getStatus() == CrowdTestTaskStatus.HAS_TIME_OUT) {
+        if (user == null) {
             return taskOperationControl;
         }
 
-        // 任务已结束,如果存在配置项的任务展示token则显示 任务面板按钮
-        if(task.getStatus() == CrowdTestTaskStatus.HAS_FINISHED){
+        if (user.getRoleList().stream().anyMatch(role -> role.getName().equals("SystemAdministrator"))
+                || (user.getRegionalManager() != null && user.getId().equals(project.getRegionalManagerId()))) {
+            taskOperationControl.setTestCaseExam(true);
+        }
+
+        List<TaskToUser> acceptedUserList = task.getAcceptedUserList();
+        Optional<TaskToUser> taskToUserOptional = acceptedUserList.stream().filter(taskToUser -> taskToUser.getUserId().equals(user.getId())).findFirst();
+        if (taskToUserOptional.isPresent()) {
+            taskOperationControl.setTestCaseManage(true);
+        }
+
+        if(task.getStatus() == CrowdTestTaskStatus.HAS_FINISHED){// 任务已结束,如果存在配置项的任务展示token则显示 任务面板按钮
             if(endPointPOOptional.isPresent()){
                 if(endPointPOOptional.get().getToken() != null &&  !endPointPOOptional.get().getToken().equals("")){
                     taskOperationControl.setTaskDemonstrate(true);
@@ -1704,10 +1714,7 @@ public class WebMediatorImpl implements ViewMediator {
             //区域管理员或系统管理员视角
             if (user.getRoleList().stream().anyMatch(role -> role.getName().equals("SystemAdministrator"))
                     || (user.getRegionalManager() != null && user.getId().equals(project.getRegionalManagerId()))) {
-                List<TaskToUser> acceptedUserList = task.getAcceptedUserList();
-                Optional<TaskToUser> taskToUserOptional = acceptedUserList.stream().filter(taskToUser -> taskToUser.getUserId().equals(user.getId())).findFirst();
                 if (task.getStatus() < CrowdTestTaskStatus.HAS_RECEIVED) {
-
                     taskOperationControl.setUpdate(true);
                     taskOperationControl.setTaskRecommend(true);
                     taskOperationControl.setReceive(true);
@@ -1716,10 +1723,10 @@ public class WebMediatorImpl implements ViewMediator {
                         taskOperationControl.setWriteReport(true);
                     }
                 }else if(task.getStatus() == CrowdTestTaskStatus.HAS_RECEIVED&&taskToUserOptional.isPresent()){
-                        taskOperationControl.setUploadReport(true);
-                        if (taskToUserOptional.get().getHasReport() == 1 && taskToUserOptional.get().getIsCommitted() == 0) {
-                            taskOperationControl.setFinish(true);
-                        } else if (taskToUserOptional.get().getHasReport() == 1 && taskToUserOptional.get().getIsCommitted() == 1) {
+                    taskOperationControl.setUploadReport(true);
+                    if (taskToUserOptional.get().getHasReport() == 1 && taskToUserOptional.get().getIsCommitted() == 0) {
+                        taskOperationControl.setFinish(true);
+                    } else if (taskToUserOptional.get().getHasReport() == 1 && taskToUserOptional.get().getIsCommitted() == 1) {
                         taskOperationControl.setFinish(false);
                         taskOperationControl.setUploadReport(false);
                     }
@@ -1748,9 +1755,6 @@ public class WebMediatorImpl implements ViewMediator {
             else if (AuthCheckServiceImpl.isAgency(user) && task.getStatus() != CrowdTestTaskStatus.HAS_REJECTED) {
                 if ((task.getDistributionType() == 0 && task.getEvaluationAgencyId().equals(user.getId()))
                         || (task.getDistributionType() == 2 && task.getStatus() >= CrowdTestTaskStatus.HAS_RECEIVED)) {
-                    List<TaskToUser> acceptedUserList = task.getAcceptedUserList();
-                    Optional<TaskToUser> taskToUserOptional = acceptedUserList.stream().filter(taskToUser -> taskToUser.getUserId().equals(user.getId())).findFirst();
-
                     if (taskToUserOptional.isPresent()) {
                         // 已接收用户
                         if (task.getStatus() == CrowdTestTaskStatus.HAS_RELEASED) {
@@ -1806,8 +1810,6 @@ public class WebMediatorImpl implements ViewMediator {
             }
         }
 
-
-
         System.out.println(taskOperationControl);
         return taskOperationControl;
     }

+ 5 - 3
site/src/main/java/com/mooctest/crowd/site/service/CrowdTaskService.java

@@ -3,10 +3,8 @@ package com.mooctest.crowd.site.service;
 import com.mooctest.crowd.site.command.CrowdTestTaskCommand;
 import com.mooctest.crowd.site.data.dto.TaskDetailsDTO;
 import com.mooctest.crowd.site.data.dto.TaskSquareDTO;
+import com.mooctest.crowd.site.data.vo.*;
 import com.mooctest.crowd.site.data.tfidf.JabaResult;
-import com.mooctest.crowd.site.data.vo.CrowdTaskVO;
-import com.mooctest.crowd.site.data.vo.SimpleTaskDataVO;
-import com.mooctest.crowd.site.data.vo.SimpleUserTaskDataVO;
 
 import java.util.List;
 
@@ -52,4 +50,8 @@ public interface CrowdTaskService {
     List<SimpleUserTaskDataVO> findSimpleTaskDatasByUserId(Long userId);
 
     List<SimpleTaskDataVO> findSimpleTaskDatasByProjectCode(String projectCode);
+
+    TaskStatisticsVO getTaskStatistics(Long userId, String taskCode);
+
+    TaskMoreInfoVO getTaskMoreInfo(Long userId, String taskCode);
 }

+ 5 - 1
site/src/main/java/com/mooctest/crowd/site/service/DefectService.java

@@ -6,6 +6,7 @@ import com.mooctest.crowd.site.command.DefectAddedCommand;
 import com.mooctest.crowd.site.command.DefectUpdatedCommand;
 import org.springframework.validation.annotation.Validated;
 
+import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 
 @Validated
@@ -13,5 +14,8 @@ public interface DefectService {
     Defect add(@Validated DefectAddedCommand defectAddedCommand);
     void delete(@NotNull(message = "提交者id不能为空") Long commiterId, @NotNull(message = "id不能为空") Long id);
     Defect update(@Validated DefectUpdatedCommand defectUpdatedCommand);
-    DOPage<Defect> findUserDefects(@NotNull(message = "提交者id不能为空") Long commiterId, String taskCode, Integer pageNo, Integer pageSize);
+    DOPage<Defect> findUserDefects(@NotNull(message = "提交者id不能为空") Long commiterId, @NotNull(message = "读用户id不能为空") Long readUserId, String taskCode, Integer pageNo, Integer pageSize);
+    void importDefects(@NotNull(message = "文件内容不能为空") byte[] bs,
+                         @NotEmpty(message = "任务编号不能为空") String taskCode,
+                         @NotNull(message = "用户id不能为空") Long userId);
 }

+ 4 - 0
site/src/main/java/com/mooctest/crowd/site/service/TestCaseService.java

@@ -9,6 +9,7 @@ import com.mooctest.crowd.site.data.dto.TestCaseExamCommand;
 import com.mooctest.crowd.site.data.dto.TestCaseSearchDTO;
 import org.springframework.validation.annotation.Validated;
 
+import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
 
 @Validated
@@ -18,4 +19,7 @@ public interface TestCaseService {
     TestCase update(@Validated TestCaseUpdatedCommand testCaseUpdatedCommand);
     DOPage<TestCase> find(Long designerId, Long readUserId, String taskCode, Integer pageNo, Integer pageSize, TestCaseSearchDTO testCaseSearchDTO);
     void exam(@Validated TestCaseExamCommand testCaseExamCommand);
+    void importTestCases(@NotNull(message = "文件内容不能为空") byte[] bs,
+                         @NotEmpty(message = "任务编号不能为空") String taskCode,
+                         @NotNull(message = "用户id不能为空") Long userId);
 }

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


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

@@ -1,7 +1,11 @@
 package com.mooctest.crowd.site.service.impl;
 
+import com.alibaba.druid.util.StringUtils;
 import com.mooctest.crowd.domain.dao.*;
 import com.mooctest.crowd.domain.domainobject.*;
+import com.mooctest.crowd.domain.env.DefectType;
+import com.mooctest.crowd.domain.env.Seriousness;
+import com.mooctest.crowd.domain.env.TestCaseExamStatus;
 import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.CrowdTestTaskNotExistException;
 import com.mooctest.crowd.domain.exception.UnauthorizedException;
@@ -15,21 +19,19 @@ import com.mooctest.crowd.site.data.dto.TaskSquareDTO;
 import com.mooctest.crowd.site.data.enums.ProjectType;
 import com.mooctest.crowd.site.data.tfidf.JabaResult;
 import com.mooctest.crowd.site.data.tfidf.TFIDFAnalyzer;
-import com.mooctest.crowd.site.data.vo.CrowdTaskVO;
-import com.mooctest.crowd.site.data.vo.SimpleTaskDataVO;
-import com.mooctest.crowd.site.data.vo.SimpleUserTaskDataVO;
+import com.mooctest.crowd.site.data.vo.*;
 import com.mooctest.crowd.site.mediator.ViewMediator;
 import com.mooctest.crowd.site.service.CrowdTaskService;
 import com.mooctest.crowd.site.util.GenerateFlowCodeUtil;
+import com.mooctest.crowd.site.util.RequestUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.http.client.utils.DateUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
+import java.sql.Timestamp;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -72,7 +74,22 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
     private TaskToUserDao taskToUserDao;
 
     @Autowired
-    private TestCaseRepo testCaseRepo;
+    private ITestCaseRepo testCaseRepo;
+
+    @Autowired
+    private TestCaseDao testCaseDao;
+
+    @Autowired
+    private DefectDao defectDao;
+
+    @Autowired
+    private IDefectRepo defectRepo;
+
+    @Autowired
+    private ITestEnvRepo testEnvRepo;
+
+    @Autowired
+    private ITestToolRepo testToolRepo;
 
     @Override
     public List<CrowdTaskVO> findMoreHotTasks() {
@@ -290,5 +307,170 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         }).collect(Collectors.toList());
     }
 
+    @Override
+    public TaskStatisticsVO getTaskStatistics(Long userId, String taskCode) {
+        CrowdTestTask task = crowdTestTaskRepo.findByCode(taskCode);
+        if (task == null) {
+            throw new CrowdTestTaskNotExistException();
+        }
+        CrowdTestProject crowdTestProject = projectRepo.getByProjectCode(task.getCrowdTestProjectCode());
+        if (!crowdTestProject.getRegionalManagerId().equals(userId)) {
+            throw new BaseException("您无权访问该任务!");
+        }
+        List<DefectPO> defects = defectDao.findAllByTaskCode(taskCode);
+        TaskStatisticsVO taskStatisticsVO = new TaskStatisticsVO();
+        int testCaseCount = testCaseDao.countAllByTaskCode(taskCode);
+        int validTestCaseCount = testCaseDao.countAllByTaskCodeAndExamStatus(taskCode, TestCaseExamStatus.VALID.getValue());
+        int notExamedTestCaseCount = testCaseDao.countAllByTaskCodeAndExamStatus(taskCode, TestCaseExamStatus.WAIT.getValue());
+        int defectCount = defects.size();
+        int testerCount = taskToUserDao.countAllByTaskCode(taskCode);
+        taskStatisticsVO.setTaskCode(taskCode);
+        taskStatisticsVO.setTaskName(task.getName());
+        taskStatisticsVO.setDefectCount(defectCount);
+        taskStatisticsVO.setTestCaseCount(testCaseCount);
+        taskStatisticsVO.setValidTestCaseCount(validTestCaseCount);
+        taskStatisticsVO.setNoExamedTestCaseCount(notExamedTestCaseCount);
+        taskStatisticsVO.setTesterCount(testerCount);
+        taskStatisticsVO.setProjectCode(task.getCrowdTestProjectCode());
+        int status = task.getStatus();
+        String statusDescr = "";
+        switch(status) {
+            case -1:
+                statusDescr = "定向发布被拒";
+                break;
+            case 0:
+                statusDescr = "创建任务";
+                break;
+            case 1:
+                statusDescr = "发布任务";
+                break;
+            case 2:
+                statusDescr = "接受任务";
+                break;
+            case 3:
+                statusDescr = "区域管理员提交任务";
+                break;
+            case 4:
+                statusDescr = "结束任务";
+                break;
+            case 5:
+                statusDescr = "时间截止";
+                break;
+        }
+        taskStatisticsVO.setStatus(status);
+        taskStatisticsVO.setStatusDescr(statusDescr);
+        String createTime = "";
+        String endTime = "";
+        createTime = DateUtils.formatDate(new Date(task.getCreateTime().getTime()), "yyyy-MM-dd HH:mm");
+        if (task.getEndTime() != null) {
+            endTime = DateUtils.formatDate(new Date(task.getEndTime().getTime()), "yyyy-MM-dd HH:mm");
+        }
+        taskStatisticsVO.setCreateTime(createTime);
+        taskStatisticsVO.setEndTime(endTime);
+        taskStatisticsVO.setProjectName(crowdTestProject.getName());
+        taskStatisticsVO.setTesters(getTaskDetails(task.getCrowdTestProjectCode(), taskCode, userId)
+                .getAcceptedUserList().stream().map(taskToUserVO -> {
+            UserVO userVO = taskToUserVO.getUserVO();
+            TaskStatisticsVO.TesterVO testerVO = new TaskStatisticsVO.TesterVO();
+            testerVO.setName(userVO.getName());
+            testerVO.setId(userVO.getId());
+            testerVO.setScore(-1);
+            testerVO.setCity(userVO.getCity());
+            return testerVO;
+        }).collect(Collectors.toList()));
+
+        User user = userRepo.getByID(crowdTestProject.getUserId());
+        taskStatisticsVO.setCompanyCity(user.getCity());
+        taskStatisticsVO.setCompanyName(user.getUnit());
+
+        List<Integer> defectSeriCounts = new ArrayList(5);
+        defectSeriCounts.add(0);
+        defectSeriCounts.add(0);
+        defectSeriCounts.add(0);
+        defectSeriCounts.add(0);
+        defectSeriCounts.add(0);
+        Map<String, Integer> defectTypeCountMap = new HashMap();
+        for(DefectType defectType: DefectType.values()) {
+            defectTypeCountMap.put(defectType.getName(), 0);
+        }
+        Map<Integer, Integer> defectTimeCountMap = new HashMap();
+        long taskCreateTime = task.getCreateTime().getTime();
+        defects.forEach(defectPO -> {
+            switch (defectPO.getSeriousness()) {
+                case ((byte)1):
+                    defectSeriCounts.set(0, defectSeriCounts.get(0) + 1);
+                    break;
+                case ((byte)2):
+                    defectSeriCounts.set(1, defectSeriCounts.get(1) + 1);
+                    break;
+                case ((byte)3):
+                    defectSeriCounts.set(2, defectSeriCounts.get(2) + 1);
+                    break;
+                case ((byte)4):
+                    defectSeriCounts.set(3, defectSeriCounts.get(3) + 1);
+                    break;
+                case ((byte)5):
+                    defectSeriCounts.set(4, defectSeriCounts.get(4) + 1);
+                    break;
+            }
+            String defectTypeName = DefectType.fromValue(defectPO.getDefectType()).getName();
+            defectTypeCountMap.put(defectTypeName, defectTypeCountMap.get(defectTypeName) + 1);
+            Timestamp defectCommitTime = defectPO.getCommitTime();
+            Integer hours = (int)((defectCommitTime.getTime() - taskCreateTime)/(60*60*1000));
+            Integer count = defectTimeCountMap.get(hours);
+            if (count == null) {
+                count = 0;
+            }
+            count = count + 1;
+            defectTimeCountMap.put(hours, count);
+        });
+        taskStatisticsVO.setDefectSeriCounts(defectSeriCounts);
+        taskStatisticsVO.setDefectTypeCountMap(defectTypeCountMap);
+        taskStatisticsVO.setDefectTimeCountMap(defectTimeCountMap);
+        return taskStatisticsVO;
+    }
+
+    @Override
+    public TaskMoreInfoVO getTaskMoreInfo(Long userId, String taskCode) {
+        TaskMoreInfoVO taskMoreInfoVO = new TaskMoreInfoVO();
+
+        CrowdTestTask task = crowdTestTaskRepo.findByCode(taskCode);
+        if (task == null) {
+            throw new CrowdTestTaskNotExistException();
+        }
+        CrowdTestProject crowdTestProject = projectRepo.getByProjectCode(task.getCrowdTestProjectCode());
+        if (!crowdTestProject.getRegionalManagerId().equals(userId)) {
+            throw new BaseException("您无权访问该任务!");
+        }
+        List<Defect> defects = defectRepo.findAllByTaskCode(taskCode);
+        List<TestCase> testCases = testCaseRepo.findAllByTaskCode(taskCode);
+        List<TestEnv> testEnvs = testEnvRepo.findAllByTaskCode(taskCode);
+        List<TestTool> testTools = testToolRepo.findAllByTaskCode(taskCode);
+        TaskMoreInfoVO.TaskInfoVO taskInfoVO = Converter.convert(TaskMoreInfoVO.TaskInfoVO.class, task);
+        TaskMoreInfoVO.ProjectInfoVO projectInfoVO = Converter.convert(TaskMoreInfoVO.ProjectInfoVO.class, crowdTestProject);
+        User demandUnitUser = userRepo.getByID(crowdTestProject.getUserId());
+        User receivingOrgUser = userRepo.getByID(crowdTestProject.getRegionalManagerId());
+        TaskMoreInfoVO.DemandUnitInfoVO demandUnitInfoVO = Converter.convert(TaskMoreInfoVO.DemandUnitInfoVO.class, demandUnitUser);
+        TaskMoreInfoVO.ReceivingOrgInfoVO receivingOrgInfoVO = Converter.convert(TaskMoreInfoVO.ReceivingOrgInfoVO.class, receivingOrgUser);
+        List<TaskMoreInfoVO.TesterInfoVO> testerInfoVOs = getTaskDetails(task.getCrowdTestProjectCode(), taskCode, userId)
+                .getAcceptedUserList().stream().map(taskToUserVO -> {
+                    UserVO userVO = taskToUserVO.getUserVO();
+                    TaskMoreInfoVO.TesterInfoVO testerInfoVO = Converter.convert(TaskMoreInfoVO.TesterInfoVO.class, userVO);
+                    return testerInfoVO;
+                }).collect(Collectors.toList());
+
+        taskMoreInfoVO.setTestCases(testCases);
+        taskMoreInfoVO.setDefects(defects);
+        taskMoreInfoVO.setTestEnvs(testEnvs);
+        taskMoreInfoVO.setTestTools(testTools);
+        taskMoreInfoVO.setTesters(testerInfoVOs);
+        taskMoreInfoVO.setTask(taskInfoVO);
+        taskMoreInfoVO.setProject(projectInfoVO);
+        taskMoreInfoVO.setDemandUnit(demandUnitInfoVO);
+        taskMoreInfoVO.setReceivingOrg(receivingOrgInfoVO);
+
+        return taskMoreInfoVO;
+    }
+
 }
 

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

@@ -1,20 +1,46 @@
 package com.mooctest.crowd.site.service.impl;
 
+import com.alibaba.druid.util.StringUtils;
+import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
+import com.mooctest.crowd.domain.domainobject.CrowdTestTask;
 import com.mooctest.crowd.domain.domainobject.Defect;
+import com.mooctest.crowd.domain.domainobject.DeletedStatus;
 import com.mooctest.crowd.domain.domainobject.TestCase;
+import com.mooctest.crowd.domain.env.DefectType;
+import com.mooctest.crowd.domain.env.Priority;
+import com.mooctest.crowd.domain.env.Seriousness;
+import com.mooctest.crowd.domain.env.TestStatus;
 import com.mooctest.crowd.domain.exception.BaseException;
+import com.mooctest.crowd.domain.exception.CrowdTestProjectNotExistException;
+import com.mooctest.crowd.domain.exception.CrowdTestTaskNotExistException;
+import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
 import com.mooctest.crowd.domain.page.DOPage;
+import com.mooctest.crowd.domain.repository.ICrowdTaskRepo;
 import com.mooctest.crowd.domain.repository.IDefectRepo;
 import com.mooctest.crowd.domain.repository.ITestCaseRepo;
 import com.mooctest.crowd.domain.util.Converter;
 import com.mooctest.crowd.site.command.DefectAddedCommand;
 import com.mooctest.crowd.site.command.DefectUpdatedCommand;
+import com.mooctest.crowd.site.command.TestCaseAddedCommand;
+import com.mooctest.crowd.site.command.TestCaseUpdatedCommand;
 import com.mooctest.crowd.site.service.DefectService;
 import com.mooctest.crowd.site.util.GenerateFlowCodeUtil;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.sql.Timestamp;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 @Service
 public class DefectServiceImpl implements DefectService {
@@ -22,6 +48,10 @@ public class DefectServiceImpl implements DefectService {
     private IDefectRepo defectRepo;
     @Autowired
     private ITestCaseRepo testCaseRepo;
+    @Autowired
+    private ICrowdTaskRepo crowdTaskRepo;
+    @Autowired
+    private CrowdTestProjectDao crowdTestProjectDao;
 
     @Override
     public Defect add(DefectAddedCommand defectAddedCommand) {
@@ -71,7 +101,169 @@ public class DefectServiceImpl implements DefectService {
     }
 
     @Override
-    public DOPage<Defect> findUserDefects(Long commiterId, String taskCode, Integer pageNo, Integer pageSize) {
+    public DOPage<Defect> findUserDefects(Long commiterId, Long readUserId, String taskCode, Integer pageNo, Integer pageSize) {
+        if (!readUserId.equals(commiterId)) {
+            CrowdTestTask crowdTestTask = crowdTaskRepo.findByCode(taskCode);
+            if (crowdTestTask == null) {
+                throw new CrowdTestTaskNotExistException();
+            }
+            CrowdTestProjectPO crowdTestProjectPO = crowdTestProjectDao.findByCodeAndIsDeleted(crowdTestTask.getCrowdTestProjectCode(), DeletedStatus.isNotDeleted);
+            if (crowdTestProjectPO == null) {
+                throw new CrowdTestProjectNotExistException();
+            }
+            if (!crowdTestProjectPO.getRegionalManagerId().equals(readUserId)) {
+                throw new BaseException("当前用户无权获取该数据");
+            }
+        }
+
         return defectRepo.findUserDefects(commiterId, taskCode, pageNo, pageSize);
     }
+
+    @Override
+    public void importDefects(byte[] bs, String taskCode, Long userId) {
+        try {
+            Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(bs));
+            Sheet sheet = wb.getSheetAt(0);
+            int lastRowNum = sheet.getLastRowNum();
+            Row firstRow = sheet.getRow(0);
+            if (firstRow.getLastCellNum() != 14) {
+                throw new BaseException("模板异常");
+            }
+            String name0 = firstRow.getCell(0).getStringCellValue();
+            String name1 = firstRow.getCell(1).getStringCellValue();
+            String name2 = firstRow.getCell(2).getStringCellValue();
+            String name3 = firstRow.getCell(3).getStringCellValue();
+            String name4 = firstRow.getCell(4).getStringCellValue();
+            String name5 = firstRow.getCell(5).getStringCellValue();
+            String name6 = firstRow.getCell(6).getStringCellValue();
+            String name7 = firstRow.getCell(7).getStringCellValue();
+            String name8 = firstRow.getCell(8).getStringCellValue();
+            String name9 = firstRow.getCell(9).getStringCellValue();
+            String name10 = firstRow.getCell(10).getStringCellValue();
+            String name11 = firstRow.getCell(11).getStringCellValue();
+            String name12 = firstRow.getCell(12).getStringCellValue();
+            String name13 = firstRow.getCell(13).getStringCellValue();
+            if (!name0.equals("缺陷编号")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name1.equals("用例编号")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name2.equals("缺陷名称")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name3.equals("缺陷描述")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name4.equals("严重程序")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name5.equals("优先级")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name6.equals("问题类型")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name7.equals("前置条件")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name8.equals("环境配置")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name9.equals("操作步骤")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name10.equals("输入数据")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name11.equals("预期结果")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name12.equals("实际结果")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name13.equals("其他说明")) {
+                throw new BaseException("模板异常");
+            }
+
+            for (int i = 1; i <= lastRowNum; i++) {
+                Row row = sheet.getRow(i);
+                Cell cell0 = row.getCell(0);
+                Cell cell1 = row.getCell(1);
+                Cell cell2 = row.getCell(2);
+                Cell cell3 = row.getCell(3);
+                Cell cell4 = row.getCell(4);
+                Cell cell5 = row.getCell(5);
+                Cell cell6 = row.getCell(6);
+                Cell cell7 = row.getCell(7);
+                Cell cell8 = row.getCell(8);
+                Cell cell9 = row.getCell(9);
+                Cell cell10 = row.getCell(10);
+                Cell cell11 = row.getCell(11);
+                Cell cell12 = row.getCell(12);
+                Cell cell13 = row.getCell(13);
+                String importCode = cell0 == null ? "" : cell0.getStringCellValue();
+                String importTestCaseCode = cell1 == null ? "" : cell1.getStringCellValue();
+                String name = cell2 == null ? "" : cell2.getStringCellValue();
+                String descr = cell3 == null ? "" : cell3.getStringCellValue();
+                Seriousness seriousness = Seriousness.fromName(cell4.getStringCellValue());
+                Priority priority = Priority.fromName(cell5.getStringCellValue());
+                DefectType defectType = DefectType.fromName(cell6.getStringCellValue());
+                String preconditions = cell7 == null ? "" : cell7.getStringCellValue();
+                String envConfig = cell8 == null ? "" : cell8.getStringCellValue();
+                String opeSteps = cell9 == null ? "" : cell9.getStringCellValue();
+                String inputDatas = cell10 == null ? "" : cell10.getStringCellValue();
+                String expectedResult = cell11 == null ? "" : cell11.getStringCellValue();
+                String testResult = cell12 == null ? "" : cell12.getStringCellValue();
+                String others = cell13 == null ? "" : cell13.getStringCellValue();
+
+                if (StringUtils.isEmpty(importTestCaseCode)) {
+                    throw new BaseException("用例编号不能为空!");
+                }
+                TestCase testCase = testCaseRepo.findByTaskCodeAndDesignerIdAndImportCode(taskCode, userId, importTestCaseCode);
+                if (testCase == null) {
+                    throw new BaseException(String.format("找不到用例编号%s对应的测试用例", importTestCaseCode));
+                }
+                Defect defect = defectRepo.findByTaskCodeAndCommiterIdAndImportCode(taskCode, userId, importCode);
+                if (defect == null) {
+                    DefectAddedCommand defectAddedCommand = new DefectAddedCommand();
+                    defectAddedCommand.setDefectType(defectType);
+                    defectAddedCommand.setDescr(descr);
+                    defectAddedCommand.setEnvConfig(envConfig);
+                    defectAddedCommand.setExpectedResult(expectedResult);
+                    defectAddedCommand.setInputDatas(inputDatas);
+                    defectAddedCommand.setOthers(others);
+                    defectAddedCommand.setPriority(priority);
+                    defectAddedCommand.setCommiterId(userId);
+                    defectAddedCommand.setOpeSteps(opeSteps);
+                    defectAddedCommand.setPreconditions(preconditions);
+                    defectAddedCommand.setSeriousness(seriousness);
+                    defectAddedCommand.setTaskCode(taskCode);
+                    defectAddedCommand.setTestCaseCode(testCase.getCode());
+                    defectAddedCommand.setTestResult(testResult);
+                    defectAddedCommand.setImportCode(importCode);
+                    add(defectAddedCommand);
+                } else {
+                    DefectUpdatedCommand defectUpdatedCommand = new DefectUpdatedCommand();
+                    defectUpdatedCommand.setDefectType(defectType);
+                    defectUpdatedCommand.setDescr(descr);
+                    defectUpdatedCommand.setCommiterId(userId);
+                    defectUpdatedCommand.setEnvConfig(envConfig);
+                    defectUpdatedCommand.setSeriousness(seriousness);
+                    defectUpdatedCommand.setPriority(priority);
+                    defectUpdatedCommand.setExpectedResult(expectedResult);
+                    defectUpdatedCommand.setId(defect.getId());
+                    defectUpdatedCommand.setInputDatas(inputDatas);
+                    defectUpdatedCommand.setOpeSteps(opeSteps);
+                    defectUpdatedCommand.setOthers(others);
+                    defectUpdatedCommand.setPreconditions(preconditions);
+                    defectUpdatedCommand.setTestResult(testResult);
+                    defectUpdatedCommand.setImportCode(importCode);
+                    update(defectUpdatedCommand);
+                }
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

+ 190 - 6
site/src/main/java/com/mooctest/crowd/site/service/impl/TestCaseServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.druid.util.StringUtils;
 import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
 import com.mooctest.crowd.domain.dao.TaskToUserDao;
 import com.mooctest.crowd.domain.domainobject.*;
+import com.mooctest.crowd.domain.env.Priority;
 import com.mooctest.crowd.domain.env.TestCaseExamStatus;
 import com.mooctest.crowd.domain.env.TestStatus;
 import com.mooctest.crowd.domain.exception.BaseException;
@@ -20,19 +21,28 @@ import com.mooctest.crowd.site.data.dto.TestCaseExamCommand;
 import com.mooctest.crowd.site.data.dto.TestCaseSearchDTO;
 import com.mooctest.crowd.site.service.TestCaseService;
 import com.mooctest.crowd.site.util.GenerateFlowCodeUtil;
+import org.apache.poi.hssf.usermodel.HSSFRow;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 @Service
-public class TestCaseServiceImpl implements TestCaseService {
+public class
+TestCaseServiceImpl implements TestCaseService {
     @Autowired
     private ITestCaseRepo testCaseRepo;
     @Autowired
@@ -122,7 +132,9 @@ public class TestCaseServiceImpl implements TestCaseService {
                 throw new BaseException("当前用户无权获取该数据");
             }
         }
-        DOPage<TestCase> page = testCaseRepo.find(designerId, taskCode, pageNo, pageSize, testCaseSearchDTO.getTestStatus(), testCaseSearchDTO.getExamStatus());
+        DOPage<TestCase> page = testCaseRepo.find(designerId, taskCode, pageNo, pageSize,
+                testCaseSearchDTO == null ? null : testCaseSearchDTO.getTestStatus(),
+                testCaseSearchDTO == null ? null : testCaseSearchDTO.getExamStatus());
         Map<String, TestCase> testCaseCodeMap = new HashMap();
         page.getDatas().stream().forEach(testCase -> {
             testCase.setDefects(new ArrayList());
@@ -168,4 +180,176 @@ public class TestCaseServiceImpl implements TestCaseService {
         testCaseRepo.exam(testCaseExamCommand.getId(), TestCaseExamStatus.valueOf(testCaseExamCommand.getExamStatus()),
                 testCaseExamCommand.getExamDescr());
     }
+
+    @Override
+    @Transactional
+    public void importTestCases(byte[] bs, String taskCode, Long userId) {
+        try {
+            Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(bs));
+            Sheet sheet = wb.getSheetAt(0);
+            int lastRowNum = sheet.getLastRowNum();
+            Map<String, TestCase> importCodeTestCaseMap = new HashMap();
+            Map<String, String> hasAssociatedCodeImportCodeMap = new LinkedHashMap();
+            Row firstRow = sheet.getRow(0);
+            if (firstRow.getLastCellNum() != 15) {
+                throw new BaseException("模板异常");
+            }
+            String name0 = firstRow.getCell(0).getStringCellValue();
+            String name1 = firstRow.getCell(1).getStringCellValue();
+            String name2 = firstRow.getCell(2).getStringCellValue();
+            String name3 = firstRow.getCell(3).getStringCellValue();
+            String name4 = firstRow.getCell(4).getStringCellValue();
+            String name5 = firstRow.getCell(5).getStringCellValue();
+            String name6 = firstRow.getCell(6).getStringCellValue();
+            String name7 = firstRow.getCell(7).getStringCellValue();
+            String name8 = firstRow.getCell(8).getStringCellValue();
+            String name9 = firstRow.getCell(9).getStringCellValue();
+            String name10 = firstRow.getCell(10).getStringCellValue();
+            String name11 = firstRow.getCell(11).getStringCellValue();
+            String name12 = firstRow.getCell(12).getStringCellValue();
+            String name13 = firstRow.getCell(13).getStringCellValue();
+            String name14 = firstRow.getCell(14).getStringCellValue();
+            if (!name0.equals("用例编号")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name1.equals("关联用例编号")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name2.equals("关联需求")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name3.equals("用例名称")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name4.equals("优先级")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name5.equals("用例描述")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name6.equals("前置条件")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name7.equals("环境配置")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name8.equals("操作步骤")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name9.equals("输入数据")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name10.equals("预期结果")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name11.equals("评判标准")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name12.equals("其他说明")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name13.equals("测试结果")) {
+                throw new BaseException("模板异常");
+            }
+            if (!name14.equals("测试结论")) {
+                throw new BaseException("模板异常");
+            }
+
+            for (int i = 1; i <= lastRowNum; i++) {
+                Row row = sheet.getRow(i);
+                Cell cell0 = row.getCell(0);
+                Cell cell1 = row.getCell(1);
+                Cell cell2 = row.getCell(2);
+                Cell cell3 = row.getCell(3);
+                Cell cell4 = row.getCell(4);
+                Cell cell5 = row.getCell(5);
+                Cell cell6 = row.getCell(6);
+                Cell cell7 = row.getCell(7);
+                Cell cell8 = row.getCell(8);
+                Cell cell9 = row.getCell(9);
+                Cell cell10 = row.getCell(10);
+                Cell cell11 = row.getCell(11);
+                Cell cell12 = row.getCell(12);
+                Cell cell13 = row.getCell(13);
+                Cell cell14 = row.getCell(14);
+                String importCode = cell0 == null ? "" : cell0.getStringCellValue();
+                String associatedImportCode = cell1 == null ? "" : cell1.getStringCellValue();
+                String demand = cell2 == null ? "" : cell2.getStringCellValue();
+                String name = cell3 == null ? "" : cell3.getStringCellValue();
+                Priority priority = Priority.fromName(cell4.getStringCellValue());
+                String descr = cell5 == null ? "" : cell5.getStringCellValue();
+                String preconditions = cell6 == null ? "" : cell6.getStringCellValue();
+                String envConfig = cell7 == null ? "" : cell7.getStringCellValue();
+                String opeSteps = cell8 == null ? "" : cell8.getStringCellValue();
+                String inputDatas = cell9 == null ? "" : cell9.getStringCellValue();
+                String expectedResult = cell10 == null ? "" : cell10.getStringCellValue();
+                String evaCriteria = cell11 == null ? "" : cell11.getStringCellValue();
+                String others = cell12 == null ? "" : cell12.getStringCellValue();
+                String testResult = cell13 == null ? "" : cell13.getStringCellValue();
+                TestStatus testStatus = TestStatus.fromName(cell14.getStringCellValue());
+
+                if (!StringUtils.isEmpty(associatedImportCode)) {
+                    hasAssociatedCodeImportCodeMap.put(importCode, associatedImportCode);
+                }
+
+                TestCase testCase = testCaseRepo.findByTaskCodeAndDesignerIdAndImportCode(taskCode, userId, importCode);
+                if (testCase == null) {
+                    TestCaseAddedCommand testCaseAddedCommand = new TestCaseAddedCommand();
+                    testCaseAddedCommand.setDesignerId(userId);
+                    testCaseAddedCommand.setTestStatus(testStatus);
+                    testCaseAddedCommand.setDemand(demand);
+                    testCaseAddedCommand.setDescr(descr);
+                    testCaseAddedCommand.setEnvConfig(envConfig);
+                    testCaseAddedCommand.setEvaCriteria(evaCriteria);
+                    testCaseAddedCommand.setExpectedResult(expectedResult);
+                    testCaseAddedCommand.setInputDatas(inputDatas);
+                    testCaseAddedCommand.setName(name);
+                    testCaseAddedCommand.setOpeSteps(opeSteps);
+                    testCaseAddedCommand.setOthers(others);
+                    testCaseAddedCommand.setPreconditions(preconditions);
+                    testCaseAddedCommand.setPriority(priority);
+                    testCaseAddedCommand.setTaskCode(taskCode);
+                    testCaseAddedCommand.setTestResult(testResult);
+                    testCaseAddedCommand.setImportCode(importCode);
+                    testCase = add(testCaseAddedCommand);
+                } else {
+                    TestCaseUpdatedCommand testCaseUpdatedCommand = new TestCaseUpdatedCommand();
+                    testCaseUpdatedCommand.setDesignerId(userId);
+                    testCaseUpdatedCommand.setDemand(demand);
+                    testCaseUpdatedCommand.setDescr(descr);
+                    testCaseUpdatedCommand.setEnvConfig(envConfig);
+                    testCaseUpdatedCommand.setTestStatus(testStatus);
+                    testCaseUpdatedCommand.setTestResult(testResult);
+                    testCaseUpdatedCommand.setEvaCriteria(evaCriteria);
+                    testCaseUpdatedCommand.setExpectedResult(expectedResult);
+                    testCaseUpdatedCommand.setPriority(priority);
+                    testCaseUpdatedCommand.setId(testCase.getId());
+                    testCaseUpdatedCommand.setInputDatas(inputDatas);
+                    testCaseUpdatedCommand.setName(name);
+                    testCaseUpdatedCommand.setOpeSteps(opeSteps);
+                    testCaseUpdatedCommand.setOthers(others);
+                    testCaseUpdatedCommand.setPreconditions(preconditions);
+                    testCaseUpdatedCommand.setAssociatedCode(null);
+                    testCase = update(testCaseUpdatedCommand);
+                }
+
+                importCodeTestCaseMap.put(testCase.getImportCode(), testCase);
+            }
+
+            for (String importCode: hasAssociatedCodeImportCodeMap.keySet()) {
+                TestCase testCase = importCodeTestCaseMap.get(importCode);
+                String associatedImportCode = hasAssociatedCodeImportCodeMap.get(importCode);
+                if (associatedImportCode.equals(importCode)) {
+                    throw new BaseException(String.format("用例编号为%s的用例不能设置关联自己的用例编号!", importCode));
+                }
+                TestCase associatedTestCase = importCodeTestCaseMap.get(associatedImportCode);
+                if (associatedTestCase == null) {
+                    throw new BaseException(String.format("找不到关联的用例编号%s对应的用例!", associatedImportCode));
+                }
+                testCaseRepo.updateAssociatedCodeById(testCase.getId(), associatedTestCase.getCode());
+            }
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
 }

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


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