Bläddra i källkod

add: 首页机构分页信息

guo00guo 5 år sedan
förälder
incheckning
c4b7c21947

+ 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);

+ 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);
 }

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 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);
     }

+ 3 - 0
site/src/main/java/com/mooctest/crowd/site/service/CommonService.java

@@ -3,6 +3,7 @@ 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 org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
@@ -17,4 +18,6 @@ public interface CommonService {
     IndexInfoDTO getIndexInfos();
 
     Page<CrowdProjectVO> getProjectInfo(Pageable pageable, String keyword, int deletedStatus);
+
+    Page<AgencyVO> getAgencyInfo(Pageable pageable, String keyword, int deletedStatus);
 }

+ 10 - 0
site/src/main/java/com/mooctest/crowd/site/service/impl/CommonServiceImpl.java

@@ -1,9 +1,11 @@
 package com.mooctest.crowd.site.service.impl;
 
 import com.mooctest.crowd.domain.repository.CrowdTestProjectRepo;
+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.mediator.ViewMediator;
 import com.mooctest.crowd.site.service.CommonService;
@@ -23,6 +25,9 @@ public class CommonServiceImpl implements CommonService {
     @Autowired
     private CrowdTestProjectRepo projectRepo;
 
+    @Autowired
+    private EvaluationAgencyRepo agencyRepo;
+
     @Override
     public IndexDTO getIndexInfo() {
         return viewMediator.renderIndex();
@@ -43,4 +48,9 @@ public class CommonServiceImpl implements CommonService {
         return projectRepo.findAllByPage(pageable, keyword, deletedStatus).map(crowdTestProject -> new CrowdProjectVO(crowdTestProject));
     }
 
+    @Override
+    public Page<AgencyVO> getAgencyInfo(Pageable pageable, String keyword, int deletedStatus) {
+        return agencyRepo.findAllByPage(pageable, keyword, deletedStatus).map(agency -> new AgencyVO(agency));
+    }
+
 }

Vissa filer visades inte eftersom för många filer har ändrats