Sfoglia il codice sorgente

feature:
1. 完成删除周报时,删除对应的周报附件

eyes4 5 mesi fa
parent
commit
2bcc7642ac

+ 0 - 73
base-lib/src/core-models/PrjWeekReportAttachment.ts

@@ -1,73 +0,0 @@
-import {Model} from "sequelize";
-import { Sequelize, DataTypes }  from 'sequelize';
-import {AcsUserInfo} from "@core-models/AcsUserInfo";
-import {PrjWeekReport} from "./PrjWeekReport";
-
-/**
- * 项目周报附件表
- */
-
-export class PrjWeekReportAttachment extends Model {
-    declare id: string;
-    declare object_name: string;
-    declare filename: string;
-    declare uploaded_at: string;
-
-    static table_name = 'tb_prj_week_report_attachment';
-
-    static attributes = {
-        id: {
-            type: DataTypes.STRING(16),
-            primaryKey: true,
-            comment: '编号',
-        },
-        report_id: {
-            type: DataTypes.STRING(16),
-            allowNull: false,
-            comment: '周报id',
-            references: {
-                model: PrjWeekReport,
-                key: 'id'
-            }
-        },
-        uploaded: {
-            type: DataTypes.BOOLEAN,
-            allowNull: false,
-            defaultValue: false,
-            comment: '申请上传地址后,有没有真正上传'
-        },
-        req_upload_time: {
-            type: DataTypes.DATE,
-            allowNull: true,
-            comment: '请求获取上传url时间'
-        },
-        uploaded_at: {
-            type: DataTypes.DATE,
-            allowNull: false,
-            comment: '上传完成时间',
-            defaultValue: DataTypes.NOW
-        },
-        object_name: {
-            type: DataTypes.STRING,
-            allowNull: false,
-            comment: 'oss object name'
-        },
-        filename: {
-            type: DataTypes.STRING,
-            allowNull: false,
-            comment: '附件原始文件'
-        }
-    }
-
-    static indexes = [
-
-    ]
-
-    static associate(sequelize: Sequelize) {
-
-    }
-
-    static init_sqls = [
-
-    ]
-}

+ 9 - 1
pmr-biz-manager/src/routes/api/prj/week_report/remove.ts

@@ -2,6 +2,8 @@ import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined
 import {Resp} from "@util/Resp";
 import {PrjWeekReport} from "@core-models/PrjWeekReport";
 import dayjs from "dayjs";
+import {Oss} from "@util/Oss";
+import {PrjFile} from "@core-models/PrjFile";
 
 interface IData {
     /**
@@ -33,7 +35,13 @@ async function remove(json: IRequest, _params: IMethodParams, _cached_data: ICac
     let data = <IData>json.data;
     let t = await PrjWeekReport.sequelize!.transaction();
     try {
-        //TODO: 移除所有该周报的附件
+        let attachments = await PrjFile.findAll({where: {dependent_id: data.id, category_id: 'week_report'}, raw: true});
+
+        let oss = Oss.get_instance('pmr-doc');
+        for (let file of attachments) {
+            await oss.remove_object(oss.bucket, file.id);
+            await PrjFile.destroy({where: {id: file.id}, transaction: t});
+        }
         await PrjWeekReport.destroy({where: {id: data.id}, transaction: t});
         await t.commit();
     } catch (e) {