| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import cn.hutool.core.lang.Validator; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.constant.UserConstants; |
| | | import com.ruoyi.common.core.mybatisplus.core.ServicePlusImpl; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.exception.CustomException; |
| | | import com.ruoyi.common.utils.PageUtils; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.UserConstants; |
| | | 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.mapper.SysPostMapper; |
| | | import com.ruoyi.system.mapper.SysUserPostMapper; |
| | | import com.ruoyi.system.service.ISysPostService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Arrays; |
| | |
| | | /** |
| | | * 岗位信息 服务层处理 |
| | | * |
| | | * @author ruoyi |
| | | * @author Lion Li |
| | | */ |
| | | @RequiredArgsConstructor |
| | | @Service |
| | | public class SysPostServiceImpl extends ServicePlusImpl<SysPostMapper, SysPost, SysPost> implements ISysPostService { |
| | | public class SysPostServiceImpl implements ISysPostService { |
| | | |
| | | @Autowired |
| | | private SysUserPostMapper userPostMapper; |
| | | private final SysPostMapper baseMapper; |
| | | private final SysUserPostMapper userPostMapper; |
| | | |
| | | @Override |
| | | public TableDataInfo<SysPost> selectPagePostList(SysPost post) { |
| | | public TableDataInfo<SysPost> selectPagePostList(SysPost post, PageQuery pageQuery) { |
| | | LambdaQueryWrapper<SysPost> lqw = new LambdaQueryWrapper<SysPost>() |
| | | .like(StrUtil.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) |
| | | .eq(StrUtil.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) |
| | | .like(StrUtil.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName()); |
| | | return PageUtils.buildDataInfo(page(PageUtils.buildPage(),lqw)); |
| | | .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); |
| | | return TableDataInfo.build(page); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<SysPost> selectPostList(SysPost post) { |
| | | return list(new LambdaQueryWrapper<SysPost>() |
| | | .like(StrUtil.isNotBlank(post.getPostCode()), SysPost::getPostCode, post.getPostCode()) |
| | | .eq(StrUtil.isNotBlank(post.getStatus()), SysPost::getStatus, post.getStatus()) |
| | | .like(StrUtil.isNotBlank(post.getPostName()), SysPost::getPostName, post.getPostName())); |
| | | 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())); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<SysPost> selectPostAll() { |
| | | return list(); |
| | | return baseMapper.selectList(); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SysPost selectPostById(Long postId) { |
| | | return getById(postId); |
| | | return baseMapper.selectById(postId); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return 选中岗位ID列表 |
| | | */ |
| | | @Override |
| | | public List<Integer> selectPostListByUserId(Long userId) { |
| | | public List<Long> selectPostListByUserId(Long userId) { |
| | | return baseMapper.selectPostListByUserId(userId); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public String checkPostNameUnique(SysPost post) { |
| | | Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | SysPost info = getOne(new LambdaQueryWrapper<SysPost>() |
| | | .eq(SysPost::getPostName, post.getPostName()).last("limit 1")); |
| | | if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { |
| | | 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; |
| | |
| | | */ |
| | | @Override |
| | | public String checkPostCodeUnique(SysPost post) { |
| | | Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId(); |
| | | SysPost info = getOne(new LambdaQueryWrapper<SysPost>() |
| | | .eq(SysPost::getPostCode, post.getPostCode()).last("limit 1")); |
| | | if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) { |
| | | 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 结果 |
| | | */ |
| | | @Override |
| | | public int countUserPostById(Long postId) { |
| | | return userPostMapper.selectCount(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getPostId,postId)); |
| | | public long countUserPostById(Long postId) { |
| | | return userPostMapper.selectCount(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getPostId, 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())); |
| | | throw new ServiceException(String.format("%1$s已分配,不能删除", post.getPostName())); |
| | | } |
| | | } |
| | | return baseMapper.deleteBatchIds(Arrays.asList(postIds)); |