Quellcode durchsuchen

refactor:
1. 重构了对任务、交付物进行CURD操作时,根据项目状态的判断是否可执行的代码。

eyes4 vor 5 Monaten
Ursprung
Commit
245ccd1a4d

+ 33 - 30
pmr-biz-manager/src/routes/api/prj/outcome/add.ts

@@ -6,12 +6,12 @@ import {IdGen} from "@util/IdGen";
 import dayjs from "dayjs";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
 import {PrjInfo} from "@core-models/PrjInfo";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {PrjTaskOutcomeDraft} from "@core-models/PrjTaskOutcomeDraft";
-import {start_plan_alt_flow} from "../../../../utils/plan_task_helper";
-import {ChangeMarker, TaskStatus} from "../../../../utils/define";
+import {start_plan_alt_flow} from "@src/utils/plan_task_helper";
+import {ChangeMarker, TaskStatus} from "@src/utils/define";
+import {if_project_task_manageable_in_current_phase} from "@src/utils/prj_premission_helper";
 
 interface IData {
     /**
@@ -52,33 +52,36 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
         if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目不存在。'));
 
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许添加交付物。'));
-
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许添加交付物。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许添加交付物。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许添加交付物。'));
-        }
-
-        // if (data.draft == true) {
-        if (phase.order_index >= 60 && phase.order_index <= 65) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许添加交付物。'));
-        }
-        // } else {
-        if (data.draft === false) {
-            if (phase.order_index >= 30 && phase.order_index <= 40)
-                return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许添加。'));
-            // if (phase.order_index === 70)
-            //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接添加交付物,应在草稿中添加后重新提交计划变更审核。'));
-        }
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        //
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许添加交付物。'));
+        //
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许添加交付物。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许添加交付物。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许添加交付物。'));
+        // }
+        //
+        // // if (data.draft == true) {
+        // if (phase.order_index >= 60 && phase.order_index <= 65) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许添加交付物。'));
+        // }
+        // // } else {
+        // if (data.draft === false) {
+        //     if (phase.order_index >= 30 && phase.order_index <= 40)
+        //         return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许添加。'));
+        //     // if (phase.order_index === 70)
+        //     //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接添加交付物,应在草稿中添加后重新提交计划变更审核。'));
+        // }
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '添加交付物');
+        if (!result.manageable)
+            return reject(result.error);
         if (task.status >= TaskStatus.apply_for_review) {
             return reject(Resp.gen_err(Resp.InvalidFlow, '当前任务阶段不允许添加交付物。'));
         }

+ 30 - 28
pmr-biz-manager/src/routes/api/prj/outcome/modify.ts

@@ -10,8 +10,8 @@ import {start_plan_alt_flow} from "@src/utils/plan_task_helper";
 import {ChangeMarker, TaskStatus} from "@src/utils/define";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {PrjInfo} from "@core-models/PrjInfo";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {
+    if_project_task_manageable_in_current_phase,
     is_project_task_outcome_modifiable
 } from "@src/utils/prj_premission_helper";
 
@@ -86,33 +86,35 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
 
         let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
         if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目不存在。'));
-
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许修改交付物。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改交付物。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改交付物。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改交付物。'));
-        }
-
-        // if (data.draft == true) {
-            if (phase.order_index >= 60 && phase.order_index <= 65) {
-                return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许修改交付物。'));
-            }
-        // } else {
-        if (!data.draft) {
-            if (phase.order_index >=30 && phase.order_index <= 40)
-                return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
-            // if (phase.order_index === 70)
-            //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改交付物,应在草稿中修改后重新提交计划变更审核。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '修改交付物信息');
+        if (!result.manageable)
+            return reject(result.error);
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        //
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许修改交付物。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改交付物。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改交付物。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改交付物。'));
+        // }
+        //
+        // // if (data.draft == true) {
+        //     if (phase.order_index >= 60 && phase.order_index <= 65) {
+        //         return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许修改交付物。'));
+        //     }
+        // // } else {
+        // if (!data.draft) {
+        //     if (phase.order_index >=30 && phase.order_index <= 40)
+        //         return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
+        //     // if (phase.order_index === 70)
+        //     //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改交付物,应在草稿中修改后重新提交计划变更审核。'));
+        // }
         if (task.status >= TaskStatus.apply_for_review) {
             return reject(Resp.gen_err(Resp.InvalidFlow, '当前任务阶段不允许修改交付物。'));
         }

+ 29 - 27
pmr-biz-manager/src/routes/api/prj/outcome/remove.ts

@@ -1,7 +1,6 @@
 import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import {PrjInfo} from "@core-models/PrjInfo";
 import {Resp} from "@util/Resp";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
 import {PrjTaskOutcomeDraft} from "@core-models/PrjTaskOutcomeDraft";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
@@ -11,6 +10,7 @@ import {ChangeMarker, TaskStatus} from "@src/utils/define";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {Transaction} from "sequelize";
 import {
+    if_project_task_manageable_in_current_phase,
     is_project_task_outcome_modifiable
 } from "@src/utils/prj_premission_helper";
 
@@ -98,32 +98,34 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
 
         let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
         if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目不存在。'));
-
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许删除交付物。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许删除交付物。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许删除交付物。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许删除交付物。'));
-        }
-        // if (data.draft == true) {
-            if (phase.order_index >= 60 && phase.order_index <= 65) {
-                return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许删除交付物。'));
-            }
-        // } else {
-        if (!data.draft) {
-            if (phase.order_index >=30 && phase.order_index <= 40)
-                return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许删除。'));
-            // if (phase.order_index === 70)
-            //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接删除交付物,应在草稿中修改后重新提交计划变更审核。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '删除交付物信息');
+        if (!result.manageable)
+            return reject(result.error);
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        //
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许删除交付物。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许删除交付物。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许删除交付物。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许删除交付物。'));
+        // }
+        // // if (data.draft == true) {
+        //     if (phase.order_index >= 60 && phase.order_index <= 65) {
+        //         return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许删除交付物。'));
+        //     }
+        // // } else {
+        // if (!data.draft) {
+        //     if (phase.order_index >=30 && phase.order_index <= 40)
+        //         return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许删除。'));
+        //     // if (phase.order_index === 70)
+        //     //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接删除交付物,应在草稿中修改后重新提交计划变更审核。'));
+        // }
         if (task.status >= TaskStatus.apply_for_review) {
             return reject(Resp.gen_err(Resp.InvalidFlow, '当前任务阶段不允许删除交付物。'));
         }

+ 28 - 23
pmr-biz-manager/src/routes/api/prj/outcome/remove_file.ts

@@ -7,8 +7,10 @@ import {OutcomeStatus, TaskStatus} from "@src/utils/define";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {PrjInfo} from "@core-models/PrjInfo";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
-import {is_project_task_progress_modifiable} from "@src/utils/prj_premission_helper";
+import {
+    if_project_task_manageable_in_current_phase,
+    is_project_task_progress_modifiable
+} from "@src/utils/prj_premission_helper";
 
 interface IData {
     /**
@@ -39,27 +41,30 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
 
         let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
         if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目不存在。'));
-
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许删除交付物。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许删除交付文档。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许删除交付文档。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许删除交付文档。'));
-        }
-
-        if (phase.order_index >=30 && phase.order_index <= 40)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许删除交付文档。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,当前阶段不允许删除交付文档。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(false, prj_info.id, prj_info.phase_id, '删除交付文档');
+        if (!result.manageable)
+            return reject(result.error);
+
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        //
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许删除交付物。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许删除交付文档。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许删除交付文档。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许删除交付文档。'));
+        // }
+        //
+        // if (phase.order_index >=30 && phase.order_index <= 40)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许删除交付文档。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,当前阶段不允许删除交付文档。'));
+        // }
 
         if (task.status >= TaskStatus.apply_for_review) {
             return reject(Resp.gen_err(Resp.InvalidFlow, '当前任务阶段不允许删除交付文档。'));

+ 26 - 21
pmr-biz-manager/src/routes/api/prj/outcome/upload.ts

@@ -7,9 +7,11 @@ import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {QueryTypes} from "sequelize";
 import {PrjFile} from "@core-models/PrjFile";
 import dayjs from "dayjs";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjFileType, TaskStatus} from "@src/utils/define";
-import {is_project_task_progress_modifiable} from "@src/utils/prj_premission_helper";
+import {
+    if_project_task_manageable_in_current_phase,
+    is_project_task_progress_modifiable
+} from "@src/utils/prj_premission_helper";
 
 interface IData {
     /**
@@ -39,25 +41,28 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
 
         let prj_info = await PrjInfo.findOne({where: {id: task.prj_id}, raw: true});
         if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目不存在。'));
-
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项。'));
-        if (phase.order_index >= 20 && phase.order_index <= 40)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划制订或审核中,当前阶段不允许上传交付文档。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划变更正在审核中,当前阶段不允许上传交付文档。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '项目收尾阶段不允许上传交付文档。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许上传交付文档。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许上传交付文档。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许上传交付文档。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(false, prj_info.id, prj_info.phase_id, '上传交付文档');
+        if (!result.manageable)
+            return reject(result.error);
+
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        //
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项。'));
+        // if (phase.order_index >= 20 && phase.order_index <= 40)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划制订或审核中,当前阶段不允许上传交付文档。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划变更正在审核中,当前阶段不允许上传交付文档。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '项目收尾阶段不允许上传交付文档。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许上传交付文档。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许上传交付文档。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许上传交付文档。'));
+        // }
 
         // if (phase.order_index >= 60 && phase.order_index <= 65) {
         //     return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,当前阶段不允许上传交付文档。'));

+ 24 - 21
pmr-biz-manager/src/routes/api/prj/plan/add_task.ts

@@ -4,7 +4,6 @@ import DataCURD from "@core/DataCURD";
 import {IdGen} from "@util/IdGen";
 import dayjs from "dayjs";
 import {PrjInfo} from "@core-models/PrjInfo";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {start_plan_alt_flow, update_parent_task_info} from "@src/utils/plan_task_helper";
 import {FlowEngine} from "@src/bpmn/flow_engine";
@@ -13,7 +12,7 @@ import {BpmnModel} from "@core-models/BpmnModel";
 import {bpmn_flow_on_end} from "@src/utils/bpmn_work_helper";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {ChangeMarker} from "@src/utils/define";
-import {is_project_task_addable} from "@src/utils/prj_premission_helper";
+import {if_project_task_manageable_in_current_phase, is_project_task_addable} from "@src/utils/prj_premission_helper";
 import {PrjTaskOutcomeDraft} from "@core-models/PrjTaskOutcomeDraft";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
 
@@ -82,25 +81,29 @@ function guard(json: IRequest, cached_data: ICachedData): Promise<void> {
         if (!await is_project_task_addable(user, prj_info.id)) {
             return reject(Resp.gen_err(Resp.Forbidden, '您不是项目负责人或特权人员,不能添加任务。'));
         }
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        if (phase.order_index >= 30 && phase.order_index <= 40 && !data.draft)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许添加。'));
-        // if (phase.order_index >= 60 && phase.order_index <= 65 && !data.draft)
-        //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接添加计划,应在草稿中修改后重新提交审核。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许添加计划。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许添加计划。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许添加计划。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许添加计划。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许添加计划。'));
-        }
+
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '添加任务');
+        if (!result.manageable)
+            return reject(result.error);
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // if (phase.order_index >= 30 && phase.order_index <= 40 && !data.draft)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许添加。'));
+        // // if (phase.order_index >= 60 && phase.order_index <= 65 && !data.draft)
+        // //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接添加计划,应在草稿中修改后重新提交审核。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许添加计划。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许添加计划。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许添加计划。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许添加计划。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许添加计划。'));
+        // }
         resolve();
     });
 }

+ 24 - 18
pmr-biz-manager/src/routes/api/prj/plan/modify_task.ts

@@ -4,7 +4,6 @@ import {Transaction, WhereOptions} from "sequelize";
 import {PrjInfo} from "@core-models/PrjInfo";
 import dayjs from "dayjs";
 import {Resp} from "@util/Resp";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {
     get_outcome_max_plan_time,
@@ -14,7 +13,10 @@ import {
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {Logger} from "@util/Logger";
 import {ChangeMarker, TaskStatus} from "@src/utils/define";
-import {is_project_task_modifiable} from "@src/utils/prj_premission_helper";
+import {
+    if_project_task_manageable_in_current_phase,
+    is_project_task_modifiable
+} from "@src/utils/prj_premission_helper";
 
 interface IData {
     /**
@@ -91,24 +93,28 @@ function guard(json: IRequest, cached_data: ICachedData): Promise<void> {
         if (task.status === TaskStatus.completed || task.status === TaskStatus.cancelled) {
             return reject(Resp.gen_err(Resp.InvalidFlow, '任务已完成或已取消,不允许修改。'));
         }
+
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '修改任务');
+        if (!result.manageable)
+            return reject(result.error);
         // if (data.draft) return resolve();/// 草稿允许随意修改
 
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        if (phase.order_index >= 30 && phase.order_index <= 40 && !data.draft)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许修改计划。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改计划。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改计划。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改计划。'));
-        }
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // if (phase.order_index >= 30 && phase.order_index <= 40 && !data.draft)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许修改计划。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改计划。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改计划。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改计划。'));
+        // }
 
         resolve();
     });

+ 25 - 20
pmr-biz-manager/src/routes/api/prj/plan/remove_task.ts

@@ -1,14 +1,16 @@
 import {ADMINISTRATOR, IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import {PrjInfo} from "@core-models/PrjInfo";
 import {Resp} from "@util/Resp";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {start_plan_alt_flow, update_parent_task_info} from "@src/utils/plan_task_helper";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
 import {PrjTaskOutcomeDraft} from "@core-models/PrjTaskOutcomeDraft";
 import {ChangeMarker, TaskStatus} from "@src/utils/define";
-import {is_project_task_modifiable} from "@src/utils/prj_premission_helper";
+import {
+    if_project_task_manageable_in_current_phase,
+    is_project_task_modifiable
+} from "@src/utils/prj_premission_helper";
 
 interface IData {
     /**
@@ -44,8 +46,7 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         if (task.status === TaskStatus.completed || task.status === TaskStatus.cancelled) {
             return reject(Resp.gen_err(Resp.InvalidFlow, '任务已完成或已取消,不允许删除。'));
         }
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+
 
 
 
@@ -58,22 +59,26 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         //     if (phase.order_index >= 60 && phase.order_index <= 65) return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更已提交审核,当前阶段不允许删除。'));
         //     return resolve();/// 其它情况下草稿允许随意删除
         // }
-
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        if (phase.order_index >= 30 && phase.order_index <= 40 && !data.draft)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许删除。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许删除计划。'));
-
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许删除计划。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许删除计划。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许删除计划。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '删除任务');
+        if (!result.manageable)
+            return reject(result.error);
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // if (phase.order_index >= 30 && phase.order_index <= 40 && !data.draft)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许删除。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许删除计划。'));
+        //
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许删除计划。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许删除计划。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许删除计划。'));
+        // }
         resolve();
     });
 }

+ 25 - 20
pmr-biz-manager/src/routes/api/prj/plan/set_check_flow.ts

@@ -1,12 +1,14 @@
 import {ADMINISTRATOR, IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import {Resp} from "@util/Resp";
 import {PrjInfo} from "@core-models/PrjInfo";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {ChangeMarker, TaskStatus} from "@src/utils/define";
 import {start_plan_alt_flow} from "@src/utils/plan_task_helper";
-import {is_project_task_modifiable} from "@src/utils/prj_premission_helper";
+import {
+    if_project_task_manageable_in_current_phase,
+    is_project_task_modifiable
+} from "@src/utils/prj_premission_helper";
 import {Transaction} from "sequelize";
 
 interface IData {
@@ -62,24 +64,27 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         if (task.status >= TaskStatus.apply_for_review)
             return reject(Resp.gen_err(Resp.InvalidFlow, '计划任务项已提交审核,不允许修改。'));
 
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-        if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        if (phase.order_index >= 30 && phase.order_index <= 40 && data.draft === false)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
-        // if (phase.order_index >= 60 && phase.order_index <= 65 && data.draft === false) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改计划,应在草稿中修改后重新提交审核。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许修改计划。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许修改计划。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改计划。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改计划。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改计划。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '修改任务审核流程');
+        if (!result.manageable)
+            return reject(result.error);
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // if (phase.order_index >= 30 && phase.order_index <= 40 && data.draft === false)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
+        // // if (phase.order_index >= 60 && phase.order_index <= 65 && data.draft === false) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改计划,应在草稿中修改后重新提交审核。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许修改计划。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许修改计划。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改计划。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改计划。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改计划。'));
+        // }
         resolve();
     });
 }

+ 23 - 21
pmr-biz-manager/src/routes/api/prj/plan/sort_task.ts

@@ -2,13 +2,12 @@ import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined
 import {QueryTypes} from "sequelize";
 import {PrjInfo} from "@core-models/PrjInfo";
 import {Resp} from "@util/Resp";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {IdGen} from "@util/IdGen";
 import {start_plan_alt_flow, update_parent_task_info} from "@src/utils/plan_task_helper";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {ChangeMarker} from "@src/utils/define";
-import {is_project_modifiable} from "@src/utils/prj_premission_helper";
+import {if_project_task_manageable_in_current_phase, is_project_modifiable} from "@src/utils/prj_premission_helper";
 
 interface IData {
     /**
@@ -44,25 +43,28 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         if (!await is_project_modifiable(user, prj_info.id))
             return reject(Resp.gen_err(Resp.Forbidden, '您没有权限对任务进行排序。'));
 
-        let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
-        if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
-        // if (phase.order_index >= 30 && data.draft === false) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改计划,应在草稿中修改后重新提交审核。'));
-        // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
-        if (phase.order_index >=30 && phase.order_index <= 40 && !data.draft)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
-        // if (phase.order_index >= 60 && phase.order_index <=65 && !data.draft) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改计划,应在草稿中修改后重新提交审核。'));
-        // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许修改计划。'));
-        if (phase.order_index >= 60 && phase.order_index <= 65)
-            return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许修改计划。'));
-        if (phase.order_index === 80) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改计划。'));
-        }
-        if (phase.order_index === 90) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改计划。'));
-        }
-        if (phase.order_index === 100) {
-            return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改计划。'));
-        }
+        let result = await if_project_task_manageable_in_current_phase(data.draft, prj_info.id, prj_info.phase_id, '调整任务顺序');
+        if (!result.manageable)
+            return reject(result.error);
+        // let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
+        // if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj_info.id));
+        // // if (phase.order_index >= 30 && data.draft === false) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改计划,应在草稿中修改后重新提交审核。'));
+        // // if (phase.order_index < 20) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
+        // if (phase.order_index >=30 && phase.order_index <= 40 && !data.draft)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许修改。'));
+        // // if (phase.order_index >= 60 && phase.order_index <=65 && !data.draft) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接修改计划,应在草稿中修改后重新提交审核。'));
+        // // if (phase.order_index >= 80) return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许修改计划。'));
+        // if (phase.order_index >= 60 && phase.order_index <= 65)
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目处于计划变更审核过程中,不允许修改计划。'));
+        // if (phase.order_index === 80) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目验收中,不允许修改计划。'));
+        // }
+        // if (phase.order_index === 90) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已作废,不允许修改计划。'));
+        // }
+        // if (phase.order_index === 100) {
+        //     return reject(Resp.gen_err(Resp.InvalidFlow, '项目已完成,不允许修改计划。'));
+        // }
         resolve();
     });
 }

+ 4 - 3
pmr-biz-manager/src/utils/plan_task_helper.ts

@@ -63,8 +63,6 @@ export async function update_parent_task_info(draft: boolean, prj_id: string, ta
     } else {
         await PrjInfo.update({progress: progress}, {where: {id: prj_id}, transaction: t, returning: false});
     }
-
-    // }
 }
 
 export async function start_plan_alt_flow(prj_id: string, user_id: string, t?: any): Promise<void> {
@@ -103,6 +101,7 @@ export interface TaskInfo {
     outcome_status: number;
 }
 
+// 通过交付物id获取任务信息
 export async function get_task_info_by_outcome_id(draft: boolean, outcome_id: string, t?: any): Promise<TaskInfo | undefined> {
     let outcome_model = draft ? PrjTaskOutcomeDraft : PrjTaskOutcome;
     let outcome = await outcome_model.findOne({
@@ -125,6 +124,7 @@ export async function get_task_info_by_outcome_id(draft: boolean, outcome_id: st
     };
 }
 
+// 获取任务的最大计划时间
 export async function get_outcome_max_plan_time(draft: boolean, task_id: string, t?: any): Promise<Date | null> {
 
     let outcome_model = draft ? PrjTaskOutcomeDraft : PrjTaskOutcome;
@@ -141,4 +141,5 @@ export async function get_outcome_max_plan_time(draft: boolean, task_id: string,
     if (!outcome || outcome.length === 0) return null;
 
     return outcome[0].max_time;
-}
+}
+

+ 50 - 1
pmr-biz-manager/src/utils/prj_premission_helper.ts

@@ -5,6 +5,8 @@ import {QueryTypes} from "sequelize";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {Logger} from "@util/Logger";
 import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
+import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
+import {Resp} from "@util/Resp";
 
 /// 是否是项目特权账户
 export async function is_project_privileged_account(account_id: string): Promise<boolean> {
@@ -186,4 +188,51 @@ export async function is_project_task_outcome_modifiable(account_id: string, tas
 
     Logger.trace(`${account_id} 没有权限修改任务 ${task_id}的进度。`);
     return false;
-}
+}
+
+
+export interface ITaskManageableCheckResult {
+    manageable: boolean;
+    error: any;
+}
+
+// 检查当前项目状态下是否可以对计划任务进行添加、修改、删除、排序及设置审核人
+export async function if_project_task_manageable_in_current_phase(draft: boolean, prj_id: string, phase_id: string, action: string): Promise<ITaskManageableCheckResult> {
+    let result = {
+        manageable: false,
+        error: undefined
+    }
+    let phase = await PrjPhaseDefine.findOne({where: {id: phase_id}, raw: true});
+    if (!phase) {
+        result.error = Resp.gen_err(Resp.ResourceNotFound, `项目状态信息出错(${action}),项目编号:  ${prj_id}`);
+        return result;
+    }
+    if (phase.order_index < 20)  {
+        result.error = Resp.gen_err(Resp.InvalidFlow, `需要先对项目进行立项,立项后才可${action}。`);
+        return result;
+    }
+    if (phase.order_index >= 30 && phase.order_index <= 40 && !draft) {
+        result.error = Resp.gen_err(Resp.InvalidFlow, `项目计划审核中,当前阶段不允许${action}。`);
+        return result;
+    }
+
+    if (phase.order_index >= 60 && phase.order_index <= 65) {
+        result.error = Resp.gen_err(Resp.InvalidFlow, `当前项目处于计划变更审核过程中,不允许${action}。`);
+        return result;
+    }
+    if (phase.order_index === 80) {
+        result.error = Resp.gen_err(Resp.InvalidFlow, `项目验收中,不允许${action}。`);
+        return result;
+    }
+    if (phase.order_index === 90) {
+        result.error = Resp.gen_err(Resp.InvalidFlow, `项目已作废,不允许${action}。`);
+        return result;
+    }
+    if (phase.order_index === 100) {
+        result.error =  Resp.gen_err(Resp.InvalidFlow, `项目已完成,不允许${action}。`);
+        return result;
+    }
+
+    result.manageable = true;
+    return result;
+}