Procházet zdrojové kódy

hanyuwei 众测技术获取技术文章列表

weihanyu před 5 roky
rodič
revize
82796b8520

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

@@ -0,0 +1,28 @@
+package com.mooctest.crowd.domain.dao;
+
+import com.mooctest.crowd.domain.model.TechnicalArticlesPO;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.PagingAndSortingRepository;
+import java.util.Optional;
+
+
+
+
+import javax.transaction.Transactional;
+
+
+
+@Transactional
+public interface TechnicalArticlesDao extends PagingAndSortingRepository<TechnicalArticlesPO, Long>, JpaSpecificationExecutor<TechnicalArticlesPO> {
+
+    @Override
+    Page<TechnicalArticlesPO> findAll(Pageable pageable);
+
+    Optional<TechnicalArticlesPO> findById(Long userId);
+
+
+
+
+}

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

@@ -0,0 +1,103 @@
+package com.mooctest.crowd.domain.model;
+
+import lombok.Data;
+
+import javax.persistence.*;
+import java.sql.Timestamp;
+
+
+@Data
+@Entity
+@Table(name = "technical_articles")
+public class TechnicalArticlesPO {
+
+    @Id
+    @Column(name = "TA_ID")
+    private Long id;
+
+    @Column(name = "TA_TITLE")
+    private String name;
+
+    @Column(name = "TA_PHOTO_URL")
+    private String photoUrl;
+
+    @Column(name = "TA_ARTICLES_URL")
+    private String  articlesUrl;
+
+    @Column(name = "TA_AUTHOR")
+    private String author;
+
+    @Column(name = "TA_SOURCE")
+    private String source;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhotoUrl() {
+        return photoUrl;
+    }
+
+    public void setPhotoUrl(String photoUrl) {
+        this.photoUrl = photoUrl;
+    }
+
+    public String getArticlesUrl() {
+        return articlesUrl;
+    }
+
+    public void setArticlesUrl(String articlesUrl) {
+        this.articlesUrl = articlesUrl;
+    }
+
+    public String getAuthor() {
+        return author;
+    }
+
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
+
+    public int getReading() {
+        return reading;
+    }
+
+    public void setReading(int reading) {
+        this.reading = reading;
+    }
+
+    public Timestamp getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Timestamp createTime) {
+        this.createTime = createTime;
+    }
+
+    @Column(name = "TA_READING")
+    private int reading;
+
+    @Column(name = "TA_CREATE_TIME")
+    private Timestamp createTime;
+
+}

+ 41 - 0
site/src/main/java/com/mooctest/crowd/site/controller/TechnicalArticlesController.java

@@ -0,0 +1,41 @@
+package com.mooctest.crowd.site.controller;
+
+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.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+
+/**
+ * @Author: hanyuwei
+ * @Date: 2020.6.22
+ */
+@RestController
+@RequestMapping("/api/articles")
+   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);
+    }
+
+    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));
+    }
+}

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

@@ -0,0 +1,85 @@
+package com.mooctest.crowd.site.data.vo;
+
+import com.mooctest.crowd.domain.model.TechnicalArticlesPO;
+
+import java.sql.Timestamp;
+
+public class TechnicalArticlesVO {
+    private Long id;
+    private String name;
+    private String photoUrl;
+    private String  articlesUrl;
+    private String author;
+    private String source;
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getPhotoUrl() {
+        return photoUrl;
+    }
+
+    public void setPhotoUrl(String photoUrl) {
+        this.photoUrl = photoUrl;
+    }
+
+    public String getArticlesUrl() {
+        return articlesUrl;
+    }
+
+    public void setArticlesUrl(String articlesUrl) {
+        this.articlesUrl = articlesUrl;
+    }
+
+    public String getAuthor() {
+        return author;
+    }
+
+    public void setAuthor(String author) {
+        this.author = author;
+    }
+
+    public String getSource() {
+        return source;
+    }
+
+    public void setSource(String source) {
+        this.source = source;
+    }
+
+    public int getReading() {
+        return reading;
+    }
+
+    public void setReading(int reading) {
+        this.reading = reading;
+    }
+
+    public Timestamp getCreateTime() {
+        return createTime;
+    }
+
+    public void setCreateTime(Timestamp createTime) {
+        this.createTime = createTime;
+    }
+
+    private int reading;
+    private Timestamp createTime;
+
+    public void setName(Iterable<TechnicalArticlesPO> technicalArticlesPO) {
+
+    }
+}

+ 4 - 5
site/src/main/java/com/mooctest/crowd/site/mediator/ViewMediator.java

@@ -1,17 +1,14 @@
 package com.mooctest.crowd.site.mediator;
 
 import com.mooctest.crowd.domain.domainobject.CrowdTestProject;
-import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
 import com.mooctest.crowd.domain.domainobject.User;
 import com.mooctest.crowd.site.command.*;
 import com.mooctest.crowd.site.data.dto.*;
 import com.mooctest.crowd.domain.exception.AccountNotExistException;
 import com.mooctest.crowd.domain.exception.BadRequestException;
 import com.mooctest.crowd.domain.exception.PasswordErrorException;
