| | |
| | | import com.zy.asrs.entity.AppVersion; |
| | | import com.zy.asrs.service.AppVersionService; |
| | | import com.zy.common.web.BaseController; |
| | | import com.zy.system.entity.Permission; |
| | | import com.zy.system.entity.RolePermission; |
| | | import com.zy.system.service.PermissionService; |
| | | import com.zy.system.service.RolePermissionService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.util.ClassUtils; |
| | |
| | | import java.io.*; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @RestController |
| | | public class AppVersionController extends BaseController { |
| | | |
| | | @Autowired |
| | | private PermissionService permissionService; |
| | | @Autowired |
| | | private RolePermissionService rolePermissionService; |
| | | @Autowired |
| | | private AppVersionService appVersionService; |
| | | |
| | |
| | | public R checkUpdate(@PathVariable("version") String version, |
| | | @PathVariable("type") Integer type) { |
| | | EntityWrapper<AppVersion> wrapper = new EntityWrapper<>(); |
| | | wrapper.eq("type", type); |
| | | AppVersion appVersion = appVersionService.selectOne(wrapper); |
| | | if (Cools.isEmpty(appVersion)) { |
| | | return R.ok("已是最新版本"); |
| | |
| | | response.setStatus(404); |
| | | } |
| | | } |
| | | @RequestMapping("/menu/pda/auth") |
| | | @ManagerAuth |
| | | public R menuPda(){ |
| | | // 直接从 sys_permission 表读取所有菜单,不检查权限分配 |
| | | // 查询所有状态为1(正常)的权限 |
| | | List<Permission> permissions = permissionService.selectList( |
| | | new EntityWrapper<Permission>() |
| | | .eq("status", 1) // 只返回正常状态的权限 |
| | | ); |
| | | |
| | | // 检查是否有层级结构(父菜单:action为空字符串,子菜单:resource_id指向父菜单的permission.id) |
| | | // 查询所有父菜单(action为空字符串的权限) |
| | | List<Permission> parentMenus = permissions.stream() |
| | | .filter(p -> p.getAction() == null || p.getAction().isEmpty()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 收集所有父菜单ID(用于过滤独立菜单) |
| | | java.util.Set<Long> parentMenuIds = parentMenus.stream() |
| | | .map(Permission::getId) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | if (!parentMenus.isEmpty()) { |
| | | // 构建层级结构 |
| | | List<Map<String, Object>> result = new ArrayList<>(); |
| | | |
| | | for (Permission parentMenu : parentMenus) { |
| | | // 查找该父菜单下的子菜单 |
| | | // 方式1:resource_id指向父菜单的id |
| | | // 方式2:resource_id为0或null,但根据action路径匹配父菜单 |
| | | List<Permission> children = permissions.stream() |
| | | .filter(p -> { |
| | | // 排除父菜单本身 |
| | | if (p.getAction() == null || p.getAction().isEmpty()) { |
| | | return false; |
| | | } |
| | | // 方式1:resource_id指向父菜单的id |
| | | if (p.getResourceId() != null && p.getResourceId().equals(parentMenu.getId())) { |
| | | return true; |
| | | } |
| | | // 方式2:resource_id为0或null,根据action路径匹配 |
| | | if ((p.getResourceId() == null || p.getResourceId() == 0)) { |
| | | String action = p.getAction(); |
| | | String parentName = parentMenu.getName(); |
| | | // 根据父菜单名称匹配action路径 |
| | | if ("入库管理".equals(parentName)) { |
| | | return action != null && (action.startsWith("/pakin/") || action.startsWith("/order/")); |
| | | } else if ("AGV管理".equals(parentName)) { |
| | | return action != null && action.startsWith("/AGV/"); |
| | | } else if ("库存管理".equals(parentName)) { |
| | | return action != null && action.startsWith("/stock/"); |
| | | } |
| | | } |
| | | return false; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | // 只有有子菜单的父菜单才返回 |
| | | if (!children.isEmpty()) { |
| | | Map<String, Object> parentMap = new HashMap<>(); |
| | | parentMap.put("id", parentMenu.getId()); |
| | | parentMap.put("name", parentMenu.getName()); |
| | | parentMap.put("action", parentMenu.getAction()); |
| | | parentMap.put("type", "parent"); // 标识为父菜单 |
| | | |
| | | // 构建子菜单列表 |
| | | List<Map<String, Object>> childrenList = new ArrayList<>(); |
| | | for (Permission child : children) { |
| | | Map<String, Object> childMap = new HashMap<>(); |
| | | childMap.put("id", child.getId()); |
| | | childMap.put("name", child.getName()); |
| | | childMap.put("action", child.getAction()); |
| | | childMap.put("type", "child"); // 标识为子菜单 |
| | | childrenList.add(childMap); |
| | | } |
| | | parentMap.put("children", childrenList); |
| | | result.add(parentMap); |
| | | } |
| | | } |
| | | |
| | | // 添加没有父菜单的独立权限(resource_id为NULL的权限) |
| | | List<Permission> standalonePermissions = permissions.stream() |
| | | .filter(p -> { |
| | | // 只返回有action的权限(排除父菜单) |
| | | if (p.getAction() == null || p.getAction().isEmpty()) { |
| | | return false; |
| | | } |
| | | // 如果resource_id为NULL,说明是独立菜单 |
| | | return p.getResourceId() == null; |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | |
| | | for (Permission permission : standalonePermissions) { |
| | | Map<String, Object> item = new HashMap<>(); |
| | | item.put("id", permission.getId()); |
| | | item.put("name", permission.getName()); |
| | | item.put("action", permission.getAction()); |
| | | item.put("type", "standalone"); // 独立菜单 |
| | | result.add(item); |
| | | } |
| | | |
| | | return R.ok().add(result); |
| | | } |
| | | |
| | | // 如果没有层级结构,返回原来的平铺结构(兼容旧逻辑) |
| | | return R.ok().add(permissions); |
| | | } |
| | | } |
| | | |