Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Service/Permission/DepartmentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function updateById(mixed $id, array $data): mixed
if (empty($entity)) {
throw new BusinessException(ResultCode::NOT_FOUND);
}
$this->repository->updateById($id, $data);
$this->handleEntity($entity, $data);
Comment on lines +47 to 48
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

请在 Line 47 先校验更新结果,并在 Line 48 前刷新实体后再同步关联。

DepartmentRepository::updateById() 返回 bool,当前忽略结果会导致“基础字段更新失败,但 handleEntity 仍执行”的部分成功状态;同时 $entity 仍是旧内存对象。建议先判定更新成功,再 refresh() 后做关系同步。

建议修改
-            $this->repository->updateById($id, $data);
-            $this->handleEntity($entity, $data);
+            $updated = $this->repository->updateById($id, $data);
+            if (! $updated) {
+                throw new \RuntimeException('Failed to update department base fields.');
+            }
+            $entity->refresh();
+            $this->handleEntity($entity, $data);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/Service/Permission/DepartmentService.php` around lines 47 - 48, 在
DepartmentService 的更新逻辑中,不要忽略 DepartmentRepository::updateById($id, $data)
的返回值;先把返回值赋给一个变量并判断是否为真(更新成功),若失败直接返回或抛出错误;如果成功,先对当前实体 $entity 调用
refresh()(确保内存中是最新数据),然后再调用 handleEntity($entity, $data) 进行关联同步和后续处理。

});
}
Expand Down
Loading