|
@ -117,7 +117,27 @@ public class AnnounceService extends BaseService implements IAnnounceService {
|
117
|
117
|
if (!AnnoType.contains(req.type)) {
|
118
|
118
|
throw new Exception("req.type 参数错误");
|
119
|
119
|
}
|
120
|
|
List<Announce> list = repository.findByKey(req.type, req.key);
|
|
120
|
Specification<Announce> spec = new Specification<Announce>() {
|
|
121
|
@Override
|
|
122
|
public Predicate toPredicate(Root<Announce> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
|
|
123
|
List<Predicate> predicateList = new ArrayList<>();
|
|
124
|
|
|
125
|
if (!TextUtils.isEmpty(req.key)) {
|
|
126
|
String pattern = "%" + req.key + "%";
|
|
127
|
Predicate title = criteriaBuilder.like(root.get("title").as(String.class), pattern);
|
|
128
|
Predicate content = criteriaBuilder.like(root.get("content").as(String.class), pattern);
|
|
129
|
Predicate or = criteriaBuilder.or(title, content);
|
|
130
|
predicateList.add(or);//模糊查询
|
|
131
|
}
|
|
132
|
predicateList.add(criteriaBuilder.equal(root.get("type").as(Integer.class), req.type));
|
|
133
|
|
|
134
|
Predicate[] pre = new Predicate[predicateList.size()];
|
|
135
|
pre = predicateList.toArray(pre);
|
|
136
|
return criteriaQuery.where(pre).getRestriction();
|
|
137
|
}
|
|
138
|
};
|
|
139
|
// List<Announce> list = repository.findByKey(req.type, req.key);
|
|
140
|
List<Announce> list = repository.findAll(spec);
|
121
|
141
|
Map map = new LinkedHashMap();
|
122
|
142
|
map.put("total", list.size());
|
123
|
143
|
map.put("list", list);
|