From 5ca038d888922e93bf45c7bd37f3c6dce849dcff Mon Sep 17 00:00:00 2001 From: 疯狂的狮子li <15040126243@163.com> Date: 星期五, 24 十二月 2021 11:36:02 +0800 Subject: [PATCH] update 调整监控依赖 从 common 迁移到 framework --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java | 365 ++++++++++++++++++++++++++------------------------- 1 files changed, 186 insertions(+), 179 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java index 127ed3f..058d7ed 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java @@ -1,179 +1,186 @@ -package com.ruoyi.system.service.impl; - -import java.util.List; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import com.ruoyi.common.constant.UserConstants; -import com.ruoyi.common.exception.CustomException; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.domain.SysPost; -import com.ruoyi.system.mapper.SysPostMapper; -import com.ruoyi.system.mapper.SysUserPostMapper; -import com.ruoyi.system.service.ISysPostService; - -/** - * 宀椾綅淇℃伅 鏈嶅姟灞傚鐞� - * - * @author ruoyi - */ -@Service -public class SysPostServiceImpl implements ISysPostService -{ - @Autowired - private SysPostMapper postMapper; - - @Autowired - private SysUserPostMapper userPostMapper; - - /** - * 鏌ヨ宀椾綅淇℃伅闆嗗悎 - * - * @param post 宀椾綅淇℃伅 - * @return 宀椾綅淇℃伅闆嗗悎 - */ - @Override - public List<SysPost> selectPostList(SysPost post) - { - return postMapper.selectPostList(post); - } - - /** - * 鏌ヨ鎵�鏈夊矖浣� - * - * @return 宀椾綅鍒楄〃 - */ - @Override - public List<SysPost> selectPostAll() - { - return postMapper.selectPostAll(); - } - - /** - * 閫氳繃宀椾綅ID鏌ヨ宀椾綅淇℃伅 - * - * @param postId 宀椾綅ID - * @return 瑙掕壊瀵硅薄淇℃伅 - */ - @Override - public SysPost selectPostById(Long postId) - { - return postMapper.selectPostById(postId); - } - - /** - * 鏍规嵁鐢ㄦ埛ID鑾峰彇宀椾綅閫夋嫨妗嗗垪琛� - * - * @param userId 鐢ㄦ埛ID - * @return 閫変腑宀椾綅ID鍒楄〃 - */ - @Override - public List<Integer> selectPostListByUserId(Long userId) - { - return postMapper.selectPostListByUserId(userId); - } - - /** - * 鏍¢獙宀椾綅鍚嶇О鏄惁鍞竴 - * - * @param post 宀椾綅淇℃伅 - * @return 缁撴灉 - */ - @Override - public String checkPostNameUnique(SysPost post) - { - Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); - SysPost info = postMapper.checkPostNameUnique(post.getPostName()); - if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) - { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; - } - - /** - * 鏍¢獙宀椾綅缂栫爜鏄惁鍞竴 - * - * @param post 宀椾綅淇℃伅 - * @return 缁撴灉 - */ - @Override - public String checkPostCodeUnique(SysPost post) - { - Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); - SysPost info = postMapper.checkPostCodeUnique(post.getPostCode()); - if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) - { - return UserConstants.NOT_UNIQUE; - } - return UserConstants.UNIQUE; - } - - /** - * 閫氳繃宀椾綅ID鏌ヨ宀椾綅浣跨敤鏁伴噺 - * - * @param postId 宀椾綅ID - * @return 缁撴灉 - */ - @Override - public int countUserPostById(Long postId) - { - return userPostMapper.countUserPostById(postId); - } - - /** - * 鍒犻櫎宀椾綅淇℃伅 - * - * @param postId 宀椾綅ID - * @return 缁撴灉 - */ - @Override - public int deletePostById(Long postId) - { - return postMapper.deletePostById(postId); - } - - /** - * 鎵归噺鍒犻櫎宀椾綅淇℃伅 - * - * @param postIds 闇�瑕佸垹闄ょ殑宀椾綅ID - * @return 缁撴灉 - * @throws Exception 寮傚父 - */ - @Override - public int deletePostByIds(Long[] postIds) - { - for (Long postId : postIds) - { - SysPost post = selectPostById(postId); - if (countUserPostById(postId) > 0) - { - throw new CustomException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", post.getPostName())); - } - } - return postMapper.deletePostByIds(postIds); - } - - /** - * 鏂板淇濆瓨宀椾綅淇℃伅 - * - * @param post 宀椾綅淇℃伅 - * @return 缁撴灉 - */ - @Override - public int insertPost(SysPost post) - { - return postMapper.insertPost(post); - } - - /** - * 淇敼淇濆瓨宀椾綅淇℃伅 - * - * @param post 宀椾綅淇℃伅 - * @return 缁撴灉 - */ - @Override - public int updatePost(SysPost post) - { - return postMapper.updatePost(post); - } -} +package com.ruoyi.system.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.ruoyi.common.constant.UserConstants; +import com.ruoyi.common.core.domain.PageQuery; +import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.system.domain.SysPost; +import com.ruoyi.system.domain.SysUserPost; +import com.ruoyi.system.mapper.SysPostMapper; +import com.ruoyi.system.mapper.SysUserPostMapper; +import com.ruoyi.system.service.ISysPostService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; + +/** + * 宀椾綅淇℃伅 鏈嶅姟灞傚鐞� + * + * @author Lion Li + */ +@Service +public class SysPostServiceImpl extends ServicePlusImpl<SysPostMapper, SysPost, SysPost> implements ISysPostService { + + @Autowired + private 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 = page(pageQuery.build(), lqw); + return TableDataInfo.build(page); + } + + /** + * 鏌ヨ宀椾綅淇℃伅闆嗗悎 + * + * @param post 宀椾綅淇℃伅 + * @return 宀椾綅淇℃伅闆嗗悎 + */ + @Override + public List<SysPost> selectPostList(SysPost post) { + return list(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())); + } + + /** + * 鏌ヨ鎵�鏈夊矖浣� + * + * @return 宀椾綅鍒楄〃 + */ + @Override + public List<SysPost> selectPostAll() { + return list(); + } + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 瑙掕壊瀵硅薄淇℃伅 + */ + @Override + public SysPost selectPostById(Long postId) { + return getById(postId); + } + + /** + * 鏍规嵁鐢ㄦ埛ID鑾峰彇宀椾綅閫夋嫨妗嗗垪琛� + * + * @param userId 鐢ㄦ埛ID + * @return 閫変腑宀椾綅ID鍒楄〃 + */ + @Override + public List<Long> selectPostListByUserId(Long userId) { + return baseMapper.selectPostListByUserId(userId); + } + + /** + * 鏍¢獙宀椾綅鍚嶇О鏄惁鍞竴 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkPostNameUnique(SysPost post) { + Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); + long count = count(new LambdaQueryWrapper<SysPost>() + .eq(SysPost::getPostName, post.getPostName()) + .ne(SysPost::getPostId, postId)); + if (count > 0) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 鏍¢獙宀椾綅缂栫爜鏄惁鍞竴 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public String checkPostCodeUnique(SysPost post) { + Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId(); + long count = count(new LambdaQueryWrapper<SysPost>() + .eq(SysPost::getPostCode, post.getPostCode()) + .ne(SysPost::getPostId, postId)); + if (count > 0) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 閫氳繃宀椾綅ID鏌ヨ宀椾綅浣跨敤鏁伴噺 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + @Override + public long countUserPostById(Long postId) { + return userPostMapper.selectCount(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getPostId, postId)); + } + + /** + * 鍒犻櫎宀椾綅淇℃伅 + * + * @param postId 宀椾綅ID + * @return 缁撴灉 + */ + @Override + public int deletePostById(Long postId) { + return baseMapper.deleteById(postId); + } + + /** + * 鎵归噺鍒犻櫎宀椾綅淇℃伅 + * + * @param postIds 闇�瑕佸垹闄ょ殑宀椾綅ID + * @return 缁撴灉 + * @throws Exception 寮傚父 + */ + @Override + public int deletePostByIds(Long[] postIds) { + for (Long postId : postIds) { + SysPost post = selectPostById(postId); + if (countUserPostById(postId) > 0) { + throw new ServiceException(String.format("%1$s宸插垎閰�,涓嶈兘鍒犻櫎", post.getPostName())); + } + } + return baseMapper.deleteBatchIds(Arrays.asList(postIds)); + } + + /** + * 鏂板淇濆瓨宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public int insertPost(SysPost post) { + return baseMapper.insert(post); + } + + /** + * 淇敼淇濆瓨宀椾綅淇℃伅 + * + * @param post 宀椾綅淇℃伅 + * @return 缁撴灉 + */ + @Override + public int updatePost(SysPost post) { + return baseMapper.updateById(post); + } +} -- Gitblit v1.9.3