ludc
2023-12-26 ff15fb3ec4e29dc0ddcddfda711209831fd2ac59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package com.vci.ubcs.system.service.impl;
 
import cn.hutool.db.ds.pooled.ConnectionWraper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vci.ubcs.system.entity.ClassifyAuth;
import com.vci.ubcs.system.mapper.ClassifyAuthMapper;
import com.vci.ubcs.system.service.IClassifyAuthService;
import com.vci.ubcs.system.vo.ClassifyAuthVO;
import com.vci.ubcs.system.wrapper.ClassifyAuthWrapper;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.redisson.api.condition.Conditions;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 分类授权
 * @author ludc
 * @date 2023/12/25 15:35
 */
@Service
@AllArgsConstructor
public class ClassifyAuthServiceImpl extends ServiceImpl<ClassifyAuthMapper,ClassifyAuth> implements IClassifyAuthService {
 
    private final ClassifyAuthMapper classifyAuthMapper;
 
    /**
     * 分类授权保存接口
     * @param classifyAuthList
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R submit(List<ClassifyAuth> classifyAuthList) {
        if(classifyAuthList.isEmpty()){
            R.fail("授权列表不能为空!");
        }
        // 如果传过来的集合中该分类id下删除了部分角色的授权,就需要将该库中classifyId下不存在的数据删掉
        List<String> roleIds = classifyAuthList.stream().map(ClassifyAuth::getRoleId).collect(Collectors.toList());
        // 删除
        LambdaUpdateWrapper<ClassifyAuth> updateWrapper = Wrappers.<ClassifyAuth>update()
            .lambda().eq(ClassifyAuth::getClassifyId, classifyAuthList.get(0).getClassifyId())
            .notIn(ClassifyAuth::getRoleId, roleIds);
        try {
            this.classifyAuthMapper.delete(updateWrapper);
        }catch (Exception e){
            throw new ServiceException("分类授权过程中出现错误,错误原因:"+e.getMessage());
        }
        return R.status(saveOrUpdateBatch(classifyAuthList));
    }
 
    /**
     * 获取分类授权集合
     * @param classifyAuthVO
     * @return
     */
    @Override
    public List<ClassifyAuthVO> getClassifyAuthList(ClassifyAuthVO classifyAuthVO) {
        if(Func.isBlank(classifyAuthVO.getClassifyId())){
            throw new ServiceException("缺少必传参数分类id");
        }
        LambdaQueryWrapper<ClassifyAuth> wrapper = Wrappers.<ClassifyAuth>query()
            .lambda().eq(ClassifyAuth::getClassifyId,classifyAuthVO.getClassifyId());
        List<ClassifyAuth> classifyAuths = this.classifyAuthMapper.selectList(wrapper);
        if(!classifyAuths.isEmpty()){
            return ClassifyAuthWrapper.build().listVO(classifyAuths);
        }
        return new ArrayList<ClassifyAuthVO>();
    }
 
}