Browse Source

优化首页查询和机构和人员排行的查询

guo00guo 5 years ago
parent
commit
47c4b9d732

+ 20 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/UserTaskCountDao.java

@@ -0,0 +1,20 @@
+package com.mooctest.crowd.domain.dao;
+
+import com.mooctest.crowd.domain.model.UserTaskCountPO;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.CrudRepository;
+
+import javax.transaction.Transactional;
+import java.util.List;
+import java.util.Optional;
+
+@Transactional
+public interface UserTaskCountDao extends CrudRepository<UserTaskCountPO, Long>, JpaSpecificationExecutor<UserTaskCountPO> {
+
+    Optional<UserTaskCountPO> findByUserId(Long userId);
+
+    List<UserTaskCountPO> findByType(Long type);
+
+    Optional<UserTaskCountPO> findById(Long id);
+
+}

+ 25 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/UserTaskCount.java

@@ -0,0 +1,25 @@
+package com.mooctest.crowd.domain.domainobject;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class UserTaskCount {
+    private Long id;
+    private Long userId;
+    private Long count;
+    private Long type;
+
+    public UserTaskCount(Long userId, Long count, Long type) {
+        this.userId = userId;
+        this.count = count;
+        this.type = type;
+    }
+}

+ 27 - 0
core/src/main/java/com/mooctest/crowd/domain/model/UserTaskCountPO.java

@@ -0,0 +1,27 @@
+package com.mooctest.crowd.domain.model;
+
+import lombok.Data;
+
+import javax.persistence.*;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+@Data
+@Entity(name = "user_task_count")
+public class UserTaskCountPO {
+    @Id
+    @Column(name = "UTC_ID")
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @Column(name = "UTC_USER_ID")
+    private Long userId;
+
+    @Column(name = "UTC_COUNT")
+    private Long count;
+
+    @Column(name = "UTC_TYPE")
+    private Long type;
+}

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

