Explorar o código

Merge branch 'Dev' into 'Test'

Dev

See merge request crowd-2019/crowd-test-service-backend!48
郭超 %!s(int64=5) %!d(string=hai) anos
pai
achega
28c6ae7f36

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

@@ -27,8 +27,8 @@ public interface CrowdTestTaskDao extends CrudRepository<CrowdTestTaskPO, Long>
 
     List<CrowdTestTaskPO> findAllByIsDeleted(int isDeleted);
 
-    @Query(value = "SELECT new com.mooctest.crowd.domain.model.RankInfo(SUM(p.quotedPrice), p.evaluationAgencyId) FROM CrowdTestTaskPO p where p.evaluationAgencyId is not null and p.status>1 GROUP BY p.evaluationAgencyId ORDER BY SUM(p.quotedPrice) DESC")
-    List<RankInfo> findTotalPriceOfAgency(Pageable pageable);
+//    @Query(value = "SELECT new com.mooctest.crowd.domain.model.RankInfo(SUM(p.quotedPrice), p.evaluationAgencyId) FROM CrowdTestTaskPO p where p.evaluationAgencyId is not null and p.status>1 GROUP BY p.evaluationAgencyId ORDER BY SUM(p.quotedPrice) DESC")
+//    List<RankInfo> findTotalPriceOfAgency(Pageable pageable);
 
     @Query(nativeQuery = true, value = "select * from crowd_test_task where CTT_STATUS=1 and CTT_DISTRIBUTION_TYPE=2 order by CTT_QUOTED_PRICE DESC LIMIT 4")
     List<CrowdTestTaskPO> findHotTask();

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

@@ -1,6 +1,9 @@
 package com.mooctest.crowd.domain.dao;
 
+import com.mooctest.crowd.domain.model.RankInfo;
 import com.mooctest.crowd.domain.model.TaskToUserPO;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.CrudRepository;
 
 import javax.transaction.Transactional;
@@ -20,4 +23,7 @@ public interface TaskToUserDao extends CrudRepository<TaskToUserPO,Long> {
     List<TaskToUserPO> findByTaskCodeAndHasReport(String taskCode, int hasReport);
 
     TaskToUserPO save(TaskToUserPO taskToUserPO);
+
+    @Query(value = "SELECT new com.mooctest.crowd.domain.model.RankInfo(SUM(t.quotedPrice), t.userId) FROM TaskToUserPO t where t.userId is not null GROUP BY t.userId ORDER BY SUM(t.quotedPrice) DESC")
+    List<RankInfo> findTotalPriceOfAgency(Pageable pageable);
 }

+ 29 - 7
core/src/main/java/com/mooctest/crowd/domain/domainobject/CrowdTestTask.java

