Browse Source

新增提交测试用例接口,提交后有推荐

郭超 3 years ago
parent
commit
79e08d6b9f

+ 26 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/TestCaseToUserDao.java

@@ -0,0 +1,26 @@
+package com.mooctest.crowd.domain.dao;
+
+import com.mooctest.crowd.domain.domainobject.TestCaseToUser;
+import com.mooctest.crowd.domain.model.RankCountInfo;
+import com.mooctest.crowd.domain.model.RankInfo;
+import com.mooctest.crowd.domain.model.TestCaseToUserPO;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.CrudRepository;
+
+import javax.transaction.Transactional;
+import java.util.List;
+import java.util.Optional;
+
+@Transactional
+public interface TestCaseToUserDao extends CrudRepository<TestCaseToUserPO,Long> {
+
+    @Override
+    Optional<TestCaseToUserPO> findById(Long id);
+
+    List<TestCaseToUserPO> findByUserId(Long userId);
+
+    List<TestCaseToUserPO> findByTaskCode(String taskCode);
+
+    TestCaseToUserPO save(TestCaseToUserPO testCaseToUserPO);
+}

+ 20 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/CrowdTestTask.java

@@ -2,6 +2,7 @@ package com.mooctest.crowd.domain.domainobject;
 
 import com.mooctest.crowd.domain.domainobject.enums.DistributeType;
 import com.mooctest.crowd.domain.exception.CrowdTestTaskException;
+import com.mooctest.crowd.domain.model.TestCaseToUserPO;
 import lombok.Data;
 
 import java.sql.Timestamp;