@@ -18,6 +18,8 @@ public interface IUserRepo {
 
     User getByID(Long id) throws UserNotExistException, RoleNotFoundException;
 
+    User getByIDJustInfo(Long userId) throws UserNotExistException, RoleNotFoundException;
+
     List<User> getByIdList(List<Long> ids) throws RoleNotFoundException;
 
     List<User> getAllUser() throws RoleNotFoundException;

+ 10 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/UserRepo.java

@@ -81,6 +81,16 @@ public class UserRepo implements IUserRepo {
     }
 
     @Override
+    public User getByIDJustInfo(Long userId) throws UserNotExistException, RoleNotFoundException {
+        Optional<UserPO> userPOOptional = userDao.findById(userId);
+        if (!userPOOptional.isPresent()) {
+            throw new UserNotExistException("用户不存在");
+        }else{
+            return Converter.convert(User.class, userPOOptional.get());
+        }
+    }
+
+    @Override
     public User getByMobileNum(String mobileNum) throws UserNotExistException, RoleNotFoundException {
         UserPO userPO = userDao.findByMobile(mobileNum);
         if (userPO == null) {

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


+ 2 - 2
site/src/main/java/com/mooctest/crowd/site/data/enums/RoleType.java

@@ -1,7 +1,6 @@
 package com.mooctest.crowd.site.data.enums;
 
 import lombok.AllArgsConstructor;
-import lombok.Data;
 import lombok.NoArgsConstructor;
 
 /**
@@ -17,7 +16,8 @@ public enum RoleType {
     AGENCY(2L, "evaluationAgency"),
     REGIONAL_MANAGER(3L, "RegionalManager"),
     SYSTEM_ADMIN(4L, "SystemAdministrator"),
-    ENTERPRISE_USER(5L, "enterpriseUser");
+    ENTERPRISE_USER(5L, "enterpriseUser"),
+    EVALUATION_USER(6L, "evaluationUser");
 
     private Long id;
     private String name;

+ 19 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/UserTaskCountVO.java

@@ -0,0 +1,19 @@
+package com.mooctest.crowd.site.data.vo;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class UserTaskCountVO {
+    private Long id;
+    private Long userId;
+    private Long count;
+    private Long type;
+}

+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/mediator/ViewMediator.java

@@ -37,6 +37,8 @@ public interface ViewMediator {
 
     IndexDTO renderIndex();
 
+    IndexInfoDTO renderIndexInfosCache();
+
     IndexInfoDTO renderIndexInfos();
 
     MyCrowdDTO renderMyCrowd(Long userId);

+ 149 - 103
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -58,6 +58,9 @@ public class WebMediatorImpl implements ViewMediator {
     private CrowdTestTaskDao taskDao;
 
     @Autowired
+    private UserTaskCountDao userTaskCountDao;
+
+    @Autowired
     private UserDao userDao;
 
     @Autowired
@@ -114,17 +117,27 @@ public class WebMediatorImpl implements ViewMediator {
     @Override
     public List<UserVO> renderMoreUser(Pageable pageable) {
         //获取众测人员排名
-        String agencyName = agencyDao.findById(Long.parseLong(agencyId)).get().getEvaluationAgencyName();
-        List<UserVO> userVOS = taskToUserDao.findTotalCountOfUser().stream().map(rankInfo -> {
-            EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
-            if (agency != null && agency.getEvaluationAgencyName().equals(agencyName)) {
-                User user = userRepo.getByID(agency.getUserId());
-                UserVO userVO = new UserVO(user);
-                userVO.setTaskCount(rankInfo.getCount());
-                return userVO;
-            }
-            return null;
-        }).filter(Objects::nonNull).collect(Collectors.toList());
+//        String agencyName = agencyDao.findById(Long.parseLong(agencyId)).get().getEvaluationAgencyName();
+//        List<UserVO> userVOS = taskToUserDao.findTotalCountOfUser().stream().map(rankInfo -> {
+//            EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
+//            if (agency != null && agency.getEvaluationAgencyName().equals(agencyName)) {
+//                User user = userRepo.getByID(agency.getUserId());
+//                UserVO userVO = new UserVO(user);
+//                userVO.setTaskCount(rankInfo.getCount());
+//                return userVO;
+//            }
+//            return null;
+//        }).filter(Objects::nonNull).collect(Collectors.toList());
+
+
+        List<UserVO> userVOS = userTaskCountDao.findByType(RoleType.EVALUATION_USER.getId())
+                .stream().sorted(Comparator.comparing(UserTaskCountPO::getCount)).collect(Collectors.toList())
+                .stream().map(userTaskCountPO -> {
+                    User user = userRepo.getByIDJustInfo(userTaskCountPO.getUserId());
+                    UserVO userVO = new UserVO(user);
+                    userVO.setTaskCount(userTaskCountPO.getCount());
+                    return userVO;
+                }).collect(Collectors.toList());
         return userVOS;
     }
 
@@ -190,70 +203,9 @@ public class WebMediatorImpl implements ViewMediator {
     }
 
     @Override
-    public IndexInfoDTO renderIndexInfos() {
+    public IndexInfoDTO renderIndexInfosCache() {
         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> applicationTypeRanks = new ArrayList<>();
-        if (applicationTypeRanks.size() > top) {
-            for (int i = 0; i < top; i++) {
-                applicationTypeRanks.add(applicationTypeRank.get(i));
-            }
-        } else {
-            applicationTypeRanks = applicationTypeRank;
-        }
-
-        //获取机构排名
-        String agencyName = agencyDao.findById(Long.parseLong(agencyId)).get().getEvaluationAgencyName();
-        List<EvaluationAgencyVO> agencyRank = taskToUserDao.findTotalCountOfUser().stream().map(rankInfo -> {
-            EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
-            if (agency != null && !agency.getEvaluationAgencyName().equals(agencyName)) {
-                EvaluationAgencyVO agencyVO = new EvaluationAgencyVO();
-                agencyVO.setEvaluationAgencyName(agency.getEvaluationAgencyName());
-                agencyVO.setAgencyPhoto(agency.getAgencyPhoto());
-                agencyVO.setTaskCount(rankInfo.getCount());
-                agencyVO.setId(agency.getId());
-                agencyVO.setUserId(agency.getUserId());
-                return agencyVO;
-            }
-            return null;
-        }).filter(Objects::nonNull).collect(Collectors.toList());
-        List<EvaluationAgencyVO> agencyRanks = new ArrayList<>();
-        if (agencyRank.size() > top) {
-            for (int i = 0; i < top; i++) {
-                agencyRanks.add(agencyRank.get(i));
-            }
-        } else {
-            agencyRanks = agencyRank;
-        }
-
-        //获取众测人员排名
-        List<UserVO> userRank = taskToUserDao.findTotalCountOfUser().stream().map(rankInfo -> {
-            EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
-            if (agency != null && agency.getEvaluationAgencyName().equals(agencyName)) {
-                User user = userRepo.getByID(agency.getUserId());
-                UserVO userVO = new UserVO(user);
-                userVO.setTaskCount(rankInfo.getCount());
-                return userVO;
-            }
-            return null;
-        }).filter(Objects::nonNull).collect(Collectors.toList());
-        List<UserVO> userRanks = new ArrayList<>();
-        if (userRank.size() > top) {
-            for (int i = 0; i < top; i++) {
-                userRanks.add(userRank.get(i));
-            }
-        } else {
-            userRanks = userRank;
-        }
-
         // 获取大赛信息
         List<Competition> competitionList = commonRepo.getAllCompetition();
         List<Competition> competitionLists = new ArrayList<>();
@@ -278,17 +230,18 @@ public class WebMediatorImpl implements ViewMediator {
         }).collect(Collectors.toList());
 
         // 获取应用类型
-        List<ApplicationType> allApplicationType = commonRepo.getAllApplicationType();
-        List<ApplicationTypeVO> applicationTypeVOS = allApplicationType.stream().map(applicationType -> {
-            ApplicationTypeVO applicationTypeVO = new ApplicationTypeVO(applicationType);
-            List<TestType> testTypeList = commonRepo.getTestTypeListByAppCode(applicationType.getCode());
-            List<TestTypeVO> typeVOS = testTypeList.stream().map(testType -> {
-                TestTypeVO testTypeVO = new TestTypeVO(testType);
-                return testTypeVO;
-            }).collect(Collectors.toList());
-            applicationTypeVO.setTestTypeList(typeVOS);
-            return applicationTypeVO;
-        }).collect(Collectors.toList());
+        List<ApplicationTypeVO> applicationTypeVOS = commonRepo.getAllApplicationType().stream().map(ApplicationTypeVO::new).collect(Collectors.toList());
+//        List<ApplicationType> allApplicationType = commonRepo.getAllApplicationType();
+//        List<ApplicationTypeVO> applicationTypeVOS = allApplicationType.stream().map(applicationType -> {
+//            ApplicationTypeVO applicationTypeVO = new ApplicationTypeVO(applicationType);
+//            List<TestType> testTypeList = commonRepo.getTestTypeListByAppCode(applicationType.getCode());
+//            List<TestTypeVO> typeVOS = testTypeList.stream().map(testType -> {
+//                TestTypeVO testTypeVO = new TestTypeVO(testType);
+//                return testTypeVO;
+//            }).collect(Collectors.toList());
+//            applicationTypeVO.setTestTypeList(typeVOS);
+//            return applicationTypeVO;
+//        }).collect(Collectors.toList());
 
         // 获取领域划分
         List<Field> fieldList = commonRepo.getAllFieldType();
@@ -297,21 +250,7 @@ public class WebMediatorImpl implements ViewMediator {
             return fieldVO;
         }).collect(Collectors.toList());
 
-        // 获取资源和工具
-        List<Resource> resourceList = commonRepo.getAllResource();
-        List<ResourceVO> resourceVOS = resourceList.stream().map(resource -> {
-            ResourceVO resourceVO = new ResourceVO(resource);
-            return resourceVO;
-        }).collect(Collectors.toList());
-
         // 获取入驻品牌机构
-        List<Partner> partnerList = commonRepo.getAllPartner();
-        List<PartnerVO> partnerVOS = partnerList.stream().map(partner -> {
-            PartnerVO partnerVO = new PartnerVO(partner);
-            return partnerVO;
-        }).collect(Collectors.toList());
-
-        // 获取合作机构
         List<ResidentAgency> allResidentAgency = commonRepo.getAllResidentAgency();
         List<EvaluationAgencyVO> agencyVOS = allResidentAgency.stream().map(residentAgency -> {
             EvaluationAgency agency = evaluationAgencyRepo.findAgencyById(residentAgency.getAgencyId());
@@ -319,16 +258,123 @@ public class WebMediatorImpl implements ViewMediator {
             return evalutionAgencyVO;
         }).collect(Collectors.toList());
 
-        indexInfoDTO.setApplicationTypeRank(applicationTypeRanks);
-        indexInfoDTO.setAgencyRank(agencyRanks);
-        indexInfoDTO.setUserRank(userRanks);
+        // 获取合作机构
+//        List<Partner> partnerList = commonRepo.getAllPartner();
+//        List<PartnerVO> partnerVOS = partnerList.stream().map(partner -> {
+//            PartnerVO partnerVO = new PartnerVO(partner);
+//            return partnerVO;
+//        }).collect(Collectors.toList());
+
         indexInfoDTO.setTestTypeList(testTypeVOS);
         indexInfoDTO.setApplicationTypeList(applicationTypeVOS);
         indexInfoDTO.setFieldList(fieldVOS);
         indexInfoDTO.setCompetitionList(competitionVOS);
-        indexInfoDTO.setResourceList(resourceVOS);
         indexInfoDTO.setResidentAgencyList(agencyVOS);
-        indexInfoDTO.setPartnerList(partnerVOS);
+//        indexInfoDTO.setPartnerList(partnerVOS);
+        return indexInfoDTO;
+    }
+
+    @Override
+    public IndexInfoDTO renderIndexInfos() {
+        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> applicationTypeRanks = new ArrayList<>();
+        if (applicationTypeRanks.size() > top) {
+            for (int i = 0; i < top; i++) {
+                applicationTypeRanks.add(applicationTypeRank.get(i));
+            }
+        } else {
+            applicationTypeRanks = applicationTypeRank;
+        }
+
+        //获取机构排名
+//        String agencyName = agencyDao.findById(Long.parseLong(agencyId)).get().getEvaluationAgencyName();
+//        List<EvaluationAgencyVO> agencyRank = taskToUserDao.findTotalCountOfUser().stream().map(rankInfo -> {
+//            EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
+//            if (agency != null && !agency.getEvaluationAgencyName().equals(agencyName)) {
+//                EvaluationAgencyVO agencyVO = new EvaluationAgencyVO();
+//                agencyVO.setEvaluationAgencyName(agency.getEvaluationAgencyName());
+//                agencyVO.setAgencyPhoto(agency.getAgencyPhoto());
+//                agencyVO.setTaskCount(rankInfo.getCount());
+//                agencyVO.setId(agency.getId());
+//                agencyVO.setUserId(agency.getUserId());
+//                return agencyVO;
+//            }
+//            return null;
+//        }).filter(Objects::nonNull).collect(Collectors.toList());
+
+        List<EvaluationAgencyVO> agencyRanks = userTaskCountDao.findByType(RoleType.AGENCY.getId())
+                .stream().sorted(Comparator.comparing(UserTaskCountPO::getCount)).limit(top).collect(Collectors.toList())
+                .stream().map(userTaskCountPO -> {
+                    EvaluationAgencyPO agency = agencyDao.findByUserId(userTaskCountPO.getUserId());
+                    EvaluationAgencyVO agencyVO = new EvaluationAgencyVO();
+                    agencyVO.setAgencyPhoto(agency.getAgencyPhoto());
+                    agencyVO.setTaskCount(userTaskCountPO.getCount());
+                    agencyVO.setId(agency.getId());
+                    agencyVO.setUserId(agency.getUserId());
+                    agencyVO.setEvaluationAgencyName(agency.getEvaluationAgencyName());
+                    return agencyVO;
+                }).collect(Collectors.toList());
+
+//        List<EvaluationAgencyVO> agencyRanks = new ArrayList<>();
+//        if (agencyRank.size() > top) {
+//            for (int i = 0; i < top; i++) {
+//                agencyRanks.add(agencyRank.get(i));
+//            }
+//        } else {
+//            agencyRanks = agencyRank;
+//        }
+
+        //获取众测人员排名
+//        List<UserVO> userRank = taskToUserDao.findTotalCountOfUser().stream().map(rankInfo -> {
+//            EvaluationAgencyPO agency = agencyDao.findByUserId(rankInfo.getEntityId());
+//            if (agency != null && agency.getEvaluationAgencyName().equals(agencyName)) {
+//                User user = userRepo.getByID(agency.getUserId());
+//                UserVO userVO = new UserVO(user);
+//                userVO.setTaskCount(rankInfo.getCount());
+//                return userVO;
+//            }
+//            return null;
+//        }).filter(Objects::nonNull).collect(Collectors.toList());
+
+        List<UserVO> userRanks = userTaskCountDao.findByType(RoleType.EVALUATION_USER.getId())
+                .stream().sorted(Comparator.comparing(UserTaskCountPO::getCount)).limit(top).collect(Collectors.toList())
+                .stream().map(userTaskCountPO -> {
+            User user = userRepo.getByIDJustInfo(userTaskCountPO.getUserId());
+            UserVO userVO = new UserVO(user);
+            userVO.setTaskCount(userTaskCountPO.getCount());
+            return userVO;
+        }).collect(Collectors.toList());
+
+//        List<UserVO> userRanks = new ArrayList<>();
+//        if (userRank.size() > top) {
+//            for (int i = 0; i < top; i++) {
+//                userRanks.add(userRank.get(i));
+//            }
+//        } else {
+//            userRanks = userRank;
+//        }
+
+        // 获取资源和工具
+        List<Resource> resourceList = commonRepo.getAllResource();
+        List<ResourceVO> resourceVOS = resourceList.stream().map(resource -> {
+            ResourceVO resourceVO = new ResourceVO(resource);
+            return resourceVO;
+        }).collect(Collectors.toList());
+
+        indexInfoDTO.setApplicationTypeRank(applicationTypeRanks);
+        indexInfoDTO.setAgencyRank(agencyRanks);
+        indexInfoDTO.setUserRank(userRanks);
+        indexInfoDTO.setResourceList(resourceVOS);
+
         return indexInfoDTO;
     }
 

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

@@ -22,7 +22,9 @@ public interface CommonService {
 
     UserDataDTO getPersonCrowdData(Long userId);
 
-    IndexInfoDTO getIndexInfos(Long userId);
+    IndexInfoDTO getIndexInfosCache(Long userId);
+
+    IndexInfoDTO getIndexInfosNoCache();
 
     IndexPageDTO getIndexPageInfo(Pageable pageable, Map<String, String> extraCondition, String keyword, int deletedStatus);
 

+ 18 - 21
site/src/main/java/com/mooctest/crowd/site/service/impl/AgencyServiceImpl.java

@@ -3,6 +3,7 @@ package com.mooctest.crowd.site.service.impl;
 import com.mooctest.crowd.domain.dao.EvaluationAgencyDao;
 import com.mooctest.crowd.domain.dao.TaskToUserDao;
 import com.mooctest.crowd.domain.dao.UserDao;
+import com.mooctest.crowd.domain.dao.UserTaskCountDao;
 import com.mooctest.crowd.domain.domainobject.*;
 import com.mooctest.crowd.domain.exception.BaseException;
 import com.mooctest.crowd.domain.exception.EvaluationAgencyNotExistException;
@@ -10,7 +11,7 @@ import com.mooctest.crowd.domain.exception.HttpBadRequestException;
 import com.mooctest.crowd.domain.exception.UserNotExistException;
 import com.mooctest.crowd.domain.model.EvaluationAgencyPO;
 import com.mooctest.crowd.domain.model.RankCountInfo;
-import com.mooctest.crowd.domain.model.UserPO;
+import com.mooctest.crowd.domain.model.UserTaskCountPO;
 import com.mooctest.crowd.domain.repository.EvaluationAgencyRepo;
 import com.mooctest.crowd.domain.repository.UserRepo;
 import com.mooctest.crowd.site.anticorruption.UserAntiCorruption;
@@ -19,6 +20,7 @@ import com.mooctest.crowd.site.command.AgencyResourceCommand;
 import com.mooctest.crowd.site.command.ApplyAgencyAuthCommand;
 import com.mooctest.crowd.site.command.GenerateAgencyCommand;
 import com.mooctest.crowd.site.data.dto.UserDTO;
+import com.mooctest.crowd.site.data.enums.RoleType;
 import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.EvaluationAgencyVO;
 import com.mooctest.crowd.site.data.vo.UserVO;
@@ -61,6 +63,8 @@ public class AgencyServiceImpl implements AgencyService {
     private TaskToUserDao taskToUserDao;
     @Autowired
     private EvaluationAgencyDao agencyDao;
+    @Autowired
+    private UserTaskCountDao userTaskCountDao;
 
     @Value("${agency}")
     private String agencyId;
@@ -89,26 +93,19 @@ public class AgencyServiceImpl implements AgencyService {
 
     @Override
     public List<EvaluationAgencyVO> findMoreAgencyVO(String keyword) {
-        List<EvaluationAgencyVO> list = new ArrayList<EvaluationAgencyVO>();//机构列表
-        List<RankCountInfo> rankInfos = taskToUserDao.findTotalCountOfUser();//用户接包信息
-        String agencyName = agencyDao.findById(Long.parseLong(agencyId)).get().getEvaluationAgencyName();
-        for (int i = 0; i < rankInfos.size(); i++) {
-            Optional<UserPO> user = userDao.findById(rankInfos.get(i).getEntityId());
-            EvaluationAgencyPO evaluationAgencyPO = agencyDao.findByUserId(rankInfos.get(i).getEntityId());
-            if (evaluationAgencyPO != null && !evaluationAgencyPO.getEvaluationAgencyName().equals(agencyName)) {
-                if(keyword != null && keyword != ""){
-                    if(!evaluationAgencyPO.getEvaluationAgencyName().contains(keyword)){
-                        continue;
-                    }
-                }
-                EvaluationAgency evaluationAgency = new EvaluationAgency(evaluationAgencyPO);
-                EvaluationAgencyVO evalutionAgencyVO = new EvaluationAgencyVO(evaluationAgency);
-                evalutionAgencyVO.setTaskCount(rankInfos.get(i).getCount());
-                evalutionAgencyVO.setAddress(evaluationAgency.getAddress());
-//                evalutionAgencyVO.setAddress((user.get().getProvince() + user.get().getCity()).replaceAll("null", ""));
-                list.add(evalutionAgencyVO);
-            }
-        }
+        List<EvaluationAgencyVO> list = userTaskCountDao.findByType(RoleType.AGENCY.getId())
+                .stream().sorted(Comparator.comparing(UserTaskCountPO::getCount)).collect(Collectors.toList())
+                .stream().map(userTaskCountPO -> {
+                    EvaluationAgencyPO agency = agencyDao.findByUserId(userTaskCountPO.getUserId());
+                    EvaluationAgencyVO agencyVO = new EvaluationAgencyVO();
+                    agencyVO.setAgencyPhoto(agency.getAgencyPhoto());
+                    agencyVO.setTaskCount(userTaskCountPO.getCount());
+                    agencyVO.setId(agency.getId());
+                    agencyVO.setUserId(agency.getUserId());
+                    agencyVO.setEvaluationAgencyName(agency.getEvaluationAgencyName());
+                    agencyVO.setAddress(agency.getAddress());
+                    return agencyVO;
+                }).collect(Collectors.toList());
         return list.stream().sorted(Comparator.comparing(EvaluationAgencyVO::getTaskCount).reversed()).collect(Collectors.toList());
     }
 

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

@@ -54,7 +54,6 @@ public class CommonServiceImpl implements CommonService {
 
     @Override
     public List<UserVO> getMoreUser(Pageable pageable) {
-
         return  viewMediator.renderMoreUser(pageable);
     }
 
@@ -75,7 +74,13 @@ public class CommonServiceImpl implements CommonService {
 
     @Override
     @Cacheable(value = "userCache",key = "#userId")
-    public IndexInfoDTO getIndexInfos(Long userId){
+    public IndexInfoDTO getIndexInfosCache(Long userId){
+        IndexInfoDTO indexInfoDTO = viewMediator.renderIndexInfosCache();
+        return indexInfoDTO;
+    }
+
+    @Override
+    public IndexInfoDTO getIndexInfosNoCache(){
         IndexInfoDTO indexInfoDTO = viewMediator.renderIndexInfos();
         return indexInfoDTO;
     }

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

@@ -4,17 +4,21 @@ import com.google.common.collect.Lists;
 import com.mooctest.crowd.domain.dao.ApplicationTypeDao;
 import com.mooctest.crowd.domain.dao.FieldDao;
 import com.mooctest.crowd.domain.dao.TestTypeDao;
+import com.mooctest.crowd.domain.dao.UserTaskCountDao;
 import com.mooctest.crowd.domain.domainobject.*;
 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.UserTaskCountPO;
 import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
 import com.mooctest.crowd.domain.repository.UserRepo;
+import com.mooctest.crowd.domain.util.Converter;
 import com.mooctest.crowd.site.command.CrowdTestProjectCommand;
 import com.mooctest.crowd.site.command.GenerateProjectCommand;
 import com.mooctest.crowd.site.data.dto.ProjectDetailsDTO;
 import com.mooctest.crowd.site.data.enums.ProjectType;
+import com.mooctest.crowd.site.data.enums.RoleType;
 import com.mooctest.crowd.site.data.vo.CrowdProjectVO;
 import com.mooctest.crowd.site.data.vo.CrowdTestProjectVO;
 import com.mooctest.crowd.site.data.vo.RegionalManagerVO;
@@ -37,6 +41,7 @@ import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Comparator;
 import java.util.List;
+import java.util.Optional;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.regex.PatternSyntaxException;
@@ -71,6 +76,9 @@ public class CrowdProjectServiceImpl implements CrowdProjectService {
 
     @Autowired
     private FieldDao fieldDao;
+    
+    @Autowired
+    private UserTaskCountDao userTaskCountDao;
 
     @Autowired
     private ThemeSchedulerService themeSchedulerService;
@@ -310,6 +318,28 @@ public class CrowdProjectServiceImpl implements CrowdProjectService {
     @Override
     public ProjectDetailsDTO confirmFinished(String projectCode, Long userId) {
         CrowdTestProject project = projectRepo.getByProjectCode(projectCode);
+
+        // 更新项目下测评机构或者测试人员的接包次数
+        project.getCrowdTestTaskList().stream().map(crowdTestTask -> {
+            List<TaskToUser> acceptedUserList = crowdTestTask.getAcceptedUserList();
+            acceptedUserList.stream().map(taskToUser -> {
+                User user = userRepo.getByID(taskToUser.getUserId());
+                // 对用户判断认证类型 测评机构为1 测试人员为2
+
+                Optional<UserTaskCountPO> userTaskCountPOOptional = userTaskCountDao.findByUserId(user.getId());
+                if(!userTaskCountPOOptional.isPresent()){
+                    UserTaskCount userTaskCount = new UserTaskCount(user.getId(), 1L, RoleType.EVALUATION_USER.getId());
+                    userTaskCountDao.save(Converter.convert(UserTaskCountPO.class, userTaskCount));
+                }else{
+                    UserTaskCountPO userTaskCountPO = userTaskCountPOOptional.get();
+                    userTaskCountPO.setCount(userTaskCountPO.getCount()+1);
+                    userTaskCountDao.save(userTaskCountPO);
+                }
+                return null;
+            });
+            return null;
+        }).collect(Collectors.toList());
+
         project.finishCrowdTestProject(userRepo.getByID(userId));
         projectRepo.saveCrowdTestProject(project);
         return getProjectDetails(projectCode, userId);

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