|
@@ -1,9 +1,11 @@
|
|
|
package com.mooctest.crowd.site.mediator.impl;
|
|
package com.mooctest.crowd.site.mediator.impl;
|
|
|
|
|
|
|
|
-import com.mooctest.crowd.domain.dao.CrowdTestProjectDao;
|
|
|
|
|
-import com.mooctest.crowd.domain.dao.CrowdTestTaskDao;
|
|
|
|
|
|
|
+import com.mooctest.crowd.domain.dao.*;
|
|
|
import com.mooctest.crowd.domain.domainobject.*;
|
|
import com.mooctest.crowd.domain.domainobject.*;
|
|
|
import com.mooctest.crowd.domain.exception.AccountNotExistException;
|
|
import com.mooctest.crowd.domain.exception.AccountNotExistException;
|
|
|
|
|
+import com.mooctest.crowd.domain.model.EvaluationAgencyPO;
|
|
|
|
|
+import com.mooctest.crowd.domain.model.RegionalManagerPO;
|
|
|
|
|
+import com.mooctest.crowd.domain.model.UserPO;
|
|
|
import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
|
|
import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
|
|
|
import com.mooctest.crowd.domain.repository.EvaluationAgencyRepo;
|
|
import com.mooctest.crowd.domain.repository.EvaluationAgencyRepo;
|
|
|
import com.mooctest.crowd.domain.repository.UserRepo;
|
|
import com.mooctest.crowd.domain.repository.UserRepo;
|
|
@@ -14,6 +16,8 @@ import com.mooctest.crowd.site.mediator.ViewMediator;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.data.domain.PageRequest;
|
|
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -40,6 +44,15 @@ public class WebMediatorImpl implements ViewMediator {
|
|
|
private CrowdTestTaskDao taskDao;
|
|
private CrowdTestTaskDao taskDao;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
|
|
+ private UserDao userDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private RegionalManagerDao regionalManagerDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private EvaluationAgencyDao agencyDao;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
private CrowdTestProjectDao projectDao;
|
|
private CrowdTestProjectDao projectDao;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -54,88 +67,44 @@ public class WebMediatorImpl implements ViewMediator {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public IndexDTO renderIndex() {
|
|
public IndexDTO renderIndex() {
|
|
|
- ArrayList<CrowdTaskVO> allTasks = new ArrayList<>();
|
|
|
|
|
- List<CrowdTestProject> allProjects = projectRepo.getAllCrowdTestProject();
|
|
|
|
|
- allProjects.forEach(project -> {
|
|
|
|
|
- allTasks.addAll(project.getCrowdTestTaskList()
|
|
|
|
|
- .stream().filter(crowdTestTask -> crowdTestTask.getStatus() == CrowdTestTaskStatus.HAS_RELEASED)
|
|
|
|
|
- .map(crowdTestTask -> new CrowdTaskVO(crowdTestTask)).collect(Collectors.toList()));
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- //对Project按照UserId进行分组
|
|
|
|
|
- Map<Long, List<CrowdTestProject>> projectsGroup = new HashMap<>();
|
|
|
|
|
- allProjects.forEach(project -> {
|
|
|
|
|
- if (!projectsGroup.keySet().contains(project.getUserId()))
|
|
|
|
|
- projectsGroup.put(project.getUserId(), new ArrayList<>());
|
|
|
|
|
- projectsGroup.get(project.getUserId()).add(project);
|
|
|
|
|
- });
|
|
|
|
|
- //根据组的项目总价进行排序,提取UserId
|
|
|
|
|
- List<Long> userIds = projectsGroup.entrySet().stream().sorted((o1, o2) -> {
|
|
|
|
|
- Double sumPrice1 = o1.getValue().stream().mapToDouble(CrowdTestProject::getQuotedPrice).sum();
|
|
|
|
|
- Double sumPrice2 = o2.getValue().stream().mapToDouble(CrowdTestProject::getQuotedPrice).sum();
|
|
|
|
|
- if (sumPrice1 > sumPrice2)
|
|
|
|
|
- return -1;
|
|
|
|
|
- else if (sumPrice1 < sumPrice2)
|
|
|
|
|
- return 1;
|
|
|
|
|
- else
|
|
|
|
|
- return 0;
|
|
|
|
|
- }).map(Map.Entry::getKey).collect(Collectors.toList());
|
|
|
|
|
- for (Long id : userIds)
|
|
|
|
|
- log.info("UserId from Project: " + id);
|
|
|
|
|
- if (userIds.size()>10)
|
|
|
|
|
- userIds = userIds.subList(0,9);
|
|
|
|
|
- List<UserVO> userRanks = userIds.stream().map(id -> new UserVO(userRepo.getByID(id))).collect(Collectors.toList());
|
|
|
|
|
- userRanks.forEach(userVO -> userVO.setAllProjectPrice(projectsGroup.get(userVO.getId()).stream().mapToDouble(CrowdTestProject::getQuotedPrice).sum()));
|
|
|
|
|
-
|
|
|
|
|
- allTasks.sort(Comparator.comparing(CrowdTaskVO::getQuotePrice).reversed());
|
|
|
|
|
- List<CrowdTaskVO> hotTasks = allTasks.subList(0,3);
|
|
|
|
|
- List<EvolutionAgencyVO> agencyVOS = new ArrayList<>();
|
|
|
|
|
- EvolutionAgencyVO agency1 = new EvolutionAgencyVO();
|
|
|
|
|
- agency1.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency1.setName("agency1");
|
|
|
|
|
- EvolutionAgencyVO agency2 = new EvolutionAgencyVO();
|
|
|
|
|
- agency2.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency2.setName("agency2");
|
|
|
|
|
- EvolutionAgencyVO agency3 = new EvolutionAgencyVO();
|
|
|
|
|
- agency3.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency3.setName("agency3");
|
|
|
|
|
- EvolutionAgencyVO agency4 = new EvolutionAgencyVO();
|
|
|
|
|
- agency4.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency4.setName("agency4");
|
|
|
|
|
- EvolutionAgencyVO agency5 = new EvolutionAgencyVO();
|
|
|
|
|
- agency5.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency5.setName("agency5");
|
|
|
|
|
- EvolutionAgencyVO agency6 = new EvolutionAgencyVO();
|
|
|
|
|
- agency6.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency6.setName("agency6");
|
|
|
|
|
- EvolutionAgencyVO agency7 = new EvolutionAgencyVO();
|
|
|
|
|
- agency7.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency7.setName("agency7");
|
|
|
|
|
- EvolutionAgencyVO agency8 = new EvolutionAgencyVO();
|
|
|
|
|
- agency8.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency8.setName("agency8");
|
|
|
|
|
- EvolutionAgencyVO agency9 = new EvolutionAgencyVO();
|
|
|
|
|
- agency9.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency9.setName("agency9");
|
|
|
|
|
- EvolutionAgencyVO agency10 = new EvolutionAgencyVO();
|
|
|
|
|
- agency10.setLogo("http://www.mooctest.net/assets/img/mooctest.png");
|
|
|
|
|
- agency10.setName("agency10");
|
|
|
|
|
- agencyVOS.add(agency1);
|
|
|
|
|
- agencyVOS.add(agency2);
|
|
|
|
|
- agencyVOS.add(agency3);
|
|
|
|
|
- agencyVOS.add(agency4);
|
|
|
|
|
- agencyVOS.add(agency5);
|
|
|
|
|
- agencyVOS.add(agency6);
|
|
|
|
|
- agencyVOS.add(agency7);
|
|
|
|
|
- agencyVOS.add(agency8);
|
|
|
|
|
- agencyVOS.add(agency9);
|
|
|
|
|
- agencyVOS.add(agency10);
|
|
|
|
|
- IndexDTO indexDTO = new IndexDTO();
|
|
|
|
|
|
|
|
|
|
|
|
+ Pageable pageable = PageRequest.of(0, 10);
|
|
|
|
|
+ //获取用户排名
|
|
|
|
|
+ List<UserVO> userRanks = projectDao.findTotalPriceOfUser(pageable).stream().map(rankInfo -> {
|
|
|
|
|
+ Optional<UserPO> userPO = userDao.findById(rankInfo.getEntityId());
|
|
|
|
|
+ if (userPO.isPresent()) {
|
|
|
|
|
+ UserVO userVO = new UserVO();
|
|
|
|
|
+ userVO.setName(userPO.get().getName());
|
|
|
|
|
+ userVO.setUserName(userPO.get().getUserName());
|
|
|
|
|
+ userVO.setAllProjectPrice(rankInfo.getTotalPrice());
|
|
|
|
|
+ return userVO;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
+ //获取机构排名
|
|
|
|
|
+ List<EvolutionAgencyVO> agencyRanks = taskDao.findTotalPriceOfAgency(pageable).stream().map(rankInfo -> {
|
|
|
|
|
+ Optional<EvaluationAgencyPO> agency = agencyDao.findById(rankInfo.getEntityId());
|
|
|
|
|
+ if (agency.isPresent()) {
|
|
|
|
|
+ EvolutionAgencyVO agencyVO = new EvolutionAgencyVO();
|
|
|
|
|
+ agencyVO.setName(agency.get().getEvaluationAgencyName());
|
|
|
|
|
+ agencyVO.setLogo(agency.get().getAgencyPhoto());
|
|
|
|
|
+ agencyVO.setAllTaskPrice(rankInfo.getTotalPrice());
|
|
|
|
|
+ return agencyVO;
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }).filter(Objects::nonNull).collect(Collectors.toList());
|
|
|
|
|
+
|
|
|
|
|
+ //获取热门任务
|
|
|
|
|
+ List<CrowdTaskVO> hotTasks = taskDao.findHotTask().stream().map(crowdTestTaskPO -> {
|
|
|
|
|
+ CrowdTestTask task = new CrowdTestTask();
|
|
|
|
|
+ BeanUtils.copyProperties(crowdTestTaskPO, task);
|
|
|
|
|
+ return new CrowdTaskVO(task);
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
+ IndexDTO indexDTO = new IndexDTO();
|
|
|
indexDTO.setHotTaskList(hotTasks);
|
|
indexDTO.setHotTaskList(hotTasks);
|
|
|
indexDTO.setUserRank(userRanks);
|
|
indexDTO.setUserRank(userRanks);
|
|
|
- indexDTO.setAgencyRank(agencyVOS);
|
|
|
|
|
|
|
+ indexDTO.setAgencyRank(agencyRanks);
|
|
|
List<String> img = new ArrayList<>();
|
|
List<String> img = new ArrayList<>();
|
|
|
img.add("http://mooctest-crowd-service.oss-cn-hangzhou.aliyuncs.com/Image/daylight.jpg");
|
|
img.add("http://mooctest-crowd-service.oss-cn-hangzhou.aliyuncs.com/Image/daylight.jpg");
|
|
|
img.add("http://mooctest-crowd-service.oss-cn-hangzhou.aliyuncs.com/Image/invictus.jpg");
|
|
img.add("http://mooctest-crowd-service.oss-cn-hangzhou.aliyuncs.com/Image/invictus.jpg");
|
|
@@ -216,9 +185,23 @@ public class WebMediatorImpl implements ViewMediator {
|
|
|
@Override
|
|
@Override
|
|
|
public UserDTO renderUser(User user) {
|
|
public UserDTO renderUser(User user) {
|
|
|
UserDTO userDTO = new UserDTO();
|
|
UserDTO userDTO = new UserDTO();
|
|
|
|
|
+ userDTO.setRoleList(user.getRoleList().stream().map(Role::getName).collect(Collectors.toList()));
|
|
|
userDTO.setUserVO(new UserVO(user));
|
|
userDTO.setUserVO(new UserVO(user));
|
|
|
if (user.getEvaluationAgency() != null)
|
|
if (user.getEvaluationAgency() != null)
|
|
|
userDTO.setAgencyVO(new AgencyVO(user.getEvaluationAgency()));
|
|
userDTO.setAgencyVO(new AgencyVO(user.getEvaluationAgency()));
|
|
|
return userDTO;
|
|
return userDTO;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public List<RegionalManagerVO> renderRegionManager() {
|
|
|
|
|
+ List<RegionalManagerVO> regionalManagerVOList = new ArrayList<>();
|
|
|
|
|
+ regionalManagerDao.findAll().forEach(regionalManagerPO -> {
|
|
|
|
|
+ RegionalManagerVO regionalManagerVO = new RegionalManagerVO();
|
|
|
|
|
+ regionalManagerVO.setId(regionalManagerPO.getUserId());
|
|
|
|
|
+ regionalManagerVO.setName(userDao.findById(regionalManagerPO.getUserId()).get().getName());
|
|
|
|
|
+ regionalManagerVOList.add(regionalManagerVO);
|
|
|
|
|
+ });
|
|
|
|
|
+ List<RegionalManagerVO> results = regionalManagerVOList.stream().distinct().collect(Collectors.toList());
|
|
|
|
|
+ return results;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|