You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							71 lines
						
					
					
						
							2.4 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							71 lines
						
					
					
						
							2.4 KiB
						
					
					
				| package com.aiprose.querydsl.service; | |
| 
 | |
| import com.aiprose.base.BasicServiceImpl; | |
| import com.aiprose.querydsl.entity.Emp; | |
| import com.aiprose.querydsl.entity.QEmp; | |
| import com.aiprose.querydsl.repository.EmpRepository; | |
| import com.aiprose.querydsl.util.FixedPageData; | |
| import com.querydsl.core.QueryResults; | |
| import com.querydsl.core.types.ExpressionUtils; | |
| import com.querydsl.core.types.Predicate; | |
| import com.querydsl.jpa.impl.JPAQueryFactory; | |
| import org.apache.commons.lang3.StringUtils; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.data.jpa.repository.JpaRepository; | |
| import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | |
| import org.springframework.stereotype.Service; | |
| import org.springframework.transaction.annotation.Transactional; | |
| 
 | |
| import javax.annotation.PostConstruct; | |
| import javax.persistence.EntityManager; | |
| import javax.persistence.PersistenceContext; | |
| 
 | |
| /** | |
|  * @version 1.0 | |
|  * @Auther: nelson | |
|  * @company 北京中经网软件有限公司 | |
|  * @Date: 2020/9/14 | |
|  */ | |
| @Transactional | |
| @Service | |
| public class EmpService extends BasicServiceImpl<Emp,Integer> { | |
| 
 | |
|     @Autowired | |
|     private JPAQueryFactory queryFactory; | |
| 
 | |
|     @Autowired | |
|     private EmpRepository repository; | |
| 
 | |
|     @Override | |
|     public JpaRepository<Emp, Integer> getJpaRepository() { | |
|         return repository; | |
|     } | |
| 
 | |
|     @Override | |
|     public JpaSpecificationExecutor<Emp> getJpaSpecificationExecutor() { | |
|         return null; | |
|     } | |
| 
 | |
|     public FixedPageData list(Integer page, Integer size, Emp emp) { | |
|         FixedPageData pageData = new FixedPageData(page, size); | |
|         QEmp qEmp = QEmp.emp; | |
|         Integer deptId = emp.getDeptId(); | |
|         String empName = emp.getEmpName(); | |
|         Long mobile = emp.getMobile(); | |
|         Predicate predicate = qEmp.isNotNull(); | |
|         if (StringUtils.isNotBlank(empName)) { | |
|             predicate = ExpressionUtils.and(predicate, qEmp.empName.eq(empName)); | |
|         } | |
|         if (deptId != null) { | |
|             predicate = ExpressionUtils.and(predicate, qEmp.deptId.eq(deptId)); | |
|         } | |
|         if (mobile != null) { | |
|             predicate = ExpressionUtils.and(predicate, qEmp.mobile.eq(mobile)); | |
|         } | |
|         QueryResults<Emp> queryResults = queryFactory.selectFrom(qEmp).where(predicate).offset(pageData.getOffset()) | |
|                 .limit(pageData.getSize()).fetchResults(); | |
|         pageData.setResults(queryResults.getResults()); | |
|         pageData.setTotal(queryResults.getTotal()); | |
|         return pageData; | |
|     } | |
| }
 | |
| 
 |