From e4b9383e969b1c354ae2133493f25005a2546b8f Mon Sep 17 00:00:00 2001 From: kuaifan Date: Sun, 9 Jan 2022 18:20:36 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E8=AE=BE=E7=BD=AE=E5=AD=90=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=B6=E9=97=B4=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E4=B8=BB=E4=BB=BB=E5=8A=A1=E6=B2=A1=E6=9C=89=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=88=99=E8=87=AA=E5=8A=A8=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/ProjectController.php | 10 ++--- app/Models/ProjectTask.php | 43 ++++++++++++------- resources/assets/js/store/actions.js | 18 +++++--- 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/app/Http/Controllers/Api/ProjectController.php b/app/Http/Controllers/Api/ProjectController.php index 3a6ab5ed..02a99d53 100755 --- a/app/Http/Controllers/Api/ProjectController.php +++ b/app/Http/Controllers/Api/ProjectController.php @@ -1218,15 +1218,11 @@ class ProjectController extends AbstractController // $task = ProjectTask::userTask($task_id, true, 2); // 更新任务 - $updateProject = false; - $updateContent = false; - $updateSubTask = false; - $task->updateTask($data, $updateProject, $updateContent, $updateSubTask); + $updateMarking = []; + $task->updateTask($data, $updateMarking); // $data = ProjectTask::oneTask($task->id)->toArray(); - $data['is_update_project'] = $updateProject; - $data['is_update_content'] = $updateContent; - $data['is_update_subtask'] = $updateSubTask; + $data['update_marking'] = $updateMarking ?: json_decode('{}'); $task->pushMsg('update', $data); // return Base::retSuccess('修改成功', $data); diff --git a/app/Models/ProjectTask.php b/app/Models/ProjectTask.php index 5943321a..436ce590 100644 --- a/app/Models/ProjectTask.php +++ b/app/Models/ProjectTask.php @@ -478,14 +478,16 @@ class ProjectTask extends AbstractModel /** * 修改任务 * @param $data - * @param bool $updateProject 是否更新项目数据(项目统计) - * @param bool $updateContent 是否更新任务详情 - * @param bool $updateSubTask 是否更新子任务 + * @param array $updateMarking 更新的标记 + * - is_update_project 是否更新项目数据(项目统计) + * - is_update_content 是否更新任务详情 + * - is_update_maintask 是否更新主任务 + * - is_update_subtask 是否更新子任务 * @return bool */ - public function updateTask($data, &$updateProject = false, &$updateContent = false, &$updateSubTask = false) + public function updateTask($data, &$updateMarking = []) { - AbstractModel::transaction(function () use ($data, &$updateProject, &$updateContent, &$updateSubTask) { + AbstractModel::transaction(function () use ($data, &$updateMarking) { // 工作流 if (Arr::exists($data, 'flow_item_id')) { if ($this->flow_item_id == $data['flow_item_id']) { @@ -540,7 +542,7 @@ class ProjectTask extends AbstractModel } $this->completeTask(null); } - $updateProject = true; + $updateMarking['is_update_project'] = true; return; } // 标题 @@ -592,7 +594,7 @@ class ProjectTask extends AbstractModel $row->delete(); } } - $updateProject = true; + $updateMarking['is_update_project'] = true; $this->syncDialogUser(); } // 计划时间 @@ -608,13 +610,22 @@ class ProjectTask extends AbstractModel list($start, $end) = is_string($times) ? explode(",", $times) : (is_array($times) ? $times : []); if (Base::isDate($start) && Base::isDate($end) && $start != $end) { if ($this->parent_id > 0 && $data['skipTimesCheck'] !== true) { - // 如果是子任务,则不能超过主任务时间 + // 子任务时间判断 $mainTask = self::find($this->parent_id); - if (Carbon::parse($start)->lt($mainTask->start_at)) { - throw new ApiException('子任务开始时间不能小于主任务开始时间'); - } - if (Carbon::parse($end)->gt($mainTask->end_at)) { - throw new ApiException('子任务结束时间不能大于主任务结束时间'); + if (empty($mainTask->end_at)) { + // 如果主任务没有时间则自动设置 + $mainTask->start_at = Carbon::parse($start); + $mainTask->end_at = Carbon::parse($end); + $mainTask->save(); + $updateMarking['is_update_maintask'] = true; + } else { + // 限制不能超过主任务时间 + if (Carbon::parse($start)->lt($mainTask->start_at)) { + throw new ApiException('子任务开始时间不能小于主任务开始时间'); + } + if (Carbon::parse($end)->gt($mainTask->end_at)) { + throw new ApiException('子任务结束时间不能大于主任务结束时间'); + } } } $this->start_at = Carbon::parse($start); @@ -622,11 +633,11 @@ class ProjectTask extends AbstractModel } if ($this->parent_id == 0) { // 如果是主任务,则同步跟主任务相同时间的子任务 - self::where($originalWhere)->chunk(100, function($list) use ($times, &$updateSubTask) { + self::where($originalWhere)->chunk(100, function($list) use ($times, &$updateMarking) { foreach ($list as $item) { $item->updateTask(['times' => $times, 'skipTimesCheck' => true]); } - $updateSubTask = true; + $updateMarking['is_update_subtask'] = true; }); } $this->addLog("修改{任务}时间"); @@ -691,7 +702,7 @@ class ProjectTask extends AbstractModel ]); $this->desc = Base::getHtml($data['content'], 100); $this->addLog("修改{任务}详细描述"); - $updateContent = true; + $updateMarking['is_update_content'] = true; } // 优先级 $p = false; diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 9deb2efe..76295dad 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -857,6 +857,13 @@ export default { if (data.flow_item_name && data.flow_item_name.indexOf("|") !== -1) { [data.flow_item_status, data.flow_item_name] = data.flow_item_name.split("|") } + // + let updateMarking = {}; + if (typeof data.update_marking !== "undefined") { + updateMarking = $A.isJson(data.update_marking) ? data.update_marking : {}; + delete data.update_marking; + } + // let index = state.cacheTasks.findIndex(({id}) => id == data.id); if (index > -1) { state.cacheTasks.splice(index, 1, Object.assign({}, state.cacheTasks[index], data)); @@ -864,19 +871,16 @@ export default { state.cacheTasks.push(data); } // - if (data.parent_id > 0 && state.cacheTasks.findIndex(({id}) => id == data.parent_id) === -1) { + if (updateMarking.is_update_maintask === true || (data.parent_id > 0 && state.cacheTasks.findIndex(({id}) => id == data.parent_id) === -1)) { dispatch("getTaskOne", data.parent_id); } - if (data.is_update_project) { - data.is_update_project = false; + if (updateMarking.is_update_project === true) { dispatch("getProjectOne", data.project_id); } - if (data.is_update_content) { - data.is_update_content = false; + if (updateMarking.is_update_content === true) { dispatch("getTaskContent", data.id); } - if (data.is_update_subtask) { - data.is_update_subtask = false; + if (updateMarking.is_update_subtask === true) { dispatch("getTaskForParent", data.id); } //