diff --git a/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java b/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java index cf1bb62..645e3eb 100644 --- a/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java +++ b/austin-support/src/main/java/com/java3y/austin/support/dao/MessageTemplateDao.java @@ -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 { +public interface MessageTemplateDao extends JpaRepository, JpaSpecificationExecutor { /** diff --git a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java index 4d9776a..6fc6748 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java +++ b/austin-web/src/main/java/com/java3y/austin/web/controller/MessageTemplateController.java @@ -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> result = Convert4Amis.flatListMap(messageTemplateService.queryList(messageTemplateParam)); - - long count = messageTemplateService.count(); - MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(count).rows(result).build(); + Page messageTemplates = messageTemplateService.queryList(messageTemplateParam); + List> result = Convert4Amis.flatListMap(messageTemplates.toList()); + MessageTemplateVo messageTemplateVo = MessageTemplateVo.builder().count(messageTemplates.getTotalElements()).rows(result).build(); return BasicResultVO.success(messageTemplateVo); } diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/MessageTemplateService.java b/austin-web/src/main/java/com/java3y/austin/web/service/MessageTemplateService.java index 3359321..bdceb26 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/MessageTemplateService.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/MessageTemplateService.java @@ -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 queryList(MessageTemplateParam messageTemplateParam); + Page queryList(MessageTemplateParam messageTemplateParam); /** * 统计未删除的条数 diff --git a/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java b/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java index d457982..d29817a 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java +++ b/austin-web/src/main/java/com/java3y/austin/web/service/impl/MessageTemplateServiceImpl.java @@ -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 queryList(MessageTemplateParam param) { + public Page queryList(MessageTemplateParam param) { PageRequest pageRequest = PageRequest.of(param.getPage() - 1, param.getPerPage()); - return messageTemplateDao.findAllByIsDeletedEqualsOrderByUpdatedDesc(CommonConstant.FALSE, pageRequest); + return messageTemplateDao.findAll((Specification) (root, query, cb) -> { + List 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 diff --git a/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java b/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java index 13bba44..af28f93 100644 --- a/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java +++ b/austin-web/src/main/java/com/java3y/austin/web/vo/MessageTemplateParam.java @@ -46,4 +46,9 @@ public class MessageTemplateParam { * 下发参数信息 */ private String msgContent; + + /** + * 模版名称 + */ + private String keywords; }