Kaynağa Gözat

weihanyu 众测技术

git 5 yıl önce
ebeveyn
işleme
9fcf13a180

+ 10 - 8
core/src/main/java/com/mooctest/crowd/domain/dao/TechnicalArticlesDao.java

@@ -3,9 +3,14 @@ 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.domain.Specification;
+import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.CrudRepository;
 import org.springframework.data.repository.PagingAndSortingRepository;
-import java.util.Optional;
+
+import java.util.List;
 
 
 
@@ -15,14 +20,11 @@ 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);
-
+public interface TechnicalArticlesDao extends PagingAndSortingRepository<TechnicalArticlesPO, Long> ,CrudRepository<TechnicalArticlesPO, Long>, JpaRepository<TechnicalArticlesPO, Long> ,JpaSpecificationExecutor<TechnicalArticlesPO>{
 
+    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);
 
 }

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

@@ -0,0 +1,17 @@
+package com.mooctest.crowd.domain.domainobject;
+
+import lombok.Data;
+
+import java.sql.Timestamp;
+
+@Data
+public class TechnicalArticles {
+    private Long id;
+    private String name;
+    private String photoUrl;
+    private String  articlesUrl;
+    private String author;
+    private String source;
+    private int reading;
+    private Timestamp createTime;
+}

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

@@ -0,0 +1,17 @@
+package com.mooctest.crowd.domain.repository;
+
+import com.mooctest.crowd.domain.domainobject.TechnicalArticles;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+import java.util.List;
+
+/**
+ * @Author: xuexb
+ * @Date: 2019.7.5 14:58
+ */
+public interface ITechnicalArticlesRepo {
+
+    Page<TechnicalArticles> getTechnicalArticles(Pageable pageable, String keyword);
+
+}

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

@@ -0,0 +1,49 @@
+package com.mooctest.crowd.domain.repository;
+
+import com.mooctest.crowd.domain.dao.TechnicalArticlesDao;
+import com.mooctest.crowd.domain.domainobject.TechnicalArticles;
+import com.mooctest.crowd.domain.model.TechnicalArticlesPO;
+import com.mooctest.crowd.domain.util.Converter;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.data.jpa.domain.Specifications;
+import org.springframework.stereotype.Component;
+
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+
+@Slf4j
+@Component
+public class TechnicalArticlesRepo implements ITechnicalArticlesRepo{
+
+
+    @Autowired
+    private TechnicalArticlesDao technicalarticlesDao;
+
+    @Override
+    public Page<TechnicalArticles> getTechnicalArticles(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
+            public Predicate toPredicate(Root<TechnicalArticlesPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
+                Predicate predicate = cb.conjunction();
+                if(keyword != null) {
+                    predicate.getExpressions().add(
+                            cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
+                    );
+                }
+                return predicate;
+            }
+        };
+    }
+}

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

@@ -67,6 +67,10 @@ public interface ViewMediator {
 
     List<CrowdTaskVO>    crowdTaskVos();
 
+    List<TechnicalArticlesVO>  articlesRanking();
+
+    UserVO getinformation(long userId);
+
 
 
 }

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

@@ -82,6 +82,7 @@ public class WebMediatorImpl implements ViewMediator {
     @Autowired
     private TaskToUserDao taskToUserDao;
 
+    @Autowired
     private TechnicalArticlesDao technicalarticlesDao;
 
     @Value("${agency}")
@@ -721,6 +722,37 @@ public class WebMediatorImpl implements ViewMediator {
         return authingList;
     }
 
+    @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 UserVO getinformation(long userId) {
+        Optional<UserPO> userPO = userDao.findById(userId);
+        if (userPO.isPresent()) {
+            UserVO userVO = new UserVO();
+            userVO.setName(userPO.get().getName());
+            userVO.setUserName(userPO.get().getUserName());
+            userVO.setGender(userPO.get().getGender());
+            userVO.setEmail(userPO.get().getEmail());
+            return userVO;
+        }
+        return null;
+    }
+
     private ProjectOperationControl initProjectPermission(CrowdTestProject project, User user) {
         ProjectOperationControl operationControl = new ProjectOperationControl();
         if (user == null)

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

@@ -1,7 +1,5 @@
 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;
@@ -17,6 +15,7 @@ import java.util.List;
 
 public interface TechnicalArticlesService {
 
-    List<TechnicalArticlesVO> getTechnicalArticles(Pageable pageable);
+    Page<TechnicalArticlesVO> getArticles(Pageable pageable, String keyword);
 
+    List<TechnicalArticlesVO> articlesRanking();
 }

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

@@ -1,10 +1,12 @@
 package com.mooctest.crowd.site.service.impl;
 
 
+import com.mooctest.crowd.domain.repository.TechnicalArticlesRepo;
 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.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
 
@@ -19,9 +21,16 @@ public class TechnicalArticlesServiceImpl implements TechnicalArticlesService{
     @Autowired
     private ViewMediator viewMediator;
 
+    @Autowired
+    private TechnicalArticlesRepo technicalArticlesRepo;
+
+    @Override
+    public Page<TechnicalArticlesVO> getArticles(Pageable pageable, String keyword) {
+        return technicalArticlesRepo.getTechnicalArticles(pageable, keyword).map(TechnicalArticles -> new TechnicalArticlesVO(TechnicalArticles));
+    }
 
     @Override
-    public List<TechnicalArticlesVO> getTechnicalArticles(Pageable pageable) {
-        return viewMediator.technicalArticles(pageable);
+    public List<TechnicalArticlesVO> articlesRanking() {
+        return viewMediator.articlesRanking();
     }
 }