Bläddra i källkod

导入,预付款相关

MaiXinRong 2 år sedan
förälder
incheckning
bcbc7eb237
2 ändrade filer med 32 tillägg och 11 borttagningar
  1. 16 11
      app/controller/file_controller.js
  2. 16 0
      app/extend/helper.js

+ 16 - 11
app/controller/file_controller.js

@@ -230,12 +230,11 @@ module.exports = app => {
                 const rela_tender = await ctx.subProject.rela_tender.split(',');
                 const result = tenderList.filter(x => { return rela_tender.indexOf(x.id + '') >= 0});
                 for (const r of result) {
-                    // 预付款附件未上传oss,暂不导入
-                    // r.advance = await ctx.service.advance.getAllDataByCondition({ columns: ['id', 'order', 'type'], where: { tid: r.id }});
-                    // r.advance.forEach(a => {
-                    //     const type = advanceConst.typeCol.find(x => { return x.type === a.type });
-                    //     if (type) a.type_str = type.name;
-                    // });
+                    r.advance = await ctx.service.advance.getAllDataByCondition({ columns: ['id', 'order', 'type'], where: { tid: r.id }});
+                    r.advance.forEach(a => {
+                        const type = advanceConst.typeCol.find(x => { return x.type === a.type });
+                        if (type) a.type_str = type.name;
+                    });
                     r.stage = await ctx.service.stage.getAllDataByCondition({ columns: ['id', 'order'], where: { tid: r.id, status: auditConst.stage.status.checked } });
                 }
                 ctx.body = {err: 0, msg: '', data: result };
@@ -258,7 +257,14 @@ module.exports = app => {
         }
         async _loadAdvanceAtt(data) {
             if (!data.stage) throw '参数错误';
-            return await this.ctx.service.advanceFile.getAllDataByCondition({ where: { vid: data.stage }, order: [['id', 'desc']]});
+            const self = this;
+            const result = await this.ctx.service.advanceFile.getAllDataByCondition({ where: { vid: data.stage }, order: [['id', 'desc']]});
+            result.forEach(x => {
+                const info = path.parse(x.filename);
+                x.filename = info.name;
+                x.filesize = self.ctx.helper.sizeToBytes(x.filesize);
+            });
+            return result;
         }
         async loadRelaFiles(ctx) {
             try {
@@ -273,10 +279,9 @@ module.exports = app => {
                     case 'stage':
                         files = await this._loadStageAtt(data);
                         break;
-                    // 预付款附件未上传oss,暂不导入
-                    // case 'advance':
-                    //     files = await this._loadAdvanceAtt(data);
-                    //     break;
+                    case 'advance':
+                        files = await this._loadAdvanceAtt(data);
+                        break;
                     default: throw '未知文件类型';
                 }
                 ctx.body = {err: 0, msg: '', data: files };

+ 16 - 0
app/extend/helper.js

@@ -83,6 +83,22 @@ module.exports = {
         // return (bytes / Math.pow(k, i)) + ' ' + sizes[i];
         return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
     },
+    sizeToBytes(size) {
+        const sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
+        const sizesConverse = sizes.reverse();
+        let index, matchSize;
+        for (const [i, s] of sizesConverse.entries()) {
+            if (size.indexOf(s) > 0) {
+                matchSize = s;
+                index = sizes.length - i;
+                break;
+            }
+        }
+
+        const num = parseFloat(_.trim(size.replace(matchSize, '')));
+        const k = 1024;
+        return Math.ceil(num * Math.pow(k, index - 1));
+    },
 
     /**
      * 浮点乘法计算