|  |  | 
 |  |  | 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.groupMenu.GroupMenuDTO; | 
 |  |  | import com.moral.api.pojo.dto.groupMenu.GroupMenuQueryDTO; | 
 |  |  | import com.moral.api.pojo.form.groupMenu.GroupMenuQueryForm; | 
 |  |  | import com.moral.api.pojo.form.groupMenu.GroupMenuUpdateForm; | 
 |  |  | import com.moral.api.service.GroupMenuService; | 
 |  |  | 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.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * <p> | 
 |  |  | 
 |  |  |  */ | 
 |  |  | @Service | 
 |  |  | public class GroupMenuServiceImpl extends ServiceImpl<GroupMenuMapper, GroupMenu> implements GroupMenuService { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     GroupMenuMapper groupMenuMapper; | 
 |  |  |     @Autowired | 
 |  |  |     GroupMapper groupMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     @Transactional | 
 |  |  |     public GroupMenuDTO updateGroupMenu(GroupMenuUpdateForm form) { | 
 |  |  |         //创建返回对象 | 
 |  |  |         GroupMenuDTO dto = new GroupMenuDTO(); | 
 |  |  |         //取参 | 
 |  |  |         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; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public GroupMenuQueryDTO queryGroupMenu(GroupMenuQueryForm form) { | 
 |  |  |         //创建返回对象 | 
 |  |  |         GroupMenuQueryDTO dto = new GroupMenuQueryDTO(); | 
 |  |  |         //取参 | 
 |  |  |         Integer organizationId = form.getOrganizationId(); | 
 |  |  |         //查询组织admin角色 | 
 |  |  |         Group group = queryAdminGroupByOrganizationId(organizationId); | 
 |  |  |         if (ObjectUtils.isEmpty(group)) {//如果没有角色则证明组织还没有账号 | 
 |  |  |             dto.setCode(ResponseCodeEnum.ORGANIZATION_USER_NOT_EXIST.getCode()); | 
 |  |  |             dto.setMsg(ResponseCodeEnum.ORGANIZATION_USER_NOT_EXIST.getMsg()); | 
 |  |  |             return dto; | 
 |  |  |         } | 
 |  |  |         //根据角色查询对应的所有菜单 | 
 |  |  |         QueryWrapper<GroupMenu> queryGroupMenuWrapper = new QueryWrapper<>(); | 
 |  |  |         queryGroupMenuWrapper.eq("group_id", group.getId()); | 
 |  |  |         queryGroupMenuWrapper.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         List<GroupMenu> groupMenus = groupMenuMapper.selectList(queryGroupMenuWrapper); | 
 |  |  |         //封装返回结果 | 
 |  |  |         List<GroupMenuDTO> dtos = new ArrayList<>(); | 
 |  |  |         for (GroupMenu groupMenu : groupMenus) { | 
 |  |  |             GroupMenuDTO groupMenuDTO = new GroupMenuDTO(); | 
 |  |  |             groupMenuDTO.setGroupMenu(groupMenu); | 
 |  |  |             dtos.add(groupMenuDTO); | 
 |  |  |         } | 
 |  |  |         dto.setDtos(dtos); | 
 |  |  |         dto.setCode(ResponseCodeEnum.SUCCESS.getCode()); | 
 |  |  |         dto.setMsg(ResponseCodeEnum.SUCCESS.getMsg()); | 
 |  |  |         return dto; | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     private 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); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  | } |