-import com.mooctest.crowd.site.data.vo.AgencyVO;
-import com.mooctest.crowd.site.data.vo.BaseAuthVO;
-import com.mooctest.crowd.site.data.vo.EvolutionAgencyVO;
-import com.mooctest.crowd.site.data.vo.RegionalManagerVO;
+import com.mooctest.crowd.site.data.vo.*;
+import org.springframework.data.domain.Pageable;
 
 import java.util.List;
 
@@ -48,4 +45,6 @@ public interface ViewMediator {
     List<BaseAuthVO> renderAuthingList();
 
     List<BaseAuthVO> renderAuthedList();
+
+    List<TechnicalArticlesVO> technicalArticles(Pageable pageable);
 }

+ 33 - 10
site/src/main/java/com/mooctest/crowd/site/mediator/impl/WebMediatorImpl.java

@@ -78,6 +78,9 @@ public class WebMediatorImpl implements ViewMediator {
     @Autowired
     private TaskToUserDao taskToUserDao;
 
+    @Autowired
+    private TechnicalArticlesDao technicalarticlesDao;
+
     @Value("${agency}")
     private String agencyId;
 
@@ -95,16 +98,16 @@ public class WebMediatorImpl implements ViewMediator {
     public IndexDTO renderIndex() {
 
         Pageable pageable = PageRequest.of(0, 10);
-        //获取用户排名
-        List<UserVO> userRanks = projectDao.findTotalPriceOfUser(pageable).stream().map(rankInfo -> {
-            Optional<UserPO> userPO = userDao.findById(rankInfo.getEntityId());
-            if (userPO.isPresent()) {
-                UserVO userVO = new UserVO();
-                userVO.setName(userPO.get().getName());
-                userVO.setUserName(userPO.get().getUserName());
-                userVO.setAllProjectPrice(rankInfo.getTotalPrice());
-                return userVO;
-            }
+            //获取用户排名
+            List<UserVO> userRanks = projectDao.findTotalPriceOfUser(pageable).stream().map(rankInfo -> {
+                Optional<UserPO> userPO = userDao.findById(rankInfo.getEntityId());
+                if (userPO.isPresent()) {
+                    UserVO userVO = new UserVO();
+                    userVO.setName(userPO.get().getName());
+                    userVO.setUserName(userPO.get().getUserName());
+                    userVO.setAllProjectPrice(rankInfo.getTotalPrice());
+                    return userVO;
+                }
             return null;
         }).filter(Objects::nonNull).collect(Collectors.toList());
         //获取机构排名
@@ -524,6 +527,26 @@ public class WebMediatorImpl implements ViewMediator {
         }).collect(Collectors.toList()));
         authingList.sort(Comparator.comparing(BaseAuthVO::getApplytime).reversed());
         return authingList;
+
+    }
+
+    @Override
+    public List<TechnicalArticlesVO> technicalArticles(Pageable pageable) {
+        List<TechnicalArticlesVO> technicalArticlesVOList = new ArrayList<>();
+        technicalarticlesDao.findAll(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.setAuthor(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getAuthor());
+            technicalArticlesVO.setSource(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getSource());
+            technicalArticlesVO.setReading(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getReading());
+            technicalArticlesVO.setCreateTime(technicalarticlesDao.findById(technicalArticlesPO.getId()).get().getCreateTime());
+            technicalArticlesVOList.add(technicalArticlesVO);
+        });
+        List<TechnicalArticlesVO> results = technicalArticlesVOList.stream().distinct().collect(Collectors.toList());
+        return results;
     }
 
     private ProjectOperationControl initProjectPermission(CrowdTestProject project, User user){

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

@@ -0,0 +1,22 @@
+package com.mooctest.crowd.site.service;
+
+import com.mooctest.crowd.domain.model.TechnicalArticlesPO;
+import com.mooctest.crowd.site.data.vo.RegionalManagerVO;
+import com.mooctest.crowd.site.data.vo.TechnicalArticlesVO;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+
+/**
+ * @author: Diors.Po
+ * @Email: 171256175@qq.com
+ * @date 2019-08-12 01:18
+ */
+
+public interface TechnicalArticlesService {
+
+    List<TechnicalArticlesVO> getTechnicalArticles(Pageable pageable);
+
+}

+ 27 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/TechnicalArticlesServiceImpl.java

@@ -0,0 +1,27 @@
+package com.mooctest.crowd.site.service.impl;
+
+
+import com.mooctest.crowd.site.data.vo.TechnicalArticlesVO;
+import com.mooctest.crowd.site.mediator.ViewMediator;
+import com.mooctest.crowd.site.service.TechnicalArticlesService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class TechnicalArticlesServiceImpl implements TechnicalArticlesService {
+
+
+
+
+    @Autowired
+    private ViewMediator viewMediator;
+
+
+    @Override
+    public List<TechnicalArticlesVO> getTechnicalArticles(Pageable pageable) {
+        return viewMediator.technicalArticles(pageable);
+    }
+}