{"record":{"id":"f0e432c823aed074","repo":"jeecgboot/JeecgBoot","slug":"pcode","errorCode":null,"errorMessage":"该编码【${pcode}】不存在，请核实!","messagePattern":"该编码【(.+?)】不存在，请核实!","errorType":"exception","errorClass":"JeecgBootException","httpStatus":null,"severity":"error","filePath":"jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysCategoryServiceImpl.java","lineNumber":80,"sourceCode":"\t\t\tsysCategory.setPid(ISysCategoryService.ROOT_PID_VALUE);\n\t\t}else{\n\t\t\t//如果当前节点父ID不为空 则设置父节点的hasChild 为1\n\t\t\tSysCategory parent = baseMapper.selectById(sysCategory.getPid());\n\t\t\tif(parent!=null && !ISysCategoryService.HAS_CHILD.equals(parent.getHasChild())){\n\t\t\t\tparent.setHasChild(ISysCategoryService.HAS_CHILD);\n\t\t\t\tbaseMapper.updateById(parent);\n\t\t\t}\n\t\t}\n\t\tbaseMapper.updateById(sysCategory);\n\t}\n\n\t@Override\n\tpublic List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException{\n\t\tString pid = ROOT_PID_VALUE;\n\t\tif(oConvertUtils.isNotEmpty(pcode)) {\n\t\t\tList<SysCategory> list = baseMapper.selectList(new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));\n\t\t\tif(list==null || list.size() ==0) {\n\t\t\t\tthrow new JeecgBootException(\"该编码【\"+pcode+\"】不存在，请核实!\");\n\t\t\t}\n\t\t\tif(list.size()>1) {\n\t\t\t\tthrow new JeecgBootException(\"该编码【\"+pcode+\"】存在多个，请核实!\");\n\t\t\t}\n\t\t\tpid = list.get(0).getId();\n\t\t}\n\t\treturn baseMapper.queryListByPid(pid,null);\n\t}\n\n\t@Override\n\tpublic List<TreeSelectModel> queryListByPid(String pid) {\n\t\tif(oConvertUtils.isEmpty(pid)) {\n\t\t\tpid = ROOT_PID_VALUE;\n\t\t}\n\t\treturn baseMapper.queryListByPid(pid,null);\n\t}\n\n\t@Override","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysCategoryServiceImpl.java#L62-L98","documentation":"SysCategoryServiceImpl.queryListByCode resolves a tree parent by its category code (pcode). If no sys_category row matches the code, there is no parent id to build the tree from, so a JeecgBootException is thrown rather than returning an ambiguous/empty result.","triggerScenarios":"Calling queryListByCode with a pcode that has no matching sys_category.code row (typo, deleted category, code from another environment).","commonSituations":"Dictionary/category code typo in configuration; category was deleted but referencing code remains; code configured per-tenant and missing in the current tenant; case mismatch.","solutions":["Verify the pcode exists: SELECT * FROM sys_category WHERE code = ?.","Use the correct code or create the category with that code first.","Treat an empty result as 'use root' only if business logic permits, otherwise surface a clear error to the caller."],"exampleFix":"// before\nList<TreeSelectModel> tree = sysCategoryService.queryListByCode(\"regin\"); // typo\n// after\nString code = \"region\";\nif (categoryCodeMissing(code)) {\n    return Collections.emptyList(); // or a user-facing error\n}\nList<TreeSelectModel> tree = sysCategoryService.queryListByCode(code);","handlingStrategy":"validation","validationCode":"// Confirm the category code exists before resolving the tree.\nList<SysCategory> rows = sysCategoryMapper.selectList(\n    new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));\nif (rows == null || rows.isEmpty()) {\n    return Collections.emptyList(); // or a user-facing error\n}","typeGuard":"public boolean categoryCodeExists(String code) {\n    Long n = baseMapper.selectCount(\n        new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, code));\n    return n != null && n > 0;\n}","tryCatchPattern":"try {\n    return sysCategoryService.queryListByCode(pcode);\n} catch (JeecgBootException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"不存在\")) {\n        return Collections.emptyList();\n    }\n    throw e;\n}","preventionTips":["Validate pcode against sys_category before calling queryListByCode.","Centralize category codes as constants/dictionary entries.","Return empty list (or a clear message) instead of letting the exception reach users."],"tags":["category","tree","dictionary","validation"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}