Parcourir la source

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

 Conflicts:
	site/src/main/java/com/mooctest/crowd/site/service/CommonService.java
	site/src/main/java/com/mooctest/crowd/site/service/impl/CommonServiceImpl.java
xuxuan il y a 5 ans
Parent
commit
a882b28b69

+ 1 - 1
core/src/main/java/com/mooctest/crowd/domain/dao/AgencyAbilityDao.java

@@ -17,7 +17,7 @@ public interface AgencyAbilityDao extends PagingAndSortingRepository<EvaluationA
 
     List<EvaluationAgencyAbilityPO> findAll();
 
-//    void deleteAll(List<EvaluationAgencyAbilityPO> evaluationAgencyAbilityPOList);
+    //    void deleteAll(List<EvaluationAgencyAbilityPO> evaluationAgencyAbilityPOList);
 
     @Override
     void deleteAll(Iterable<? extends EvaluationAgencyAbilityPO> iterable);

+ 17 - 0
core/src/main/java/com/mooctest/crowd/domain/dao/ExpertDao.java

@@ -0,0 +1,17 @@
+package com.mooctest.crowd.domain.dao;
+
+import com.mooctest.crowd.domain.model.ExpertPO;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.CrudRepository;
+
+import javax.transaction.Transactional;
+import java.util.List;
+import java.util.Optional;
+
+@Transactional
+public interface ExpertDao extends CrudRepository<ExpertPO, Long>, JpaSpecificationExecutor<ExpertPO> {
+
+    Optional<ExpertPO> findById(Long id);
+
+    List<ExpertPO> findAll();
+}

+ 2 - 2
core/src/main/java/com/mooctest/crowd/domain/dao/ResourceDao.java

@@ -1,7 +1,7 @@
 package com.mooctest.crowd.domain.dao;
 
 import com.mooctest.crowd.domain.model.ResourcePO;
-import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.CrudRepository;
 
 import javax.transaction.Transactional;
@@ -9,7 +9,7 @@ import java.util.List;
 import java.util.Optional;
 
 @Transactional
-public interface ResourceDao extends CrudRepository<ResourcePO, Long>{
+public interface ResourceDao extends CrudRepository<ResourcePO, Long>, JpaSpecificationExecutor<ResourcePO> {
 
     Optional<ResourcePO> findByCode(String code);
 

+ 16 - 0
core/src/main/java/com/mooctest/crowd/domain/domainobject/Expert.java

@@ -0,0 +1,16 @@
+package com.mooctest.crowd.domain.domainobject;
+
+import lombok.Data;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+@Data
+public class Expert {
+    private Long id;
+    private String name;
+    private String photo;
+    private String introduction;
+
+}

+ 28 - 0
core/src/main/java/com/mooctest/crowd/domain/model/ExpertPO.java

@@ -0,0 +1,28 @@
+package com.mooctest.crowd.domain.model;
+
+import lombok.Data;
+
+import javax.persistence.*;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+@Data
+@Entity(name = "expert")
+public class ExpertPO {
+    @Id
+    @Column(name = "E_ID")
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    private Long id;
+
+    @Column(name = "E_NAME")
+    private String name;
+
+    @Column(name = "E_PHOTO")
+    private String photo;
+
+    @Column(name = "E_INTRODUCTION")
+    private String introduction;
+    
+}

+ 50 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/CommonRepo.java

@@ -7,10 +7,18 @@ import com.mooctest.crowd.domain.exception.FieldNoExistException;
 import com.mooctest.crowd.domain.exception.TestTypeNoExistException;
 import com.mooctest.crowd.domain.model.*;
 import com.mooctest.crowd.domain.util.Converter;
+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;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -45,6 +53,9 @@ public class CommonRepo {
     @Autowired
     private PartnerDao partnerDao;
 
+    @Autowired
+    private ExpertDao expertDao;
+
     public List<TestType> getAllTestType(){
         return testTypeDao.findAll().stream().map(testTypePO -> Converter.convert(TestType.class, testTypePO)).collect(Collectors.toList());
     }
@@ -122,4 +133,43 @@ public class CommonRepo {
         return testTypeList;
     }
 
+    public Page<Resource> findAllResourceByPage(Pageable pageable, String keyword){
+        Specifications<ResourcePO> where =  Specifications.where(getResource(keyword));
+        return resourceDao.findAll(where, pageable).map(resourcePO -> Converter.convert(Resource.class, resourcePO));
+    }
+
+    private Specification<ResourcePO> getResource(String keyword) {
+        return new Specification<ResourcePO>() {
+            @Override
+            public Predicate toPredicate(Root<ResourcePO> 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;
+            }
+        };
+    }
+
+    public Page<Expert> findAllExpertByPage(Pageable pageable, String keyword){
+        Specifications<ExpertPO> where =  Specifications.where(getExpert(keyword));
+        return expertDao.findAll(where, pageable).map(expertPO -> Converter.convert(Expert.class, expertPO));
+    }
+
+    private Specification<ExpertPO> getExpert(String keyword) {
+        return new Specification<ExpertPO>() {
+            @Override
+            public Predicate toPredicate(Root<ExpertPO> 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;
+            }
+        };
+    }
 }

+ 1 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/CrowdTestProjectRepo.java

@@ -78,6 +78,7 @@ public class CrowdTestProjectRepo implements ICrowdTestProjectRepo {
             }
         };
     }
