git hace 5 años
padre
commit
209ffeca89

+ 0 - 4
core/src/main/java/com/mooctest/crowd/domain/dao/TechnicalArticlesDao.java

@@ -12,7 +12,6 @@ import org.springframework.data.repository.CrudRepository;
 import org.springframework.data.repository.PagingAndSortingRepository;
 import org.springframework.data.repository.query.Param;
 
-import java.util.List;
 
 
 
@@ -26,9 +25,6 @@ public interface TechnicalArticlesDao extends PagingAndSortingRepository<Technic
 
     Page<TechnicalArticlesPO> findAll(Specification<TechnicalArticlesPO> spec , Pageable pageable);
 
-    @Query(nativeQuery = true, value = "select * from technical_articles order by TA_READING DESC")
-    List<TechnicalArticlesPO> findReading(Pageable pageable);
-
     @Modifying
     @Query(nativeQuery = true,value="update  technical_articles set TA_READING=TA_READING+1 where TA_ID=?")
     int updateReading(@Param("id") long id);

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

@@ -8,7 +8,7 @@ import java.sql.Timestamp;
 public class Publications {
     private Long id;
     private String title;
-    private String publicYear;
+    private String publicTime;
     private String  conferenceJournal;
     private String authorList;
     private String longTitle;

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

@@ -13,5 +13,5 @@ public class TechnicalArticles {
     private String author;
     private String source;
     private int reading;
-    private Timestamp createTime;
+    private Timestamp publicTime;
 }

+ 1 - 1
core/src/main/java/com/mooctest/crowd/domain/model/PublicationsPO.java

@@ -20,7 +20,7 @@ public class PublicationsPO {
     private String title;
 
     @Column(name = "P_YEAR")
-    private String publicYear;
+    private String publicTime;
 
     @Column(name = "P_CONFERENCE_JOURNAL")
     private String  conferenceJournal;

+ 1 - 1
core/src/main/java/com/mooctest/crowd/domain/model/TechnicalArticlesPO.java

@@ -35,6 +35,6 @@ public class TechnicalArticlesPO {
     private int reading;
 
     @Column(name = "TA_CREATE_TIME")
-    private Timestamp createTime;
+    private Timestamp publicTime;
 
 }

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

@@ -10,4 +10,6 @@ public interface ITechnicalArticlesRepo {
 
     Page<TechnicalArticles> getTechnicalArticles(Pageable pageable, String keyword);
 
+    Page<TechnicalArticles> articlesRanking(Pageable pageable,String keyword);
+
 }

+ 6 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/TechnicalArticlesRepo.java

@@ -32,6 +32,12 @@ public class TechnicalArticlesRepo implements ITechnicalArticlesRepo{
         return  technicalarticlesDao.findAll(where, pageable).map(TechnicalArticlesPO -> Converter.convert(TechnicalArticles.class, TechnicalArticlesPO));
     }
 
+    @Override
+    public Page<TechnicalArticles> articlesRanking(Pageable pageable,String keyword) {
+        Specifications<TechnicalArticlesPO> where =  Specifications.where(getArticlesByIsNotDeleted(keyword));
+        return  technicalarticlesDao.findAll(where, pageable).map(TechnicalArticlesPO -> Converter.convert(TechnicalArticles.class, TechnicalArticlesPO));
+    }
+
     private Specification<TechnicalArticlesPO> getArticlesByIsNotDeleted(String keyword) {
         return new Specification<TechnicalArticlesPO>() {
             @Override

+ 14 - 5
site/src/main/java/com/mooctest/crowd/site/controller/TechnicalArticlesController.java

@@ -31,7 +31,7 @@ public class TechnicalArticlesController extends BaseSearchController{
     private TechnicalArticlesService technical;
 
     @RequestMapping(value = "/articles", method = RequestMethod.POST)
-    public ResponseVO<TechnicalArticlesDTO> technicalarticles(@RequestBody SearchConditionVO searchConditionVO){
+    public ResponseVO<TechnicalArticlesDTO> technicalArticles(@RequestBody SearchConditionVO searchConditionVO){
         Map<String, String> extraCondition = searchConditionVO.getColumnFilters()==null? new HashMap<>() :super.getExtraCondition(searchConditionVO);
         Pageable pageable = this.getPageable(searchConditionVO);
         String keyword = searchConditionVO.getKeyword();
@@ -45,13 +45,22 @@ public class TechnicalArticlesController extends BaseSearchController{
 
     Pageable getPageable(SearchConditionVO searchConditionVO){
         int activePage = searchConditionVO.getActivePage() == 0?1:searchConditionVO.getActivePage();
-        Sort sort = new Sort(Sort.Direction.ASC,"id");
+        Sort sort = new Sort(Sort.Direction.DESC,"publicTime");
         return new PageRequest(activePage-1, CommonConstant.DEFAULT_ROWS_ON_PAGE, sort);
     }
 
-    @RequestMapping(value = "/ranking", method = RequestMethod.GET)
-    public List<TechnicalArticlesVO> ranking(){
-        return  technical.articlesRanking();
+    Pageable getRanking(SearchConditionVO searchConditionVO){
+        int activePage = searchConditionVO.getActivePage() == 0?1:searchConditionVO.getActivePage();
+        Sort sort = new Sort(Sort.Direction.DESC,"reading");
+        return new PageRequest(activePage-1, CommonConstant.DEFAULT_ROWS_ON_PAGE, sort);
+    }
+
+
+    @RequestMapping(value = "/ranking", method = RequestMethod.POST)
+    public ResponseVO<TechnicalArticlesDTO> ranking(@RequestBody SearchConditionVO searchConditionVO){
+        Pageable pageable = this.getRanking(searchConditionVO);
+        String keyword = searchConditionVO.getKeyword();
+        return new ResponseVO<>(ServerCode.SUCCESS, technical.articlesRanking(pageable,keyword));
     }
 
     @RequestMapping(value = "/updateranking/{id:\\d+}", method = RequestMethod.GET)

+ 2 - 2
site/src/main/java/com/mooctest/crowd/site/data/vo/PublicationsVO.java

@@ -11,7 +11,7 @@ import java.sql.Timestamp;
 public class PublicationsVO {
     private Long id;
     private String title;
-    private String publicYear;
+    private String publicTime;
     private String  conferenceJournal;
     private String authorList;
     private String longTitle;
@@ -22,7 +22,7 @@ public class PublicationsVO {
     public PublicationsVO(Publications publications){
         this.id=publications.getId();
         this.title=publications.getTitle();
-        this.publicYear=publications.getPublicYear();
+        this.publicTime=publications.getPublicTime();
         this.conferenceJournal=publications.getConferenceJournal();
         this.authorList=publications.getAuthorList();
         this.longTitle=publications.getLongTitle();

+ 3 - 3
site/src/main/java/com/mooctest/crowd/site/data/vo/TechnicalArticlesVO.java

@@ -22,7 +22,7 @@ public class TechnicalArticlesVO {
     private String source;
     private String time_interval;
     private int reading;
-    private Timestamp createTime;
+    private Timestamp publicTime;
 
 
     public TechnicalArticlesVO(TechnicalArticles project){
@@ -33,10 +33,10 @@ public class TechnicalArticlesVO {
         this.author=project.getAuthor();
         this.source=project.getSource();
         this.reading=project.getReading();
-        this.createTime=project.getCreateTime();
+        this.publicTime=project.getPublicTime();
         DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         try {
-            Date date = df.parse(df.format(project.getCreateTime()));
+            Date date = df.parse(df.format(project.getPublicTime()));
             long[] times = getDistanceTimes(date);
             if(times[0]>0){
                 this.time_interval=times[0]+"天前发布";

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

@@ -65,8 +65,6 @@ public interface ViewMediator {
 
     List<CrowdTaskVO>    crowdTaskVos();
 
-    List<TechnicalArticlesVO>  articlesRanking();
-
     UserDTO getInformation(long userId);
 
     UserDTO updateInformation(long userId, UserVO userVO);

+ 0 - 17
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -714,23 +714,6 @@ public class WebMediatorImpl implements ViewMediator {
     }
 
     @Override
-    public List<TechnicalArticlesVO> articlesRanking() {
-        Pageable pageable = PageRequest.of(0, 10);
-        List<TechnicalArticlesVO> technicalArticlesVOList = new ArrayList<>();
-        technicalarticlesDao.findReading(pageable).forEach(technicalArticlesPO -> {
-            TechnicalArticlesVO technicalArticlesVO = new TechnicalArticlesVO();
-            technicalArticlesVO.setId(technicalArticlesPO.getId());
-            technicalArticlesVO.setName(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getName());
-            technicalArticlesVO.setPhotoUrl(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getPhotoUrl());
-            technicalArticlesVO.setArticlesUrl(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getArticlesUrl());
-            technicalArticlesVO.setReading(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getReading());
-            technicalArticlesVOList.add(technicalArticlesVO);
-        });
-        List<TechnicalArticlesVO> results = technicalArticlesVOList.stream().distinct().collect(Collectors.toList());
-        return results;
-    }
-
-    @Override
     public UserDTO getInformation(long userId) {
         UserDTO userDTO=new UserDTO();
         Optional<UserPO> userPO = userDao.findById(userId);

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

@@ -18,7 +18,7 @@ public interface TechnicalArticlesService {
 
     TechnicalArticlesDTO getArticles(Pageable pageable,String keyword,Map<String, String> extraCondition);
 
-    List<TechnicalArticlesVO> articlesRanking();
+    TechnicalArticlesDTO articlesRanking(Pageable pageable,String keyword);
 
     TechnicalArticlesDTO  updateRanking(long id);
 }

+ 4 - 3
site/src/main/java/com/mooctest/crowd/site/service/impl/TechnicalArticlesServiceImpl.java

@@ -12,7 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
-import java.util.List;
 import java.util.Map;
 
 @Service
@@ -45,8 +44,10 @@ public class TechnicalArticlesServiceImpl implements TechnicalArticlesService{
     }
 
     @Override
-    public List<TechnicalArticlesVO> articlesRanking() {
-        return viewMediator.articlesRanking();
+    public TechnicalArticlesDTO articlesRanking(Pageable pageable,String keyword) {
+        TechnicalArticlesDTO  technicalArticlesDTO= new  TechnicalArticlesDTO();
+        technicalArticlesDTO.setTechnicalArticlesPage(technicalArticlesRepo.articlesRanking(pageable, keyword).map(technicalArticles -> new TechnicalArticlesVO(technicalArticles)));
+        return technicalArticlesDTO;
     }
 
     @Override