fix: resolve demand dept display for task groups
This commit is contained in:
parent
6635a248e6
commit
e51ee0163c
@ -44,6 +44,8 @@ public class TaskItemService {
|
||||
private final ExternalAssetService externalAssetService;
|
||||
private final SystemConfigService systemConfigService;
|
||||
private final DemandTypeMapper demandTypeMapper;
|
||||
private final com.designhub.mapper.DeptBrandRelationMapper deptBrandRelationMapper;
|
||||
private final com.designhub.mapper.UserDepartmentMapper userDepartmentMapper;
|
||||
private final com.designhub.mapper.UserMapper userMapper;
|
||||
private final ObjectMapper objectMapper;
|
||||
private final com.designhub.util.WorkHoursCalculator workHoursCalculator;
|
||||
@ -1931,7 +1933,8 @@ public class TaskItemService {
|
||||
com.designhub.entity.User detailCompleter = userMapper.selectById(mainTask.getDetailCompleterId());
|
||||
if (detailCompleter != null) {
|
||||
groupInfo.put("publisherName", detailCompleter.getRealName());
|
||||
groupInfo.put("publisherDeptName", detailCompleter.getDeptName());
|
||||
groupInfo.put("publisherDeptName",
|
||||
resolveDisplayPublisherDeptName(mainTask, mainTask.getDetailCompleterId(), mainTask.getPublisherDeptId()));
|
||||
}
|
||||
} else {
|
||||
// 普通任务:发起人 = 原始发起人
|
||||
@ -1940,7 +1943,8 @@ public class TaskItemService {
|
||||
com.designhub.entity.User publisher = userMapper.selectById(mainTask.getPublisherId());
|
||||
if (publisher != null) {
|
||||
groupInfo.put("publisherName", publisher.getRealName());
|
||||
groupInfo.put("publisherDeptName", publisher.getDeptName());
|
||||
groupInfo.put("publisherDeptName",
|
||||
resolveDisplayPublisherDeptName(mainTask, mainTask.getPublisherId(), mainTask.getPublisherDeptId()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2042,6 +2046,112 @@ public class TaskItemService {
|
||||
|
||||
return new java.util.ArrayList<>(groupMap.values());
|
||||
}
|
||||
|
||||
private String resolveDisplayPublisherDeptName(Task mainTask, Long displayUserId, Long fallbackDeptId) {
|
||||
if (displayUserId == null) {
|
||||
return fallbackDeptId != null ? getDepartmentNameById(fallbackDeptId) : null;
|
||||
}
|
||||
|
||||
com.designhub.entity.Department displayDept =
|
||||
resolveDemandDepartmentForTaskUser(displayUserId, mainTask != null ? mainTask.getBrandId() : null, fallbackDeptId);
|
||||
if (displayDept != null) {
|
||||
return displayDept.getDeptName();
|
||||
}
|
||||
|
||||
if (fallbackDeptId != null) {
|
||||
String fallbackDeptName = getDepartmentNameById(fallbackDeptId);
|
||||
if (fallbackDeptName != null) {
|
||||
return fallbackDeptName;
|
||||
}
|
||||
}
|
||||
|
||||
com.designhub.entity.User user = userMapper.selectById(displayUserId);
|
||||
return user != null ? user.getDeptName() : null;
|
||||
}
|
||||
|
||||
private com.designhub.entity.Department resolveDemandDepartmentForTaskUser(Long userId, Long brandId, Long fallbackDeptId) {
|
||||
if (userId == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<com.designhub.entity.UserDepartment> userDepartments = userDepartmentMapper.selectList(
|
||||
new LambdaQueryWrapper<com.designhub.entity.UserDepartment>()
|
||||
.eq(com.designhub.entity.UserDepartment::getUserId, userId)
|
||||
.orderByDesc(com.designhub.entity.UserDepartment::getIsPrimary)
|
||||
.orderByAsc(com.designhub.entity.UserDepartment::getId)
|
||||
);
|
||||
|
||||
if (userDepartments == null || userDepartments.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<com.designhub.entity.Department> demandDepartments = new java.util.ArrayList<>();
|
||||
com.designhub.entity.Department primaryDemandDepartment = null;
|
||||
|
||||
for (com.designhub.entity.UserDepartment userDepartment : userDepartments) {
|
||||
if (userDepartment == null || userDepartment.getDeptId() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
com.designhub.entity.Department department = departmentMapper.selectById(userDepartment.getDeptId());
|
||||
if (!isActiveDemandDepartment(department)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
demandDepartments.add(department);
|
||||
if (primaryDemandDepartment == null && Integer.valueOf(1).equals(userDepartment.getIsPrimary())) {
|
||||
primaryDemandDepartment = department;
|
||||
}
|
||||
}
|
||||
|
||||
if (demandDepartments.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (brandId != null) {
|
||||
for (com.designhub.entity.Department department : demandDepartments) {
|
||||
List<Long> brandIds = deptBrandRelationMapper.getBrandIdsByDeptId(department.getId());
|
||||
if (brandIds != null && brandIds.contains(brandId)) {
|
||||
return department;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fallbackDeptId != null) {
|
||||
for (com.designhub.entity.Department department : demandDepartments) {
|
||||
if (fallbackDeptId.equals(department.getId())) {
|
||||
return department;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (primaryDemandDepartment != null) {
|
||||
return primaryDemandDepartment;
|
||||
}
|
||||
|
||||
return demandDepartments.get(0);
|
||||
}
|
||||
|
||||
private boolean isActiveDemandDepartment(com.designhub.entity.Department department) {
|
||||
if (department == null) {
|
||||
return false;
|
||||
}
|
||||
if (department.getStatus() == null || department.getStatus() != 1) {
|
||||
return false;
|
||||
}
|
||||
if (department.getDeleted() != null && department.getDeleted() == 1) {
|
||||
return false;
|
||||
}
|
||||
return "demand".equals(department.getDeptType()) || "primary_demand".equals(department.getDeptType());
|
||||
}
|
||||
|
||||
private String getDepartmentNameById(Long deptId) {
|
||||
if (deptId == null) {
|
||||
return null;
|
||||
}
|
||||
com.designhub.entity.Department department = departmentMapper.selectById(deptId);
|
||||
return department != null ? department.getDeptName() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从子任务编号解析部门序号
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user