| | |
| | | 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.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; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void allotMenus(Map<String, Object> parameters, String token) { |
| | | public void allotMenus(Map<String, Object> parameters) { |
| | | HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest(); |
| | | String token = request.getHeader("token"); |
| | | |
| | | 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> 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); |
| | | deleteWrapper.eq("group_id", groupId).eq("channel", Constants.WEB_CHANNEL); |
| | | groupMenuMapper.delete(deleteWrapper); |
| | | List<String> menus = new ArrayList<>(); |
| | | if (menuIds != null && !menuIds.isEmpty()) { |
| | | for (Integer menuId : 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) orgInfo.get("id")); |
| | | groupMenuMapper.insert(groupMenu); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | | //日志 |
| | | String groupName = groupMapper.selectById((Integer) parameters.get("groupId")).getGroupName(); |
| | | String content = "给组:" + groupName + "分配了菜单:" + menus.toString(); |
| | | OperationLogUtils.insertLog(request, content, Constants.UPDATE_OPERATE_TYPE); |
| | | } |
| | | |
| | | @Override |
| | |
| | | queryWrapper.eq("group_id", groupId).eq("is_delete", Constants.NOT_DELETE); |
| | | List<GroupMenu> groupMenus = groupMenuMapper.selectList(queryWrapper); |
| | | List<Integer> menuIds = new ArrayList<>(); |
| | | for (GroupMenu groupMenu : groupMenus) { |
| | | menuIds.add(groupMenu.getMenuId()); |
| | | } |
| | | groupMenus.forEach(groupMenu -> menuIds.add(groupMenu.getMenuId())); |
| | | return menuIds; |
| | | } |
| | | } |