|
@@ -13,7 +13,12 @@ import {start_plan_alt_flow, update_parent_task_info} from "@src/utils/plan_task
|
|
|
import {PrjFile} from "@core-models/PrjFile";
|
|
|
import {BizContractInfo} from "@core-models/BizContractInfo";
|
|
|
import {IdGen} from "@util/IdGen";
|
|
|
-import {is_project_modifiable} from "@src/utils/prj_premission_helper";
|
|
|
+import {is_project_modifiable, is_project_privileged_account} from "@src/utils/prj_premission_helper";
|
|
|
+import {AcsUserInfo} from "@core-models/AcsUserInfo";
|
|
|
+import {BpmnCase} from "@core-models/BpmnCase";
|
|
|
+import {BpmnWork} from "@core-models/BpmnWork";
|
|
|
+import {FlowEngine} from "@src/bpmn/flow_engine";
|
|
|
+import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
|
|
|
|
|
|
interface IData {
|
|
|
/**
|
|
@@ -61,12 +66,30 @@ interface IData {
|
|
|
function permission_guard(content: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
|
let data = <IData>content.data;
|
|
|
- let prj = await PrjInfo.findOne({where: {id: data.id}, raw: true});
|
|
|
+ let prj = await PrjInfo.findOne({where: {id: data.id}, raw: true});
|
|
|
if (!prj)
|
|
|
return reject(Resp.gen_err(Resp.ResourceNotFound, '项目不存在。'));
|
|
|
+ let phase = await PrjPhaseDefine.findOne({where: {id: prj.phase_id}, raw: true});
|
|
|
+ if (!phase) return reject(Resp.gen_err(Resp.ResourceNotFound, '项目状态信息出错,id: ' + prj.id));
|
|
|
+ if (phase.order_index >= 20 ) {
|
|
|
+ if (data.type_id !== undefined) {
|
|
|
+ return reject(Resp.gen_err(Resp.Forbidden, '项目立项后不允许修改项目类型。'))
|
|
|
+ }
|
|
|
+ if (!await is_project_privileged_account(cached_data.user_id)) {
|
|
|
+ if (data.deliver_at)
|
|
|
+ return reject(Resp.gen_err(Resp.Forbidden, '项目已立项,您没有权限修改项目交付时间,请确认您是特权人员。'));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ /// 只有项目特权人员才可以修改项目负责人
|
|
|
+ if (data.leader_id && data.leader_id !== prj.leader_id) {
|
|
|
+ if (!await is_project_privileged_account(cached_data.user_id)) {
|
|
|
+ return reject(Resp.gen_err(Resp.Forbidden, '您没有权限修改项目负责人,请确认您是特权人员。'));
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!await is_project_modifiable(cached_data.user_id, prj.id))
|
|
|
- return reject(Resp.gen_err(Resp.Forbidden, '您没有权限修改该项目,请确认您是项目负责人或特权人员。'));
|
|
|
+ return reject(Resp.gen_err(Resp.Forbidden, '您没有权限修改该项目信息,请确认您是项目负责人或特权人员。'));
|
|
|
if (data.deliver_at) {
|
|
|
data.deliver_at += ' 23:59:59';
|
|
|
}
|
|
@@ -74,7 +97,7 @@ function permission_guard(content: IRequest, cached_data: ICachedData): Promise<
|
|
|
if (task) {
|
|
|
return reject(Resp.gen_err(Resp.Forbidden, '项目交付时间不能早于项目计划中任务的结束时间。'));
|
|
|
}
|
|
|
- task = await PrjPlanTaskDraft.findOne({where: {prj_id: prj.id, end_at: {[Op.gt]: data.deliver_at}}, raw: true});
|
|
|
+ task = await PrjPlanTaskDraft.findOne({where: {prj_id: prj.id, end_at: {[Op.gt]: data.deliver_at}}, raw: true});
|
|
|
if (task) {
|
|
|
return reject(Resp.gen_err(Resp.Forbidden, '项目交付时间不能早于项目计划草稿中任务的结束时间。'));
|
|
|
}
|
|
@@ -115,6 +138,28 @@ function modify(content: IRequest, params: IMethodParams, cached_data: ICachedDa
|
|
|
if (!prj) {
|
|
|
throw Resp.gen_err(Resp.ResourceNotFound, '项目不存在.');
|
|
|
}
|
|
|
+
|
|
|
+ // 修改了项目负责人,这个问题就严重了,要改很多东西
|
|
|
+ // 要将该项目的项目流程全部移交给新负责人,
|
|
|
+ // 涉及bpmn case和bpmn work中与项目相关部分, 以及flow实例中的owner
|
|
|
+ // task相关的work不变
|
|
|
+ if (data.leader_id && data.leader_id !== prj.leader_id) {
|
|
|
+ let new_leader = await AcsUserInfo.findOne({where: {id: data.leader_id}, raw: true, transaction: t});
|
|
|
+ if (!new_leader) {
|
|
|
+ throw Resp.gen_err(Resp.ResourceNotFound, '新选中的项目负责人不存在.');
|
|
|
+ }
|
|
|
+ let [count, flow_cases] = await BpmnCase.update({creator_id: data.leader_id},
|
|
|
+ {where: {prj_id: prj.id, task_id: {[Op.is]: null}, completed_at: {[Op.is]: null}}, transaction: t, returning: true});
|
|
|
+ await BpmnWork.update({assigned_to: data.leader_id},
|
|
|
+ {where: {prj_id: prj.id, task_id: {[Op.is]: null}, status: {[Op.ne]: 2}}, transaction: t});
|
|
|
+ if (flow_cases && flow_cases.length > 0) {
|
|
|
+ for (let flow_case of flow_cases) {
|
|
|
+ let engine = FlowEngine.case_engine_map.get(flow_case.id);
|
|
|
+ if (engine) engine.owner = data.leader_id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
let contract_id = prj.contract_id;
|
|
|
// 修改合同id,需要在项目文档中移除原合同附件,移入新合同附件
|
|
|
Logger.trace(`new contract_id: ${data.contract_id} old contract id: ${contract_id}`);
|
|
@@ -124,7 +169,11 @@ function modify(content: IRequest, params: IMethodParams, cached_data: ICachedDa
|
|
|
await PrjFile.destroy({where: {prj_id: data.id, category_id: 'contract'}, transaction: t});
|
|
|
}
|
|
|
/// 将新合同附件移入项目文档
|
|
|
- let contract = await BizContractInfo.findOne({where: {id: data.contract_id}, raw: true, transaction: t});
|
|
|
+ let contract = await BizContractInfo.findOne({
|
|
|
+ where: {id: data.contract_id},
|
|
|
+ raw: true,
|
|
|
+ transaction: t
|
|
|
+ });
|
|
|
if (!contract) throw Resp.gen_err(Resp.ResourceNotFound, '合同不存在.');
|
|
|
Logger.trace(contract);
|
|
|
if (contract.doc_uploaded) {
|
|
@@ -285,7 +334,7 @@ const v1_0: IApiProcessor = {
|
|
|
model: PrjInfo,
|
|
|
where: get_where,
|
|
|
fixed_input_data: {
|
|
|
- updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
+ updated_at: dayjs().format('YYYY-MM-DD HH:mm:ss')
|
|
|
},
|
|
|
input_data_map: {
|
|
|
name: "name",
|