fix: preserve task publisher dept while editing
This commit is contained in:
parent
d5c62318a8
commit
b6aa49580a
@ -1847,7 +1847,8 @@ public class TaskService {
|
||||
}
|
||||
|
||||
User editor = userService.getUserById(userId);
|
||||
Department publisherDept = resolvePublisherDeptForTaskUpdate(existTask, task.getPublisherDeptId(), editor, isAdmin);
|
||||
boolean allowDeptOverride = isAdmin || userId.equals(existTask.getPublisherId());
|
||||
Department publisherDept = resolvePublisherDeptForTaskUpdate(existTask, task.getPublisherDeptId(), editor, isAdmin, allowDeptOverride);
|
||||
task.setPublisherDeptId(publisherDept.getId());
|
||||
|
||||
task.setId(id);
|
||||
@ -1975,7 +1976,8 @@ public class TaskService {
|
||||
|
||||
// 检查部门积分是否充足(管理员跳过积分检查,一级需求部门无明细提交场景跳过)
|
||||
User user = userService.getUserById(userId);
|
||||
Department publisherDept = resolvePublisherDeptForTaskUpdate(existTask, dto.getPublisherDeptId(), user, isAdmin);
|
||||
boolean allowDeptOverride = isAdmin || userId.equals(existTask.getPublisherId());
|
||||
Department publisherDept = resolvePublisherDeptForTaskUpdate(existTask, dto.getPublisherDeptId(), user, isAdmin, allowDeptOverride);
|
||||
existTask.setPublisherDeptId(publisherDept.getId());
|
||||
if (!isAdmin && !allowPrimaryTaskWithoutItems && publisherDept.getId() != null) {
|
||||
if (!teamScorePoolService.checkBalance(publisherDept.getId(), totalScoreInt)) {
|
||||
@ -2097,12 +2099,16 @@ public class TaskService {
|
||||
log.info("流水线任务更新成功: taskId={}, userId={}", id, userId);
|
||||
}
|
||||
|
||||
private Department resolvePublisherDeptForTaskUpdate(Task existTask, Long requestedDeptId, User editor, boolean isAdmin) {
|
||||
if (editor != null && requestedDeptId != null) {
|
||||
return resolvePublishingDepartment(editor, requestedDeptId, isAdmin);
|
||||
private Department resolvePublisherDeptForTaskUpdate(Task existTask, Long requestedDeptId, User editor, boolean isAdmin, boolean allowDeptOverride) {
|
||||
if (allowDeptOverride && editor != null && requestedDeptId != null) {
|
||||
try {
|
||||
return resolvePublishingDepartment(editor, requestedDeptId, isAdmin);
|
||||
} catch (BusinessException ex) {
|
||||
log.info("任务 {} 指定的发起部门 {} 无法继续使用,改为自动解析: {}", existTask.getId(), requestedDeptId, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (editor != null && (isAdmin || editor.getId().equals(existTask.getPublisherId()))) {
|
||||
if (allowDeptOverride && editor != null) {
|
||||
try {
|
||||
return resolvePublishingDepartment(editor, existTask.getPublisherDeptId(), isAdmin);
|
||||
} catch (BusinessException ex) {
|
||||
@ -2110,6 +2116,10 @@ public class TaskService {
|
||||
}
|
||||
}
|
||||
|
||||
if (!allowDeptOverride && requestedDeptId != null && !requestedDeptId.equals(existTask.getPublisherDeptId())) {
|
||||
log.info("任务 {} 由非发布人编辑,忽略前端传入的发起部门 {},继续沿用任务归属部门", existTask.getId(), requestedDeptId);
|
||||
}
|
||||
|
||||
Department fallbackDept = resolveDisplayPublisherDept(existTask);
|
||||
if (fallbackDept != null) {
|
||||
return fallbackDept;
|
||||
|
||||
@ -8,17 +8,17 @@
|
||||
<div class="balance-label">团队积分余额</div>
|
||||
<div class="balance-value">{{ teamScore }} 分</div>
|
||||
</div>
|
||||
<div v-if="availablePublishingDepartments.length > 0" class="publisher-dept-card">
|
||||
<div v-if="publishingDepartmentOptions.length > 0" class="publisher-dept-card">
|
||||
<div class="publisher-dept-label">发起部门</div>
|
||||
<a-select
|
||||
v-model:value="selectedPublishingDeptId"
|
||||
size="large"
|
||||
class="publisher-dept-select"
|
||||
:disabled="editMode || formData.isPrimaryTaskEdit || availablePublishingDepartments.length === 1"
|
||||
:placeholder="availablePublishingDepartments.length > 1 ? '请选择发起部门' : '当前发起部门'"
|
||||
:disabled="editMode || formData.isPrimaryTaskEdit || publishingDepartmentOptions.length === 1"
|
||||
:placeholder="publishingDepartmentOptions.length > 1 ? '请选择发起部门' : '当前发起部门'"
|
||||
>
|
||||
<a-select-option
|
||||
v-for="dept in availablePublishingDepartments"
|
||||
v-for="dept in publishingDepartmentOptions"
|
||||
:key="dept.deptId"
|
||||
:value="dept.deptId"
|
||||
>
|
||||
@ -665,6 +665,7 @@ const loading = ref(false)
|
||||
// 团队积分余额
|
||||
const teamScore = ref(0)
|
||||
const selectedPublishingDeptId = ref<number | undefined>(undefined)
|
||||
const editingPublishingDept = ref<PublishingDepartmentOption | null>(null)
|
||||
|
||||
// 判断是否是管理员(管理员跳过积分检查)
|
||||
const isAdmin = computed(() => {
|
||||
@ -740,8 +741,17 @@ const availablePublishingDepartments = computed<PublishingDepartmentOption[]>(()
|
||||
return result
|
||||
})
|
||||
|
||||
const publishingDepartmentOptions = computed<PublishingDepartmentOption[]>(() => {
|
||||
const departments = [...availablePublishingDepartments.value]
|
||||
const editDept = editingPublishingDept.value
|
||||
if (editDept && !departments.some(dept => dept.deptId === editDept.deptId)) {
|
||||
departments.unshift(editDept)
|
||||
}
|
||||
return departments
|
||||
})
|
||||
|
||||
const activePublishingDept = computed(() => {
|
||||
return availablePublishingDepartments.value.find(dept => dept.deptId === selectedPublishingDeptId.value)
|
||||
return publishingDepartmentOptions.value.find(dept => dept.deptId === selectedPublishingDeptId.value)
|
||||
})
|
||||
|
||||
// 任务子类型列表
|
||||
@ -843,7 +853,7 @@ const formData = reactive({
|
||||
})
|
||||
|
||||
const initializePublishingDept = (preferredDeptId?: number) => {
|
||||
const departments = availablePublishingDepartments.value
|
||||
const departments = publishingDepartmentOptions.value
|
||||
if (!departments.length) {
|
||||
selectedPublishingDeptId.value = undefined
|
||||
return
|
||||
@ -873,6 +883,32 @@ const initializePublishingDept = (preferredDeptId?: number) => {
|
||||
selectedPublishingDeptId.value = primaryPublishingDept?.deptId || departments[0].deptId
|
||||
}
|
||||
|
||||
const syncEditingPublishingDept = (task: any) => {
|
||||
const deptId = task?.publisherDeptId || task?.primaryPublisherDeptId
|
||||
const deptName = task?.publisherDeptName || task?.primaryPublisherDeptName
|
||||
|
||||
if (!deptId || !deptName) {
|
||||
editingPublishingDept.value = null
|
||||
return
|
||||
}
|
||||
|
||||
if (availablePublishingDepartments.value.some(dept => dept.deptId === deptId)) {
|
||||
editingPublishingDept.value = null
|
||||
return
|
||||
}
|
||||
|
||||
const deptType = task?.isPrimaryTask === 1 && task?.primaryPublisherDeptId === deptId
|
||||
? 'primary_demand'
|
||||
: 'demand'
|
||||
|
||||
editingPublishingDept.value = {
|
||||
deptId,
|
||||
deptName,
|
||||
deptType,
|
||||
isPrimary: 0
|
||||
}
|
||||
}
|
||||
|
||||
const getPreferredPublishingDeptId = () => {
|
||||
const routeDeptId = route.query.publisherDeptId ? Number(route.query.publisherDeptId) : undefined
|
||||
if (routeDeptId) return routeDeptId
|
||||
@ -2539,6 +2575,7 @@ const loadTaskForEdit = async (taskId: number) => {
|
||||
|
||||
if (task) {
|
||||
console.log('加载任务数据:', task)
|
||||
syncEditingPublishingDept(task)
|
||||
initializePublishingDept(task.publisherDeptId || task.primaryPublisherDeptId)
|
||||
|
||||
// 填充基本表单数据
|
||||
@ -2754,6 +2791,7 @@ const loadPrimaryTaskForEdit = async () => {
|
||||
}
|
||||
|
||||
console.log('加载一级需求任务数据:', task)
|
||||
syncEditingPublishingDept(task)
|
||||
initializePublishingDept(task.publisherDeptId || task.primaryPublisherDeptId)
|
||||
|
||||
// 设置编辑模式
|
||||
@ -2916,7 +2954,7 @@ onMounted(async () => {
|
||||
window.addEventListener('configUpdated', handleConfigUpdate as EventListener)
|
||||
})
|
||||
|
||||
watch(availablePublishingDepartments, (departments) => {
|
||||
watch(publishingDepartmentOptions, (departments) => {
|
||||
if (!departments.length) {
|
||||
selectedPublishingDeptId.value = undefined
|
||||
return
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user