Переглянути джерело

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

xuxuan 5 роки тому
батько
коміт
a920d4690a

+ 1 - 1
site/src/main/java/com/mooctest/crowd/site/controller/AgencyController.java

@@ -159,7 +159,7 @@ public class AgencyController extends BaseSearchController {
     @RequestMapping(value = "resident/agency/more", method = RequestMethod.POST)
     public ResponseVO getMoreResidentList(@RequestBody SearchConditionVO searchConditionVO) {
         Pageable pageable = this.getPageable(searchConditionVO);
-        return new ResponseVO(ServerCode.SUCCESS, residentAgencyService.findAll(pageable));
+        return new ResponseVO(ServerCode.SUCCESS, residentAgencyService.findAll(pageable, searchConditionVO.getKeyword()));
     }
 
     @RequestMapping(value = "agency/{agencyId}", method = RequestMethod.GET)

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

@@ -1,16 +1,13 @@
 package com.mooctest.crowd.site.service;
 
 
-import com.mooctest.crowd.domain.model.ResidentAgencyPO;
 import com.mooctest.crowd.site.data.vo.ResidentAgencyVO;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 
-import java.awt.*;
-
 public interface ResidentAgencyService {
 
-    Page<ResidentAgencyVO> findAll(Pageable pageable);
+    Page<ResidentAgencyVO> findAll(Pageable pageable, String keyword);
 
 
 }

+ 12 - 24
site/src/main/java/com/mooctest/crowd/site/service/impl/ResidentServiceImpl.java

@@ -5,9 +5,6 @@ import com.mooctest.crowd.domain.dao.ResidentAgencyDao;
 import com.mooctest.crowd.domain.dao.TaskToUserDao;
 import com.mooctest.crowd.domain.dao.UserDao;
 import com.mooctest.crowd.domain.model.EvaluationAgencyPO;
-import com.mooctest.crowd.domain.model.RankCountInfo;
-import com.mooctest.crowd.domain.model.ResidentAgencyPO;
-import com.mooctest.crowd.domain.model.UserPO;
 import com.mooctest.crowd.site.data.vo.ResidentAgencyVO;
 import com.mooctest.crowd.site.service.ResidentAgencyService;
 import com.mooctest.crowd.site.util.DataUtils;
@@ -17,9 +14,8 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
-import java.util.ArrayList;
 import java.util.List;
-import java.util.Optional;
+import java.util.stream.Collectors;
 
 /**
  * @author:xx
@@ -40,30 +36,22 @@ public class ResidentServiceImpl implements ResidentAgencyService {
 
 
     @Override
-    public Page<ResidentAgencyVO> findAll(Pageable pageable) {
-        List<ResidentAgencyVO> list = new ArrayList<>();
-        List<RankCountInfo> totalCountOfUser = taskToUserDao.findTotalCountOfUser();
-        long ids[] = new long[totalCountOfUser.size()];
-        List<ResidentAgencyPO> residentAgencyPOS = residentAgencyDao.findAll();
-        //获取品牌机构的用户id
-        long resagency[] = new long[residentAgencyPOS.size()];
-        for (int i = 0; i < residentAgencyPOS.size(); i++) {
+    public Page<ResidentAgencyVO> findAll(Pageable pageable, String keyword) {
+        List<ResidentAgencyVO> residentAgencyVOList = residentAgencyDao.findAll().stream().map(residentAgencyPO -> {
             ResidentAgencyVO residentAgencyVO = new ResidentAgencyVO();
-            Optional<UserPO> userPO = userDao.findById(residentAgencyPOS.get(i).getUserId());
-            resagency[i] = residentAgencyPOS.get(i).getUserId();
-            EvaluationAgencyPO evaluationAgencyPO = agencyDao.findByUserId(resagency[i]);
+            EvaluationAgencyPO evaluationAgencyPO = agencyDao.findByUserId(residentAgencyPO.getUserId());
             residentAgencyVO.setName(evaluationAgencyPO.getEvaluationAgencyName());
             residentAgencyVO.setAgencyPhoto(evaluationAgencyPO.getAgencyPhoto());
-            residentAgencyVO.setTaskCount(totalCountOfUser.get(i).getCount());
             residentAgencyVO.setAddress(evaluationAgencyPO.getAddress());
-            residentAgencyVO.setAgencyId(residentAgencyPOS.get(i).getAgencyId());
-            residentAgencyVO.setId(residentAgencyPOS.get(i).getId());
-            residentAgencyVO.setUserId(residentAgencyPOS.get(i).getUserId());
-            list.add(residentAgencyVO);
+            residentAgencyVO.setAgencyId(evaluationAgencyPO.getId());
+            residentAgencyVO.setId(residentAgencyPO.getId());
+            residentAgencyVO.setUserId(residentAgencyPO.getUserId());
+            return residentAgencyVO;
+        }).collect(Collectors.toList());
+        if(keyword != null && keyword != ""){
+            residentAgencyVOList = residentAgencyVOList.stream().filter(residentAgencyVO -> residentAgencyVO.getName().contains(keyword)).collect(Collectors.toList());
         }
-
-
-        Page<ResidentAgencyVO> page = DataUtils.listToPage(list, pageable);
+        Page<ResidentAgencyVO> page = DataUtils.listToPage(residentAgencyVOList, pageable);
         return page;
     }
 }