|
@@ -153,7 +153,7 @@ class RationRepositoryController extends baseController {
|
|
uploadDir: './public/tmp'
|
|
uploadDir: './public/tmp'
|
|
};
|
|
};
|
|
const form = new multiparty.Form(uploadOption);
|
|
const form = new multiparty.Form(uploadOption);
|
|
- form.parse(request, function(err, fields, files) {
|
|
|
|
|
|
+ form.parse(request, async function(err, fields, files) {
|
|
const rationRepId = fields.rationRepId !== undefined && fields.rationRepId.length > 0 ?
|
|
const rationRepId = fields.rationRepId !== undefined && fields.rationRepId.length > 0 ?
|
|
fields.rationRepId[0] : 0;
|
|
fields.rationRepId[0] : 0;
|
|
if (rationRepId <= 0) {
|
|
if (rationRepId <= 0) {
|
|
@@ -176,7 +176,11 @@ class RationRepositoryController extends baseController {
|
|
throw 'excel没有对应数据';
|
|
throw 'excel没有对应数据';
|
|
}
|
|
}
|
|
|
|
|
|
- rationItem.batchAddFromExcel(rationRepId, sheet[0].data);
|
|
|
|
|
|
+ const result = await rationItem.batchAddFromExcel(rationRepId, sheet[0].data);
|
|
|
|
+ // 删除文件
|
|
|
|
+ if (result) {
|
|
|
|
+ fs.unlink(uploadFullName, null);
|
|
|
|
+ }
|
|
response.json(responseData);
|
|
response.json(responseData);
|
|
});
|
|
});
|
|
} catch (error) {
|
|
} catch (error) {
|
|
@@ -188,6 +192,39 @@ class RationRepositoryController extends baseController {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 导出内容数据
|
|
|
|
+ *
|
|
|
|
+ * @param {Object} request
|
|
|
|
+ * @param {Object} response
|
|
|
|
+ * @return {void}
|
|
|
|
+ */
|
|
|
|
+ async exportRationData(request, response) {
|
|
|
|
+ let rationRepId = request.query.rationRepId;
|
|
|
|
+ rationRepId = parseInt(rationRepId);
|
|
|
|
+ try {
|
|
|
|
+ if (isNaN(rationRepId) || rationRepId <= 0) {
|
|
|
|
+ throw '参数错误';
|
|
|
|
+ }
|
|
|
|
+ const excelData = await rationItem.exportExcelData(rationRepId);
|
|
|
|
+ const buffer = excel.build([{name: "sheet", data: excelData}]);
|
|
|
|
+ const filePath = './public/tmp/export.xlsx';
|
|
|
|
+ fs.writeFileSync(filePath, buffer, 'binary');
|
|
|
|
+ const stats = fs.statSync(filePath);
|
|
|
|
+ // 下载相关header
|
|
|
|
+ response.set({
|
|
|
|
+ 'Content-Type': 'application/octet-stream',
|
|
|
|
+ 'Content-Disposition': 'attachment; filename=ration.xlsx',
|
|
|
|
+ 'Content-Length': stats.size
|
|
|
|
+ });
|
|
|
|
+ fs.createReadStream(filePath).pipe(response);
|
|
|
|
+ fs.unlink(filePath);
|
|
|
|
+ } catch (error) {
|
|
|
|
+ response.end(error);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
export default RationRepositoryController;
|
|
export default RationRepositoryController;
|