!36 模版列表的关键词搜索查询

Merge pull request !36 from sunday/master
pull/26/head
Java3y 2 years ago committed by Gitee
commit 24d1a78afe
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -3,6 +3,7 @@ package com.java3y.austin.support.dao;
import com.java3y.austin.support.domain.MessageTemplate; import com.java3y.austin.support.domain.MessageTemplate;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import java.util.List; import java.util.List;
@ -11,7 +12,7 @@ import java.util.List;
* Dao * Dao
* @author 3y * @author 3y
*/ */
public interface MessageTemplateDao extends JpaRepository<MessageTemplate, Long> { public interface MessageTemplateDao extends JpaRepository<MessageTemplate, Long>, JpaSpecificationExecutor<MessageTemplate> {
/** /**

@ -24,6 +24,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
@ -75,10 +76,9 @@ public class MessageTemplateController {
@GetMapping("/list") @GetMapping("/list")
@ApiOperation("/列表页") @ApiOperation("/列表页")
public BasicResultVO queryList(@Validated MessageTemplateParam messageTemplateParam) { public BasicResultVO queryList(@Validated MessageTemplateParam messageTemplateParam) {
List<Map<String, Object>> result = Convert4Amis.flatListMap(messageTemplateService.queryList(messageTemplateParam)); Page<MessageTemplate> messageTemplates = messageTemplateService.queryList(messageTemplateParam);
List<Map<String, Object>> result = Convert4Amis.flatListMap(messageTemplates.toList());
long count = messageTemplateService.count(); MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(messageTemplates.getTotalElements()).rows(result).build();
MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(count).rows(result).build();
return BasicResultVO.success(messageTemplateVo); return BasicResultVO.success(messageTemplateVo);
} }

@ -4,6 +4,7 @@ package com.java3y.austin.web.service;
import com.java3y.austin.common.vo.BasicResultVO; import com.java3y.austin.common.vo.BasicResultVO;
import com.java3y.austin.support.domain.MessageTemplate; import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.web.vo.MessageTemplateParam; import com.java3y.austin.web.vo.MessageTemplateParam;
import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
@ -21,7 +22,7 @@ public interface MessageTemplateService {
* @param messageTemplateParam * @param messageTemplateParam
* @return * @return
*/ */
List<MessageTemplate> queryList(MessageTemplateParam messageTemplateParam); Page<MessageTemplate> queryList(MessageTemplateParam messageTemplateParam);
/** /**
* *

@ -18,9 +18,16 @@ import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.web.service.MessageTemplateService; import com.java3y.austin.web.service.MessageTemplateService;
import com.java3y.austin.web.vo.MessageTemplateParam; import com.java3y.austin.web.vo.MessageTemplateParam;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -43,9 +50,22 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
private XxlJobUtils xxlJobUtils; private XxlJobUtils xxlJobUtils;
@Override @Override
public List<MessageTemplate> queryList(MessageTemplateParam param) { public Page<MessageTemplate> queryList(MessageTemplateParam param) {
PageRequest pageRequest = PageRequest.of(param.getPage() - 1, param.getPerPage()); PageRequest pageRequest = PageRequest.of(param.getPage() - 1, param.getPerPage());
return messageTemplateDao.findAllByIsDeletedEqualsOrderByUpdatedDesc(CommonConstant.FALSE, pageRequest); return messageTemplateDao.findAll((Specification<MessageTemplate>) (root, query, cb) -> {
List<Predicate> predicateList = new ArrayList<>();
// 加搜索条件
if (StrUtil.isNotBlank(param.getKeywords())) {
predicateList.add(cb.like(root.get("name").as(String.class), "%" + param.getKeywords() + "%"));
}
predicateList.add(cb.equal(root.get("isDeleted").as(Integer.class), CommonConstant.FALSE));
Predicate[] p = new Predicate[predicateList.size()];
// 查询
query.where(cb.and(predicateList.toArray(p)));
// 排序
query.orderBy(cb.desc(root.get("updated")));
return query.getRestriction();
}, pageRequest);
} }
@Override @Override

@ -46,4 +46,9 @@ public class MessageTemplateParam {
* *
*/ */
private String msgContent; private String msgContent;
/**
*
*/
private String keywords;
} }

Loading…
Cancel
Save