|
@@ -11,6 +11,7 @@
|
|
|
const fs = require('fs');
|
|
|
const path = require('path');
|
|
|
const excel = require('node-xlsx');
|
|
|
+const sendToWormhole = require('stream-wormhole');
|
|
|
|
|
|
module.exports = app => {
|
|
|
class DealBillsController extends app.BaseController {
|
|
@@ -43,11 +44,6 @@ module.exports = app => {
|
|
|
* @return {Promise<void>}
|
|
|
*/
|
|
|
async loadExcel(ctx) {
|
|
|
- const responseData = {
|
|
|
- err: 0,
|
|
|
- msg: '',
|
|
|
- data: [],
|
|
|
- };
|
|
|
let stream;
|
|
|
try {
|
|
|
stream = await ctx.getFileStream();
|
|
@@ -66,7 +62,8 @@ module.exports = app => {
|
|
|
throw '导入数据失败';
|
|
|
}
|
|
|
|
|
|
- responseData.data = await this.ctx.service.dealBills.getAllDataByCondition({ where: { tender_id: ctx.tender.id } });
|
|
|
+ const dealBills = await this.ctx.service.dealBills.getAllDataByCondition({ where: { tender_id: ctx.tender.id } });
|
|
|
+ ctx.body = {err: 0, msg: '', data: dealBills};
|
|
|
} catch (err) {
|
|
|
this.log(err);
|
|
|
// 失败需要消耗掉stream 以防卡死
|
|
@@ -74,9 +71,12 @@ module.exports = app => {
|
|
|
await sendToWormhole(stream);
|
|
|
}
|
|
|
this.setMessage(err.toString(), this.messageType.ERROR);
|
|
|
+ if (err.stack) {
|
|
|
+ ctx.body = {err: 1, msg: '导入的Excel的数据类型有误', data: null};
|
|
|
+ } else {
|
|
|
+ ctx.body = {err: 1, msg: err.toString(), data: null};
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
- ctx.body = responseData;
|
|
|
}
|
|
|
|
|
|
/**
|