zhuhaiwen лет назад: 3
Родитель
Сommit
d91f3f8ca9

+ 0 - 6
oa-app/src/main/java/com/css/oa/exam/announce/repository/IAnnounceRepository.java

@ -19,10 +19,4 @@ public interface IAnnounceRepository extends JpaRepository<Announce, String>, Jp
19 19
    @Query("delete from Announce an where an.uuid in :ids")
20 20
    void deleteRealByIds(@Param("ids") List<String> ids);
21 21
22
    @Modifying
23
    @Transactional
24
    @Query("select annou from Announce annou where annou.type = :type and (annou.title like :key or annou.content like :key)")
25
    List<Announce> findByKey(int type, String key);
26
27
28 22
}

+ 21 - 1
oa-app/src/main/java/com/css/oa/exam/announce/service/AnnounceService.java

@ -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);