| package com.moral.api.service.impl; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
| import com.moral.api.entity.Group; | 
| import com.moral.api.entity.GroupMenu; | 
| import com.moral.api.mapper.GroupMapper; | 
| import com.moral.api.mapper.GroupMenuMapper; | 
| import com.moral.api.pojo.dto.group.GroupDTO; | 
| import com.moral.api.pojo.form.group.AdminGroupUpdateMenuForm; | 
| import com.moral.api.service.GroupService; | 
| import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
| import com.moral.constant.Constants; | 
| import com.moral.constant.ResponseCodeEnum; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.transaction.annotation.Transactional; | 
| import org.springframework.util.ObjectUtils; | 
|   | 
| import java.util.List; | 
|   | 
| /** | 
|  * <p> | 
|  * 用户自定义角色表 服务实现类 | 
|  * </p> | 
|  * | 
|  * @author moral | 
|  * @since 2021-03-09 | 
|  */ | 
| @Service | 
| public class GroupServiceImpl extends ServiceImpl<GroupMapper, Group> implements GroupService { | 
|   | 
|     @Autowired | 
|     GroupMapper groupMapper; | 
|     @Autowired | 
|     GroupMenuMapper groupMenuMapper; | 
|   | 
|     @Override | 
|     public Group queryAdminGroupByOrganizationId(Integer OrganizationId) { | 
|         QueryWrapper<Group> queryGroupWrapper = new QueryWrapper<>(); | 
|         Group groupConditon = new Group(); | 
|         groupConditon.setOrganizationId(OrganizationId); | 
|         groupConditon.setGroupName("admin"); | 
|         groupConditon.setIsDelete(Constants.NOT_DELETE); | 
|         queryGroupWrapper.setEntity(groupConditon); | 
|         return groupMapper.selectOne(queryGroupWrapper); | 
|     } | 
|   | 
|     @Override | 
|     @Transactional | 
|     public GroupDTO updateAdminGroupMenu(AdminGroupUpdateMenuForm form) { | 
|         //创建返回对象 | 
|         GroupDTO dto = new GroupDTO(); | 
|         //取参 | 
|         Integer orgId = form.getOrganizationId(); | 
|         String channelKey = form.getChannelKey(); | 
|         List<Integer> insertMenuIds = form.getMenuIds(); | 
|         //根据orgId查询组织admin角色id | 
|         Group group = queryAdminGroupByOrganizationId(orgId); | 
|         if (ObjectUtils.isEmpty(group)) {//如果没有角色则证明组织还没有账号 | 
|             dto.setCode(ResponseCodeEnum.ORGANIZATION_USER_NOT_EXIST.getCode()); | 
|             dto.setMsg(ResponseCodeEnum.ORGANIZATION_USER_NOT_EXIST.getMsg()); | 
|             return dto; | 
|         } | 
|         //删除角色当前所有的菜单 | 
|         UpdateWrapper deleteWrapper = new UpdateWrapper(); | 
|         deleteWrapper.set("is_delete", Constants.DELETE); | 
|         deleteWrapper.eq("group_id", group.getId()); | 
|         groupMenuMapper.update(null, deleteWrapper); | 
|         //重新添加 | 
|         for (Integer menuId : insertMenuIds) { | 
|             GroupMenu groupMenu = new GroupMenu(); | 
|             groupMenu.setChannelKey(channelKey); | 
|             groupMenu.setGroupId(group.getId()); | 
|             groupMenu.setMenuId(menuId); | 
|             groupMenu.setOrganizationId(orgId); | 
|             groupMenuMapper.insert(groupMenu); | 
|         } | 
|         //封装返回对象 | 
|         dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
|         dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
|         return dto; | 
|     } | 
| } |