From c7e6667f8f8e0079dc7776c631b16bdb5b22621e Mon Sep 17 00:00:00 2001 From: linfeng <2445465217@qq.com> Date: Wed, 11 May 2022 17:17:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=96=E5=AD=90=E7=AE=A1=E7=90=86=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E6=9F=A5=E8=AF=A2&=E5=89=8D=E7=AB=AF=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/linfeng/common/utils/WechatUtil.java | 11 ++++ .../admin/service/impl/PostServiceImpl.java | 36 ++++++---- .../src/views/modules/admin/post.vue | 65 +++++++++++-------- 3 files changed, 73 insertions(+), 39 deletions(-) diff --git a/src/main/java/io/linfeng/common/utils/WechatUtil.java b/src/main/java/io/linfeng/common/utils/WechatUtil.java index f08bd93..df5cab5 100644 --- a/src/main/java/io/linfeng/common/utils/WechatUtil.java +++ b/src/main/java/io/linfeng/common/utils/WechatUtil.java @@ -73,4 +73,15 @@ public class WechatUtil { } return null; } + + /** + * @Title: isEmpty + * @Description: 判断对象是否为空 + * @param obj + * @return + * @return Integer + */ + public static boolean isEmpty(Object obj) { + return null == obj || "".equals(obj); + } } diff --git a/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java b/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java index 3bd7eb2..4ccfe1e 100644 --- a/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java +++ b/src/main/java/io/linfeng/modules/admin/service/impl/PostServiceImpl.java @@ -1,5 +1,6 @@ package io.linfeng.modules.admin.service.impl; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -53,30 +54,43 @@ public class PostServiceImpl extends ServiceImpl implements @Override public PageUtils queryPage(Map params) { + QueryWrapper queryWrapper=new QueryWrapper<>(); + //条件查询 + String key = (String)params.get("key"); + String status = (String)params.get("status"); + if(!WechatUtil.isEmpty(key)){ + params.put("page","1");//如果是查询分页重置为第一页 + queryWrapper.like("content", key).or().like("title",key); + } + if(!WechatUtil.isEmpty(status)){ + params.put("page","1");//如果是查询分页重置为第一页 + queryWrapper.eq("status", Integer.parseInt(status)); + } + queryWrapper.lambda().orderByDesc(PostEntity::getId); IPage page = this.page( new Query().getPage(params), - new QueryWrapper<>() + queryWrapper ); List data = page.getRecords(); - List responseList = new ArrayList<>(); - data.forEach(l -> { - PostListResponse response = new PostListResponse(); - BeanUtils.copyProperties(l, response); - if (response.getDiscussId() > 0) { + List responseList=new ArrayList<>(); + data.forEach(l->{ + PostListResponse response=new PostListResponse(); + BeanUtils.copyProperties(l,response); + if(ObjectUtil.isNotNull(response.getDiscussId())&&response.getDiscussId()>0){ DiscussEntity discussEntity = discussService.getById(response.getDiscussId()); - response.setDiscussTitle(discussEntity.getTitle()); + if(ObjectUtil.isNotNull(discussEntity)){ + response.setDiscussTitle(discussEntity.getTitle()); + } } response.setTopicName(topicService.getById(response.getTopicId()).getTopicName()); response.setCollectionCount(postCollectionService.collectCount(response.getId())); response.setCommentCount(commentService.getCountByTopicId(response.getId())); response.setUserInfo(appUserService.getById(response.getUid())); - String jsonString = l.getMedia(); - List list = JsonUtils.JsonToList(jsonString); - response.setMedia(list); + response.setMedia(JsonUtils.JsonToList(l.getMedia())); responseList.add(response); }); - PageUtils pageUtils = new PageUtils(page); + PageUtils pageUtils=new PageUtils(page); pageUtils.setList(responseList); return pageUtils; } diff --git a/src/main/resources/static/linfeng-community-vue/src/views/modules/admin/post.vue b/src/main/resources/static/linfeng-community-vue/src/views/modules/admin/post.vue index 90e9e69..5f27ed0 100644 --- a/src/main/resources/static/linfeng-community-vue/src/views/modules/admin/post.vue +++ b/src/main/resources/static/linfeng-community-vue/src/views/modules/admin/post.vue @@ -5,21 +5,26 @@ :model="dataForm" @keyup.enter.native="getDataList()" > - - - - + + + + + + + + 查询 + 重置 - 点击预览 点击查看 @@ -162,13 +153,13 @@ label="点赞数" > - + { if (data && data.code === 0) {