Просмотр исходного кода

feature: 添加了删除项目文档的接口

eyes4 6 месяцев назад
Родитель
Сommit
783613743e

+ 4 - 3
base-lib/src/core-models/AcsFunction.ts

@@ -189,9 +189,10 @@ export class AcsFunction extends Model {
             (2145, 308, 'upload_file', '上传周报附件', 'prj.week_report.upload_file', true, 1),
             (2146, 308, 'download_file', '下载周报附件', 'prj.week_report.download_file', true, 0),
             
-            (2160, 309, 'get_list', '获取周报列表', 'prj.doc.get_list', true, 0),
-            (2161, 309, 'upload', ' 添加周报', 'prj.doc.upload', true, 1),
-            (2162, 309, 'download', '修改周报信息', 'prj.doc.download', true, 0),
+            (2160, 309, 'get_list', '获取项目文档列表', 'prj.doc.get_list', true, 0),
+            (2161, 309, 'upload', ' 添加项目文档', 'prj.doc.upload', true, 1),
+            (2162, 309, 'download', '下载项目文档', 'prj.doc.download', true, 0),
+            (2163, 309, 'remove', '删除项目文档', 'prj.doc.remove', true, 1),
             
             (2180, 310, 'milestone', '查看项目里程碑', 'prj.kanban.milestone', true, 0),
             

+ 1 - 0
base-lib/src/core-models/AcsRoleFunction.ts

@@ -170,6 +170,7 @@ export class AcsRoleFunction extends Model {
             ('admin', 2160),
             ('admin', 2161),
             ('admin', 2162),
+            ('admin', 2163),
             
             ('admin', 2180),
             

+ 2 - 2
pmr-biz-manager/src/app.ts

@@ -55,10 +55,10 @@ new ServiceApp().start(new MyRouter('@src/routes', guards), Models).then(async (
                                     break;
                             }
                             await PrjFile.update({
-                                uploaded_at: dayjs(),
+                                uploaded_at: dayjs().format('YYYY-MM-DD HH:mm:ss'),
                                 uploaded: true,
                                 size: record.size
-                            }, {where: {id: record.object}, transaction: t})
+                            }, {where: {id: record.object.key}, transaction: t})
                             break;
                         case 'contract':
                             let contract_id = path[1];

+ 1 - 1
pmr-biz-manager/src/routes/api/prj/doc/get_list.ts

@@ -66,7 +66,7 @@ function get_list(json: IRequest, params: IMethodParams, cached_data: ICachedDat
                     prj_file.prj_id, prj.name as prj_name,
                     prj_file.creator_id, creator.name as creator_name,
                     prj_file.size,
-                    
+                    prj_file.uploaded,
                     TO_CHAR(prj_file.uploaded_at, 'yyyy-MM-dd HH24' || ':' || 'MI' || ':' || 'ss') as uploaded_at
             `;
             let condition = `

+ 94 - 0
pmr-biz-manager/src/routes/api/prj/doc/remove.ts

@@ -0,0 +1,94 @@
+import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined";
+import {Resp} from "@util/Resp";
+import {Oss} from "@util/Oss";
+import {PrjFile} from "@core-models/PrjFile";
+
+interface IData {
+    id: string;
+}
+
+// TODO: 部分文档不允许删除,或删除时需要与其它信息同步
+
+function remove(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<any> {
+    return new Promise(async (resolve, reject) => {
+        try {
+            let data = <IData>json.data;
+            let file = await PrjFile.findOne({where: {id: data.id}, raw: true});
+            if (!file) throw Resp.gen_err(Resp.ResourceNotFound, `文档(id:${data.id})不存在。`);
+            await PrjFile.destroy({where: {id: data.id}});
+            let object_name = file.id;
+            let oss = Oss.get_instance('pmr-doc');
+            await oss.remove_object(oss.bucket, object_name);
+            resolve({});
+        } catch (e) {
+            reject(Resp.throw_err(e));
+        }
+    });
+}
+
+const v1_0: IApiProcessor = {
+    schema: {
+        "type": "object",
+        "properties": {
+            "data": {
+                "type": "object",
+                "properties": {
+                    "id": {
+                        "type": "string",
+                        "title": "附件id"
+                    }
+                },
+                "x-apifox-orders": [
+                    "id"
+                ],
+                "title": "请求参数内容",
+                "required": [
+                    "id"
+                ]
+            },
+            "ver": {
+                "type": "string",
+                "title": "版本号",
+                "description": "文档中没有说明时,默认为1.0",
+                "default": "1.0"
+            },
+            "app_id": {
+                "type": "string",
+                "title": "应用id",
+                "description": "平台分配给客户端的app id。一个应用一个id。"
+            },
+            "timestamp": {
+                "type": "integer",
+                "title": "UTC时间戳",
+                "description": "UTC时间戳,精确到毫秒。平台对超过五分钟的消息,将做忽略处理"
+            },
+            "token": {
+                "type": "string",
+                "title": "身份认证token",
+                "description": "平台登录后分配的token"
+            }
+        },
+        "x-apifox-orders": [
+            "ver",
+            "app_id",
+            "timestamp",
+            "token",
+            "data"
+        ],
+        "required": [
+            "data",
+            "ver",
+            "app_id",
+            "timestamp",
+            "token"
+        ]
+    },
+    method: remove,
+    method_params: {},
+    guards: []
+};
+
+module.exports = {
+    default: v1_0,
+    v1_0: v1_0
+};