|
@@ -11,6 +11,9 @@ import BaseController from '../../common/base/base_controller';
|
|
|
import moment from 'moment';
|
|
|
const billsGuidanceFacade = require('../facade/facades');
|
|
|
let logger = require('../../../logs/log_helper').logger;
|
|
|
+const fs = require("fs");
|
|
|
+// excel解析
|
|
|
+const excel = require("node-xlsx");
|
|
|
let callback = function (req, res, err, msg, data) {
|
|
|
res.json({error: err, message: msg, data: data});
|
|
|
};
|
|
@@ -138,6 +141,28 @@ class BillsGuideLibController extends BaseController{
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ async exportClassExcel(req, res) {
|
|
|
+ try{
|
|
|
+ const excelData = await billsGuidanceFacade.getClassExcelData(req.query.libID);
|
|
|
+ const buffer = excel.build([{name: "清单分类库", data: excelData}], {'!cols': [{wch:6}, {wch:12},{wch:14},{wch:24}, {wch:45}]});
|
|
|
+ const filePath = './public/export.xlsx';
|
|
|
+ fs.writeFileSync(filePath, buffer, 'binary');
|
|
|
+ const stats = fs.statSync(filePath);
|
|
|
+ // 下载相关header
|
|
|
+ res.set({
|
|
|
+ 'Content-Type': 'application/octet-stream',
|
|
|
+ 'Content-Disposition': 'attachment; filename=billClass.xlsx',
|
|
|
+ 'Content-Length': stats.size
|
|
|
+ });
|
|
|
+ fs.createReadStream(filePath).pipe(res);
|
|
|
+ fs.unlink(filePath);
|
|
|
+ }
|
|
|
+ catch(err){
|
|
|
+ console.log(err);
|
|
|
+ response.end(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
async testItems(req, res){
|
|
|
try{
|
|
|
let data = JSON.parse(req.body.data);
|