lrf402788946 4 gadi atpakaļ
vecāks
revīzija
03f7333490
2 mainītis faili ar 7 papildinājumiem un 5 dzēšanām
  1. 4 2
      app/service/order/transport.js
  2. 3 3
      app/service/util/excel.js

+ 4 - 2
app/service/order/transport.js

@@ -157,6 +157,7 @@ class TransportService extends CrudService {
     if (type === 'car') data = await this.carCalculate(query);
     else data = await this.calculate(query);
     const res = await this.export({ data, ...query });
+    return res;
   }
 
 
@@ -188,7 +189,6 @@ class TransportService extends CrudService {
       return obj;
     });
     arr.push(...excelData);
-    console.log(arr);
     // 文字位置样式,都加上
     const text = { vertAlign: 'superscript', size: 18 };
     const alignment = { vertical: 'middle', horizontal: 'center' };
@@ -197,7 +197,9 @@ class TransportService extends CrudService {
       i.font = { ...text, ..._.get(i, 'font', {}) };
       return i;
     });
-    await this.ctx.service.util.excel.toExcel({ data: arr });
+    const res = await this.ctx.service.util.excel.toExcel({ data: arr });
+    console.log(res);
+    return res;
   }
 
   /**

+ 3 - 3
app/service/util/excel.js

@@ -30,7 +30,7 @@ class ExcelService extends CrudService {
    */
   async toExcel({ data = [], meta, fn = 'excel导出结果' } = {}) {
     const nowDate = new Date().getTime();
-    const filename = `${fn}.xlsx`; // -${nowDate}
+    const filename = `${fn}-${nowDate}.xlsx`;
     const path = `${this.root_path}${this.file_type}${this.excel_path}`;
     if (!path) {
       throw new BusinessError(ErrorCode.BUSINESS, '服务端没有设置存储路径');
@@ -45,7 +45,6 @@ class ExcelService extends CrudService {
       sheet.columns = meta;
       sheet.addRows(data);
     } else {
-      // console.log(data);
       for (const row of data) {
         const { scell, ecell, content, alignment, font } = row;
         if (scell && ecell) {
@@ -54,7 +53,6 @@ class ExcelService extends CrudService {
           if (alignment) sheet.getCell(ecell).alignment = alignment;
           if (font) sheet.getCell(ecell).font = font;
         } else {
-          console.log('in function:');
           if (_.isObject(content)) {
             const keys = Object.keys(content);
             for (const cell of keys) {
@@ -71,6 +69,8 @@ class ExcelService extends CrudService {
     const filepath = `${path}${filename}`;
     if (data.length <= 0) return;
     await workbook.xlsx.writeFile(filepath);
+    // TODO 返回文件地址
+    return `/file-zhwl/excel/${filename}`;
   }
 
   numberToLetter(num) {