|
@@ -77,6 +77,8 @@ function guard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
|
|
|
let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
|
|
let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
|
|
if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound));
|
|
if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound));
|
|
|
|
+ cached_data.deliver_at = prj_info.deliver_at; // 缓存项目的交付时间
|
|
|
|
+
|
|
// 检查用户是否是项目负责人,只有项目负责人才可以修改任务
|
|
// 检查用户是否是项目负责人,只有项目负责人才可以修改任务
|
|
if (cached_data.user_id !== prj_info.leader_id) {
|
|
if (cached_data.user_id !== prj_info.leader_id) {
|
|
return reject(Resp.gen_err(Resp.Forbidden, '您不是项目负责人,不能修改任务。'));
|
|
return reject(Resp.gen_err(Resp.Forbidden, '您不是项目负责人,不能修改任务。'));
|
|
@@ -121,6 +123,12 @@ function modify(json: IRequest, params: IMethodParams, cached_data: ICachedData)
|
|
// 检查起止时间是否合法
|
|
// 检查起止时间是否合法
|
|
let begin_at = data.begin_at || task.begin_at;
|
|
let begin_at = data.begin_at || task.begin_at;
|
|
let end_at = data.end_at || task.end_at;
|
|
let end_at = data.end_at || task.end_at;
|
|
|
|
+
|
|
|
|
+ // 检查计划结束时间不能晚于项目交付时间
|
|
|
|
+ if (dayjs(data.end_at).diff(dayjs(cached_data.deliver_at)) > 0) {
|
|
|
|
+ return reject(Resp.gen_err(Resp.ParamsError, `计划结束时间不能晚于项目交付时间 ${dayjs(cached_data.deliver_at).format('YYYY-MM-DD')}。`));
|
|
|
|
+ }
|
|
|
|
+
|
|
if (dayjs(end_at).diff(dayjs(begin_at)) <= 0)
|
|
if (dayjs(end_at).diff(dayjs(begin_at)) <= 0)
|
|
throw Resp.gen_err(Resp.ParamsError, '任务结束时间必须晚于开始时间。');
|
|
throw Resp.gen_err(Resp.ParamsError, '任务结束时间必须晚于开始时间。');
|
|
|
|
|
|
@@ -146,8 +154,7 @@ function modify(json: IRequest, params: IMethodParams, cached_data: ICachedData)
|
|
updated_at: "updated_at"
|
|
updated_at: "updated_at"
|
|
}
|
|
}
|
|
}, cached_data, t);
|
|
}, cached_data, t);
|
|
- // await update_parent_task_time(data.task_id, t);
|
|
|
|
- // await update_parent_task_info(result.pid, t);
|
|
|
|
|
|
+
|
|
await update_parent_task_info(data.draft, result.prj_id, result.pid, t as Transaction);
|
|
await update_parent_task_info(data.draft, result.prj_id, result.pid, t as Transaction);
|
|
|
|
|
|
/// 如果计划任务是草稿,且还没有生成计划变更任务,则生成任务
|
|
/// 如果计划任务是草稿,且还没有生成计划变更任务,则生成任务
|
|
@@ -164,48 +171,6 @@ function modify(json: IRequest, params: IMethodParams, cached_data: ICachedData)
|
|
})
|
|
})
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
-/// 递归逐级更新任务起止时间
|
|
|
|
-async function update_parent_task_time(task_id: string, t: Transaction, max?: Dayjs, min?: Dayjs): Promise<void> {
|
|
|
|
- let task = await PrjPlanTask.findOne({where: {id: task_id}, transaction: t});
|
|
|
|
-
|
|
|
|
- if (!task) {
|
|
|
|
- throw new Error(`Task with ID ${task_id} not found.`);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (task.pid) {
|
|
|
|
- let child_tasks = await PrjPlanTask.findAll({
|
|
|
|
- where: {pid: task.pid},
|
|
|
|
- transaction: t
|
|
|
|
- });
|
|
|
|
- let total_duration = 0;
|
|
|
|
- let completed = 0;
|
|
|
|
- for (let i = 0; i < child_tasks.length; i++) {
|
|
|
|
- let child_task = child_tasks[i];
|
|
|
|
- let begin = dayjs(child_task.begin_at);
|
|
|
|
- let end = dayjs(child_task.end_at);
|
|
|
|
- if (max === undefined) max = end;
|
|
|
|
- else max = end.diff(max) > 0 ? end : max;
|
|
|
|
- if (min === undefined) min = begin;
|
|
|
|
- else min = begin.diff(min) < 0 ? begin : min;
|
|
|
|
- let duration = dayjs(child_task.end_at).diff(child_task.begin_at, 'hours');
|
|
|
|
- total_duration += duration;
|
|
|
|
- completed += duration * child_task.progress / 100;
|
|
|
|
- }
|
|
|
|
- let progress = total_duration !== 0 ? (completed * 100 / total_duration) : 0;
|
|
|
|
- if (progress > 0 && progress < 1) progress = 1;
|
|
|
|
- else if (progress < 100 && progress > 99) progress = 99;
|
|
|
|
- else progress = Math.round(progress);
|
|
|
|
- await PrjPlanTask.update({begin_at: min!, end_at: max!, progress: progress}, {
|
|
|
|
- where: {id: task.pid},
|
|
|
|
- transaction: t
|
|
|
|
- })
|
|
|
|
- await update_parent_task_time(task.pid, t);
|
|
|
|
- // await update_parent_task_info(task.prj_id, task.pid, t);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
async function before_respond(content: IRequest, params: IMethodParams, cached_data: ICachedData | any, result: any): Promise<unknown> {
|
|
async function before_respond(content: IRequest, params: IMethodParams, cached_data: ICachedData | any, result: any): Promise<unknown> {
|
|
result = DataCURD.filter_null(result, new Map(Object.entries({
|
|
result = DataCURD.filter_null(result, new Map(Object.entries({
|
|
"updated_at": "YYYY-MM-DD HH:mm:ss",
|
|
"updated_at": "YYYY-MM-DD HH:mm:ss",
|