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