@@ -52,6 +53,7 @@ public class CrowdTestTask {
     private String exportUrl;
     private int needTestcase;
     private List<TestCase> testCaseList = new ArrayList<>();
+    private List<TestCaseToUser> testCaseToUserList = new ArrayList<>();
 
     /**
      * 接收任务(测评机构)
@@ -97,6 +99,14 @@ public class CrowdTestTask {
             TaskToUser taskToUser = new TaskToUser();
             taskToUser.setValue(this.code, userId, this.quotedPrice, 0, this.getDistributionType(), 1, new Timestamp(System.currentTimeMillis()));
             this.getAcceptedUserList().add(taskToUser);
+
+            // 关联用例 TODO 定向发布没做
+            List<TestCase> testCaseList = this.getTestCaseList();
+            testCaseList.stream().forEach(testCase -> {
+                TestCaseToUser testCaseToUser = new TestCaseToUser();
+                testCaseToUser.setValue(this.code, testCase.getId(), userId, new Timestamp(System.currentTimeMillis()));
+                this.getTestCaseToUserList().add(testCaseToUser);
+            });
         }
 
         this.setAcceptedUserList(acceptedUserList);
@@ -201,4 +211,14 @@ public class CrowdTestTask {
             this.setAcceptedUserList(acceptedUserList);
         }
     }
+
+    public void commitTestCase(Long testCaseId, Long userId) {
+        this.getTestCaseToUserList().stream().filter(testCaseToUser -> testCaseToUser.getTestCaseId().equals(testCaseId) && testCaseToUser.getUserId().equals(userId))
+                .forEach(testCaseToUser -> {
+                    testCaseToUser.setIsCommitted(1);
+                    testCaseToUser.setCommitTime(new Timestamp(System.currentTimeMillis()));
+                });
+        this.getTestCaseList().stream().filter(testCase -> testCase.getId().equals(testCaseId))
+                .forEach(testCase -> testCase.setCompleteCount(testCase.getCompleteCount()+1));
+    }
 }

+ 3 - 1
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestCase.java

@@ -9,8 +9,10 @@ import java.util.List;
 @NoArgsConstructor
 public class TestCase {
     private Long id;
+    private String name;
     private String taskCode;
     private int completeCount;
-    private List<TestAction> testActions;
+    private List<TestAction> testActionsPre;
+    private List<TestAction> testActionsNext;
 }
 

+ 29 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/TestCaseToUser.java

@@ -0,0 +1,29 @@
+package com.mooctest.crowd.domain.domainobject;
+
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.sql.Timestamp;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class TestCaseToUser {
+    private Long id;
+    private String taskCode;
+    private Long testCaseId;
+    private Long userId;
+    private int isCommitted;
+    private String description;
+    private Timestamp commitTime;
+    private TestCase testCase;
+
+    public void setValue(String taskCode, Long testCaseId, Long userId, Timestamp commitTime) {
+        this.taskCode = taskCode;
+        this.testCaseId = testCaseId;
+        this.userId = userId;
+        this.commitTime = commitTime;
+    }
+}

+ 3 - 0
core/src/main/java/com/mooctest/crowd/domain/model/TestCasePO.java

@@ -16,6 +16,9 @@ public class TestCasePO {
     @Column(name = "TC_TASK_CODE")
     private String taskCode;
 
+    @Column(name = "TC_NAME")
+    private String name;
+
     @Column(name = "TC_COMPLETE_COUNT")
     private int completeCount;
 }

+ 34 - 0
core/src/main/java/com/mooctest/crowd/domain/model/TestCaseToUserPO.java

@@ -0,0 +1,34 @@
+package com.mooctest.crowd.domain.model;
+
+
+import lombok.Data;
+
+import javax.persistence.*;
+import java.sql.Timestamp;
+
+@Data
+@Entity(name = "test_case_to_user")
+public class TestCaseToUserPO {
+    @Id
+    @Column(name = "TCTU_ID")
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @Column(name = "TCTU_TASK_CODE")
+    private String taskCode;
+
+    @Column(name = "TCTU_TEST_CASE_ID")
+    private Long testCaseId;
+
+    @Column(name = "TCTU_U_ID")
+    private Long userId;
+
+    @Column(name = "TCTU_IS_COMMITTED")
+    private int isCommitted;
+
+    @Column(name = "TCTU_DESCRIPTION")
+    private String description;
+
+    @Column (name = "TCTU_COMMIT_TIME")
+    private Timestamp commitTime;
+}

+ 41 - 1
core/src/main/java/com/mooctest/crowd/domain/repository/CrowdTestProjectRepo.java

@@ -22,6 +22,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -50,6 +51,9 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
     private TestActionDao testActionDao;
 
     @Autowired
+    private TestCaseToUserDao testCaseToUserDao;
+
+    @Autowired
     private TestCaseDao testCaseDao;
 
     @Autowired
@@ -177,7 +181,10 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
         CrowdTestProjectPO crowdTestProjectPO = Converter.convert(CrowdTestProjectPO.class, crowdTestProject);
         crowdTestProjectDao.save(crowdTestProjectPO);
         List<CrowdTestTask> crowdTestTaskList = crowdTestProject.getCrowdTestTaskList();
+
         Optional.ofNullable(crowdTestTaskList).orElse(new ArrayList<>()).stream().forEach(crowdTestTask -> {
+
+            // 保存接包信息
             List<TaskToUser> acceptedUserList = crowdTestTask.getAcceptedUserList();
             Optional.ofNullable(acceptedUserList).orElse(new ArrayList<>()).stream().forEach(taskToUser -> {
                 // 保存接包信息
@@ -187,6 +194,27 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
                 Optional.ofNullable(crowdTestReportList).orElse(new ArrayList<>()).stream()
                         .forEach(crowdTestReport -> crowdTestReportDao.save(Converter.convert(CrowdTestReportPO.class, crowdTestReport)));
             });
+
+            // 保存用例信息
+            List<TestCase> testCaseList = crowdTestTask.getTestCaseList();
+            Optional.ofNullable(testCaseList).orElse(new ArrayList<>()).stream().forEach(testCase -> {
+                // 进行数据库存储
+                TestCasePO testCasePO = testCaseDao.save(Converter.convert(TestCasePO.class, testCase));
+                List<TestAction> testActions = testCase.getTestActionsPre();
+                List<TestAction> testActionsNext = testCase.getTestActionsNext();
+                testActions.addAll(testActionsNext);
+                testActions.stream().forEach(testAction -> {
+                    testAction.setTestCaseId(testCasePO.getId());
+                    testActionDao.save(Converter.convert(TestActionPO.class, testAction));
+                });
+            });
+
+            // 保存用户用例完成情况
+            List<TestCaseToUser> testCaseToUserList = crowdTestTask.getTestCaseToUserList();
+            Optional.ofNullable(testCaseToUserList).orElse(new ArrayList<>()).stream().forEach(testCaseToUser -> {
+                testCaseToUserDao.save(Converter.convert(TestCaseToUserPO.class, testCaseToUser));
+            });
+
             // 保存任务基本信息
             crowdTestTaskDao.save(Converter.convert(CrowdTestTaskPO.class, crowdTestTask));
             // 保存任务配置信息
@@ -429,10 +457,22 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
                     TestCase testCase = Converter.convert(TestCase.class, testCasePO);
                     List<TestActionPO> testActionPOList = testActionDao.findByTestCaseId(testCasePO.getId());
                     List<TestAction> testActionList = testActionPOList.stream().map(testActionPO -> Converter.convert(TestAction.class, testActionPO)).collect(Collectors.toList());
-                    testCase.setTestActions(testActionList);
+                    testCase.setTestActionsPre(testActionList.stream().filter(testAction -> testAction.getType() == 0).collect(Collectors.toList()));
+                    testCase.setTestActionsNext(testActionList.stream().filter(testAction -> testAction.getType() == 1).collect(Collectors.toList()));
                     return testCase;
                 }).collect(Collectors.toList());
                 crowdTestTaskResult.setTestCaseList(testCaseList);
+
+                // 检索任务中的用例完成信息
+                List<TestCaseToUserPO> testCaseToUserPOList = testCaseToUserDao.findByTaskCode(crowdTestTaskResult.getCode());
+                List<TestCaseToUser> testCaseToUserList = testCaseToUserPOList.stream().map(testCaseToUserPO -> {
+                    TestCaseToUser testCaseToUser = Converter.convert(TestCaseToUser.class, testCaseToUserPO);
+                    TestCase testCaseResult = testCaseList.stream().filter(testCase -> testCase.getId().equals(testCaseToUser.getTestCaseId())).findFirst().get();
+                    testCaseToUser.setTestCase(testCaseResult);
+                    return testCaseToUser;
+                }).sorted(Comparator.comparing(TestCaseToUser::getIsCommitted).thenComparing(TestCaseToUser::getCommitTime)).collect(Collectors.toList());
+                crowdTestTaskResult.setTestCaseToUserList(testCaseToUserList);
+
 //            // 检索任务中的所有的报告
 //            List<CrowdTestReport> crowdTestReportListResult = getCrowdTestReportByCrowdTestTask(crowdTestTaskPO.getCode());
 //            crowdTestTaskResult.setCrowdTestReportList(crowdTestReportListResult);

+ 9 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CrowdTaskController.java

@@ -59,6 +59,15 @@ public class CrowdTaskController{
         return taskService.createTask(projectCode, command, Long.parseLong((String) session.getAttribute("userId")));
     }
 
+
+    @LoginRequired
+    @RequestMapping(value = "/project/{projectCode}/task/{taskCode}/testcase/{testCaseId}", method = RequestMethod.PUT)
+    public void commitTestCase(@PathVariable("projectCode") String projectCode, @PathVariable("taskCode") String taskCode,
+                                  @PathVariable("testCaseId") Long testCaseId, HttpSession session){
+        Long userId = Long.parseLong((String)session.getAttribute("userId"));
+        taskService.commitTestCase(projectCode, taskCode, testCaseId, userId);
+    }
+
     @LoginRequired
     @RequestMapping(value = "/project/{projectCode}/task/{taskCode}/writerReportUrl", method = RequestMethod.GET)
     public ResponseVO<String> getWriterReportUrl(@PathVariable("projectCode") String projectCode, @PathVariable("taskCode") String taskCode,  HttpSession session){

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/data/dto/TaskDetailsDTO.java

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.site.data.dto;
 
 import com.mooctest.crowd.domain.domainobject.TestCase;
+import com.mooctest.crowd.domain.domainobject.TestCaseToUser;
 import com.mooctest.crowd.site.data.TaskOperationControl;
 import com.mooctest.crowd.site.data.vo.CrowdReportVO;
 import com.mooctest.crowd.site.data.vo.CrowdTaskVO;
@@ -20,6 +21,7 @@ public class TaskDetailsDTO {
     private CrowdTaskVO crowdTaskVO;
     private List<TaskToUserVO> acceptedUserList;
     private List<TestCase> testCaseList;
+    private List<TestCaseToUser> testCaseToUserList;
     private List<CrowdReportVO> crowdReportVOList;
     private TaskOperationControl taskOperationControl;
 }

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

@@ -838,6 +838,7 @@ public class WebMediatorImpl implements ViewMediator {
             taskDetailsDTO.setTaskOperationControl(this.initTaskPermission(project, crowdTestTask, user));
             // 区域管理员视图
             List<TaskToUserVO> taskToUserVOS = new ArrayList<>();
+            List<TestCaseToUser> testCaseToUserList = new ArrayList<>();
             if (userId.equals(project.getRegionalManagerId())) {
                 // 判断否存在配置项
                 if(endPoint != null){
@@ -886,6 +887,7 @@ public class WebMediatorImpl implements ViewMediator {
                             return taskToUserVO;
                         }).collect(Collectors.toList());
 
+                testCaseToUserList = crowdTestTask.getTestCaseToUserList().stream().filter(testCaseToUser -> testCaseToUser.getUserId().equals(userId)).collect(Collectors.toList());
                 // 测评机构的endPoint
                 // 判断否存在配置项
                 if(endPoint != null){
@@ -893,8 +895,8 @@ public class WebMediatorImpl implements ViewMediator {
                 }
             }
             taskDetailsDTO.setAcceptedUserList(taskToUserVOS);
-
             taskDetailsDTO.setTestCaseList(crowdTestTask.getTestCaseList());
+            taskDetailsDTO.setTestCaseToUserList(testCaseToUserList);
 
             // 判断是否具有配置项
             if(endPoint != null){

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/service/CrowdTaskService.java

@@ -67,4 +67,6 @@ public interface CrowdTaskService {
     List<CrowdTaskVO> findWaitingAcceptByNameLike(int showTaskCount, String keyword, String testTypeCode);
 
     ExamVO getExamInfo(Long examId);
+
+    void commitTestCase(String projectCode, String taskCode, Long testCaseId, Long userId);
 }

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

@@ -223,6 +223,15 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
     }
 
     @Override
+    public void commitTestCase(String projectCode, String taskCode, Long testCaseId, Long userId) {
+        CrowdTestProject project = projectRepo.getByProjectCodeAndTaskCode(projectCode, taskCode);
+        CrowdTestTask task = project.getTask(taskCode);
+        task.commitTestCase(testCaseId, userId);
+//        project.setRestPrice(project.getRestPrice() + task.getQuotedPrice());
+        projectRepo.saveCrowdTestProject(project);
+    }
+
+    @Override
     public void jumpPublicTesting(String projectCode, String taskCode, Long userId) {
         viewMediator.jumpPublicTesting(projectCode, taskCode, userId);
     }
@@ -279,7 +288,6 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         project.addTask(task);
         projectRepo.saveCrowdTestProject(project);
         return getTaskDetails(projectCode, taskCode, userId);
-//        return getTaskDetails(projectCode, "TASK-JKCS-2022030715008", userId);
     }
 
     private void createTaskToCrowdService(CrowdTestTaskCommand command, Long userId, CrowdTestTask task, EndPoint endPoint) {
@@ -389,18 +397,18 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         if (task.getNeedTestcase() == 1) {
             String testcaseData = this.generateTestcase();
             List<TestCase> testcaseList = JSON.parseArray(testcaseData, TestCase.class);
-            // 进行数据库存储
+            List<TestCase> testcaseListResult = new ArrayList<>();
+
             for (int i = 0; i < testcaseList.size(); i++) {
                 TestCase testCase = new TestCase();
                 testCase.setTaskCode(task.getCode());
-                TestCasePO testCasePO = testCaseDao.save(Converter.convert(TestCasePO.class, testCase));
-                List<TestAction> testActions = testcaseList.get(i).getTestActions();
-                for (int j = 0; j < testActions.size(); j++) {
-                    TestAction testAction = testActions.get(j);
-                    testAction.setTestCaseId(testCasePO.getId());
-                    testActionDao.save(Converter.convert(TestActionPO.class, testAction));
-                }
+                testCase.setName(testcaseList.get(i).getName());
+
+                testCase.setTestActionsPre(testcaseList.get(i).getTestActionsPre());
+                testCase.setTestActionsNext(testcaseList.get(i).getTestActionsNext());
+                testcaseListResult.add(testCase);
             }
+            task.setTestCaseList(testcaseListResult);
         }
     }