Browse Source

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

xuxuan 5 years ago
parent
commit
11a6dd0f38

+ 29 - 17
site/src/main/java/com/mooctest/crowd/site/controller/TechnicalArticlesController.java

@@ -1,41 +1,53 @@
 package com.mooctest.crowd.site.controller;
 
+import com.google.gson.Gson;
+import com.mooctest.crowd.site.constants.CommonConstant;
+import com.mooctest.crowd.site.data.dto.TechnicalArticlesDTO;
+import com.mooctest.crowd.site.data.response.ResponseVO;
+import com.mooctest.crowd.site.data.response.ServerCode;
+import com.mooctest.crowd.site.data.vo.SearchConditionVO;
 import com.mooctest.crowd.site.data.vo.TechnicalArticlesVO;
 import com.mooctest.crowd.site.service.TechnicalArticlesService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Pageable;
+import org.springframework.data.domain.Sort;
 import org.springframework.web.bind.annotation.*;
 
-import javax.servlet.http.HttpServletRequest;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @Author: hanyuwei
  * @Date: 2020.6.22
  */
 @RestController
-@RequestMapping("/api/articles")
-   public class TechnicalArticlesController {
+@RequestMapping("/api/technical")
+public class TechnicalArticlesController {
 
     @Autowired
     private TechnicalArticlesService technical;
 
-    @RequestMapping(value = "/display", method = RequestMethod.GET)
-    public List<TechnicalArticlesVO> display(HttpServletRequest request){
-        Pageable pageable = getPageInfo(request);
-        System.out.println(pageable.getPageNumber());
-        return  technical.getTechnicalArticles(pageable);
+//    @RequestMapping(value = "/articles", method = RequestMethod.POST)
+//    public ResponseVO<TechnicalArticlesDTO> technicalarticles(@RequestBody SearchConditionVO searchConditionVO){
+//        Map<String, String> extraCondition = searchConditionVO.getColumnFilters()==null? new HashMap<>() :super.getExtraCondition(searchConditionVO);
+//        Gson gson = new Gson();
+//        SearchConditionVO searchConditionVO = gson.fromJson(searchCondition, SearchConditionVO.class);
+//        Pageable pageable = this.getPageable(searchConditionVO);
+//        String keyword = searchConditionVO.getKeyword();
+//        return new ResponseVO<>(ServerCode.SUCCESS, technical.getArticles(pageable, keyword));
+//    }
+
+    Pageable getPageable(SearchConditionVO searchConditionVO){
+        int activePage = searchConditionVO.getActivePage() == 0?1:searchConditionVO.getActivePage();
+        Sort sort = new Sort(Sort.Direction.ASC,"id");
+        return new PageRequest(activePage-1, CommonConstant.DEFAULT_ROWS_ON_PAGE, sort);
     }
 
-    private Pageable getPageInfo(HttpServletRequest request) {
-        String activePage = request.getHeader("activePage");
-        String rowsOnPage = request.getHeader("rowsOnPage");
-        System.out.println(activePage);
-        System.out.println(rowsOnPage);
-        if (activePage == null || rowsOnPage == null) {
-            throw new IllegalArgumentException("缺少分页信息");
-        }
-        return new PageRequest(Integer.parseInt(activePage) - 1, Integer.parseInt(rowsOnPage));
+    @RequestMapping(value = "/ranking", method = RequestMethod.GET)
+    public List<TechnicalArticlesVO> ranking(){
+        return  technical.articlesRanking();
     }
 }

+ 10 - 0
site/src/main/java/com/mooctest/crowd/site/data/dto/TechnicalArticlesDTO.java

@@ -0,0 +1,10 @@
+package com.mooctest.crowd.site.data.dto;
+
+import com.mooctest.crowd.site.data.vo.TechnicalArticlesVO;
+import lombok.Data;
+import org.springframework.data.domain.Page;
+
+@Data
+public class TechnicalArticlesDTO {
+    Page<TechnicalArticlesVO>  technicalArticlespage;
+}

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

@@ -1,9 +1,17 @@
 package com.mooctest.crowd.site.data.vo;
 
+import com.alibaba.fastjson.JSONArray;
+import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
+import com.mooctest.crowd.domain.domainobject.TechnicalArticles;
 import com.mooctest.crowd.domain.model.TechnicalArticlesPO;
+import lombok.Data;
+import lombok.NoArgsConstructor;
 
 import java.sql.Timestamp;
-
+import java.util.HashMap;
+import java.util.List;
+@Data
+@NoArgsConstructor
 public class TechnicalArticlesVO {
     private Long id;
     private String name;
@@ -82,4 +90,15 @@ public class TechnicalArticlesVO {
     public void setName(Iterable<TechnicalArticlesPO> technicalArticlesPO) {
 
     }
+
+    public TechnicalArticlesVO(TechnicalArticles project){
+        this.id = project.getId();
+        this.name = project.getName();
+        this.photoUrl=project.getPhotoUrl();
+        this.articlesUrl=project.getArticlesUrl();
+        this.author=project.getAuthor();
+        this.source=project.getSource();
+        this.reading=project.getReading();
+        this.createTime=project.getCreateTime();
+    }
 }

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

@@ -1,5 +1,6 @@
 package com.mooctest.crowd.site.service;
 
+import com.mooctest.crowd.site.data.dto.TechnicalArticlesDTO;
 import com.mooctest.crowd.site.data.vo.TechnicalArticlesVO;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -15,7 +16,7 @@ import java.util.List;
 
 public interface TechnicalArticlesService {
 
-    Page<TechnicalArticlesVO> getArticles(Pageable pageable, String keyword);
+    TechnicalArticlesDTO getArticles(Pageable pageable, String keyword);
 
     List<TechnicalArticlesVO> articlesRanking();
 }

+ 5 - 2
site/src/main/java/com/mooctest/crowd/site/service/impl/TechnicalArticlesServiceImpl.java

@@ -2,6 +2,7 @@ package com.mooctest.crowd.site.service.impl;
 
 
 import com.mooctest.crowd.domain.repository.TechnicalArticlesRepo;
+import com.mooctest.crowd.site.data.dto.TechnicalArticlesDTO;
 import com.mooctest.crowd.site.data.vo.TechnicalArticlesVO;
 import com.mooctest.crowd.site.mediator.ViewMediator;
 import com.mooctest.crowd.site.service.TechnicalArticlesService;
@@ -25,8 +26,10 @@ public class TechnicalArticlesServiceImpl implements TechnicalArticlesService{
     private TechnicalArticlesRepo technicalArticlesRepo;
 
     @Override
-    public Page<TechnicalArticlesVO> getArticles(Pageable pageable, String keyword) {
-        return technicalArticlesRepo.getTechnicalArticles(pageable, keyword).map(TechnicalArticles -> new TechnicalArticlesVO(TechnicalArticles));
+    public TechnicalArticlesDTO getArticles(Pageable pageable, String keyword) {
+        TechnicalArticlesDTO  technicalArticlesDTO= new  TechnicalArticlesDTO();
+        technicalArticlesDTO.setTechnicalArticlespage(technicalArticlesRepo.getTechnicalArticles(pageable, keyword).map(technicalArticles -> new TechnicalArticlesVO(technicalArticles)));
+        return technicalArticlesDTO;
     }
 
     @Override