疯狂的狮子li
2021-10-15 a6fb88d74c20cc28043d75e8a5097fce49cf9a78
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysPostServiceImpl.java
@@ -1,30 +1,42 @@
package com.ruoyi.system.service.impl;
import cn.hutool.core.lang.Validator;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.exception.CustomException;
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.PageUtils;
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 ruoyi
 * @author Lion Li
 */
@Service
public class SysPostServiceImpl extends ServiceImpl<SysPostMapper, SysPost> implements ISysPostService {
    @Autowired
    private SysPostMapper postMapper;
public class SysPostServiceImpl extends ServicePlusImpl<SysPostMapper, SysPost, SysPost> implements ISysPostService {
    @Autowired
    private SysUserPostMapper userPostMapper;
    @Override
    public TableDataInfo<SysPost> selectPagePostList(SysPost post) {
        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());
        return PageUtils.buildDataInfo(page(PageUtils.buildPage(), lqw));
    }
    /**
     * 查询岗位信息集合
@@ -34,7 +46,10 @@
     */
    @Override
    public List<SysPost> selectPostList(SysPost post) {
        return postMapper.selectPostList(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()));
    }
    /**
@@ -44,7 +59,7 @@
     */
    @Override
    public List<SysPost> selectPostAll() {
        return postMapper.selectPostAll();
        return list();
    }
    /**
@@ -55,7 +70,7 @@
     */
    @Override
    public SysPost selectPostById(Long postId) {
        return postMapper.selectPostById(postId);
        return getById(postId);
    }
    /**
@@ -66,7 +81,7 @@
     */
    @Override
    public List<Integer> selectPostListByUserId(Long userId) {
        return postMapper.selectPostListByUserId(userId);
        return baseMapper.selectPostListByUserId(userId);
    }
    /**
@@ -77,9 +92,10 @@
     */
    @Override
    public String checkPostNameUnique(SysPost post) {
        Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId();
        SysPost info = postMapper.checkPostNameUnique(post.getPostName());
        if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
        Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
        SysPost info = getOne(new LambdaQueryWrapper<SysPost>()
                .eq(SysPost::getPostName, post.getPostName()).last("limit 1"));
        if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
@@ -93,9 +109,10 @@
     */
    @Override
    public String checkPostCodeUnique(SysPost post) {
        Long postId = Validator.isNull(post.getPostId()) ? -1L : post.getPostId();
        SysPost info = postMapper.checkPostCodeUnique(post.getPostCode());
        if (Validator.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
        Long postId = StringUtils.isNull(post.getPostId()) ? -1L : post.getPostId();
        SysPost info = getOne(new LambdaQueryWrapper<SysPost>()
                .eq(SysPost::getPostCode, post.getPostCode()).last("limit 1"));
        if (StringUtils.isNotNull(info) && info.getPostId().longValue() != postId.longValue()) {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
@@ -108,8 +125,8 @@
     * @return 结果
     */
    @Override
    public int countUserPostById(Long postId) {
        return userPostMapper.countUserPostById(postId);
    public long countUserPostById(Long postId) {
        return userPostMapper.selectCount(new LambdaQueryWrapper<SysUserPost>().eq(SysUserPost::getPostId, postId));
    }
    /**
@@ -120,7 +137,7 @@
     */
    @Override
    public int deletePostById(Long postId) {
        return postMapper.deletePostById(postId);
        return baseMapper.deleteById(postId);
    }
    /**
@@ -135,10 +152,10 @@
        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 postMapper.deletePostByIds(postIds);
        return baseMapper.deleteBatchIds(Arrays.asList(postIds));
    }
    /**
@@ -149,7 +166,7 @@
     */
    @Override
    public int insertPost(SysPost post) {
        return postMapper.insertPost(post);
        return baseMapper.insert(post);
    }
    /**
@@ -160,6 +177,6 @@
     */
    @Override
    public int updatePost(SysPost post) {
        return postMapper.updatePost(post);
        return baseMapper.updateById(post);
    }
}