jinpengyong
2021-03-18 db4acf4c8a81435d77a97f0aed4efc58d7799e8d
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
package com.moral.api.service.impl;
 
import java.util.HashMap;
import java.util.Map;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Group;
import com.moral.api.entity.User;
import com.moral.api.mapper.GroupMapper;
import com.moral.api.mapper.UserMapper;
import com.moral.api.service.GroupService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
/**
 * <p>
 * 用户自定义角色表 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-03-09
 */
@Service
public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService {
 
    @Autowired
    private GroupMapper groupMapper;
 
    @Autowired
    private UserMapper userMapper;
 
    @Override
    public Map<String, Object> addGroup(Group group, String currentUserId) {
        Map<String, Object> resultMap = new HashMap<>();
        User currentUser = userMapper.selectById(currentUserId);
        if (!currentUser.getIsAdmin()) {
            resultMap.put("flag", false);
            resultMap.put("msg", "添加失败,没有权限");
            return resultMap;
        }
        Integer orgId = currentUser.getOrganizationId();
        QueryWrapper<Group> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("group_name", group.getGroupName()).eq("organization_id", orgId);
        if (groupMapper.selectOne(queryWrapper) == null) {
            group.setOrganizationId(orgId);
            groupMapper.insert(group);
            resultMap.put("flag", true);
            resultMap.put("msg", "添加成功");
        } else {
            resultMap.put("flag", false);
            resultMap.put("msg", "添加失败,组已存在");
        }
        return resultMap;
    }
}