From 2e92773b8ce9e70615e61c84136bbedd702aad8c Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 31 三月 2023 10:19:28 +0800 Subject: [PATCH] update 优化 角色 sort 值一样的排序问题 --- ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java | 70 ++++++++++++++++++---------------- 1 files changed, 37 insertions(+), 33 deletions(-) diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java index 7d492d1..81e6dad 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java @@ -2,14 +2,18 @@ import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.ruoyi.common.core.constant.UserConstants; +import com.ruoyi.common.core.exception.ServiceException; +import com.ruoyi.common.core.utils.MapstructUtils; +import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.mybatis.core.page.PageQuery; import com.ruoyi.common.mybatis.core.page.TableDataInfo; -import com.ruoyi.common.core.exception.ServiceException; -import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.system.domain.SysPost; import com.ruoyi.system.domain.SysUserPost; +import com.ruoyi.system.domain.bo.SysPostBo; +import com.ruoyi.system.domain.vo.SysPostVo; import com.ruoyi.system.mapper.SysPostMapper; import com.ruoyi.system.mapper.SysUserPostMapper; import com.ruoyi.system.service.ISysPostService; @@ -32,12 +36,9 @@ private final SysUserPostMapper userPostMapper; @Override - public TableDataInfo<SysPost> selectPagePostList(SysPost post, PageQuery pageQuery) { - LambdaQueryWrapper<SysPost> lqw = new LambdaQueryWrapper<SysPost>() - .like(StringUtils.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) - .eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) - .like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName()); - Page<SysPost> page = baseMapper.selectPage(pageQuery.build(), lqw); + public TableDataInfo<SysPostVo> selectPagePostList(SysPostBo post, PageQuery pageQuery) { + LambdaQueryWrapper<SysPost> lqw = buildQueryWrapper(post); + Page<SysPostVo> page = baseMapper.selectVoPage(pageQuery.build(), lqw); return TableDataInfo.build(page); } @@ -48,11 +49,18 @@ * @return 宀椾綅淇℃伅闆嗗悎 */ @Override - public List<SysPost> selectPostList(SysPost post) { - return baseMapper.selectList(new LambdaQueryWrapper<SysPost>() - .like(StringUtils.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) - .eq(StringUtils.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) - .like(StringUtils.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName())); + public List<SysPostVo> selectPostList(SysPostBo post) { + LambdaQueryWrapper<SysPost> lqw = buildQueryWrapper(post); + return baseMapper.selectVoList(lqw); + } + + private LambdaQueryWrapper<SysPost> buildQueryWrapper(SysPostBo bo) { + LambdaQueryWrapper<SysPost> lqw = Wrappers.lambdaQuery(); + lqw.like(StringUtils.isNotBlank(bo.getPostCode()), SysPost::getPostCode, bo.getPostCode()); + lqw.like(StringUtils.isNotBlank(bo.getPostName()), SysPost::getPostName, bo.getPostName()); + lqw.eq(StringUtils.isNotBlank(bo.getStatus()), SysPost::getStatus, bo.getStatus()); + lqw.orderByAsc(SysPost::getPostSort); + return lqw; } /** @@ -61,8 +69,8 @@ * @return 宀椾綅鍒楄〃 */ @Override - public List<SysPost> selectPostAll() { - return baseMapper.selectList(); + public List<SysPostVo> selectPostAll() { + return baseMapper.selectVoList(new QueryWrapper<>()); } /** @@ -72,8 +80,8 @@ * @return 瑙掕壊瀵硅薄淇℃伅 */ @Override - public SysPost selectPostById(Long postId) { - return baseMapper.selectById(postId); + public SysPostVo selectPostById(Long postId) { + return baseMapper.selectVoById(postId); } /** @@ -94,14 +102,11 @@ * @return 缁撴灉 */ @Override - public String checkPostNameUnique(SysPost post) { + public boolean checkPostNameUnique(SysPostBo post) { boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysPost>() .eq(SysPost::getPostName, post.getPostName()) .ne(ObjectUtil.isNotNull(post.getPostId()), SysPost::getPostId, post.getPostId())); - if (exist) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; + return !exist; } /** @@ -111,14 +116,11 @@ * @return 缁撴灉 */ @Override - public String checkPostCodeUnique(SysPost post) { + public boolean checkPostCodeUnique(SysPostBo post) { boolean exist = baseMapper.exists(new LambdaQueryWrapper<SysPost>() .eq(SysPost::getPostCode, post.getPostCode()) .ne(ObjectUtil.isNotNull(post.getPostId()), SysPost::getPostId, post.getPostId())); - if (exist) { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; + return !exist; } /** @@ -152,7 +154,7 @@ @Override public int deletePostByIds(Long[] postIds) { for (Long postId : postIds) { - SysPost post = selectPostById(postId); + SysPost post = baseMapper.selectById(postId); if (countUserPostById(postId) > 0) { throw new ServiceException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", post.getPostName())); } @@ -163,22 +165,24 @@ /** * 鏂板淇濆瓨宀椾綅淇℃伅 * - * @param post 宀椾綅淇℃伅 + * @param bo 宀椾綅淇℃伅 * @return 缁撴灉 */ @Override - public int insertPost(SysPost post) { + public int insertPost(SysPostBo bo) { + SysPost post = MapstructUtils.convert(bo, SysPost.class); return baseMapper.insert(post); } /** * 淇敼淇濆瓨宀椾綅淇℃伅 * - * @param post 宀椾綅淇℃伅 + * @param bo 宀椾綅淇℃伅 * @return 缁撴灉 */ @Override - public int updatePost(SysPost post) { + public int updatePost(SysPostBo bo) { + SysPost post = MapstructUtils.convert(bo, SysPost.class); return baseMapper.updateById(post); } } -- Gitblit v1.9.3