+
     @Override
     public CrowdTestProject getByID(Long crowdTestProjectId) throws CrowdTestProjectNotExistException {
 

+ 38 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/EvaluationAgencyRepo.java

@@ -9,9 +9,19 @@ import com.mooctest.crowd.domain.model.EvaluationAgencyAbilityPO;
 import com.mooctest.crowd.domain.model.EvaluationAgencyPO;
 import com.mooctest.crowd.domain.model.EvaluationAgencyResourcePO;
 import com.mooctest.crowd.domain.util.Converter;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+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;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -31,6 +41,9 @@ public class EvaluationAgencyRepo implements IEvaluationAgencyRepo {
     @Autowired
     private EvaluationAgencyDao evaluationAgencyDao;
 
+    @Value("${agency}")
+    private String agencyId;
+
     @Override
     public EvaluationAgency findAgencyById(Long id){
         Optional<EvaluationAgencyPO> evaluationAgencyPO = evaluationAgencyDao.findById(id);
@@ -104,4 +117,29 @@ public class EvaluationAgencyRepo implements IEvaluationAgencyRepo {
         agencyAbilityDao.deleteAll(evaluationAgencyAbilityPOList);
     }
 
+    @Override
+    public Page<EvaluationAgency> findAllByPage(Pageable pageable, String keyword, int deletedStatus){
+        Specifications<EvaluationAgencyPO> where =  Specifications.where(getAgencyByIsNotDeleted(keyword, deletedStatus));
+        return evaluationAgencyDao.findAll(where, pageable).map(evaluationAgencyPO -> Converter.convert(EvaluationAgency.class, evaluationAgencyPO));
+    }
+
+    private Specification<EvaluationAgencyPO> getAgencyByIsNotDeleted(String keyword, int deletedStatus) {
+        return new Specification<EvaluationAgencyPO>() {
+            @Override
+            public Predicate toPredicate(Root<EvaluationAgencyPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
+                Predicate predicate = cb.conjunction();
+                if(keyword != null) {
+                    predicate.getExpressions().add(
+                            cb.like(a.<String>get("evaluationAgencyName"), "%" + StringUtils.trim(keyword) + "%")
+                    );
+                }
+                EvaluationAgency agencyById = findAgencyById(Long.parseLong(agencyId));
+                predicate.getExpressions().add(cb.notEqual(a.get("evaluationAgencyName"), agencyById.getEvaluationAgencyName()));
+                predicate.getExpressions().add(cb.equal(a.get("isDeleted"), deletedStatus));
+                predicate.getExpressions().add(cb.equal(a.get("isAuthentication"), AuthenticationStatus.isAuthenticated));
+                return predicate;
+            }
+        };
+    }
+
 }

+ 4 - 0
core/src/main/java/com/mooctest/crowd/domain/repository/IEvaluationAgencyRepo.java

@@ -3,6 +3,8 @@ package com.mooctest.crowd.domain.repository;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgency;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgencyAbility;
 import com.mooctest.crowd.domain.domainobject.EvaluationAgencyResource;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
 
 import java.util.List;
 
@@ -27,4 +29,6 @@ public interface IEvaluationAgencyRepo {
     List<EvaluationAgencyAbility> findEvaluationAgencyAbility(Long evaluationAgencyId);
 
     void moveEvaluationAgencyAbility(List<EvaluationAgencyAbility> evaluationAgencyAbilityList);
+
+    Page<EvaluationAgency> findAllByPage(Pageable pageable, String keyword, int deletedStatus);
 }

Fichier diff supprimé car celui-ci est trop grand
+ 0 - 0
site/src/main/java/com/mooctest/crowd/site/controller/CommonController.java


+ 2 - 0
site/src/main/java/com/mooctest/crowd/site/controller/advice/ExceptionAdvice.java

@@ -25,6 +25,8 @@ public class ExceptionAdvice {
         log.error("访问出错:"+e.getMessage(), e);
         if (e instanceof AccountNotExistException){
             return ResponseConstant.USER_NOT_EXISTS;
+        } else if (e instanceof NullPointerException){
+            return "操作失败";
         } else if (e instanceof CrowdTestProjectNotExistException){
             return "项目不存在";
         } else if (e instanceof CrowdTestTaskNotExistException){

+ 9 - 4
site/src/main/java/com/mooctest/crowd/site/data/vo/AgencyVO.java

@@ -37,10 +37,15 @@ public class AgencyVO {
 
     public AgencyVO(EvaluationAgency agency){
         BeanUtils.copyProperties(agency, this, "evaluationAgencyResourceList", "evaluationAgencyAbilityList");
-        this.setEvaluationAgencyAbilityList(agency.getEvaluationAgencyAbilityList()
-                .stream().map(EvaluationAgencyAbility::getAbilityName).collect(Collectors.toList()));
-        this.setEvaluationAgencyResourceList(agency.getEvaluationAgencyResourceList()
-                .stream().map(AgencyResourceVO::new).collect(Collectors.toList()));
+
+        if(agency.getEvaluationAgencyAbilityList() != null && agency.getEvaluationAgencyAbilityList().size() > 0){
+            this.setEvaluationAgencyAbilityList(agency.getEvaluationAgencyAbilityList()
+                    .stream().map(EvaluationAgencyAbility::getAbilityName).collect(Collectors.toList()));
+        }
+        if(agency.getEvaluationAgencyResourceList() != null && agency.getEvaluationAgencyResourceList().size() > 0){
+            this.setEvaluationAgencyResourceList(agency.getEvaluationAgencyResourceList()
+                    .stream().map(AgencyResourceVO::new).collect(Collectors.toList()));
+        }
         this.authStatus = new StatusVO();
         this.authStatus.initAuthStatus(this.isAuthentication);
     }

+ 23 - 0
site/src/main/java/com/mooctest/crowd/site/data/vo/ExpertVO.java

@@ -0,0 +1,23 @@
+package com.mooctest.crowd.site.data.vo;
+
+import com.mooctest.crowd.domain.domainobject.Expert;
+import lombok.Data;
+
+/**
+ * @author guochao
+ * @date 2019/7/6 17:54
+ */
+@Data
+public class ExpertVO {
+    private Long id;
+    private String name;
+    private String photo;
+    private String introduction;
+
+    public ExpertVO(Expert expert){
+        id = expert.getId();
+        name = expert.getName();
+        photo = expert.getPhoto();
+        introduction = expert.getIntroduction();
+    }
+}

+ 8 - 2
site/src/main/java/com/mooctest/crowd/site/service/CommonService.java

@@ -3,8 +3,10 @@ package com.mooctest.crowd.site.service;
 import com.mooctest.crowd.site.data.dto.IndexDTO;
 import com.mooctest.crowd.site.data.dto.IndexInfoDTO;
 import com.mooctest.crowd.site.data.dto.MyCrowdDTO;
+import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.CrowdProjectVO;
-import com.mooctest.crowd.site.data.vo.CrowdTaskVO;
+import com.mooctest.crowd.site.data.vo.ExpertVO;
+import com.mooctest.crowd.site.data.vo.ResourceVO;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.stereotype.Service;
@@ -19,5 +21,9 @@ public interface CommonService {
 
     Page<CrowdProjectVO> getProjectInfo(Pageable pageable, String keyword, int deletedStatus);
 
-    Page<CrowdTaskVO>   getTaskInfo(Pageable pageable,String keyword,int deletedstatus);
+    Page<AgencyVO> getAgencyInfo(Pageable pageable, String keyword, int deletedStatus);
+
+    Page<ResourceVO> getResourceInfo(Pageable pageable, String keyword);
+
+    Page<ExpertVO> getExpertInfo(Pageable pageable, String keyword);
 }

+ 20 - 6
site/src/main/java/com/mooctest/crowd/site/service/impl/CommonServiceImpl.java

@@ -1,13 +1,15 @@
 package com.mooctest.crowd.site.service.impl;
 
-import com.mooctest.crowd.domain.domainobject.CrowdTestTask;
+import com.mooctest.crowd.domain.repository.CommonRepo;
 import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
-import com.mooctest.crowd.domain.repository.CrowdTestTaskRepo;
+import com.mooctest.crowd.domain.repository.EvaluationAgencyRepo;
 import com.mooctest.crowd.site.data.dto.IndexDTO;
 import com.mooctest.crowd.site.data.dto.IndexInfoDTO;
 import com.mooctest.crowd.site.data.dto.MyCrowdDTO;
+import com.mooctest.crowd.site.data.vo.AgencyVO;
 import com.mooctest.crowd.site.data.vo.CrowdProjectVO;
-import com.mooctest.crowd.site.data.vo.CrowdTaskVO;
+import com.mooctest.crowd.site.data.vo.ExpertVO;
+import com.mooctest.crowd.site.data.vo.ResourceVO;
 import com.mooctest.crowd.site.mediator.ViewMediator;
 import com.mooctest.crowd.site.service.CommonService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,7 +29,10 @@ public class CommonServiceImpl implements CommonService {
     private CrowdTestProjectRepo projectRepo;
 
     @Autowired
-    private CrowdTestTaskRepo    taskRepo;
+    private EvaluationAgencyRepo agencyRepo;
+
+    @Autowired
+    private CommonRepo commonRepo;
 
     @Override
     public IndexDTO getIndexInfo() {
@@ -50,9 +55,18 @@ public class CommonServiceImpl implements CommonService {
     }
 
     @Override
-    public Page<CrowdTaskVO> getTaskInfo(Pageable pageable, String keyword, int deletedstatus) {
+    public Page<AgencyVO> getAgencyInfo(Pageable pageable, String keyword, int deletedStatus) {
+        return agencyRepo.findAllByPage(pageable, keyword, deletedStatus).map(agency -> new AgencyVO(agency));
+    }
 
-      return  taskRepo.findAllByPage(pageable,keyword,deletedstatus).map(crowdTestTask -> new CrowdTaskVO(crowdTestTask));
+    @Override
+    public Page<ResourceVO> getResourceInfo(Pageable pageable, String keyword) {
+        return commonRepo.findAllResourceByPage(pageable, keyword).map(resource -> new ResourceVO(resource));
+    }
+
+    @Override
+    public Page<ExpertVO> getExpertInfo(Pageable pageable, String keyword) {
+        return commonRepo.findAllExpertByPage(pageable, keyword).map(expert -> new ExpertVO(expert));
     }
 
 }

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff