|  |  | 
 |  |  | 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.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.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(); | 
 |  |  |         Integer channel = form.getChannel(); | 
 |  |  |         List<Integer> insertMenuIds = form.getMenuIds(); | 
 |  |  |         //根据orgId查询组织admin角色id | 
 |  |  |         QueryWrapper<Group> queryGroupWrapper = new QueryWrapper<>(); | 
 |  |  |         Group groupConditon = new Group(); | 
 |  |  |         groupConditon.setOrganizationId(orgId); | 
 |  |  |         groupConditon.setGroupName("admin"); | 
 |  |  |         groupConditon.setIsDelete(Constants.NOT_DELETE); | 
 |  |  |         queryGroupWrapper.setEntity(groupConditon); | 
 |  |  |         Group group = groupMapper.selectOne(queryGroupWrapper); | 
 |  |  |         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.setChannel(channel); | 
 |  |  |             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; | 
 |  |  |     } | 
 |  |  | } |