fix: 审核弹窗根据任务类型配置的接单部门获取设计师列表(包含子部门)
This commit is contained in:
parent
97bf6b514a
commit
45fe54604c
@ -132,8 +132,15 @@ public class UserController {
|
||||
@GetMapping("/designers-with-workload")
|
||||
public Result<List<Map<String, Object>>> getDesignersWithWorkload(
|
||||
@RequestParam(required = false) Long deptId,
|
||||
@RequestParam(required = false) Long taskTypeId,
|
||||
@RequestHeader("Authorization") String authHeader
|
||||
) {
|
||||
// 如果传入了 taskTypeId,则根据任务类型配置的接单部门来获取设计师
|
||||
if (taskTypeId != null) {
|
||||
log.info("根据任务类型获取设计师列表: taskTypeId={}", taskTypeId);
|
||||
return Result.success(userService.getDesignersByTaskType(taskTypeId));
|
||||
}
|
||||
|
||||
// 如果没有传入deptId,则默认为当前用户的部门
|
||||
if (deptId == null) {
|
||||
String token = jwtUtil.extractTokenFromHeader(authHeader);
|
||||
|
||||
@ -53,6 +53,9 @@ public class UserService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private com.designhub.mapper.TaskMapper taskMapper;
|
||||
|
||||
@Autowired(required = false)
|
||||
private com.designhub.mapper.DemandTypeMapper demandTypeMapper;
|
||||
|
||||
private Department getDepartmentOrThrow(Long deptId) {
|
||||
if (deptId == null) {
|
||||
@ -1472,6 +1475,117 @@ public class UserService {
|
||||
return deptIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据任务类型获取对应接单部门的设计师列表
|
||||
* @param taskTypeId 任务类型ID
|
||||
* @return 设计师列表,包含每个设计师的进行中任务数量
|
||||
*/
|
||||
public List<Map<String, Object>> getDesignersByTaskType(Long taskTypeId) {
|
||||
log.info("根据任务类型获取设计师列表: taskTypeId={}", taskTypeId);
|
||||
|
||||
if (demandTypeMapper == null) {
|
||||
log.warn("demandTypeMapper 未注入,返回空列表");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 获取任务类型配置
|
||||
com.designhub.entity.DemandType taskType = demandTypeMapper.selectById(taskTypeId);
|
||||
if (taskType == null) {
|
||||
log.warn("未找到任务类型: taskTypeId={}", taskTypeId);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
// 如果当前任务类型没有配置接单部门,递归查找父级
|
||||
String allowedDeptIds = taskType.getAllowedDeptIds();
|
||||
Long currentTypeId = taskTypeId;
|
||||
while ((allowedDeptIds == null || allowedDeptIds.trim().isEmpty()) && taskType.getParentId() != null) {
|
||||
log.info("任务类型{}没有配置接单部门,向上查找父级{}", currentTypeId, taskType.getParentId());
|
||||
taskType = demandTypeMapper.selectById(taskType.getParentId());
|
||||
if (taskType != null) {
|
||||
allowedDeptIds = taskType.getAllowedDeptIds();
|
||||
currentTypeId = taskType.getId();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (allowedDeptIds == null || allowedDeptIds.trim().isEmpty()) {
|
||||
log.warn("任务类型{}及其父级都没有配置接单部门", taskTypeId);
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
log.info("找到接单部门配置: taskTypeId={}, allowedDeptIds={}", currentTypeId, allowedDeptIds);
|
||||
|
||||
// 解析接单部门ID列表
|
||||
List<Long> targetDeptIds = new ArrayList<>();
|
||||
for (String deptIdStr : allowedDeptIds.split(",")) {
|
||||
String trimmed = deptIdStr.trim();
|
||||
if (!trimmed.isEmpty()) {
|
||||
try {
|
||||
Long deptId = Long.parseLong(trimmed);
|
||||
// 递归获取该部门及其所有子部门
|
||||
targetDeptIds.addAll(getAllSubDepartmentIds(deptId));
|
||||
} catch (NumberFormatException e) {
|
||||
log.warn("无效的部门ID: {}", trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (targetDeptIds.isEmpty()) {
|
||||
log.warn("解析后的部门列表为空");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
log.info("目标部门ID列表(含子部门): {}", targetDeptIds);
|
||||
|
||||
// 查询这些部门的设计师
|
||||
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(User::getStatus, 1);
|
||||
queryWrapper.eq(User::getDeleted, 0);
|
||||
queryWrapper.in(User::getDeptId, targetDeptIds);
|
||||
queryWrapper.orderByAsc(User::getRealName);
|
||||
|
||||
List<User> users = userMapper.selectList(queryWrapper);
|
||||
log.info("找到{}个设计师", users.size());
|
||||
|
||||
// 构建返回结果
|
||||
List<Map<String, Object>> result = new ArrayList<>();
|
||||
for (User user : users) {
|
||||
Map<String, Object> designerInfo = new HashMap<>();
|
||||
designerInfo.put("id", user.getId());
|
||||
designerInfo.put("username", user.getUsername());
|
||||
designerInfo.put("realName", user.getRealName());
|
||||
designerInfo.put("deptId", user.getDeptId());
|
||||
|
||||
// 查询进行中的任务数量
|
||||
int inProgressCount = 0;
|
||||
if (taskMapper != null) {
|
||||
Long normalTaskCount = taskMapper.selectCount(
|
||||
new LambdaQueryWrapper<com.designhub.entity.Task>()
|
||||
.eq(com.designhub.entity.Task::getReceiverId, user.getId())
|
||||
.eq(com.designhub.entity.Task::getStatus, "in_progress")
|
||||
.eq(com.designhub.entity.Task::getDeleted, 0)
|
||||
);
|
||||
Long subTaskCount = taskMapper.countSubTasksByReceiverId(user.getId());
|
||||
inProgressCount = (normalTaskCount != null ? normalTaskCount.intValue() : 0) +
|
||||
(subTaskCount != null ? subTaskCount.intValue() : 0);
|
||||
}
|
||||
designerInfo.put("inProgressCount", inProgressCount);
|
||||
|
||||
// 获取部门名称
|
||||
if (user.getDeptId() != null) {
|
||||
Department dept = departmentMapper.selectById(user.getDeptId());
|
||||
if (dept != null) {
|
||||
designerInfo.put("deptName", dept.getDeptName());
|
||||
}
|
||||
}
|
||||
|
||||
result.add(designerInfo);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置/取消管理员
|
||||
*/
|
||||
|
||||
@ -155,10 +155,13 @@ export interface DesignerWithWorkload {
|
||||
|
||||
/**
|
||||
* 获取设计师列表及工作量
|
||||
* @param deptId 部门ID(可选)
|
||||
* @param taskTypeId 任务类型ID(可选,优先根据任务类型配置的接单部门获取设计师)
|
||||
*/
|
||||
export const getDesignersWithWorkload = async (deptId?: number): Promise<DesignerWithWorkload[]> => {
|
||||
export const getDesignersWithWorkload = async (deptId?: number, taskTypeId?: number): Promise<DesignerWithWorkload[]> => {
|
||||
const params: any = {};
|
||||
if (deptId) params.deptId = deptId;
|
||||
if (taskTypeId) params.taskTypeId = taskTypeId; // 优先使用 taskTypeId
|
||||
else if (deptId) params.deptId = deptId;
|
||||
const response = await request.get('/users/designers-with-workload', { params });
|
||||
return response.data || [];
|
||||
};
|
||||
|
||||
@ -3078,16 +3078,12 @@ const formatDeadlineRelative = (deadline: string) => {
|
||||
// 显示指定设计师弹窗(接单部门审核时)
|
||||
const showAssignDesignerModal = async (task: Task) => {
|
||||
try {
|
||||
// 获取当前部门的设计师列表
|
||||
const userInfo = localStorage.getItem('userInfo')
|
||||
let deptId: number | undefined
|
||||
if (userInfo) {
|
||||
const user = JSON.parse(userInfo)
|
||||
deptId = user.deptId
|
||||
}
|
||||
|
||||
// 加载设计师列表及工作量
|
||||
const designers = await userApi.getDesignersWithWorkload(deptId)
|
||||
// 根据任务类型配置的接单部门获取设计师列表
|
||||
// 优先使用 taskTypeId 来获取对应接单部门的设计师
|
||||
const taskTypeId = task.taskTypeId
|
||||
|
||||
// 加载设计师列表及工作量(根据任务类型的接单部门配置)
|
||||
const designers = await userApi.getDesignersWithWorkload(undefined, taskTypeId)
|
||||
|
||||
if (designers.length === 0) {
|
||||
message.warning('当前部门没有可用的设计师')
|
||||
@ -3165,16 +3161,16 @@ const handleApproveConfirm = async () => {
|
||||
})
|
||||
} else {
|
||||
// 主任务审核
|
||||
const approvalData: TaskApprovalDTO = {
|
||||
comment: approveAssignType.value === 'manual' ?
|
||||
`指定设计师接单` : '审核通过,发布到任务大厅',
|
||||
assignedReceiverId: approveAssignType.value === 'manual' ? approveDesignerId.value : undefined,
|
||||
taskUpdates: {
|
||||
taskTypes: approveTaskTypes.value.map(t => ({
|
||||
taskTypeId: t.typeId,
|
||||
quantity: t.quantity
|
||||
}))
|
||||
}
|
||||
const approvalData: TaskApprovalDTO = {
|
||||
comment: approveAssignType.value === 'manual' ?
|
||||
`指定设计师接单` : '审核通过,发布到任务大厅',
|
||||
assignedReceiverId: approveAssignType.value === 'manual' ? approveDesignerId.value : undefined,
|
||||
taskUpdates: {
|
||||
taskTypes: approveTaskTypes.value.map(t => ({
|
||||
taskTypeId: t.typeId,
|
||||
quantity: t.quantity
|
||||
}))
|
||||
}
|
||||
}
|
||||
await taskApi.approveReceivingLevel(taskData.id!, approvalData)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user