fix: show pending approval tasks in leader workbench
This commit is contained in:
parent
d059481aed
commit
eb5dedde3c
@ -3184,23 +3184,102 @@ public class TaskService {
|
||||
log.info("查询负责人任务列表: userId={}, auditStatus={}", userId, auditStatus);
|
||||
|
||||
User user = userService.getUserById(userId);
|
||||
if (user == null || user.getDeptId() == null) {
|
||||
throw new BusinessException("用户不存在或未分配部门");
|
||||
if (user == null) {
|
||||
throw new BusinessException("用户不存在");
|
||||
}
|
||||
|
||||
Department dept = departmentService.getDepartmentById(user.getDeptId());
|
||||
if (dept == null) {
|
||||
throw new BusinessException("部门不存在");
|
||||
List<Long> managedDeptIds = departmentService.getUserManagedPublishingDepartments(userId).stream()
|
||||
.map(Department::getId)
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (managedDeptIds.isEmpty()) {
|
||||
throw new BusinessException("只有需求部门负责人才能查看该视图");
|
||||
}
|
||||
|
||||
// 检查是否是部门负责人
|
||||
if (!userId.equals(dept.getLeaderId())) {
|
||||
throw new BusinessException("只有部门负责人才能查看该视图");
|
||||
}
|
||||
|
||||
// 查询部门内所有任务
|
||||
Page<Task> pageParam = new Page<>(page, pageSize);
|
||||
return taskMapper.selectLeaderTaskPage(pageParam, user.getDeptId(), auditStatus);
|
||||
LambdaQueryWrapper<Task> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.in(Task::getPublisherDeptId, managedDeptIds)
|
||||
.eq(Task::getDeleted, 0);
|
||||
|
||||
applyLeaderTaskAuditFilter(wrapper, auditStatus);
|
||||
wrapper.orderByDesc(Task::getCreateTime);
|
||||
|
||||
IPage<Task> result = taskMapper.selectPage(pageParam, wrapper);
|
||||
enrichLeaderTaskList(result.getRecords());
|
||||
return result;
|
||||
}
|
||||
|
||||
private void applyLeaderTaskAuditFilter(LambdaQueryWrapper<Task> wrapper, String auditStatus) {
|
||||
if (!StringUtils.hasText(auditStatus)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (auditStatus) {
|
||||
case "draft":
|
||||
wrapper.and(w -> w
|
||||
.eq(Task::getAuditStatus, "draft")
|
||||
.and(x -> x.isNull(Task::getApprovalStatus)
|
||||
.or()
|
||||
.eq(Task::getApprovalStatus, "draft")));
|
||||
return;
|
||||
case "pending_audit":
|
||||
wrapper.and(w -> w
|
||||
.eq(Task::getAuditStatus, "pending_audit")
|
||||
.or()
|
||||
.in(Task::getApprovalStatus, Arrays.asList("pending_primary_approval", "pending_demand_approval")));
|
||||
return;
|
||||
case "audit_pass":
|
||||
wrapper.and(w -> w
|
||||
.eq(Task::getAuditStatus, "audit_pass")
|
||||
.or()
|
||||
.eq(Task::getApprovalStatus, "approved"));
|
||||
return;
|
||||
case "audit_reject":
|
||||
wrapper.and(w -> w
|
||||
.eq(Task::getAuditStatus, "audit_reject")
|
||||
.or()
|
||||
.in(Task::getApprovalStatus, Arrays.asList("rejected", "rejected_by_demand", "rejected_by_receiving")));
|
||||
return;
|
||||
default:
|
||||
wrapper.eq(Task::getAuditStatus, auditStatus);
|
||||
}
|
||||
}
|
||||
|
||||
private void enrichLeaderTaskList(List<Task> tasks) {
|
||||
if (tasks == null || tasks.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Task task : tasks) {
|
||||
if (task.getPublisherId() != null && !StringUtils.hasText(task.getPublisherName())) {
|
||||
User publisher = userMapper.selectById(task.getPublisherId());
|
||||
if (publisher != null) {
|
||||
task.setPublisherName(publisher.getRealName());
|
||||
}
|
||||
}
|
||||
|
||||
if (task.getPublisherDeptId() != null && !StringUtils.hasText(task.getPublisherDeptName())) {
|
||||
Department publisherDept = departmentMapper.selectById(task.getPublisherDeptId());
|
||||
if (publisherDept != null) {
|
||||
task.setPublisherDeptName(publisherDept.getDeptName());
|
||||
}
|
||||
}
|
||||
|
||||
if (task.getAuditorId() != null && !StringUtils.hasText(task.getAuditorName())) {
|
||||
User auditor = userMapper.selectById(task.getAuditorId());
|
||||
if (auditor != null) {
|
||||
task.setAuditorName(auditor.getRealName());
|
||||
}
|
||||
}
|
||||
|
||||
if (task.getCurrentApproverId() != null && !StringUtils.hasText(task.getCurrentApproverName())) {
|
||||
User approver = userMapper.selectById(task.getCurrentApproverId());
|
||||
if (approver != null) {
|
||||
task.setCurrentApproverName(approver.getRealName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -71,8 +71,8 @@
|
||||
<span :class="['status-badge', `status-${task.status}`]">
|
||||
{{ getStatusText(task.status) }}
|
||||
</span>
|
||||
<span v-if="task.auditStatus" :class="['audit-badge', `audit-${task.auditStatus}`]">
|
||||
{{ getAuditStatusText(task.auditStatus) }}
|
||||
<span v-if="getReviewBadgeType(task)" :class="['audit-badge', `audit-${getReviewBadgeType(task)}`]">
|
||||
{{ getReviewBadgeText(task) }}
|
||||
</span>
|
||||
<span v-if="task.publisherName" class="user-badge">
|
||||
<Icon name="user" size="sm" style="margin-right: 4px; vertical-align: middle;" />
|
||||
@ -123,7 +123,7 @@
|
||||
<!-- 需求部门负责人操作 -->
|
||||
<template v-if="activeTab === 'demand'">
|
||||
<button
|
||||
v-if="task.auditStatus === 'pending_audit'"
|
||||
v-if="canDemandLeaderAudit(task)"
|
||||
class="btn btn-success"
|
||||
@click="handleAuditTask(task)"
|
||||
>
|
||||
@ -251,6 +251,43 @@ const getAuditStatusText = (auditStatus: string | undefined) => {
|
||||
return statusMap[auditStatus || ''] || ''
|
||||
}
|
||||
|
||||
const getReviewBadgeType = (task: Task) => {
|
||||
if (task.approvalStatus === 'approved') return 'audit_pass'
|
||||
if (task.approvalStatus === 'pending_primary_approval' ||
|
||||
task.approvalStatus === 'pending_demand_approval' ||
|
||||
task.approvalStatus === 'pending_receiving_approval') {
|
||||
return 'pending_audit'
|
||||
}
|
||||
if (task.approvalStatus === 'rejected' || task.approvalStatus === 'rejected_by_demand' || task.approvalStatus === 'rejected_by_receiving') {
|
||||
return 'audit_reject'
|
||||
}
|
||||
return task.auditStatus || ''
|
||||
}
|
||||
|
||||
const getReviewBadgeText = (task: Task) => {
|
||||
switch (task.approvalStatus) {
|
||||
case 'pending_primary_approval':
|
||||
return '一级待审核'
|
||||
case 'pending_demand_approval':
|
||||
return '待审核'
|
||||
case 'pending_receiving_approval':
|
||||
return '接单待审核'
|
||||
case 'approved':
|
||||
return '审核通过'
|
||||
case 'rejected':
|
||||
case 'rejected_by_demand':
|
||||
case 'rejected_by_receiving':
|
||||
return '审核驳回'
|
||||
default:
|
||||
return getAuditStatusText(task.auditStatus)
|
||||
}
|
||||
}
|
||||
|
||||
const canDemandLeaderAudit = (task: Task) => {
|
||||
if (task.auditStatus === 'pending_audit') return true
|
||||
return task.approvalStatus === 'pending_demand_approval' && task.currentApproverRole === 'demand_leader'
|
||||
}
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (time: string | undefined) => {
|
||||
if (!time) return '--'
|
||||
@ -362,11 +399,24 @@ const submitAudit = async () => {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await taskApi.auditTask({
|
||||
taskId: currentAuditTask.value.id,
|
||||
const task = currentAuditTask.value!
|
||||
let response
|
||||
|
||||
if (task.approvalStatus === 'pending_demand_approval' && task.currentApproverRole === 'demand_leader') {
|
||||
if (auditForm.result === 'pass') {
|
||||
response = await taskApi.approveDemandLevel(task.id!, {
|
||||
comment: auditForm.comment || '审核通过'
|
||||
})
|
||||
} else {
|
||||
response = await taskApi.rejectByDemandLeader(task.id!, auditForm.comment)
|
||||
}
|
||||
} else {
|
||||
response = await taskApi.auditTask({
|
||||
taskId: task.id!,
|
||||
result: auditForm.result,
|
||||
comment: auditForm.comment
|
||||
})
|
||||
}
|
||||
|
||||
if (response.code === 200) {
|
||||
message.success(auditForm.result === 'pass' ? '审核通过' : '审核驳回')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user