模版列表关键词搜索开发

pull/26/head
zhuqinshu 2 years ago
parent 59b8f70678
commit ed642727c6

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

@ -25,6 +25,7 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@ -77,10 +78,9 @@ public class MessageTemplateController {
@GetMapping("/list")
@ApiOperation("/列表页")
public BasicResultVO queryList(@Validated MessageTemplateParam messageTemplateParam) {
List<Map<String, Object>> result = Convert4Amis.flatListMap(messageTemplateService.queryList(messageTemplateParam));
long count = messageTemplateService.count();
MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(count).rows(result).build();
Page<MessageTemplate> messageTemplates = messageTemplateService.queryList(messageTemplateParam);
List<Map<String, Object>> result = Convert4Amis.flatListMap(messageTemplates.toList());
MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(messageTemplates.getTotalElements()).rows(result).build();
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.support.domain.MessageTemplate;
import com.java3y.austin.web.vo.MessageTemplateParam;
import org.springframework.data.domain.Page;
import java.util.List;
@ -21,7 +22,7 @@ public interface MessageTemplateService {
* @param messageTemplateParam
* @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.vo.MessageTemplateParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
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;
/**
@ -43,9 +50,22 @@ public class MessageTemplateServiceImpl implements MessageTemplateService {
private XxlJobUtils xxlJobUtils;
@Override
public List<MessageTemplate> queryList(MessageTemplateParam param) {
public Page<MessageTemplate> queryList(MessageTemplateParam param) {
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

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

Loading…
Cancel
Save