🐛 修复同名业务部门展示与合同编号前缀按旧平台公司ID匹配失败
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+2
-2
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -109,9 +109,9 @@ public interface IDeptService extends IService<Dept> {
|
||||
/**
|
||||
* 业务部门下拉(是否业务部门=是)
|
||||
*
|
||||
* @return 业务部门列表
|
||||
* @return 业务部门列表(含上级组织名称,便于同名部门区分)
|
||||
*/
|
||||
List<Dept> listBusinessDept();
|
||||
List<DeptVO> listBusinessDept();
|
||||
|
||||
/**
|
||||
* 根据部门名称精确匹配获取部门ID集合
|
||||
|
||||
+34
@@ -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)
|
||||
|
||||
+42
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user