Преглед изворни кода

Merge branch 'feature-V2.0' of http://git.mooctest.com/crowd-2019/crowd-test-service-backend into feature-V2.0

 Conflicts:
	site/src/main/java/com/mooctest/crowd/site/service/impl/UserServiceImpl.java
xuxuan пре 5 година
родитељ
комит
9bc37caa43

+ 14 - 0
core/src/main/java/com/mooctest/crowd/domain/exception/UserTaskCountNoExistException.java

@@ -0,0 +1,14 @@
+package com.mooctest.crowd.domain.exception;
+
+import lombok.NoArgsConstructor;
+
+/**
+ * @Author: xuexb
+ * @Date: 2019.7.5 14:36
+ */
+@NoArgsConstructor
+public class UserTaskCountNoExistException extends BaseException {
+    public UserTaskCountNoExistException(String msg){
+        super(msg);
+    }
+}

+ 0 - 15
core/src/main/java/com/mooctest/crowd/domain/repository/ApplicationTypeRepo.java

@@ -28,23 +28,8 @@ public class ApplicationTypeRepo implements IApplicationTypeRepo{
     @Autowired
     private ApplicationTypeDao applicationTypeDao;
 
-    @Autowired
-    private CrowdTestProjectDao projectDao;
-
-    @Autowired
-    private CommonRepo commonRepo;
-
     @Override
     public Page<ApplicationType> getHotTesting(Pageable pageable,String keyword) {
-
-//        //获取热门众测
-//        List<ApplicationTypeVO> applicationTypeRank = projectDao.findTotalCountOfApplicationType(pageable).stream().map(rankInfos -> {
-//            ApplicationType applicationType = commonRepo.getApplicationTypeByAppCode(rankInfos.getCode());
-//            ApplicationTypeVO applicationTypeVO = new ApplicationTypeVO(applicationType);
-//            applicationTypeVO.setCount(rankInfos.getCount());
-//            return applicationTypeVO;
-//        }).filter(Objects::nonNull).collect(Collectors.toList());
-
         Specifications<ApplicationTypePO> where =  Specifications.where(getArticlesByIsNotDeleted(keyword));
         return applicationTypeDao.findAll(where,pageable).map(ApplicationTypePO->Converter.convert(ApplicationType.class, ApplicationTypePO));
     }

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

@@ -1,6 +1,7 @@
 package com.mooctest.crowd.domain.repository;
 
 import com.mooctest.crowd.domain.domainobject.User;
+import com.mooctest.crowd.domain.domainobject.UserTaskCount;
 import com.mooctest.crowd.domain.exception.UserNotExistException;
 import com.mooctest.crowd.domain.model.UserPO;
 
@@ -26,6 +27,8 @@ public interface IUserRepo {
 
     ArrayList<UserPO> getAllUserInfo() throws RoleNotFoundException;
 
+    UserTaskCount getUserTaskCountByUserId(Long userId);
+
 //    User getByEvaluationAgencyByUserId(Long userId) throws UserNotExistException, com.mooctest.crowd.domain.exception.RoleNotFoundException;
 
     void removeUser(User user);

+ 14 - 1
core/src/main/java/com/mooctest/crowd/domain/repository/UserRepo.java

@@ -6,13 +6,13 @@ import com.mooctest.crowd.domain.domainobject.*;
 import com.mooctest.crowd.domain.exception.PermissionNotFoundException;
 import com.mooctest.crowd.domain.exception.RoleNotFoundException;
 import com.mooctest.crowd.domain.exception.UserNotExistException;
+import com.mooctest.crowd.domain.exception.UserTaskCountNoExistException;
 import com.mooctest.crowd.domain.model.*;
 import com.mooctest.crowd.domain.util.Converter;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import javax.security.auth.login.Configuration;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.List;
@@ -41,6 +41,9 @@ public class UserRepo implements IUserRepo {
     private UserToRoleDao userToRoleDao;
 
     @Autowired
+    private UserTaskCountDao userTaskCountDao;
+
+    @Autowired
     private RoleToPermissionDao roleToPermissionDao;
 
     @Autowired
@@ -139,6 +142,16 @@ public class UserRepo implements IUserRepo {
         return userPOArrayList;
     }
 
+    @Override
+    public UserTaskCount getUserTaskCountByUserId(Long userId){
+        Optional<UserTaskCountPO> userTaskCountPO = userTaskCountDao.findByUserId(userId);
+        if(!userTaskCountPO.isPresent()){
+            throw new UserTaskCountNoExistException();
+        }else{
+            return Converter.convert(UserTaskCount.class, userTaskCountPO.get());
+        }
+    }
+
 
     //add
 //    @Override

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/constants/CommonConstant.java

@@ -12,6 +12,8 @@ public class CommonConstant {
 
     public static final Integer SQUARE_ROWS_ON_PAGE = 9;
 
+    public static final Integer HOT_CROWD_ROWS_ON_PAGE = 10;
+
     public static final Integer SQUARE_ROWS_ON_PAGE_MODIFY = 12;
 
     public static final Integer TECHNOLOGY_ROWS_ON_PAGE = 5;

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CommonController.java


+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/controller/advice/ExceptionAdvice.java

@@ -47,6 +47,8 @@ public class ExceptionAdvice {
             return "领域不存在";
         } else if (e instanceof ResourceNoExistException){
             return "资源不存在";
+        } else if (e instanceof UserTaskCountNoExistException) {
+            return "当前用户没有参与接包";
         } else
             return e.getMessage();
     }

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

@@ -22,6 +22,7 @@ import com.mooctest.crowd.site.mediator.ViewMediator;
 import lombok.extern.slf4j.Slf4j;
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -320,13 +321,7 @@ public class WebMediatorImpl implements ViewMediator {
         IndexInfoDTO indexInfoDTO = new IndexInfoDTO();
         Pageable pageable = PageRequest.of(0, 3);
         int top = 3;
-        //获取热门众测
-        List<ApplicationTypeVO> applicationTypeRank = projectDao.findTotalCountOfApplicationType(pageable).stream().map(rankInfos -> {
-            ApplicationType applicationType = commonRepo.getApplicationTypeByAppCode(rankInfos.getCode());
-            ApplicationTypeVO applicationTypeVO = new ApplicationTypeVO(applicationType);
-            applicationTypeVO.setCount(rankInfos.getCount());
-            return applicationTypeVO;
-        }).filter(Objects::nonNull).collect(Collectors.toList());
+        List<ApplicationTypeVO> applicationTypeRank = getApplicationTypeRankVOS(pageable);
         List<ApplicationTypeVO> applicationTypeRanks = new ArrayList<>();
         if (applicationTypeRanks.size() > top) {
             for (int i = 0; i < top; i++) {
@@ -419,6 +414,17 @@ public class WebMediatorImpl implements ViewMediator {
         return indexInfoDTO;
     }
 
+    @NotNull
+    public List<ApplicationTypeVO> getApplicationTypeRankVOS(Pageable pageable) {
+        //获取热门众测
+        return projectDao.findTotalCountOfApplicationType(pageable).stream().map(rankInfos -> {
+            ApplicationType applicationType = commonRepo.getApplicationTypeByAppCode(rankInfos.getCode());
+            ApplicationTypeVO applicationTypeVO = new ApplicationTypeVO(applicationType);
+            applicationTypeVO.setCount(rankInfos.getCount());
+            return applicationTypeVO;
+        }).filter(Objects::nonNull).collect(Collectors.toList());
+    }
+
     @Override
     public IndexDTO renderIndex() {
         Pageable pageable = PageRequest.of(0, 10);

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

@@ -32,7 +32,7 @@ public interface CommonService {
 
     Page<CrowdTaskVO> getTaskinfo(Pageable pageable, String keyword, int deletedStatus);
 
-    Page<ApplicationTypeVO> getHotTesting(Pageable pageable,String keyword);
+    List<ApplicationTypeVO> getHotTesting(String keyword);
 
     Page<CompetitionVO> getCompetition(Pageable pageable,String keyword);
 

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

@@ -218,17 +218,7 @@ public class AgencyServiceImpl implements AgencyService {
         if (agency == null)
             throw new EvaluationAgencyNotExistException("当前用户未申请机构认证");
         AgencyVO agencyVO = new AgencyVO(user.getEvaluationAgency());
-
-        List<RankCountInfo> rankCountInfoList = taskToUserDao.findTotalCountOfUser();
-        long ids[] = new long[rankCountInfoList.size()];
-        for (int i = 0; i < ids.length; i++) {
-            ids[i] = rankCountInfoList.get(i).getEntityId();
-            if (ids[i] == agencyVO.getUserId()) {
-                agencyVO.setTaskCount(rankCountInfoList.get(i).getCount());
-            }
-        }
+        agencyVO.setTaskCount(userRepo.getUserTaskCountByUserId(userId).getCount());
         return agencyVO;
     }
-
-
 }

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

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.site.service.impl;
 
+import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
 import com.mooctest.crowd.domain.repository.*;
 import com.mooctest.crowd.site.constants.CommonConstant;
@@ -10,6 +11,7 @@ import com.mooctest.crowd.site.data.response.ResponseVO;
 import com.mooctest.crowd.site.data.response.ServerCode;
 import com.mooctest.crowd.site.data.vo.*;
 import com.mooctest.crowd.site.mediator.ViewMediator;
+import com.mooctest.crowd.site.mediator.impl.WebMediatorImpl;
 import com.mooctest.crowd.site.service.CommonService;
 import com.mooctest.crowd.site.util.DataUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -44,11 +46,17 @@ public class CommonServiceImpl implements CommonService {
     private EvaluationAgencyRepo agencyRepo;
 
     @Autowired
+    private CrowdTestProjectDao projectDao;
+
+    @Autowired
     private CommonRepo commonRepo;
 
     @Autowired
     private ApplicationTypeRepo applicationTypeRepo;
 
+    @Autowired
+    private WebMediatorImpl webMediator;
+
 //    @Autowired
 //    private CacheUtil cacheUtil;
 
@@ -114,8 +122,17 @@ public class CommonServiceImpl implements CommonService {
     }
 
     @Override
-    public Page<ApplicationTypeVO> getHotTesting(Pageable pageable,String keyword) {
-        return applicationTypeRepo.getHotTesting(pageable,keyword).map(applicationType -> new ApplicationTypeVO(applicationType));
+    public List<ApplicationTypeVO> getHotTesting(String keyword) {
+
+        Pageable pageable = PageRequest.of(0, CommonConstant.HOT_CROWD_ROWS_ON_PAGE);
+        //获取热门众测
+        List<ApplicationTypeVO> applicationTypeRank = webMediator.getApplicationTypeRankVOS(pageable);
+
+        if (keyword != null && keyword.trim() != "") {
+            return applicationTypeRank.stream().filter(applicationTypeVO -> applicationTypeVO.getName().contains(keyword)).collect(Collectors.toList());
+        }else{
+            return applicationTypeRank;
+        }
     }
 
     @Override

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/UserServiceImpl.java


Неке датотеке нису приказане због велике количине промена