{"record":{"id":"aa48a227e3831a52","repo":"paascloud/paascloud-master","slug":"uac10013002","errorCode":"UAC10013002","errorMessage":"更新上级菜单失败,menuId=%s","messagePattern":"更新上级菜单失败,menuId=(.+?)","errorType":"error_code","errorClass":"UacBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-uac/src/main/java/com/paascloud/provider/service/impl/UacMenuServiceImpl.java","lineNumber":149,"sourceCode":"\t@Override\n\tpublic int saveUacMenu(UacMenu menu, LoginAuthDto loginAuthDto) {\n\t\tLong pid = menu.getPid();\n\t\tmenu.setUpdateInfo(loginAuthDto);\n\t\tUacMenu parentMenu = mapper.selectByPrimaryKey(pid);\n\t\tif (PublicUtil.isEmpty(parentMenu)) {\n\t\t\tthrow new UacBizException(ErrorCodeEnum.UAC10013001, pid);\n\t\t}\n\t\tif (menu.isNew()) {\n\n\t\t\tUacMenu updateMenu = new UacMenu();\n\t\t\tmenu.setLevel(parentMenu.getLevel() + 1);\n\t\t\tupdateMenu.setLeaf(MenuConstant.MENU_LEAF_NO);\n\t\t\tupdateMenu.setId(pid);\n\t\t\tLong menuId = super.generateId();\n\t\t\tmenu.setId(menuId);\n\t\t\tint result = mapper.updateByPrimaryKeySelective(updateMenu);\n\t\t\tif (result < 1) {\n\t\t\t\tthrow new UacBizException(ErrorCodeEnum.UAC10013002, menuId);\n\t\t\t}\n\n\t\t\tmenu.setStatus(UacMenuStatusEnum.ENABLE.getType());\n\t\t\tmenu.setCreatorId(loginAuthDto.getUserId());\n\t\t\tmenu.setCreator(loginAuthDto.getUserName());\n\t\t\tmenu.setLastOperatorId(loginAuthDto.getUserId());\n\t\t\tmenu.setLastOperator(loginAuthDto.getUserName());\n\t\t\t// 新增的菜单是叶子节点\n\t\t\tmenu.setLeaf(MenuConstant.MENU_LEAF_YES);\n\t\t\treturn uacMenuMapper.insertSelective(menu);\n\t\t} else {\n\t\t\treturn uacMenuMapper.updateByPrimaryKeySelective(menu);\n\t\t}\n\t}\n\n\t@Override\n\tpublic int deleteUacMenuById(Long id, LoginAuthDto loginAuthDto) {\n\t\tPreconditions.checkArgument(id != null, \"菜单id不能为空\");","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-uac/src/main/java/com/paascloud/provider/service/impl/UacMenuServiceImpl.java#L131-L167","documentation":"UacBizException UAC10013002 thrown by UacMenuServiceImpl.saveUacMenu when saving a new menu fails to update its parent menu row. After inserting the child menu, the service marks the parent as non-leaf (updateMenu.setLeaf(MENU_LEAF_NO)) and issues updateByPrimaryKeySelective; if the update affects fewer than 1 row, the parent record was not found or the update failed. Message includes the parent menuId for diagnosis.","triggerScenarios":"Calling saveUacMenu (POST /uac/menu/saveUacMenu) with a pid referencing a parent menu that does not exist in uac_menu, was deleted concurrently, or whose row cannot be updated (e.g. DB constraint/lock failure), so mapper.updateByPrimaryKeySelective returns 0.","commonSituations":"Frontend submits a stale pid after the parent menu was deleted by another admin; test data references a hardcoded parent menuId absent from the environment DB; data replication gaps between environments leave orphaned pid values.","solutions":["Verify the pid sent in the UacMenuDto exists in the uac_menu table for the target environment.","Re-query the menu tree via the menu list API and pick a valid parent menuId before saving.","Check the uac_menu row with that id for lock/constraint issues and inspect DB logs for the failed update.","Fix or clean up orphaned pid values with a SQL check: SELECT * FROM uac_menu p WHERE p.id = (child.pid)."],"exampleFix":"// before: trust the pid from the client\nmenu.setPid(dto.getPid());\ninsertMenu(menu);\n// after: validate the parent exists first\nUacMenu parent = uacMenuMapper.selectByPrimaryKey(dto.getPid());\nif (parent == null) {\n  throw new UacBizException(ErrorCodeEnum.UAC10013003, dto.getPid());\n}\nmenu.setPid(dto.getPid());\ninsertMenu(menu);","handlingStrategy":"validation","validationCode":"UacMenu parent = uacMenuMapper.selectByPrimaryKey(dto.getPid());\nif (parent == null) {\n  throw new IllegalArgumentException(\"parent menu does not exist: \" + dto.getPid());\n}","typeGuard":"boolean parentExists(Long pid) { return pid != null && uacMenuMapper.selectByPrimaryKey(pid) != null; }","tryCatchPattern":"try {\n  uacMenuService.saveUacMenu(menuDto, loginAuthDto);\n} catch (UacBizException e) {\n  if (\"UAC10013002\".equals(e.getCode())) { /* prompt: parent menu invalid/deleted */ }\n  throw e;\n}","preventionTips":["Always load the parent menu in the UI from the live menu tree, not from cached ids.","Validate pid against the DB before submitting the save request.","Refresh the parent-menu dropdown after any concurrent menu deletions."],"tags":["database","menu-management","uac","parent-update-failed"],"backgroundTag":"database-write-failed","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}