perf: 设置子任务时间时,如果主任务没有时间则自动设置
This commit is contained in:
parent
95ac9aac14
commit
e4b9383e96
@ -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);
|
||||
|
@ -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;
|
||||
|
18
resources/assets/js/store/actions.js
vendored
18
resources/assets/js/store/actions.js
vendored
@ -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);
|
||||
}
|
||||
//
|
||||
|
Loading…
x
Reference in New Issue
Block a user