43 lines
1.4 KiB
Java
43 lines
1.4 KiB
Java
package com.xkrs.util;
|
|
|
|
import com.xkrs.dao.DataDictDao;
|
|
import com.xkrs.model.entity.DataDict;
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.persistence.criteria.Predicate;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @Author: XinYi Song
|
|
* @Date: 2022/1/19 13:56
|
|
*/
|
|
@Component
|
|
public class DataDictQuery {
|
|
|
|
@Resource
|
|
private DataDictDao dataDictDao;
|
|
|
|
/**
|
|
* 动态多条件查询字典信息
|
|
*
|
|
* @return
|
|
*/
|
|
public List<DataDict> selectDataDict(String inspectionItemName, String inspectionItemCode) {
|
|
Specification<DataDict> specification = (root, criteriaQuery, criteriaBuilder) -> {
|
|
List<Predicate> list = new ArrayList<>();
|
|
if (inspectionItemName != null && !"".equals(inspectionItemName)) {
|
|
list.add(criteriaBuilder.equal(root.get("inspectionItemName").as(String.class), inspectionItemName));
|
|
}
|
|
if (inspectionItemCode != null && !"".equals(inspectionItemCode)) {
|
|
list.add(criteriaBuilder.equal(root.get("inspectionItemCode").as(String.class), inspectionItemCode));
|
|
}
|
|
Predicate[] predicates = new Predicate[list.size()];
|
|
return criteriaBuilder.and(list.toArray(predicates));
|
|
};
|
|
return dataDictDao.findAll(specification);
|
|
}
|
|
}
|