|
|
@@ -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();
|
|
|
}
|
|
|
}
|