| | |
| | | import com.emergencyrepair.business.mapper.TeamMajorMapper; |
| | | import com.emergencyrepair.common.BusinessException; |
| | | import com.emergencyrepair.system.entity.SysMenu; |
| | | import com.emergencyrepair.system.entity.SysErrorLog; |
| | | import com.emergencyrepair.system.entity.SysLoginLog; |
| | | import com.emergencyrepair.system.entity.SysOperationLog; |
| | | import com.emergencyrepair.system.entity.SysRole; |
| | |
| | | import com.emergencyrepair.system.entity.SysRoleUser; |
| | | import com.emergencyrepair.system.entity.SysTenantMenu; |
| | | import com.emergencyrepair.system.mapper.SysMenuMapper; |
| | | import com.emergencyrepair.system.mapper.SysErrorLogMapper; |
| | | import com.emergencyrepair.system.mapper.SysLoginLogMapper; |
| | | import com.emergencyrepair.system.mapper.SysOperationLogMapper; |
| | | import com.emergencyrepair.system.mapper.SysRoleMapper; |
| | |
| | | private final SysRoleUserMapper roleUserMapper; |
| | | private final SysLoginLogMapper loginLogMapper; |
| | | private final SysOperationLogMapper operationLogMapper; |
| | | private final SysErrorLogMapper errorLogMapper; |
| | | private final ButtonPermissionCatalog buttonPermissionCatalog; |
| | | private final JdbcTemplate jdbcTemplate; |
| | | private final EngineeringMajorMapper engineeringMajorMapper; |
| | |
| | | menu.setMenuType(menu.getId() == null ? 1 : menu.getMenuType()); |
| | | } |
| | | boolean isRoot = menu.getPid() == null || menu.getPid() == 0L; |
| | | if (menu.getMenuType() == 2) { |
| | | if (isRoot) { |
| | | throw new BusinessException("按钮类型只能建在菜单类型下级"); |
| | | if (menu.getId() != null && !isRoot && menu.getId().equals(menu.getPid())) { |
| | | throw new BusinessException("上级菜单不能选择当前菜单"); |
| | | } |
| | | SysMenu parent = null; |
| | | if (!isRoot) { |
| | | parent = menuMapper.selectById(menu.getPid()); |
| | | if (parent == null) { |
| | | throw new BusinessException("上级菜单不存在"); |
| | | } |
| | | SysMenu parent = menuMapper.selectById(menu.getPid()); |
| | | if (menu.getId() != null && isMenuDescendant(menu.getPid(), menu.getId())) { |
| | | throw new BusinessException("上级菜单不能选择当前菜单的下级"); |
| | | } |
| | | } |
| | | if (menu.getMenuType() == 2) { |
| | | if (parent == null || parent.getMenuType() == null || parent.getMenuType() != 1) { |
| | | throw new BusinessException("按钮类型只能建在菜单类型下级"); |
| | | } |
| | |
| | | } |
| | | menu.setUrl(null); |
| | | menu.setIcon(null); |
| | | } else if (!isRoot) { |
| | | SysMenu parent = menuMapper.selectById(menu.getPid()); |
| | | if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) { |
| | | throw new BusinessException("按钮类型下级不能再建菜单"); |
| | | } |
| | | } else if (parent != null && parent.getMenuType() != null && parent.getMenuType() == 2) { |
| | | throw new BusinessException("按钮类型下级不能再建菜单"); |
| | | } |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | menu.setUpdateTime(now); |
| | |
| | | menuMapper.updateById(menu); |
| | | } |
| | | return menuMapper.selectById(menu.getId()); |
| | | } |
| | | |
| | | private boolean isMenuDescendant(Long candidateId, Long ancestorId) { |
| | | Long cursor = candidateId; |
| | | int guard = 0; |
| | | while (cursor != null && cursor != 0L && guard++ < 64) { |
| | | if (cursor.equals(ancestorId)) { |
| | | return true; |
| | | } |
| | | SysMenu current = menuMapper.selectById(cursor); |
| | | cursor = current == null ? null : current.getPid(); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | if (!StringUtils.hasText(xNo)) { |
| | | return productTreeRoots(); |
| | | } |
| | | List<ProductNode> rootNodes = productNodeMapper.selectList(Wrappers.<ProductNode>lambdaQuery() |
| | | .and(wrapper -> wrapper.isNull(ProductNode::getParentId).or().eq(ProductNode::getParentId, 0L)) |
| | | .orderByAsc(ProductNode::getSortNo).orderByAsc(ProductNode::getId)); |
| | | List<ProductNode> sideNodes = productNodeMapper.selectList(Wrappers.<ProductNode>lambdaQuery() |
| | | .in(ProductNode::getLayer, Arrays.asList("side", "SIDE")) |
| | | .eq(ProductNode::getName, xNo.trim()) |
| | | .orderByAsc(ProductNode::getSortNo).orderByAsc(ProductNode::getId)); |
| | | Map<Long, ProductNode> roots = uniqueProductNodes(rootNodes); |
| | | Map<Long, ProductNode> sides = uniqueProductNodes(sideNodes); |
| | | Set<Long> branchIds = new HashSet<>(); |
| | | branchIds.addAll(roots.keySet()); |
| | | branchIds.addAll(sides.keySet()); |
| | | Map<Long, Map<String, Object>> rootRows = new LinkedHashMap<>(); |
| | | for (ProductNode root : sortProductNodes(roots.values())) { |
| | | rootRows.put(root.getId(), mapProduct(root, branchIds)); |
| | | } |
| | | for (ProductNode side : sortProductNodes(sides.values())) { |
| | | ProductNode root = findProductRoot(side); |
| | | Map<String, Object> rootRow = root == null ? null : rootRows.get(root.getId()); |
| | | if (rootRow != null) { |
| | | children(rootRow).add(mapProduct(side, branchIds)); |
| | | } |
| | | } |
| | | return new ArrayList<>(rootRows.values()); |
| | | return mapProductTreeNodes(sideNodes, Collections.emptySet()); |
| | | } |
| | | |
| | | public List<String> productXNumbers() { |
| | |
| | | } |
| | | } |
| | | final Set<Long> allowedIds = allowed; |
| | | Set<Long> visibleIds = new LinkedHashSet<>(expandWithAncestors(new ArrayList<>(allowed))); |
| | | List<SysMenu> navigable = listMenus().stream() |
| | | .filter(menu -> menu.getMenuType() == null || menu.getMenuType() != 2) |
| | | .filter(menu -> allowedIds.contains(menu.getId())) |
| | | .filter(menu -> visibleIds.contains(menu.getId())) |
| | | .collect(Collectors.toList()); |
| | | return buildTree(navigable); |
| | | } |
| | |
| | | return operationLogMapper.selectPage(page, wrapper); |
| | | } |
| | | |
| | | public Page<SysErrorLog> errorLogPage(int current, int size, String keyword, String module, String exceptionType, String startDate, String endDate) { |
| | | Page<SysErrorLog> page = new Page<>(current <= 0 ? 1 : current, size <= 0 ? 20 : size); |
| | | LambdaQueryWrapper<SysErrorLog> wrapper = Wrappers.lambdaQuery(); |
| | | wrapper.select(SysErrorLog::getId, SysErrorLog::getUserId, SysErrorLog::getUserName, |
| | | SysErrorLog::getNickName, SysErrorLog::getModule, SysErrorLog::getRequestMethod, |
| | | SysErrorLog::getRequestUri, SysErrorLog::getExceptionType, SysErrorLog::getMessage, |
| | | SysErrorLog::getErrorTime); |
| | | if (StringUtils.hasText(keyword)) { |
| | | String value = keyword.trim(); |
| | | wrapper.and(item -> item.like(SysErrorLog::getUserName, value) |
| | | .or().like(SysErrorLog::getNickName, value) |
| | | .or().like(SysErrorLog::getRequestUri, value) |
| | | .or().like(SysErrorLog::getExceptionType, value) |
| | | .or().like(SysErrorLog::getMessage, value)); |
| | | } |
| | | if (StringUtils.hasText(module)) { |
| | | wrapper.eq(SysErrorLog::getModule, module.trim()); |
| | | } |
| | | if (StringUtils.hasText(exceptionType)) { |
| | | wrapper.like(SysErrorLog::getExceptionType, exceptionType.trim()); |
| | | } |
| | | LocalDateTime start = parseStart(startDate); |
| | | LocalDateTime end = parseEnd(endDate); |
| | | if (start != null) { |
| | | wrapper.ge(SysErrorLog::getErrorTime, start); |
| | | } |
| | | if (end != null) { |
| | | wrapper.le(SysErrorLog::getErrorTime, end); |
| | | } |
| | | wrapper.orderByDesc(SysErrorLog::getErrorTime); |
| | | return errorLogMapper.selectPage(page, wrapper); |
| | | } |
| | | |
| | | public SysErrorLog errorLog(Long id) { |
| | | SysErrorLog log = errorLogMapper.selectById(id); |
| | | if (log == null) { |
| | | throw new BusinessException("错误日志不存在"); |
| | | } |
| | | return log; |
| | | } |
| | | |
| | | public Long resolveUserId(String username) { |
| | | if (!StringUtils.hasText(username)) { |
| | | return null; |