|
@@ -15,7 +15,7 @@ import {BpmnModel} from "@core-models/BpmnModel";
|
|
import {bpmn_flow_on_end} from "@src/utils/bpmn_work_helper";
|
|
import {bpmn_flow_on_end} from "@src/utils/bpmn_work_helper";
|
|
import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
|
|
import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
|
|
import {ChangeMarker} from "@src/utils/define";
|
|
import {ChangeMarker} from "@src/utils/define";
|
|
-import {is_project_modifiable} from "@src/utils/prj_premission_helper";
|
|
|
|
|
|
+import {is_project_modifiable, is_project_task_addable} from "@src/utils/prj_premission_helper";
|
|
|
|
|
|
interface IData {
|
|
interface IData {
|
|
/**
|
|
/**
|
|
@@ -29,7 +29,7 @@ interface IData {
|
|
/**
|
|
/**
|
|
* 计划结束时间(YYYY-MM-DD)
|
|
* 计划结束时间(YYYY-MM-DD)
|
|
*/
|
|
*/
|
|
- end_at?: string;
|
|
|
|
|
|
+ end_at: string;
|
|
/**
|
|
/**
|
|
* 负责人id
|
|
* 负责人id
|
|
*/
|
|
*/
|
|
@@ -49,28 +49,32 @@ interface IData {
|
|
/**
|
|
/**
|
|
* 父级任务id,父级任务id,为空时表示本身是一级任务
|
|
* 父级任务id,父级任务id,为空时表示本身是一级任务
|
|
*/
|
|
*/
|
|
- task_pid?: string|null;
|
|
|
|
|
|
+ task_pid?: string | null;
|
|
}
|
|
}
|
|
|
|
|
|
-/// 项目任务提交申请后,只允许在副本中添加
|
|
|
|
-function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
|
|
|
+function guard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
let user = cached_data.user_id;
|
|
let user = cached_data.user_id;
|
|
let data = <IData>json.data;
|
|
let data = <IData>json.data;
|
|
if (!user) return reject(Resp.gen_err(Resp.Forbidden));
|
|
if (!user) return reject(Resp.gen_err(Resp.Forbidden));
|
|
if (user === ADMINISTRATOR) return resolve();
|
|
if (user === ADMINISTRATOR) return resolve();
|
|
|
|
+ // 检查计划结束时间是否晚于计划开始时间
|
|
|
|
+ data.begin_at += ' 00:00:00';
|
|
|
|
+ data.end_at += ' 23:59:59';
|
|
|
|
+ if (dayjs(data.end_at).diff(dayjs(data.begin_at)) <= 0)
|
|
|
|
+ return reject(Resp.gen_err(Resp.ParamsError, '计划结束时间必须晚于计划开始时间。'));
|
|
let prj_info = await PrjInfo.findOne({where: {id: data.prj_id}, raw: true});
|
|
let prj_info = await PrjInfo.findOne({where: {id: data.prj_id}, raw: true});
|
|
if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound));
|
|
if (!prj_info) return reject(Resp.gen_err(Resp.ResourceNotFound));
|
|
- // 检查用户是否是项目负责人,只有项目负责人或特权人员才可以添加任务
|
|
|
|
- if (!await is_project_modifiable(user, prj_info.id)) {
|
|
|
|
|
|
+ // 只有项目负责人或特权人员才可以添加任务
|
|
|
|
+ if (!await is_project_task_addable(user, prj_info.id)) {
|
|
return reject(Resp.gen_err(Resp.Forbidden, '您不是项目负责人或特权人员,不能添加任务。'));
|
|
return reject(Resp.gen_err(Resp.Forbidden, '您不是项目负责人或特权人员,不能添加任务。'));
|
|
}
|
|
}
|
|
let phase = await PrjPhaseDefine.findOne({where: {id: prj_info.phase_id}, raw: true});
|
|
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) 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) return reject(Resp.gen_err(Resp.InvalidFlow, '需要先对项目进行立项,立项后才可制订计划。'));
|
|
- if (phase.order_index >=30 && phase.order_index <= 40 && data.draft === false)
|
|
|
|
|
|
+ if (phase.order_index >= 30 && phase.order_index <= 40 && data.draft === false)
|
|
return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许添加。'));
|
|
return reject(Resp.gen_err(Resp.InvalidFlow, '项目计划审核中,当前阶段不允许添加。'));
|
|
- if (phase.order_index >= 60 && phase.order_index <=70 && data.draft === false)
|
|
|
|
|
|
+ if (phase.order_index >= 60 && phase.order_index <= 70 && data.draft === false)
|
|
return reject(Resp.gen_err(Resp.InvalidFlow, '当前项目阶段不允许直接添加计划,应在草稿中修改后重新提交审核。'));
|
|
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, '当前项目阶段不允许添加计划。'));
|
|
|
|
|
|
@@ -80,7 +84,7 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
|
|
|
// 如添加的是子任务,查找父任务是否存在
|
|
// 如添加的是子任务,查找父任务是否存在
|
|
// 如任务已经执行,不能再作为主任务添加子任务
|
|
// 如任务已经执行,不能再作为主任务添加子任务
|
|
-function checkParentGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
|
|
|
+function check_parent_guard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
let data = <IData>json.data;
|
|
let data = <IData>json.data;
|
|
if (data.task_pid === undefined) return resolve();
|
|
if (data.task_pid === undefined) return resolve();
|
|
@@ -100,10 +104,10 @@ function add(json: IRequest, params: IMethodParams, cached_data: ICachedData): P
|
|
try {
|
|
try {
|
|
let user = cached_data.user_id;
|
|
let user = cached_data.user_id;
|
|
let data = <IData>json.data;
|
|
let data = <IData>json.data;
|
|
- if (data.begin_at && data.end_at) {
|
|
|
|
- if (dayjs(data.end_at).diff(data.begin_at) < 0)
|
|
|
|
- throw Resp.gen_err(Resp.IIllegalRequest, '任务预计完成时间不能早于或等于任务开始时间。')
|
|
|
|
- }
|
|
|
|
|
|
+ // if (data.begin_at && data.end_at) {
|
|
|
|
+ // if (dayjs(data.end_at).diff(data.begin_at) < 0)
|
|
|
|
+ // throw Resp.gen_err(Resp.IIllegalRequest, '任务预计完成时间不能早于或等于任务开始时间。')
|
|
|
|
+ // }
|
|
|
|
|
|
let id = IdGen.id();
|
|
let id = IdGen.id();
|
|
|
|
|
|
@@ -113,14 +117,14 @@ function add(json: IRequest, params: IMethodParams, cached_data: ICachedData): P
|
|
prj_id: data.prj_id,
|
|
prj_id: data.prj_id,
|
|
name: data.name,
|
|
name: data.name,
|
|
handler_id: data.handler_id,
|
|
handler_id: data.handler_id,
|
|
- begin_at: data.begin_at + ' 00:00:00',
|
|
|
|
- end_at: data.end_at ? data.end_at + ' 23:59:59' : null,
|
|
|
|
|
|
+ begin_at: data.begin_at,
|
|
|
|
+ end_at: data.end_at,
|
|
creator_id: user,
|
|
creator_id: user,
|
|
description: data.description,
|
|
description: data.description,
|
|
|
|
|
|
created_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
created_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
order_id: IdGen.id(),
|
|
order_id: IdGen.id(),
|
|
- change_marker: data.draft? ChangeMarker.Added: undefined
|
|
|
|
|
|
+ change_marker: data.draft ? ChangeMarker.Added : undefined
|
|
}
|
|
}
|
|
value = DataCURD.filter_null(value);
|
|
value = DataCURD.filter_null(value);
|
|
|
|
|
|
@@ -130,17 +134,24 @@ function add(json: IRequest, params: IMethodParams, cached_data: ICachedData): P
|
|
await update_parent_task_info(data.draft, data.prj_id, data.task_pid, t);
|
|
await update_parent_task_info(data.draft, data.prj_id, data.task_pid, t);
|
|
|
|
|
|
// 检查计划审核工作流程是否已经启动,没有的话就建一个
|
|
// 检查计划审核工作流程是否已经启动,没有的话就建一个
|
|
- let flow = await BpmnCase.findOne({where: {prj_id: data.prj_id, model_id: 'plan'}, transaction: t, raw: true});
|
|
|
|
|
|
+ let flow = await BpmnCase.findOne({
|
|
|
|
+ where: {prj_id: data.prj_id, model_id: 'plan'},
|
|
|
|
+ transaction: t,
|
|
|
|
+ raw: true
|
|
|
|
+ });
|
|
if (!flow && data.draft === false) {
|
|
if (!flow && data.draft === false) {
|
|
let bpmn = await BpmnModel.findOne({where: {id: 'plan'}, transaction: t});
|
|
let bpmn = await BpmnModel.findOne({where: {id: 'plan'}, transaction: t});
|
|
if (!bpmn) throw Resp.gen_err(Resp.InternalServerError, '项目流程模型数据缺失!');
|
|
if (!bpmn) throw Resp.gen_err(Resp.InternalServerError, '项目流程模型数据缺失!');
|
|
- let flow = new FlowEngine(bpmn.id, bpmn.content, {prj_id: data.prj_id, owner: cached_data.user_id}, bpmn_flow_on_end);
|
|
|
|
|
|
+ let flow = new FlowEngine(bpmn.id, bpmn.content, {
|
|
|
|
+ prj_id: data.prj_id,
|
|
|
|
+ owner: cached_data.user_id
|
|
|
|
+ }, bpmn_flow_on_end);
|
|
await flow.run();
|
|
await flow.run();
|
|
await BpmnCase.create({
|
|
await BpmnCase.create({
|
|
id: flow.id,
|
|
id: flow.id,
|
|
model_id: bpmn.id,
|
|
model_id: bpmn.id,
|
|
model: bpmn.content,
|
|
model: bpmn.content,
|
|
- started_at: dayjs(),
|
|
|
|
|
|
+ started_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
creator_id: cached_data.user_id,
|
|
creator_id: cached_data.user_id,
|
|
prj_id: data.prj_id,
|
|
prj_id: data.prj_id,
|
|
// state: await flow.state(),
|
|
// state: await flow.state(),
|
|
@@ -148,7 +159,7 @@ function add(json: IRequest, params: IMethodParams, cached_data: ICachedData): P
|
|
}
|
|
}
|
|
|
|
|
|
/// 如果计划任务是草稿,且还没有生成计划变更任务,则生成任务
|
|
/// 如果计划任务是草稿,且还没有生成计划变更任务,则生成任务
|
|
- if (data.draft === true ) {
|
|
|
|
|
|
+ if (data.draft === true) {
|
|
await start_plan_alt_flow(data.prj_id, cached_data.user_id, t);
|
|
await start_plan_alt_flow(data.prj_id, cached_data.user_id, t);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -247,7 +258,7 @@ const v1_0: IApiProcessor = {
|
|
},
|
|
},
|
|
method: add,
|
|
method: add,
|
|
method_params: {},
|
|
method_params: {},
|
|
- guards: [statusGuard, checkParentGuard]
|
|
|
|
|
|
+ guards: [guard, check_parent_guard]
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|