🐛 修复同名业务部门展示与合同编号前缀按旧平台公司ID匹配失败

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-11-09 12:44:43 +08:00
co-authored by Cursor
parent c1113f869f
commit ef098de064
6 changed files with 96 additions and 11 deletions
@@ -87,6 +87,12 @@ public class DeptVO extends Dept implements INode<DeptVO> {
*/
private String parentName;
/**
* 所属公司名称(按 belongCompanyCode 解析)
*/
@Schema(description = "所属公司名称")
private String belongCompanyName;
/**
* 机构类型名称
*/
@@ -274,8 +274,8 @@ public class DeptController extends BladeController {
@PreAuth(AuthConstant.PERMIT_ALL)
@GetMapping("/business-dept-select")
@ApiOperationSupport(order = 12)
@Operation(summary = "业务部门下拉", description = "返回是否业务部门=是的部门列表")
public R<List<Dept>> businessDeptSelect() {
@Operation(summary = "业务部门下拉", description = "返回是否业务部门=是的部门列表(含上级组织名称)")
public R<List<DeptVO>> businessDeptSelect() {
return R.data(deptService.listBusinessDept());
}
@@ -109,9 +109,9 @@ public interface IDeptService extends IService<Dept> {
/**
* 业务部门下拉(是否业务部门=是)
*
* @return 业务部门列表
* @return 业务部门列表(含上级组织名称,便于同名部门区分)
*/
List<Dept> listBusinessDept();
List<DeptVO> listBusinessDept();
/**
* 根据部门名称精确匹配获取部门ID集合
@@ -42,6 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
import lombok.RequiredArgsConstructor;
import java.util.List;
import java.util.Objects;
import static org.springblade.core.cache.constant.CacheConstant.SYS_CACHE;
@@ -88,6 +89,39 @@ public class BusinessDeptConfigServiceImpl extends BaseServiceImpl<BusinessDeptC
if (Func.isEmpty(platformCompanyId) || Func.isEmpty(businessDeptId)) {
return null;
}
BusinessDeptConfig config = findByPlatformAndDept(platformCompanyId, businessDeptId);
if (config != null) {
return config;
}
// 兼容项目仍挂旧组织 ID / 同名非平台公司节点:按平台公司名称回退匹配现行配置
Dept platformCompany = deptService.getById(platformCompanyId);
String platformCompanyName = platformCompany == null ? null : trimToNull(platformCompany.getDeptName());
if (Func.isEmpty(platformCompanyName)) {
return null;
}
List<Dept> activePlatformList = deptService.list(Wrappers.<Dept>lambdaQuery()
.eq(Dept::getIsPlatformCompany, 1)
.eq(Dept::getDeptName, platformCompanyName)
.orderByAsc(Dept::getId));
for (Dept activePlatform : activePlatformList) {
if (activePlatform == null || Func.isEmpty(activePlatform.getId())
|| Objects.equals(activePlatform.getId(), platformCompanyId)) {
continue;
}
config = findByPlatformAndDept(activePlatform.getId(), businessDeptId);
if (config != null) {
return config;
}
}
return getOne(Wrappers.<BusinessDeptConfig>lambdaQuery()
.eq(BusinessDeptConfig::getPlatformCompanyName, platformCompanyName)
.eq(BusinessDeptConfig::getBusinessDeptId, businessDeptId)
.eq(BusinessDeptConfig::getIsDeleted, 0)
.orderByDesc(BusinessDeptConfig::getUpdateTime)
.last("LIMIT 1"), false);
}
private BusinessDeptConfig findByPlatformAndDept(Long platformCompanyId, Long businessDeptId) {
return getOne(Wrappers.<BusinessDeptConfig>lambdaQuery()
.eq(BusinessDeptConfig::getPlatformCompanyId, platformCompanyId)
.eq(BusinessDeptConfig::getBusinessDeptId, businessDeptId)
@@ -321,7 +321,7 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
}
@Override
public List<Dept> listBusinessDept() {
public List<DeptVO> listBusinessDept() {
LambdaQueryWrapper<Dept> queryWrapper = Wrappers.<Dept>lambdaQuery()
.eq(Dept::getIsBusinessDept, 1)
.orderByAsc(Dept::getSort)
@@ -329,7 +329,47 @@ public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements ID
if (!AuthUtil.isAdministrator()) {
queryWrapper.eq(Dept::getTenantId, AuthUtil.getTenantId());
}
return list(queryWrapper);
List<Dept> deptList = list(queryWrapper);
if (CollectionUtil.isEmpty(deptList)) {
return Collections.emptyList();
}
// 批量补齐上级名称、所属公司名称:扁平下拉靠公司/上级区分同名业务部门
Set<Long> parentIdSet = deptList.stream()
.map(Dept::getParentId)
.filter(Func::isNotEmpty)
.collect(Collectors.toSet());
Map<Long, String> parentNameMap = Collections.emptyMap();
if (CollectionUtil.isNotEmpty(parentIdSet)) {
parentNameMap = listByIds(parentIdSet).stream()
.filter(parent -> Func.isNotEmpty(parent.getId()))
.collect(Collectors.toMap(Dept::getId, Dept::getDeptName, (left, right) -> left));
}
Set<String> companyCodeSet = deptList.stream()
.map(Dept::getBelongCompanyCode)
.filter(Func::isNotEmpty)
.collect(Collectors.toSet());
Map<String, String> companyNameMap = Collections.emptyMap();
if (CollectionUtil.isNotEmpty(companyCodeSet)) {
companyNameMap = list(Wrappers.<Dept>lambdaQuery().in(Dept::getDeptCode, companyCodeSet)).stream()
.filter(company -> Func.isNotEmpty(company.getDeptCode()))
.collect(Collectors.toMap(Dept::getDeptCode, Dept::getDeptName, (left, right) -> left));
}
Map<Long, String> finalParentNameMap = parentNameMap;
Map<String, String> finalCompanyNameMap = companyNameMap;
return deptList.stream().map(dept -> {
DeptVO deptVO = BeanUtil.copyProperties(dept, DeptVO.class);
if (deptVO == null) {
return null;
}
if (Func.isNotEmpty(dept.getParentId())) {
deptVO.setParentName(finalParentNameMap.getOrDefault(dept.getParentId(), StringPool.EMPTY));
}
if (Func.isNotEmpty(dept.getBelongCompanyCode())) {
deptVO.setBelongCompanyName(
finalCompanyNameMap.getOrDefault(dept.getBelongCompanyCode(), StringPool.EMPTY));
}
return deptVO;
}).filter(Objects::nonNull).toList();
}
@Override
@@ -907,14 +907,19 @@ public class ContractManageServiceImpl extends BaseServiceImpl<ContractManageMap
throw new ServiceException("合同负责部门不存在");
}
Dept platformCompany = SysCache.getDept(platformCompanyId);
if (platformCompany == null) {
throw new ServiceException("平台公司不存在");
}
// 合同编号前缀改由「平台公司 + 业务部门」业务部门配置维护,不再读取组织机构 Dept.contractCodePrefix
// 合同编号前缀改由「平台公司 + 业务部门」业务部门配置维护;系统侧会按同名现行平台公司回退匹配
BusinessDeptConfig config = SysCache.getBusinessDeptConfig(platformCompanyId, organizationId);
String prefix = config == null ? null : TransportBusinessSupport.trimToNull(config.getContractCodePrefix());
if (Func.isEmpty(prefix)) {
throw new ServiceException("业务部门配置中未维护该平台公司与业务部门的合同编码前缀,无法自动生成,请先在业务部门配置中维护或手动输入合同编号");
if (platformCompany == null) {
throw new ServiceException("平台公司不存在或已删除,且未匹配到同名平台公司的合同编码前缀配置,请重新选择平台公司或手动输入合同编号");
}
String platformName = TransportBusinessSupport.trimToNull(platformCompany.getDeptName());
String deptName = TransportBusinessSupport.trimToNull(dept.getDeptName());
throw new ServiceException(String.format(
"业务部门配置中未维护平台公司「%s」与业务部门「%s」的合同编码前缀,无法自动生成;请确认项目平台公司与配置中的平台公司为同一组织后维护,或手动输入合同编号",
Func.toStr(platformName, String.valueOf(platformCompanyId)),
Func.toStr(deptName, String.valueOf(organizationId))));
}
int year = LocalDate.now().getYear();
String head = prefix + "(" + year + ")";