Przeglądaj źródła

修复机构排名 任务广场排序

guo00guo 5 lat temu
rodzic
commit
56b9d4cf61

+ 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);
 }

+ 8 - 6
core/src/main/java/com/mooctest/crowd/domain/domainobject/CrowdTestTask.java

@@ -122,7 +122,7 @@ public class CrowdTestTask {
             }).collect(Collectors.toList());
         }else{
             TaskToUser taskToUser = new TaskToUser();
-            taskToUser.setValue(this.code, user.getId(), 0, this.getDistributionType(), 1, new Timestamp(System.currentTimeMillis()));
+            taskToUser.setValue(this.code, user.getId(), this.quotedPrice,0, this.getDistributionType(), 1, new Timestamp(System.currentTimeMillis()));
             this.getAcceptedUserList().add(taskToUser);
         }
         this.setAcceptedUserList(acceptedUserList);
@@ -182,12 +182,14 @@ 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) {
@@ -196,7 +198,7 @@ public class CrowdTestTask {
         if (this.getDistributionType() == DistributeType.DIRECT.getId()){
             this.setParticipantCount(1);
             TaskToUser taskToUser = new TaskToUser();
-            taskToUser.setValue(this.code, this.getEvaluationAgencyId(), 0, this.getDistributionType(), 0, null);
+            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;
 

+ 2 - 0
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();
     }

+ 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);
+                    }
                 }
             }
         }

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

@@ -135,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);
     }