diff --git a/app/Http/Controllers/Business/SystemizationTodos.php b/app/Http/Controllers/Business/SystemizationTodos.php
index 1420c6aa..e1538461 100644
--- a/app/Http/Controllers/Business/SystemizationTodos.php
+++ b/app/Http/Controllers/Business/SystemizationTodos.php
@@ -106,27 +106,6 @@ class SystemizationTodos extends Controller
});
$items = $items->sortBy('hierarchy_order')->values();
$positionGroups = $this->positionGroups($sequenceMap);
- if ($filters['type_sequence'] > 0) {
- $items = $items
- ->filter(static fn (SystemizationTodo $todo): bool =>
- (int) $todo->type_sequence === $filters['type_sequence']
- )
- ->values();
- }
- if ($filters['content_sequence'] > 0) {
- $items = $items
- ->filter(static fn (SystemizationTodo $todo): bool =>
- (int) $todo->content_sequence === $filters['content_sequence']
- )
- ->values();
- }
- if ($filters['item_sequence'] > 0) {
- $items = $items
- ->filter(static fn (SystemizationTodo $todo): bool =>
- (int) $todo->item_sequence === $filters['item_sequence']
- )
- ->values();
- }
$base = SystemizationTodo::query();
$categories = SystemizationTodo::query()
@@ -428,7 +407,11 @@ class SystemizationTodos extends Controller
);
}
- private function contentSiblings(?string $category, ?string $section): Collection
+ private function contentSiblings(
+ ?string $category,
+ ?string $section,
+ ?int $excludeId = null,
+ ): Collection
{
$categoryKey = $this->hierarchyGroupKey($this->hierarchyLabel($category));
$sectionKey = $this->hierarchyGroupKey($this->hierarchyLabel($section));
@@ -439,12 +422,54 @@ class SystemizationTodos extends Controller
->lockForUpdate()
->get()
->filter(fn (SystemizationTodo $todo): bool =>
- $this->hierarchyGroupKey($this->hierarchyLabel($todo->category)) === $categoryKey
+ (int) $todo->id !== (int) $excludeId
+ && $this->hierarchyGroupKey($this->hierarchyLabel($todo->category)) === $categoryKey
&& $this->hierarchyGroupKey($this->hierarchyLabel($todo->section)) === $sectionKey
)
->values();
}
+ private function positionForUpdate(
+ SystemizationTodo $todo,
+ int $targetPosition,
+ array &$data,
+ ): void {
+ $currentCategoryKey = $this->hierarchyGroupKey($this->hierarchyLabel($todo->category));
+ $currentSectionKey = $this->hierarchyGroupKey($this->hierarchyLabel($todo->section));
+ $targetCategoryKey = $this->hierarchyGroupKey($this->hierarchyLabel($data['category'] ?? null));
+ $targetSectionKey = $this->hierarchyGroupKey($this->hierarchyLabel($data['section'] ?? null));
+ $sameGroup = $currentCategoryKey === $targetCategoryKey
+ && $currentSectionKey === $targetSectionKey;
+
+ if ($sameGroup) {
+ $currentSiblings = $this->contentSiblings($todo->category, $todo->section);
+ $currentIndex = $currentSiblings->search(
+ static fn (SystemizationTodo $item): bool => (int) $item->id === (int) $todo->id
+ );
+ if ($currentIndex !== false && $targetPosition === ((int) $currentIndex + 1)) {
+ return;
+ }
+ }
+
+ $siblings = $this->contentSiblings(
+ $data['category'] ?? null,
+ $data['section'] ?? null,
+ (int) $todo->id,
+ );
+ if ($siblings->isEmpty()) {
+ $insertOrder = (int) SystemizationTodo::query()->max('sort_order') + 1;
+ } elseif ($targetPosition <= $siblings->count()) {
+ $insertOrder = (int) $siblings[$targetPosition - 1]->sort_order;
+ } else {
+ $insertOrder = (int) $siblings->max('sort_order') + 1;
+ }
+
+ SystemizationTodo::query()
+ ->where('sort_order', '>=', $insertOrder)
+ ->increment('sort_order');
+ $data['sort_order'] = $insertOrder;
+ }
+
private function groupTodoIds(SystemizationTodo $todo, bool $includeSection): array
{
$categoryKey = $this->hierarchyGroupKey($this->hierarchyLabel($todo->category));
@@ -480,6 +505,7 @@ class SystemizationTodos extends Controller
public function update(Request $request, SystemizationTodo $todo): RedirectResponse
{
$data = $this->validated($request);
+ $targetPosition = max(0, (int) ($data['position'] ?? 0));
unset($data['position']);
$data['updated_by'] = user_id();
$this->normalizeCompletionDates($data);
@@ -500,7 +526,16 @@ class SystemizationTodos extends Controller
}
}
- $todo->update($data);
+ DB::transaction(function () use ($todo, $data, $targetPosition): void {
+ $lockedTodo = SystemizationTodo::query()
+ ->lockForUpdate()
+ ->findOrFail($todo->id);
+ if ($targetPosition > 0) {
+ $this->positionForUpdate($lockedTodo, $targetPosition, $data);
+ }
+ $lockedTodo->update($data);
+ $todo->setRawAttributes($lockedTodo->getAttributes(), true);
+ });
$this->storeAttachments($request, $todo);
return $this->backToPage('待办事项已更新并定位。', 'success', $todo);
@@ -572,9 +607,6 @@ class SystemizationTodos extends Controller
'assignees' => $this->peopleFilter('assignee'),
'start_date' => $this->normalizeDateFilter(request('start_date')),
'due_date' => $this->normalizeDateFilter(request('due_date')),
- 'type_sequence' => max(0, (int) request('type_sequence', 0)),
- 'content_sequence' => max(0, (int) request('content_sequence', 0)),
- 'item_sequence' => max(0, (int) request('item_sequence', 0)),
'keyword' => trim((string) request('keyword', '')),
];
}
diff --git a/resources/views/business/pages/systemization-todos.blade.php b/resources/views/business/pages/systemization-todos.blade.php
index 2c555b77..380637b1 100644
--- a/resources/views/business/pages/systemization-todos.blade.php
+++ b/resources/views/business/pages/systemization-todos.blade.php
@@ -215,9 +215,6 @@
@endforeach
-
-
-
@php
$selectedOwners = $todoOwners->filter(
static fn (string $owner): bool => in_array($owner, $todoFilters['owners'], true)
@@ -345,7 +342,7 @@
- | 类型 | 内容 | 待办序号 | 待办事项 | 总负责人 | 责任人 |
+ 类型 | 内容 | 待办事项序号 | 待办事项 | 总负责人 | 责任人 |
开始时间 | 完成时间 | 状态 | 完成情况 | 完成截图 | 备注 |
@@ -363,6 +360,7 @@
};
$todoPayload = [
'id' => $item->id,
+ 'position' => (int) $item->item_sequence,
'category' => $item->category ?? '',
'section' => $sectionLabels[$loop->index] ?? '',
'title' => $titleLabels[$loop->index] ?? '',
@@ -489,7 +487,7 @@
-