jeecgboot/JeecgBoot · error · JeecgBootException

该编码【${pcode}】存在多个,请核实!

Error message

该编码【${pcode}】存在多个,请核实!

What it means

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.

Source

Thrown at jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysCategoryServiceImpl.java:83

			SysCategory parent = baseMapper.selectById(sysCategory.getPid());
			if(parent!=null && !ISysCategoryService.HAS_CHILD.equals(parent.getHasChild())){
				parent.setHasChild(ISysCategoryService.HAS_CHILD);
				baseMapper.updateById(parent);
			}
		}
		baseMapper.updateById(sysCategory);
	}

	@Override
	public List<TreeSelectModel> queryListByCode(String pcode) throws JeecgBootException{
		String pid = ROOT_PID_VALUE;
		if(oConvertUtils.isNotEmpty(pcode)) {
			List<SysCategory> list = baseMapper.selectList(new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));
			if(list==null || list.size() ==0) {
				throw new JeecgBootException("该编码【"+pcode+"】不存在,请核实!");
			}
			if(list.size()>1) {
				throw new JeecgBootException("该编码【"+pcode+"】存在多个,请核实!");
			}
			pid = list.get(0).getId();
		}
		return baseMapper.queryListByPid(pid,null);
	}

	@Override
	public List<TreeSelectModel> queryListByPid(String pid) {
		if(oConvertUtils.isEmpty(pid)) {
			pid = ROOT_PID_VALUE;
		}
		return baseMapper.queryListByPid(pid,null);
	}

	@Override
	public List<TreeSelectModel> queryListByPid(String pid, Map<String, String> condition) {
		if(oConvertUtils.isEmpty(pid)) {
			pid = ROOT_PID_VALUE;

View on GitHub (pinned to 96fb33f5ec)

Solutions

  1. Find duplicates: SELECT code, COUNT(*) FROM sys_category GROUP BY code HAVING COUNT(*) > 1.
  2. Disambiguate or rename duplicates so each code is unique; soft-delete the obsolete rows.
  3. Add a unique index/constraint on sys_category.code to prevent recurrence.

Example fix

-- before: duplicates exist
SELECT code, COUNT(*) FROM sys_category GROUP BY code HAVING COUNT(*) > 1;
-- after: keep one canonical row, soft-delete the rest
UPDATE sys_category SET del_flag = 1 WHERE id IN (<dupe ids to retire>);
ALTER TABLE sys_category ADD UNIQUE KEY uk_code (code);
Defensive patterns

Strategy: validation

Validate before calling

// Detect duplicates before resolving, and surface a data-integrity error.
long n = baseMapper.selectCount(
    new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, pcode));
if (n > 1) {
    throw new IllegalStateException("sys_category.code 重复: " + pcode + " (" + n + " 行)");
}

Type guard

public boolean categoryCodeIsUnique(String code) {
    Long n = baseMapper.selectCount(
        new LambdaQueryWrapper<SysCategory>().eq(SysCategory::getCode, code));
    return n != null && n == 1;
}

Try / catch

try {
    return sysCategoryService.queryListByCode(pcode);
} catch (JeecgBootException e) {
    if (e.getMessage() != null && e.getMessage().contains("存在多个")) {
        log.error("sys_category.code 重复, 需运维去重: {}", pcode);
        return Collections.emptyList();
    }
    throw e;
}

Prevention

When it happens

Trigger: Duplicate codes in sys_category — the code column is not enforced unique, so two+ rows exist with the same code value.

Common situations: 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.

Related errors


AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14). Data as JSON: /api/errors/c6116d6076fe9f04. Report an issue: GitHub.