|  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | import java.util.Objects; | 
 |  |  |  | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
 |  |  | import com.moral.api.entity.GroupMenu; | 
 |  |  | import com.moral.api.mapper.GroupMapper; | 
 |  |  | import com.moral.api.mapper.GroupMenuMapper; | 
 |  |  | import com.moral.api.mapper.MenuMapper; | 
 |  |  | import com.moral.api.service.GroupMenuService; | 
 |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
 |  |  | import com.moral.api.utils.OperationLogUtils; | 
 |  |  | import com.moral.constant.Constants; | 
 |  |  | import com.moral.util.TokenUtils; | 
 |  |  |  | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.util.ObjectUtils; | 
 |  |  | import org.springframework.web.context.request.RequestContextHolder; | 
 |  |  | import org.springframework.web.context.request.ServletRequestAttributes; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletRequest; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * <p> | 
 |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private GroupMenuMapper groupMenuMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private GroupMapper groupMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private MenuMapper menuMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private OperationLogUtils operationLogUtils; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public void allotMenus(Map<String, Object> parameters, String token) { | 
 |  |  |     @Transactional | 
 |  |  |     public void allotMenus(Map<String, Object> parameters) { | 
 |  |  |         Integer groupId = Integer.parseInt(parameters.get("groupId").toString()); | 
 |  |  |         List<Integer> menuIds = (ArrayList) parameters.get("menuIds"); | 
 |  |  |         Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); | 
 |  |  |         Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfo(); | 
 |  |  |         Map<String, Object> orgInfo = (Map<String, Object>) currentUserInfo.get("organization"); | 
 |  |  |         UpdateWrapper<GroupMenu> deleteWrapper = new UpdateWrapper<>(); | 
 |  |  |         deleteWrapper.set("is_delete", Constants.DELETE) | 
 |  |  |                 .eq("group_id", groupId) | 
 |  |  |                 .eq("channel", Constants.WEB_CHANNEL); | 
 |  |  |         groupMenuMapper.update(null, deleteWrapper); | 
 |  |  |         if (!menuIds.isEmpty()) { | 
 |  |  |             for (Integer menuId : menuIds) { | 
 |  |  |         deleteWrapper.eq("group_id", groupId).eq("channel_key", Constants.WEB_CHANNEL); | 
 |  |  |         groupMenuMapper.delete(deleteWrapper); | 
 |  |  |         List<String> menus = new ArrayList<>(); | 
 |  |  |         if (!ObjectUtils.isEmpty(menuIds)) { | 
 |  |  |             menuIds.forEach(menuId -> { | 
 |  |  |                 menus.add(menuMapper.selectById(menuId).getName()); | 
 |  |  |                 GroupMenu groupMenu = new GroupMenu(); | 
 |  |  |                 groupMenu.setGroupId(groupId); | 
 |  |  |                 groupMenu.setMenuId(menuId); | 
 |  |  |                 groupMenu.setChannel(Constants.WEB_CHANNEL); | 
 |  |  |                 groupMenu.setOrganizationId((Integer) currentUserInfo.get("organizationId")); | 
 |  |  |                 groupMenu.setChannelKey(Constants.WEB_CHANNEL); | 
 |  |  |                 groupMenu.setOrganizationId((Integer) orgInfo.get("id")); | 
 |  |  |                 groupMenuMapper.insert(groupMenu); | 
 |  |  |             } | 
 |  |  |             }); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         //日志 | 
 |  |  |         String groupName = groupMapper.selectById((Integer) parameters.get("groupId")).getGroupName(); | 
 |  |  |         String content = "给组:" + groupName + "分配了菜单:" + menus; | 
 |  |  |         operationLogUtils.insertLog(content, Constants.UPDATE_OPERATE_TYPE); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<Integer> getMenusIds(Integer groupId) { | 
 |  |  |         QueryWrapper<GroupMenu> queryWrapper = new QueryWrapper<>(); | 
 |  |  |         queryWrapper.eq("group_id", groupId).eq("is_delete", Constants.NOT_DELETE); | 
 |  |  |         List<GroupMenu> groupMenus = groupMenuMapper.selectList(queryWrapper); | 
 |  |  |         List<Integer> menuIds = new ArrayList<>(); | 
 |  |  |         groupMenus.forEach(groupMenu -> menuIds.add(groupMenu.getMenuId())); | 
 |  |  |         return menuIds; | 
 |  |  |     } | 
 |  |  | } |