Jelajahi Sumber

热门众测more

git 5 tahun lalu
induk
melakukan
3221a62304

+ 9 - 1
core/src/main/java/com/mooctest/crowd/domain/dao/ApplicationTypeDao.java

@@ -1,18 +1,26 @@
 package com.mooctest.crowd.domain.dao;
 
 import com.mooctest.crowd.domain.model.ApplicationTypePO;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.CrudRepository;
+import org.springframework.data.repository.PagingAndSortingRepository;
 
 import javax.transaction.Transactional;
 import java.util.List;
 import java.util.Optional;
 
 @Transactional
-public interface ApplicationTypeDao extends CrudRepository<ApplicationTypePO, Long>{
+public interface ApplicationTypeDao extends CrudRepository<ApplicationTypePO, Long>,PagingAndSortingRepository<ApplicationTypePO, Long>, JpaRepository<ApplicationTypePO, Long>,JpaSpecificationExecutor<ApplicationTypePO> {
 
     Optional<ApplicationTypePO> findByCode(String code);
 
     Optional<ApplicationTypePO> findById(Long id);
 
     List<ApplicationTypePO> findAll();
+
+    Page<ApplicationTypePO> findAll(Specification<ApplicationTypePO> spec , Pageable pageable);
 }

+ 1 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/ApplicationType.java

@@ -15,4 +15,5 @@ public class ApplicationType {
     private String name;
     private String image;
     private List<TestType> testTypeList;
+    private Long count;
 }

+ 3 - 0
core/src/main/java/com/mooctest/crowd/domain/model/ApplicationTypePO.java

@@ -24,4 +24,7 @@ public class ApplicationTypePO {
 
     @Column(name = "AT_IMAGE")
     private String image;
+
+    @Column(name="AT_COUNT")
+    private Long count;
 }

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

@@ -0,0 +1,25 @@
+package com.mooctest.crowd.domain.repository;
+
+import com.mooctest.crowd.domain.dao.ApplicationTypeDao;
+import com.mooctest.crowd.domain.domainobject.ApplicationType;
+import com.mooctest.crowd.domain.util.Converter;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Component;
+
+
+@Slf4j
+@Component
+public class ApplicationTypeRepo implements IApplicationTypeRepo{
+
+
+    @Autowired
+    private ApplicationTypeDao applicationTypeDao;
+
+    @Override
+    public Page<ApplicationType> getHotTesting(Pageable pageable) {
+        return applicationTypeDao.findAll(pageable).map(ApplicationTypePO->Converter.convert(ApplicationType.class, ApplicationTypePO));
+    }
+}

+ 12 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/IApplicationTypeRepo.java

@@ -0,0 +1,12 @@
+package com.mooctest.crowd.domain.repository;
+
+import com.mooctest.crowd.domain.domainobject.ApplicationType;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+
+public interface IApplicationTypeRepo {
+
+    Page<ApplicationType> getHotTesting(Pageable pageable);
+
+}

File diff ditekan karena terlalu besar
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CommonController.java


+ 1 - 0
site/src/main/java/com/mooctest/crowd/site/data/dto/IndexPageDTO.java

@@ -11,4 +11,5 @@ public class IndexPageDTO {
     Page<ResourceVO> resourcePage;
     Page<ExpertVO> expertPage;
     Page<CompetitionVO> competitionPage;
+    Page<ApplicationTypeVO> applicationTypePage;
 }

+ 1 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/ApplicationTypeVO.java

@@ -26,5 +26,6 @@ public class ApplicationTypeVO implements Serializable {
         code = applicationType.getCode();
         name = applicationType.getName();
         image = applicationType.getImage();
+        count=applicationType.getCount();
     }
 }

+ 1 - 11
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -925,23 +925,13 @@ public class WebMediatorImpl implements ViewMediator {
     public IndexInfoDTO getHotTesting() {
         IndexInfoDTO indexInfoDTO = new IndexInfoDTO();
         Pageable pageable = PageRequest.of(0, 10);
-        int top = 10;
-        //获取热门众测
         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;
-        }
-        indexInfoDTO.setApplicationTypeRank(applicationTypeRanks);
+        indexInfoDTO.setApplicationTypeRank(applicationTypeRank);
         return  indexInfoDTO;
     }
 

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

@@ -26,7 +26,7 @@ public interface CommonService {
 
     Page<CrowdTaskVO> getTaskinfo(Pageable pageable, String keyword, int deletedStatus);
 
-    IndexInfoDTO getHotTesting();
+    IndexPageDTO getHotTesting(Pageable pageable);
 
     IndexPageDTO getCompetition(Pageable pageable);
 }

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

@@ -1,9 +1,6 @@
 package com.mooctest.crowd.site.service.impl;
 
-import com.mooctest.crowd.domain.repository.CommonRepo;
-import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
-import com.mooctest.crowd.domain.repository.CrowdTestTaskRepo;
-import com.mooctest.crowd.domain.repository.EvaluationAgencyRepo;
+import com.mooctest.crowd.domain.repository.*;
 import com.mooctest.crowd.site.data.dto.IndexDTO;
 import com.mooctest.crowd.site.data.dto.IndexInfoDTO;
 import com.mooctest.crowd.site.data.dto.IndexPageDTO;
@@ -38,6 +35,9 @@ public class CommonServiceImpl implements CommonService {
     @Autowired
     private CommonRepo commonRepo;
 
+    @Autowired
+    private ApplicationTypeRepo applicationTypeRepo;
+
 //    @Autowired
 //    private CacheUtil cacheUtil;
 
@@ -87,9 +87,10 @@ public class CommonServiceImpl implements CommonService {
     }
 
     @Override
-    public IndexInfoDTO getHotTesting() {
-        IndexInfoDTO indexInfoDTO = viewMediator.getHotTesting();
-        return indexInfoDTO;
+    public IndexPageDTO getHotTesting(Pageable pageable) {
+        IndexPageDTO indexPageDTO = new IndexPageDTO();
+        indexPageDTO.setApplicationTypePage(applicationTypeRepo.getHotTesting(pageable).map(applicationType -> new ApplicationTypeVO(applicationType)));
+        return  indexPageDTO;
     }
 
     @Override

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini