Browse Source

feature: 项目动态和任务动态接口修改为可以获取所有动态,项目id和任务id请求参数作为可选项,不指定具体项目时,返回所有项目动态和任务动态,供dashboard中显示。

eyes4 6 months ago
parent
commit
919236fc01

+ 2 - 1
base-lib/src/core-models/PrjInfo.ts

@@ -13,6 +13,7 @@ import {BizContractInfo} from "@core-models/BizContractInfo";
 export class PrjInfo extends Model {
     declare id: string;
     declare phase_id: string;
+    declare type_id: number;
     declare flow_case_id: string;
     declare leader_id: string;
     declare bizman_id: string;
@@ -149,7 +150,7 @@ export class PrjInfo extends Model {
         {fields: ['name']}
     ]
 
-    static associate(sequelize: Sequelize) {
+    static associate(_sequelize: Sequelize) {
         try {
             // AcsDomain.hasMany(BizCustomer, {foreignKey: 'region_id', sourceKey: 'id'});
             // BizCustomer.belongsTo(AcsDomain, {foreignKey: 'region_id', targetKey: 'id'});

+ 15 - 18
pmr-biz-manager/src/routes/api/prj/info/get_logs.ts

@@ -1,18 +1,11 @@
 import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import {Resp} from "@util/Resp";
-import {Op, QueryTypes, WhereOptions} from "sequelize";
+import {WhereOptions} from "sequelize";
 import DataCURD, {ISQLReplacements} from "@core/DataCURD";
 import {BizCustomer} from "@core-models/BizCustomer";
-import {BizCustomerIndustry} from "@core-models/BizCustomerIndustry";
-import {AcsUserInfo} from "@core-models/AcsUserInfo";
-import {AcsDomain} from "@core-models/AcsDomain";
-import {PrjInfo} from "@core-models/PrjInfo";
-import {BizContractInfo} from "@core-models/BizContractInfo";
-import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
-import {BpmnWork} from "@core-models/BpmnWork";
-import {BpmnCase} from "@core-models/BpmnCase";
 import {PrjLogs} from "@core-models/PrjLogs";
-import {is_project_accessible} from "../../../../utils/prj_premission_helper";
+import {PrjInfo} from "@core-models/PrjInfo";
+import {is_project_accessible} from "@src/utils/prj_premission_helper";
 
 interface IData  {
     /**
@@ -26,7 +19,7 @@ interface IData  {
     /**
      * 项目id
      */
-    id: string;
+    id?: string;
     /**
      * 页码,从1开始
      */
@@ -40,28 +33,33 @@ interface IData  {
 function guard(json: IRequest, cached_data: ICachedData): Promise<void> {
     return new Promise<void>(async (resolve, reject) => {
         let data = <IData>json.data;
-        if (!await is_project_accessible(cached_data.user_id, data.id))
+        if (data.id !== undefined && !await is_project_accessible(cached_data.user_id, data.id))
             return reject(Resp.gen_err(Resp.Forbidden, '无权访问该项目'));
         resolve();
     });
 }
 
 
-function get_logs(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<WhereOptions> {
+function get_logs(json: IRequest, _params: IMethodParams, _cached_data: ICachedData): Promise<WhereOptions> {
     return new Promise<WhereOptions>(async (resolve, reject) => {
         try {
             let data = <IData>json.data;
             let count_sql = `select count(distinct log.id) `;
             let select_sql = `
                 select log.id, log.creator_id, log.creator_name,
-                    log.prj_id, log.content,
+                    log.prj_id, prj.name as prj_name, log.content,
                     TO_CHAR(log.ts, 'yyyy-MM-dd HH24' || ':' || 'MI' || ':' || 'ss') as ts
             `;
             let condition = `
-                from ${PrjLogs.table_name} log
-                where log.prj_id = :prj_id
+                from ${PrjLogs.table_name} log, ${PrjInfo.table_name} prj
+                where log.prj_id = prj.id
             `;
-            let replacements: ISQLReplacements = {prj_id: data.id};
+
+            let replacements: ISQLReplacements = {};
+            if (data.id !== undefined) {
+                condition += ' and log.prj_id = :id ';
+                replacements.id = data.id;
+            }
 
             if (data.begin_at !== undefined) {
                 condition += ' and log.ts >= :begin_at ';
@@ -135,7 +133,6 @@ const v1_0: IApiProcessor = {
                 ],
                 "title": "请求参数内容",
                 "required": [
-                    "id",
                     "page_no",
                     "page_size"
                 ]

+ 6 - 11
pmr-biz-manager/src/routes/api/prj/info/modify.ts

@@ -1,6 +1,6 @@
 import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import DataCURD from "@core/DataCURD";
-import {Op, Transaction, WhereOptions} from "sequelize";
+import {Op, WhereOptions} from "sequelize";
 import {PrjInfo} from "@core-models/PrjInfo";
 import dayjs from "dayjs";
 import {PrjLogger} from "@src/utils/prj_logger";
@@ -8,11 +8,8 @@ import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
 import {Resp} from "@util/Resp";
 import {Logger} from "@util/Logger";
-import {ChangeMarker} from "@src/utils/define";
-import {start_plan_alt_flow, update_parent_task_info} from "@src/utils/plan_task_helper";
 import {PrjFile} from "@core-models/PrjFile";
 import {BizContractInfo} from "@core-models/BizContractInfo";
-import {IdGen} from "@util/IdGen";
 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";
@@ -72,7 +69,7 @@ function permission_guard(content: IRequest, cached_data: ICachedData): Promise<
         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) {
+            if (data.type_id !== undefined && prj.type_id !== data.type_id)  {
                 return reject(Resp.gen_err(Resp.Forbidden, '项目立项后不允许修改项目类型。'))
             }
             if (!await is_project_privileged_account(cached_data.user_id)) {
@@ -106,7 +103,7 @@ function permission_guard(content: IRequest, cached_data: ICachedData): Promise<
     });
 }
 
-async function get_where(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<WhereOptions> {
+async function get_where(json: IRequest, _params: IMethodParams, _cached_data: ICachedData): Promise<WhereOptions> {
     let data = <IData>json.data;
 
     return {id: data.id};
@@ -135,9 +132,7 @@ function modify(content: IRequest, params: IMethodParams, cached_data: ICachedDa
         let t = await PrjInfo.sequelize!.transaction();
         try {
             let prj = await PrjInfo.findOne({where: {id: data.id}, raw: true, transaction: t});
-            if (!prj) {
-                throw Resp.gen_err(Resp.ResourceNotFound, '项目不存在.');
-            }
+            if (!prj) throw Resp.gen_err(Resp.ResourceNotFound, '项目不存在.');
 
             // 修改了项目负责人,这个问题就严重了,要改很多东西
             // 要将该项目的项目流程全部移交给新负责人,
@@ -148,10 +143,10 @@ function modify(content: IRequest, params: IMethodParams, cached_data: ICachedDa
                 if (!new_leader) {
                     throw Resp.gen_err(Resp.ResourceNotFound, '新选中的项目负责人不存在.');
                 }
-                let [count, flow_cases] = await BpmnCase.update({creator_id: data.leader_id},
+                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});
+                    {where: {prj_id: prj.id, task_id: {[Op.is]: null}, status: {[Op.ne]: 2}}, transaction: t, returning: false});
                 if (flow_cases && flow_cases.length > 0) {
                     for (let flow_case of flow_cases) {
                         let engine = FlowEngine.case_engine_map.get(flow_case.id);

+ 7 - 5
pmr-biz-manager/src/routes/api/prj/outcome/add.ts

@@ -1,6 +1,6 @@
 import {ADMINISTRATOR, IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import {Resp} from "@util/Resp";
-import {WhereOptions} from "sequelize";
+import {Transaction, WhereOptions} from "sequelize";
 import DataCURD from "@core/DataCURD";
 import {IdGen} from "@util/IdGen";
 import dayjs from "dayjs";
@@ -58,11 +58,12 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         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 (data.draft == true) {
+        // if (data.draft == true) {
             if (phase.order_index >= 60 && phase.order_index <= 65) {
                 return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许添加交付物。'));
             }
-        } else {
+        // } 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)
@@ -100,8 +101,9 @@ function add(json: IRequest, params: IMethodParams, cached_data: ICachedData): P
             if (data.draft === true ) {
                 let task = await PrjPlanTaskDraft.findOne({where: {id: data.task_id}, raw: true, transaction: t});
                 if (task) {
-                    await start_plan_alt_flow(task.prj_id, cached_data.user_id, t);
-                    await PrjPlanTaskDraft.update({change_marker: ChangeMarker.Changed}, {where: {id: data.task_id}, transaction: t});
+                    await start_plan_alt_flow(task.prj_id, cached_data.user_id, t as Transaction);
+                    await PrjPlanTaskDraft.update({change_marker: ChangeMarker.Changed},
+                        {where: {id: data.task_id}, transaction: t, returning: false});
                 }
             }
             await t.commit();

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

@@ -1,6 +1,6 @@
-import {ADMINISTRATOR, IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
+import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import DataCURD from "@core/DataCURD";
-import {WhereOptions} from "sequelize";
+import {Transaction, WhereOptions} from "sequelize";
 import dayjs from "dayjs";
 import {Resp} from "@util/Resp";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
@@ -38,7 +38,7 @@ interface IData {
     // [property: string]: any;
 }
 
-async function get_where(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<WhereOptions> {
+async function get_where(json: IRequest, _params: IMethodParams, _cached_data: ICachedData): Promise<WhereOptions> {
     let data = <IData>json.data;
     return {id: data.id};
 }
@@ -89,11 +89,12 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         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 (data.draft == true) {
+        // if (data.draft == true) {
             if (phase.order_index >= 60 && phase.order_index <= 65) {
                 return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许修改交付物。'));
             }
-        } else {
+        // } 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)
@@ -120,10 +121,10 @@ async function before_respond(content: IRequest, params: IMethodParams, cached_d
     let t = await PrjTaskOutcome.sequelize!.transaction();
     try {
         /// 如果是草稿,且还没有生成计划变更任务,则生成任务
-        if (data.draft === true ) {
+        if (data.draft ) {
             let task = await PrjPlanTaskDraft.findOne({where: {id: result.task_id}, transaction: t});
             if (task){
-                await start_plan_alt_flow(task.prj_id, cached_data.user_id, t);
+                await start_plan_alt_flow(task.prj_id, cached_data.user_id, t as Transaction);
                 await PrjPlanTaskDraft.update({change_marker: ChangeMarker.Changed},
                     {where: {id: result.task_id}, transaction: t, returning: false});
             }
@@ -137,10 +138,9 @@ async function before_respond(content: IRequest, params: IMethodParams, cached_d
     return result;
 }
 
-async function on_start(content: IRequest, params: IMethodParams, cached_data: ICachedData | any): Promise<unknown> {
+async function on_start(content: IRequest, params: IMethodParams, _cached_data: ICachedData | any): Promise<unknown> {
     let data = <IData>content.data;
-    let model = data.draft ? PrjTaskOutcomeDraft : PrjTaskOutcome;
-    params.model = model;
+    params.model = data.draft ? PrjTaskOutcomeDraft : PrjTaskOutcome;
 
     return {};
 }

+ 6 - 5
pmr-biz-manager/src/routes/api/prj/outcome/remove.ts

@@ -1,6 +1,5 @@
-import {ADMINISTRATOR, IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
+import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
 import {PrjInfo} from "@core-models/PrjInfo";
-import {PrjMembers} from "@core-models/PrjMembers";
 import {Resp} from "@util/Resp";
 import {PrjPhaseDefine} from "@core-models/PrjPhaseDefine";
 import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
@@ -10,6 +9,7 @@ import {start_plan_alt_flow} from "@src/utils/plan_task_helper";
 import {Logger} from "@util/Logger";
 import {ChangeMarker, TaskStatus} from "@src/utils/define";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
+import {Transaction} from "sequelize";
 
 interface IData {
     /**
@@ -38,7 +38,7 @@ async function remove(json: IRequest, params: IMethodParams, cached_data: ICache
             if (!outcome[1][0]) throw Resp.gen_err(Resp.ResourceNotFound);
             let task = await PrjPlanTaskDraft.findOne({where: {id: outcome[1][0].task_id}, transaction: t});
             if (task) {
-                await start_plan_alt_flow(task.prj_id, cached_data.user_id, t);
+                await start_plan_alt_flow(task.prj_id, cached_data.user_id, t as Transaction);
                 await PrjPlanTaskDraft.update({change_marker: ChangeMarker.Changed},
                     {where: {id: task.id}, transaction: t, returning: false});
             }
@@ -95,11 +95,12 @@ function statusGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
         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 (data.draft == true) {
+        // if (data.draft == true) {
             if (phase.order_index >= 60 && phase.order_index <= 65) {
                 return reject(Resp.gen_err(Resp.InvalidFlow, '计划变更审核中,现阶段不允许删除交付物。'));
             }
-        } else {
+        // } 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)

+ 28 - 22
pmr-biz-manager/src/routes/api/prj/plan/get_logs.ts

@@ -4,27 +4,19 @@ import { WhereOptions} from "sequelize";
 import DataCURD, {ISQLReplacements} from "@core/DataCURD";
 import {BizCustomer} from "@core-models/BizCustomer";
 import {PrjLogs} from "@core-models/PrjLogs";
-import {is_project_accessible} from "../../../../utils/prj_premission_helper";
+import {PrjInfo} from "@core-models/PrjInfo";
 import {PrjPlanTask} from "@core-models/PrjPlanTask";
-import {PrjPlanTaskDraft} from "@core-models/PrjPlanTaskDraft";
+import {is_project_accessible} from "@src/utils/prj_premission_helper";
 
 interface IData  {
     /**
      * 查询起始时间,YYYY-MM-DD格式
      */
-    begin_at?: string;
+    begin_at?: Date;
     /**
      * 查询结束时间,YYYY-MM-DD格式
      */
-    end_at?: string;
-    /**
-     * 项目id
-     */
-    prj_id: string;
-    /**
-     * 任务id
-     */
-    task_id: string;
+    end_at?: Date;
     /**
      * 页码,从1开始
      */
@@ -33,6 +25,14 @@ interface IData  {
      * 每页条数
      */
     page_size: number;
+    /**
+     * 项目id
+     */
+    prj_id?: string;
+    /**
+     * 任务id
+     */
+    task_id?: string;
 }
 
 // 接口访问守卫
@@ -40,27 +40,35 @@ function guard(json: IRequest, cached_data: ICachedData): Promise<void> {
     return new Promise<void>(async (resolve, reject) => {
         let user = cached_data.user_id;
         let data = <IData>json.data;
-        if (!await is_project_accessible(user, data.prj_id))
-            return reject(Resp.gen_err(Resp.Forbidden, '您没有权限访问该项目。'));
+        if (data.prj_id && !await is_project_accessible(user, data.prj_id))
+            return reject(Resp.gen_err(Resp.Forbidden, `您没有权限访问该项目,id: ${data.prj_id}。`));
         resolve();
     });
 }
 
-function get_logs(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<WhereOptions> {
+function get_logs(json: IRequest, _params: IMethodParams, _cached_data: ICachedData): Promise<WhereOptions> {
     return new Promise<WhereOptions>(async (resolve, reject) => {
         try {
             let data = <IData>json.data;
             let count_sql = `select count(distinct log.id) `;
             let select_sql = `
                 select log.id, log.creator_id, log.creator_name,
-                    log.prj_id, log.task_id, log.content,
+                    log.prj_id, prj.name as prj_name, log.task_id, task.name as task_name, log.content,
                     TO_CHAR(log.ts, 'yyyy-MM-dd HH24' || ':' || 'MI' || ':' || 'ss') as ts
             `;
             let condition = `
-                from ${PrjLogs.table_name} log
-                where log.prj_id = :prj_id and log.task_id = :task_id
+                from ${PrjLogs.table_name} log, ${PrjInfo.table_name} prj, ${PrjPlanTask.table_name} task
+                where log.prj_id = prj.id and log.task_id = task.id 
             `;
-            let replacements: ISQLReplacements = {prj_id: data.prj_id, task_id: data.task_id};
+            let replacements: ISQLReplacements = {};
+            if (data.prj_id !== undefined) {
+                condition += ' and log.prj_id = :prj_id ';
+                replacements.prj_id = data.prj_id;
+            }
+            if (data.task_id !== undefined) {
+                condition += ' and log.task_id = :task_id ';
+                replacements.task_id = data.task_id;
+            }
 
             if (data.begin_at !== undefined) {
                 condition += ' and log.ts >= :begin_at ';
@@ -139,10 +147,8 @@ const v1_0: IApiProcessor = {
                 ],
                 "title": "请求参数内容",
                 "required": [
-                    "prj_id",
                     "page_no",
-                    "page_size",
-                    "task_id"
+                    "page_size"
                 ]
             },
             "ver": {