|
@@ -9,59 +9,65 @@ import async from "async";
|
|
|
var callback = function(req, res, err, message, data){
|
|
|
res.json({error: err, message: message, data: data});
|
|
|
};
|
|
|
+// 上传控件
|
|
|
+const multiparty = require("multiparty");
|
|
|
+const fs = require("fs");
|
|
|
+// excel解析
|
|
|
+const excel = require("node-xlsx");
|
|
|
|
|
|
-class RationRepositoryController extends baseController{
|
|
|
- async getCompilationList(req, res){
|
|
|
- try{
|
|
|
- let compilationModel = new CompilationModel(), rst = [];
|
|
|
- let compilationList = await compilationModel.getCompilationList();
|
|
|
- if(compilationList.length <= 0){
|
|
|
- throw '没有数据';
|
|
|
- }
|
|
|
- else{
|
|
|
+class RationRepositoryController extends baseController {
|
|
|
+ async getCompilationList(req, res) {
|
|
|
+ try {
|
|
|
+ let compilationModel = new CompilationModel(), rst = [];
|
|
|
+ let compilationList = await compilationModel.getCompilationList();
|
|
|
+ if (compilationList.length <= 0) {
|
|
|
+ throw '没有数据';
|
|
|
+ }
|
|
|
+ else {
|
|
|
|
|
|
- compilationList.forEach(function (compilation) {
|
|
|
- rst.push({_id: compilation._id, name: compilation.name});
|
|
|
- });
|
|
|
- //获得相关编办下的工料机库
|
|
|
- let parallelFucs = [];
|
|
|
- for(let i = 0; i < rst.length; i++){
|
|
|
- parallelFucs.push((function (obj) {
|
|
|
- return function (cb) {
|
|
|
- gljMapModel.find({compilationId: obj._id, deleted: false}, function (err, result) {
|
|
|
- if(err){
|
|
|
- cb(err);
|
|
|
- }
|
|
|
- else{
|
|
|
- cb(null, result);
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- })(rst[i]));
|
|
|
- }
|
|
|
- async.parallel(parallelFucs, function (err, result) {
|
|
|
- if(err){
|
|
|
- callback(req, res, err, '没有数据', null);
|
|
|
- }
|
|
|
- else{
|
|
|
- let gljLibsRst = [];
|
|
|
- for(let i = 0; i < result.length; i++){
|
|
|
- for(let j = 0; j < result[i].length; j++){
|
|
|
- gljLibsRst.push(result[i][j]);
|
|
|
- }
|
|
|
- }
|
|
|
- callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- catch(err) {
|
|
|
+ compilationList.forEach(function (compilation) {
|
|
|
+ rst.push({_id: compilation._id, name: compilation.name});
|
|
|
+ });
|
|
|
+ //获得相关编办下的工料机库
|
|
|
+ let parallelFucs = [];
|
|
|
+ for (let i = 0; i < rst.length; i++) {
|
|
|
+ parallelFucs.push((function (obj) {
|
|
|
+ return function (cb) {
|
|
|
+ gljMapModel.find({compilationId: obj._id, deleted: false}, function (err, result) {
|
|
|
+ if (err) {
|
|
|
+ cb(err);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ cb(null, result);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })(rst[i]));
|
|
|
+ }
|
|
|
+ async.parallel(parallelFucs, function (err, result) {
|
|
|
+ if (err) {
|
|
|
+ callback(req, res, err, '没有数据', null);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ let gljLibsRst = [];
|
|
|
+ for (let i = 0; i < result.length; i++) {
|
|
|
+ for (let j = 0; j < result[i].length; j++) {
|
|
|
+ gljLibsRst.push(result[i][j]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callback(req, res, false, '', {compilation: rst, gljLibs: gljLibsRst});
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (err) {
|
|
|
callback(req, res, err, '没有数据', null);
|
|
|
}
|
|
|
}
|
|
|
- addRationRepository(req,res){
|
|
|
+
|
|
|
+ addRationRepository(req, res) {
|
|
|
var rationObj = JSON.parse(req.body.rationRepObj);
|
|
|
- rationRepository.addRationRepository(rationObj,function(err,data){
|
|
|
+ rationRepository.addRationRepository(rationObj, function (err, data) {
|
|
|
if (data) {
|
|
|
callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
@@ -69,28 +75,31 @@ class RationRepositoryController extends baseController{
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- getRationLib(req, res){
|
|
|
+
|
|
|
+ getRationLib(req, res) {
|
|
|
let libId = req.body.libId;
|
|
|
- rationRepository.getRationLib(libId, function(err, data){
|
|
|
+ rationRepository.getRationLib(libId, function (err, data) {
|
|
|
if (data) {
|
|
|
- callback(req, res, err, "has data",data);
|
|
|
+ callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
|
callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- getDisPlayRationLibs(req, res){
|
|
|
- rationRepository.getDisplayRationLibs(function(err, data){
|
|
|
+
|
|
|
+ getDisPlayRationLibs(req, res) {
|
|
|
+ rationRepository.getDisplayRationLibs(function (err, data) {
|
|
|
if (data) {
|
|
|
- callback(req, res, err, "has data",data);
|
|
|
+ callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
|
callback(req, res, err, "no data", null);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
- getRealLibName(req,res){
|
|
|
+
|
|
|
+ getRealLibName(req, res) {
|
|
|
var libName = req.body.rationName;
|
|
|
- rationRepository.getRealLibName(libName,function(err,data){
|
|
|
+ rationRepository.getRealLibName(libName, function (err, data) {
|
|
|
if (data) {
|
|
|
callback(req, res, err, "has data", data);
|
|
|
} else {
|
|
@@ -98,8 +107,9 @@ class RationRepositoryController extends baseController{
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
- getLibIDByName(req,res){
|
|
|
- rationRepository.getLibIDByName(req.body.libName, function(err,data){
|
|
|
+
|
|
|
+ getLibIDByName(req, res) {
|
|
|
+ rationRepository.getLibIDByName(req.body.libName, function (err, data) {
|
|
|
if (data) {
|
|
|
callback(req, res, err, "has ID", data);
|
|
|
} else {
|
|
@@ -108,7 +118,7 @@ class RationRepositoryController extends baseController{
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- deleteRationLib(req,res){
|
|
|
+ deleteRationLib(req, res) {
|
|
|
let oprtor = req.body.oprtor,
|
|
|
libId = req.body.libId;
|
|
|
rationRepository.deleteRationLib(oprtor, libId, function (err, message) {
|
|
@@ -123,6 +133,44 @@ class RationRepositoryController extends baseController{
|
|
|
callback(req, res, err, message, null);
|
|
|
})
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上传定额库原始数据
|
|
|
+ *
|
|
|
+ * @param {Object} request
|
|
|
+ * @param {Object} response
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
+ async uploadSourceData(request, response) {
|
|
|
+ const allowHeader = ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
|
|
|
+ try {
|
|
|
+ const uploadOption = {
|
|
|
+ uploadDir: './public/tmp'
|
|
|
+ };
|
|
|
+ const form = new multiparty.Form(uploadOption);
|
|
|
+ form.parse(request, function(err, fields, files) {
|
|
|
+ const file = files.source_file !== undefined ? files.source_file[0] : null;
|
|
|
+ if (err || file === null) {
|
|
|
+ throw '上传失败';
|
|
|
+ }
|
|
|
+ // 判断类型
|
|
|
+ if (file.headers['content-type'] === undefined || allowHeader.indexOf(file.headers['content-type']) < 0) {
|
|
|
+ throw '不支持该类型';
|
|
|
+ }
|
|
|
+ // 重命名文件名
|
|
|
+ const uploadFullName = uploadOption.uploadDir + '/' + file.originalFilename;
|
|
|
+ fs.renameSync(file.path, uploadFullName);
|
|
|
+
|
|
|
+ const test = excel.parse(uploadFullName);
|
|
|
+ console.log(test[0].data);
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error);
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default RationRepositoryController;
|