@@ -8,6 +8,7 @@ import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * @author guochao
@@ -113,9 +114,17 @@ public class CrowdTestTask {
 //        }else if(this.getDistributionType().equals(DistributeType.SQUARE.getId())){
 //            // 广场发布类型
 //        }
-        TaskToUser taskToUser = new TaskToUser();
-        taskToUser.setValue(this.code, user.getId(), 0, this.getDistributionType(), 1, new Timestamp(System.currentTimeMillis()));
-        this.getAcceptedUserList().add(taskToUser);
+        if (this.getDistributionType() == DistributeType.DIRECT.getId()){
+            this.getAcceptedUserList().stream().map(taskToUser -> {
+                taskToUser.setIsAccepted(1);
+                taskToUser.setAcceptTime(new Timestamp(System.currentTimeMillis()));
+                return taskToUser;
+            }).collect(Collectors.toList());
+        }else{
+            TaskToUser taskToUser = new TaskToUser();
+            taskToUser.setValue(this.code, user.getId(), this.quotedPrice,0, this.getDistributionType(), 1, new Timestamp(System.currentTimeMillis()));
+            this.getAcceptedUserList().add(taskToUser);
+        }
         this.setAcceptedUserList(acceptedUserList);
         this.setAcceptedCount(this.acceptedCount+1);
         if (this.getAcceptedCount() == this.getParticipantCount()){
@@ -173,12 +182,25 @@ public class CrowdTestTask {
         }
     }
 
-    public void confirmFinish(Long userId) {
-        if (this.getStatus()!=CrowdTestTaskStatus.HAS_COMMITED){
+    public void confirmFinish() {
+        if ((this.getParticipantHasCommittedCount() == this.getAcceptedCount() && this.getStatus() == CrowdTestTaskStatus.HAS_RECEIVED)|| (this.getParticipantHasCommittedCount() == this.getParticipantCount() && this.getStatus() == CrowdTestTaskStatus.HAS_COMMITED)) {
+            this.setStatus(CrowdTestTaskStatus.HAS_FINISHED);
+            this.setEndTime(new Timestamp(System.currentTimeMillis()));
+        }else {
             throw new CrowdTestTaskException("评测机构未提请结束任务,无法确认结束!");
         }
-        this.setStatus(CrowdTestTaskStatus.HAS_FINISHED);
-        this.setEndTime(new Timestamp(System.currentTimeMillis()));
+
     }
 
+    public void create(String taskCode) {
+        this.setCode(taskCode);
+        this.setStatus(CrowdTestTaskStatus.HAS_RELEASED);
+        if (this.getDistributionType() == DistributeType.DIRECT.getId()){
+            this.setParticipantCount(1);
+            TaskToUser taskToUser = new TaskToUser();
+            taskToUser.setValue(this.code, this.getEvaluationAgencyId(), this.quotedPrice,0, this.getDistributionType(), 0, null);
+            this.getAcceptedUserList().add(taskToUser);
+            this.setAcceptedUserList(acceptedUserList);
+        }
+    }
 }

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

@@ -10,7 +10,7 @@ public class CrowdTestTaskStatus {
     public static final int HAS_RELEASED = 1;   //发布任务
     public static final int HAS_RECEIVED = 2;   //接受任务
 //    public static final int HAS_REPORTED = 3; //存在任务报告
-    public static final int HAS_COMMITED = 3;   //测评机构提交任务
+    public static final int HAS_COMMITED = 3;   //区域管理员提交任务
 //    public static final int HAS_COMMITED_MANAGER = 4;   //区域管理员提交任务
     public static final int HAS_FINISHED = 4;   //结束任务
     public static final int HAS_TIME_OUT = 5; //时间截止

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

@@ -15,6 +15,7 @@ public class TaskToUser {
     private Long id;
     private String taskCode;
     private Long userId;
+    private double quotedPrice;
     private int hasReport;
     private Long distributionType;
     private int isAccepted;
@@ -25,10 +26,11 @@ public class TaskToUser {
     private Timestamp commitReportTime;
     private List<CrowdTestReport> crowdTestReportList = new ArrayList<>();
 
-    public void setValue(String taskCode, Long userId, int hasReport, Long distributionType, int isAccepted, Timestamp acceptTime) {
+    public void setValue(String taskCode, Long userId, double quotedPrice, int hasReport, Long distributionType, int isAccepted, Timestamp acceptTime) {
         this.taskCode = taskCode;
         this.userId = userId;
         this.hasReport = hasReport;
+        this.quotedPrice = quotedPrice;
         this.distributionType = distributionType;
         this.isAccepted = isAccepted;
         this.acceptTime = acceptTime;

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

@@ -24,6 +24,9 @@ public class TaskToUserPO {
     @Column(name = "TTU_U_ID")
     private Long userId;
 
+    @Column(name = "TTU_QUOTED_PRICE")
+    private double quotedPrice;
+
     @Column(name = "TTU_HAS_REPORT")
     private int hasReport;
 

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

@@ -81,6 +81,7 @@ public class CrowdTestProjectCommand {
         crowdTestProject.setRegionalManagerId(this.getInstitution());
         crowdTestProject.setDeadTime(this.datetime);
         crowdTestProject.setQuotedPrice(this.budget);
+        crowdTestProject.setRestPrice(this.budget);
         crowdTestProject.setFixedPrice(this.price);
         return crowdTestProject;
     }

+ 44 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CrowTestSquareController.java

@@ -0,0 +1,44 @@
+package com.mooctest.crowd.site.controller;
+
+import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
+import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
+import com.mooctest.crowd.site.data.dto.CrowdTestSquareIndexDTO;
+import com.mooctest.crowd.site.service.CrowdProjectService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @author:xx
+ * @date:2020/6/20
+ * @description:
+ */
+
+@RestController
+@RequestMapping("/api/square")
+public class CrowTestSquareController {
+    @Autowired
+    private CrowdProjectService crowdProjectService;
+
+
+    /**
+     * 获取众测广场首页所有的数据 包装到CrowdTestSquareIndexDTO里面
+     *
+     * @return
+     */
+
+    @GetMapping("/list")
+    public CrowdTestSquareIndexDTO getAll() {
+        CrowdTestSquareIndexDTO crowdTestSquareIndexDTO = new CrowdTestSquareIndexDTO();
+        List<CrowdTestProject> list = crowdProjectService.getAll();
+        crowdTestSquareIndexDTO.setCrowdTestProjectPOS(list);
+        return crowdTestSquareIndexDTO;
+
+
+    }
+
+
+}

+ 25 - 0
site/src/main/java/com/mooctest/crowd/site/data/dto/CrowdTestSquareIndexDTO.java

@@ -0,0 +1,25 @@
+package com.mooctest.crowd.site.data.dto;
+
+import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
+import com.mooctest.crowd.domain.domainobject.CrowdTestTask;
+import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
+import com.mooctest.crowd.domain.model.CrowdTestTaskPO;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author:xx
+ * @date:2020/6/20
+ * @description:众测广场首页所有数据
+ */
+
+
+@Data
+public class CrowdTestSquareIndexDTO {
+
+    private List<CrowdTestProject> crowdTestProjectPOS;
+
+
+    private  List<CrowdTestTask> crowdTestTaskPOS;
+}

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/data/vo/CrowdProjectVO.java

@@ -92,7 +92,7 @@ public class CrowdProjectVO {
             this.statusVO.setStyle("success");
         }else if (this.status == CrowdTestProjectStatus.HAS_TIME_OUT) {
             this.statusVO.setText("已截止");
-            this.statusVO.setStyle("primary");
+            this.statusVO.setStyle("warning");
         }
 
     }

+ 3 - 1
site/src/main/java/com/mooctest/crowd/site/data/vo/CrowdTaskVO.java

@@ -40,6 +40,7 @@ public class CrowdTaskVO {
     private int participantHasCommittedCount;
     private StatusVO statusVO;
     private FullStatusVO fullStatusVO;
+    private Timestamp createTime;
     private List<TaskToUserVO> taskToUserVOS = new ArrayList<>();
 
     public CrowdTaskVO(CrowdTestTask task){
@@ -62,6 +63,7 @@ public class CrowdTaskVO {
         datetime = task.getDeadTime();
         participantCount = task.getParticipantCount();
         acceptedCount = task.getAcceptedCount();
+        createTime = task.getCreateTime();
         participantHasCommittedCount = task.getParticipantHasCommittedCount();
         this.renderStatus();
     }
@@ -82,7 +84,7 @@ public class CrowdTaskVO {
             this.statusVO.setStyle("success");
         }else if (this.status == CrowdTestTaskStatus.HAS_TIME_OUT) {
             this.statusVO.setText("已截止");
-            this.statusVO.setStyle("primary");
+            this.statusVO.setStyle("warning");
         }
 
         this.fullStatusVO = new FullStatusVO();

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/TaskToUserVO.java

@@ -18,6 +18,7 @@ public class TaskToUserVO {
     private int hasReport;
     private Long distributionType;
     private int isAccepted;
+    private double quotedPrice;
     private Timestamp acceptTime;
     private int isCommitted;
     private Timestamp commitTaskTime;
@@ -29,6 +30,7 @@ public class TaskToUserVO {
         id = taskToUser.getId();
         taskCode = taskToUser.getTaskCode();
         userId = taskToUser.getUserId();
+        quotedPrice = taskToUser.getQuotedPrice();
         acceptTime = taskToUser.getAcceptTime();
         hasReport = taskToUser.getHasReport();
         isCommitted = taskToUser.getIsCommitted();

+ 7 - 4
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -108,7 +108,7 @@ public class WebMediatorImpl implements ViewMediator {
             return null;
         }).filter(Objects::nonNull).collect(Collectors.toList());
         //获取机构排名
-        List<EvolutionAgencyVO> agencyRanks = taskDao.findTotalPriceOfAgency(pageable).stream().map(rankInfo -> {
+        List<EvolutionAgencyVO> agencyRanks = taskToUserDao.findTotalPriceOfAgency(pageable).stream().map(rankInfo -> {
             EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
             if (agency!=null) {
                 EvolutionAgencyVO agencyVO = new EvolutionAgencyVO();
@@ -247,7 +247,7 @@ public class WebMediatorImpl implements ViewMediator {
         }).collect(Collectors.toList()).stream().filter(crowdTestTask -> crowdTestTask.getStatus() == CrowdTestTaskStatus.HAS_RELEASED ||
                 (crowdTestTask.getStatus() == CrowdTestTaskStatus.HAS_RECEIVED && crowdTestTask.getFullStatus() == CrowdTestTaskAcceptStatus.NOT_FULL))
                 .filter(crowdTestTask -> crowdTestTask.getDistributionType()==2)
-                .map(CrowdTaskVO::new).collect(Collectors.toList());
+                .map(CrowdTaskVO::new).sorted(Comparator.comparing(CrowdTaskVO::getCreateTime).reversed()).collect(Collectors.toList());
         TaskSquareDTO taskSquareDTO = new TaskSquareDTO();
         taskSquareDTO.setCrowdTaskVOList(taskVOList);
         return taskSquareDTO;
@@ -586,8 +586,7 @@ public class WebMediatorImpl implements ViewMediator {
         //区域管理员或系统管理员视角
         if (user.getRoleList().stream().anyMatch(role -> role.getName().equals("SystemAdministrator"))
                 ||(user.getRegionalManager()!=null&&user.getId().equals(project.getRegionalManagerId()))){
-            if (task.getParticipantHasCommittedCount() == task.getParticipantCount() && task.getStatus() == CrowdTestTaskStatus.HAS_COMMITED){
-                task.setStatus(CrowdTestTaskStatus.HAS_COMMITED);
+            if ((task.getParticipantHasCommittedCount() == task.getAcceptedCount() && task.getStatus() == CrowdTestTaskStatus.HAS_RECEIVED)|| (task.getParticipantHasCommittedCount() == task.getParticipantCount() && task.getStatus() == CrowdTestTaskStatus.HAS_COMMITED)){
                 taskOperationControl.setConfirmFinish(true);
             }
             if (task.getStatus()<CrowdTestTaskStatus.HAS_RECEIVED){
@@ -636,6 +635,10 @@ public class WebMediatorImpl implements ViewMediator {
             } else if (task.getDistributionType()==2){
                 if (task.getStatus()==CrowdTestTaskStatus.HAS_RELEASED){
                     taskOperationControl.setReceive(true);
+                    // 项目发起者
+                    if(project.getUserId().equals(user.getId())){
+                        taskOperationControl.setReceive(false);
+                    }
                 }
             }
         }

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

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.site.service;
 
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
+import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
 import com.mooctest.crowd.site.command.CrowdTestProjectCommand;
 import com.mooctest.crowd.site.command.GenerateProjectCommand;
 import com.mooctest.crowd.site.data.dto.ProjectDetailsDTO;
@@ -15,6 +16,7 @@ import java.util.List;
  * @date 2019-07-29 10:49
  */
 public interface CrowdProjectService {
+    List<CrowdTestProject> getAll();
     ProjectDetailsDTO getProjectDetails(String projectCode, Long userId);
 
     ProjectDetailsDTO createCrowdProject(CrowdTestProjectCommand command);

+ 6 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/CrowdProjectServiceImpl.java

@@ -7,6 +7,7 @@ import com.mooctest.crowd.domain.exception.BadRequestException;
 import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.Excel2ProjectException;
 import com.mooctest.crowd.domain.factory.CrowdTestProjectFactory;
+import com.mooctest.crowd.domain.model.CrowdTestProjectPO;
 import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
 import com.mooctest.crowd.domain.repository.UserRepo;
 import com.mooctest.crowd.site.command.CrowdTestProjectCommand;
@@ -57,6 +58,11 @@ public class CrowdProjectServiceImpl implements CrowdProjectService {
 
 
     @Override
+    public List<CrowdTestProject> getAll() {
+          return projectRepo.getAllCrowdTestProject();
+    }
+
+    @Override
     public ProjectDetailsDTO getProjectDetails(String projectCode, Long userId) {
         if (userId==null)
             return viewMediator.renderProjectDetails(projectRepo.getByProjectCode(projectCode), null);

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

@@ -2,9 +2,7 @@ package com.mooctest.crowd.site.service.impl;
 
 import com.mooctest.crowd.domain.dao.CrowdTestTaskDao;
 import com.mooctest.crowd.domain.dao.EvaluationAgencyDao;
-import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
-import com.mooctest.crowd.domain.domainobject.CrowdTestTask;
-import com.mooctest.crowd.domain.domainobject.CrowdTestTaskStatus;
+import com.mooctest.crowd.domain.domainobject.*;
 import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.CrowdTestTaskNotExistException;
 import com.mooctest.crowd.domain.exception.UnauthorizedException;
@@ -22,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.sql.Timestamp;
 import java.util.Optional;
 
 /**
@@ -61,8 +60,7 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         CrowdTestTask task = command.toCrowdTask(projectCode);
         CrowdTestProject project = projectRepo.getByProjectCode(projectCode);
         String taskCode = GenerateFlowCodeUtil.generateFlowCode("TASK-"+ ProjectType.getCode(command.getType()));
-        task.setCode(taskCode);
-        task.setStatus(CrowdTestTaskStatus.HAS_RELEASED);
+        task.create(taskCode);
         project.addTask(task);
         projectRepo.saveCrowdTestProject(project);
         return getTaskDetails(projectCode, taskCode, userId);
@@ -82,6 +80,9 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         updateTask.setCreateTime(task.get().getCreateTime());
         updateTask.setRequirementFile(task.get().getRequirementFile());
         updateTask.setStatus(task.get().getStatus());
+        if (updateTask.getDistributionType() == DistributeType.DIRECT.getId()){
+            updateTask.setParticipantCount(1);
+        }
         project.removeTask(task.get());
         project.addTask(updateTask);
         projectRepo.saveCrowdTestProject(project);
@@ -108,6 +109,7 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         CrowdTestProject project = projectRepo.getByProjectCode(projectCode);
         CrowdTestTask task = project.getTask(taskCode);
         task.reject(userId);
+        project.setRestPrice(project.getRestPrice()+task.getQuotedPrice());
         projectRepo.saveCrowdTestProject(project);
     }
 
@@ -133,7 +135,7 @@ public class CrowdTaskServiceImpl implements CrowdTaskService {
         if (!project.getRegionalManagerId().equals(userId))
             throw new UnauthorizedException("无权限对此任务进行此操作");
         CrowdTestTask task = project.getTask(taskCode);
-        task.confirmFinish(userId);
+        task.confirmFinish();
         projectRepo.saveCrowdTestProject(project);
         return getTaskDetails(projectCode, taskCode, userId);
     }