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;
/**
*
* 用户自定义角色表 服务实现类
*
*
* @author moral
* @since 2021-03-09
*/
@Service
public class GroupServiceImpl extends ServiceImpl implements GroupService {
@Autowired
private GroupMapper groupMapper;
@Autowired
private UserMapper userMapper;
@Override
public Map addGroup(Group group, String currentUserId) {
Map 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 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;
}
}