{"record":{"id":"c6116d6076fe9f04","repo":"jeecgboot/JeecgBoot","slug":"pcode-c6116d","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":83,"sourceCode":"\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\n\tpublic List<TreeSelectModel> queryListByPid(String pid, Map<String, String> condition) {\n\t\tif(oConvertUtils.isEmpty(pid)) {\n\t\t\tpid = ROOT_PID_VALUE;","sourceCodeStart":65,"sourceCodeEnd":101,"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#L65-L101","documentation":"A data-integrity guard in queryListByCode: when more than one sys_category row shares the same code, the parent is ambiguous and building the tree would be non-deterministic, so the call is rejected instead of silently picking one.","triggerScenarios":"Duplicate codes in sys_category — the code column is not enforced unique, so two+ rows exist with the same code value.","commonSituations":"Manual data entry/import created duplicates; import without dedup; missing unique index on sys_category.code; soft-delete flag not applied leaving old + new rows with the same code.","solutions":["Find duplicates: SELECT code, COUNT(*) FROM sys_category GROUP BY code HAVING COUNT(*) > 1.","Disambiguate or rename duplicates so each code is unique; soft-delete the obsolete rows.","Add a unique index/constraint on sys_category.code to prevent recurrence."],"exampleFix":"-- before: duplicates exist\nSELECT code, COUNT(*) FROM sys_category GROUP BY code HAVING COUNT(*) > 1;\n-- after: keep one canonical row, soft-delete the rest\nUPDATE sys_category SET del_flag = 1 WHERE id IN (<dupe ids to retire>);\nALTER TABLE sys_category ADD UNIQUE KEY uk_code (code);","handlingStrategy":"validation","validationCode":"// Detect duplicates before resolving, and surface a data-integrity error.\nlong n = baseMapper.selectCount(\n    new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));\nif (n > 1) {\n    throw new IllegalStateException(\"sys_category.code 重复: \" + pcode + \" (\" + n + \" 行)\");\n}","typeGuard":"public boolean categoryCodeIsUnique(String code) {\n    Long n = baseMapper.selectCount(\n        new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, code));\n    return n != null && n == 1;\n}","tryCatchPattern":"try {\n    return sysCategoryService.queryListByCode(pcode);\n} catch (JeecgBootException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"存在多个\")) {\n        log.error(\"sys_category.code 重复, 需运维去重: {}\", pcode);\n        return Collections.emptyList();\n    }\n    throw e;\n}","preventionTips":["Add a unique index on sys_category.code to prevent duplicates at the DB level.","Run a periodic duplicate-detection query as a data-quality check.","Dedup categories during data imports."],"tags":["category","tree","data-integrity","dictionary"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}