|
@@ -2,10 +2,7 @@ package com.mooctest.crowd.domain.repository;
|
|
|
|
|
|
import com.mooctest.crowd.domain.dao.*;
|
|
import com.mooctest.crowd.domain.dao.*;
|
|
import com.mooctest.crowd.domain.domainobject.*;
|
|
import com.mooctest.crowd.domain.domainobject.*;
|
|
-import com.mooctest.crowd.domain.exception.ApplicationTypeNoExistException;
|
|
|
|
-import com.mooctest.crowd.domain.exception.BadRequestException;
|
|
|
|
-import com.mooctest.crowd.domain.exception.FieldNoExistException;
|
|
|
|
-import com.mooctest.crowd.domain.exception.TestTypeNoExistException;
|
|
|
|
|
|
+import com.mooctest.crowd.domain.exception.*;
|
|
import com.mooctest.crowd.domain.model.*;
|
|
import com.mooctest.crowd.domain.model.*;
|
|
import com.mooctest.crowd.domain.util.Converter;
|
|
import com.mooctest.crowd.domain.util.Converter;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
@@ -58,43 +55,44 @@ public class CommonRepo {
|
|
private ExpertDao expertDao;
|
|
private ExpertDao expertDao;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
- private CompetitionsDao competitionsDao;
|
|
|
|
|
|
+ private CompetitionsDao competitionsDao;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private CrowdTestProjectDao crowdTestProjectDao;
|
|
private CrowdTestProjectDao crowdTestProjectDao;
|
|
|
|
|
|
- public List<TestType> getAllTestType(){
|
|
|
|
|
|
+ public List<TestType> getAllTestType() {
|
|
return testTypeDao.findAll().stream().map(testTypePO -> Converter.convert(TestType.class, testTypePO)).collect(Collectors.toList());
|
|
return testTypeDao.findAll().stream().map(testTypePO -> Converter.convert(TestType.class, testTypePO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public List<ApplicationType> getAllApplicationType(){
|
|
|
|
|
|
+ public List<ApplicationType> getAllApplicationType() {
|
|
return applicationTypeDao.findAll().stream().map(applicationTypePO -> Converter.convert(ApplicationType.class, applicationTypePO)).collect(Collectors.toList());
|
|
return applicationTypeDao.findAll().stream().map(applicationTypePO -> Converter.convert(ApplicationType.class, applicationTypePO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public List<Field> getAllFieldType(){
|
|
|
|
|
|
+ public List<Field> getAllFieldType() {
|
|
return fieldDao.findAll().stream().map(fieldPO -> Converter.convert(Field.class, fieldPO)).collect(Collectors.toList());
|
|
return fieldDao.findAll().stream().map(fieldPO -> Converter.convert(Field.class, fieldPO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public List<Resource> getAllResource(){
|
|
|
|
|
|
+ public List<Resource> getAllResource() {
|
|
return resourceDao.findAll().stream().map(resourcePO -> Converter.convert(Resource.class, resourcePO)).collect(Collectors.toList());
|
|
return resourceDao.findAll().stream().map(resourcePO -> Converter.convert(Resource.class, resourcePO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public List<Competition> getAllCompetition(){
|
|
|
|
|
|
+ public List<Competition> getAllCompetition() {
|
|
return competitionDao.findAll().stream()
|
|
return competitionDao.findAll().stream()
|
|
.map(competitionPO -> Converter.convert(Competition.class, competitionPO))
|
|
.map(competitionPO -> Converter.convert(Competition.class, competitionPO))
|
|
.filter(competition -> competition.getIsDeleted() == DeletedStatus.isNotDeleted).collect(Collectors.toList());
|
|
.filter(competition -> competition.getIsDeleted() == DeletedStatus.isNotDeleted).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public Page<Competition> findAllCompetition(Pageable pageable,String keyword) {
|
|
|
|
- Specifications<CompetitionPO> where = Specifications.where(getArticlesByIsNotDeleted(keyword));
|
|
|
|
- return competitionsDao.findAll(where,pageable).map(CompetitionPO -> Converter.convert(Competition.class, CompetitionPO));
|
|
|
|
|
|
+ public Page<Competition> findAllCompetition(Pageable pageable, String keyword) {
|
|
|
|
+ Specifications<CompetitionPO> where = Specifications.where(getArticlesByIsNotDeleted(keyword));
|
|
|
|
+ return competitionsDao.findAll(where, pageable).map(CompetitionPO -> Converter.convert(Competition.class, CompetitionPO));
|
|
}
|
|
}
|
|
|
|
+
|
|
private Specification<CompetitionPO> getArticlesByIsNotDeleted(String keyword) {
|
|
private Specification<CompetitionPO> getArticlesByIsNotDeleted(String keyword) {
|
|
return new Specification<CompetitionPO>() {
|
|
return new Specification<CompetitionPO>() {
|
|
@Override
|
|
@Override
|
|
public Predicate toPredicate(Root<CompetitionPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
public Predicate toPredicate(Root<CompetitionPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
Predicate predicate = cb.conjunction();
|
|
Predicate predicate = cb.conjunction();
|
|
- if(keyword != null) {
|
|
|
|
|
|
+ if (keyword != null) {
|
|
predicate.getExpressions().add(
|
|
predicate.getExpressions().add(
|
|
cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
);
|
|
);
|
|
@@ -103,53 +101,55 @@ public class CommonRepo {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
}
|
|
}
|
|
- public List<Competition> getAllCompetitionTop3(Pageable pageable){
|
|
|
|
|
|
+
|
|
|
|
+ public List<Competition> getAllCompetitionTop3(Pageable pageable) {
|
|
List<CompetitionPO> competitionPOS = competitionDao.findAll(pageable);
|
|
List<CompetitionPO> competitionPOS = competitionDao.findAll(pageable);
|
|
return competitionPOS.stream().map(competitionPO -> Converter.convert(Competition.class, competitionPO))
|
|
return competitionPOS.stream().map(competitionPO -> Converter.convert(Competition.class, competitionPO))
|
|
.filter(competition -> competition.getIsDeleted() == DeletedStatus.isNotDeleted).collect(Collectors.toList());
|
|
.filter(competition -> competition.getIsDeleted() == DeletedStatus.isNotDeleted).collect(Collectors.toList());
|
|
}
|
|
}
|
|
- public List<Partner> getAllPartner(){
|
|
|
|
|
|
+
|
|
|
|
+ public List<Partner> getAllPartner() {
|
|
return partnerDao.findAll().stream().map(partnerPO -> Converter.convert(Partner.class, partnerPO)).collect(Collectors.toList());
|
|
return partnerDao.findAll().stream().map(partnerPO -> Converter.convert(Partner.class, partnerPO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public List<ResidentAgency> getAllResidentAgency(){
|
|
|
|
|
|
+ public List<ResidentAgency> getAllResidentAgency() {
|
|
return residentAgencyDao.findAll().stream().map(residentAgencyPO -> Converter.convert(ResidentAgency.class, residentAgencyPO)).collect(Collectors.toList());
|
|
return residentAgencyDao.findAll().stream().map(residentAgencyPO -> Converter.convert(ResidentAgency.class, residentAgencyPO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public ApplicationType getApplicationTypeByAppCode(String appCode){
|
|
|
|
|
|
+ public ApplicationType getApplicationTypeByAppCode(String appCode) {
|
|
Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByCode(appCode);
|
|
Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByCode(appCode);
|
|
- if(!applicationTypePO.isPresent()){
|
|
|
|
|
|
+ if (!applicationTypePO.isPresent()) {
|
|
throw new ApplicationTypeNoExistException();
|
|
throw new ApplicationTypeNoExistException();
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
return Converter.convert(ApplicationType.class, applicationTypePO.get());
|
|
return Converter.convert(ApplicationType.class, applicationTypePO.get());
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- public TestType getTestTypeByAppCode(String typeCode){
|
|
|
|
|
|
+ public TestType getTestTypeByAppCode(String typeCode) {
|
|
Optional<TestTypePO> testTypePO = testTypeDao.findByCode(typeCode);
|
|
Optional<TestTypePO> testTypePO = testTypeDao.findByCode(typeCode);
|
|
- if(!testTypePO.isPresent()){
|
|
|
|
|
|
+ if (!testTypePO.isPresent()) {
|
|
throw new TestTypeNoExistException();
|
|
throw new TestTypeNoExistException();
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
return Converter.convert(TestType.class, testTypePO.get());
|
|
return Converter.convert(TestType.class, testTypePO.get());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public Field getFieldByFieldCode(String code){
|
|
|
|
|
|
+ public Field getFieldByFieldCode(String code) {
|
|
Optional<FieldPO> fieldPO = fieldDao.findByCode(code);
|
|
Optional<FieldPO> fieldPO = fieldDao.findByCode(code);
|
|
- if(!fieldPO.isPresent()){
|
|
|
|
|
|
+ if (!fieldPO.isPresent()) {
|
|
throw new FieldNoExistException();
|
|
throw new FieldNoExistException();
|
|
- }else {
|
|
|
|
|
|
+ } else {
|
|
return Converter.convert(Field.class, fieldPO.get());
|
|
return Converter.convert(Field.class, fieldPO.get());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public List<ApplicationTypeToTestType> getAppToTypeByAppCode(String appCode){
|
|
|
|
|
|
+ public List<ApplicationTypeToTestType> getAppToTypeByAppCode(String appCode) {
|
|
List<ApplicationTypeToTestTypePO> appToTypeList = applicationTypeToTestTypeDao.findByApplicationTypeCode(appCode);
|
|
List<ApplicationTypeToTestTypePO> appToTypeList = applicationTypeToTestTypeDao.findByApplicationTypeCode(appCode);
|
|
return appToTypeList.stream().map(applicationTypeToTestTypePO -> Converter.convert(ApplicationTypeToTestType.class, applicationTypeToTestTypePO)).collect(Collectors.toList());
|
|
return appToTypeList.stream().map(applicationTypeToTestTypePO -> Converter.convert(ApplicationTypeToTestType.class, applicationTypeToTestTypePO)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- public List<TestType> getTestTypeListByAppCode(String appTypeCode){
|
|
|
|
|
|
+ public List<TestType> getTestTypeListByAppCode(String appTypeCode) {
|
|
List<ApplicationTypeToTestType> appToTypeList = getAppToTypeByAppCode(appTypeCode);
|
|
List<ApplicationTypeToTestType> appToTypeList = getAppToTypeByAppCode(appTypeCode);
|
|
List<TestType> testTypeList = appToTypeList.stream().map(applicationTypeToTestType -> {
|
|
List<TestType> testTypeList = appToTypeList.stream().map(applicationTypeToTestType -> {
|
|
TestType testTypeByAppCode = getTestTypeByAppCode(applicationTypeToTestType.getTestTypeCode());
|
|
TestType testTypeByAppCode = getTestTypeByAppCode(applicationTypeToTestType.getTestTypeCode());
|
|
@@ -158,8 +158,8 @@ public class CommonRepo {
|
|
return testTypeList;
|
|
return testTypeList;
|
|
}
|
|
}
|
|
|
|
|
|
- public Page<Resource> findAllResourceByPage(Pageable pageable, String keyword){
|
|
|
|
- Specifications<ResourcePO> where = Specifications.where(getResource(keyword));
|
|
|
|
|
|
+ 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));
|
|
return resourceDao.findAll(where, pageable).map(resourcePO -> Converter.convert(Resource.class, resourcePO));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -168,7 +168,7 @@ public class CommonRepo {
|
|
@Override
|
|
@Override
|
|
public Predicate toPredicate(Root<ResourcePO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
public Predicate toPredicate(Root<ResourcePO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
Predicate predicate = cb.conjunction();
|
|
Predicate predicate = cb.conjunction();
|
|
- if(keyword != null) {
|
|
|
|
|
|
+ if (keyword != null) {
|
|
predicate.getExpressions().add(
|
|
predicate.getExpressions().add(
|
|
cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
);
|
|
);
|
|
@@ -178,16 +178,16 @@ public class CommonRepo {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- public Page<Expert> findAllExpertByPage(Pageable pageable, String keyword){
|
|
|
|
- Specifications<ExpertPO> where = Specifications.where(getExpert(keyword));
|
|
|
|
|
|
+ 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));
|
|
return expertDao.findAll(where, pageable).map(expertPO -> Converter.convert(Expert.class, expertPO));
|
|
}
|
|
}
|
|
|
|
|
|
- public Expert findExpertById(Long id){
|
|
|
|
|
|
+ public Expert findExpertById(Long id) {
|
|
Optional<ExpertPO> expertPOOptional = expertDao.findById(id);
|
|
Optional<ExpertPO> expertPOOptional = expertDao.findById(id);
|
|
- if(!expertPOOptional.isPresent()){
|
|
|
|
|
|
+ if (!expertPOOptional.isPresent()) {
|
|
throw new BadRequestException("专家信息不存在!");
|
|
throw new BadRequestException("专家信息不存在!");
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
return Converter.convert(Expert.class, expertPOOptional.get());
|
|
return Converter.convert(Expert.class, expertPOOptional.get());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -197,7 +197,7 @@ public class CommonRepo {
|
|
@Override
|
|
@Override
|
|
public Predicate toPredicate(Root<ExpertPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
public Predicate toPredicate(Root<ExpertPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
Predicate predicate = cb.conjunction();
|
|
Predicate predicate = cb.conjunction();
|
|
- if(keyword != null) {
|
|
|
|
|
|
+ if (keyword != null) {
|
|
predicate.getExpressions().add(
|
|
predicate.getExpressions().add(
|
|
cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
);
|
|
);
|
|
@@ -207,22 +207,46 @@ public class CommonRepo {
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
|
|
- public Page<CrowdTestProject> getProjectList(Pageable pageable, String code){
|
|
|
|
- Specifications<CrowdTestProjectPO> where = Specifications.where(getCode(code));
|
|
|
|
|
|
+ public Page<CrowdTestProject> getProjectList(Pageable pageable, String code, String keyword) {
|
|
|
|
+ System.out.println("code " + code);
|
|
|
|
+ Specifications<CrowdTestProjectPO> where = Specifications.where(getCode(code, keyword));
|
|
return crowdTestProjectDao.findAll(where, pageable).map(crowdTestProjectPO -> Converter.convert(CrowdTestProject.class, crowdTestProjectPO));
|
|
return crowdTestProjectDao.findAll(where, pageable).map(crowdTestProjectPO -> Converter.convert(CrowdTestProject.class, crowdTestProjectPO));
|
|
}
|
|
}
|
|
- private Specification<CrowdTestProjectPO> getCode(String code) {
|
|
|
|
|
|
+
|
|
|
|
+ private Specification<CrowdTestProjectPO> getCode(String code, String keyword) {
|
|
return new Specification<CrowdTestProjectPO>() {
|
|
return new Specification<CrowdTestProjectPO>() {
|
|
@Override
|
|
@Override
|
|
public Predicate toPredicate(Root<CrowdTestProjectPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
public Predicate toPredicate(Root<CrowdTestProjectPO> a, CriteriaQuery<?> q, CriteriaBuilder cb) {
|
|
Predicate predicate = cb.conjunction();
|
|
Predicate predicate = cb.conjunction();
|
|
- if(code != null) {
|
|
|
|
|
|
+ if (code != null) {
|
|
|
|
+ predicate.getExpressions().add(cb.equal(a.get("applicationType"), code));
|
|
|
|
+ }
|
|
|
|
+ if (keyword != null && keyword != "") {
|
|
predicate.getExpressions().add(
|
|
predicate.getExpressions().add(
|
|
- cb.equal(a.get("applicationType"), code)
|
|
|
|
|
|
+ cb.like(a.<String>get("name"), "%" + StringUtils.trim(keyword) + "%")
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+// q.orderBy(cb.desc(a.get("status").as(Integer.class)));
|
|
return predicate;
|
|
return predicate;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public String getTypeNameByCode(String code) {
|
|
|
|
+ // 测试类型的转换
|
|
|
|
+ Optional<TestTypePO> testTypePO = testTypeDao.findByCode(code);
|
|
|
|
+ if (!testTypePO.isPresent()) {
|
|
|
|
+ throw new HttpBadRequestException("请选择测试类型");
|
|
|
|
+ }
|
|
|
|
+ return testTypePO.get().getName();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public String getApplicationNameByCode(String code) {
|
|
|
|
+ Optional<ApplicationTypePO> applicationTypePO = applicationTypeDao.findByCode(code);
|
|
|
|
+ if (!applicationTypePO.isPresent()) {
|
|
|
|
+ throw new HttpBadRequestException("请选择应用类型");
|
|
|
|
+ }
|
|
|
|
+ return applicationTypePO.get().getName();
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|