明树Git Lab

Commit b542490c authored by zengfanpei's avatar zengfanpei

update

parent c04ba571
......@@ -36,6 +36,6 @@
"cron": {
"getDeviceList": false,
"getAllDevice": false,
"collectDeviceInfo": true
"collectDeviceInfo": false
}
}
\ No newline at end of file
......@@ -2,6 +2,8 @@
const ExcelJS = require('exceljs');
const _ = require('lodash');
......@@ -14,7 +16,7 @@ async function list(req, res, next) {
let skip = (page - 1) * pageSize;
let count = await DB.AgrInputRecord.countDocuments(search)
let list = await DB.AgrInputRecord.find(search).skip(skip).limit(pageSize).lean().exec();
res.sendData({count, list});
res.sendData({ count, list });
} catch (error) {
next(error)
}
......@@ -31,6 +33,40 @@ async function create(req, res, next) {
}
async function importExcel(req, res, next) {
try {
let workbook = new ExcelJS.Workbook();
console.log(req.file)
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
console.log(worksheet.actualRowCount);
let arr = [];
for (let index = 2; index < worksheet.actualRowCount; index++) {
let values = worksheet.getRow(index).values;
let obj = {
creator: req.user._id,
time: values[1],
agrProName: values[2],
name: values[3],
type: values[4],
total: values[5],
unit: values[6],
land: values[7],
area: values[8],
dosage: values[9],
}
arr.push(obj)
}
if(arr.length) {
await DB.AgrInputRecord.insertMany(arr);
}
res.sendData(arr);
} catch (error) {
next(error)
}
}
......@@ -45,5 +81,6 @@ async function create(req, res, next) {
module.exports = {
list,
create
create,
importExcel
}
\ No newline at end of file
......@@ -6,13 +6,13 @@ const _ = require('lodash');
async function upload(req, res, next) {
try {
// console.log(req.file, req.body);
let path = _.last(String(req.file.path).split('/mnt/vdb1'));
let nginxpath = _.last(String(req.file.path).split('/mnt/vdb1'));
let ret = await DB.File.create({
originalname: req.file.originalname,
mimetype: req.file.mimetype,
filename: req.file.filename,
path,
originalpath: req.file.path,
path: req.file.path,
nginxpath,
size: req.file.size,
});
res.sendData(ret);
......
......@@ -48,6 +48,12 @@ const letianAgrInputRecordSchema = new Schema({
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
comment: "创建人"
},
createdAt: {
type: Date,
default: Date.now,
......
......@@ -26,7 +26,7 @@ const fileSchema = new Schema({
path: {
type: String,
},
originalpath: {
nginxpath: {
type: String,
},
......
......@@ -6,7 +6,6 @@ const agrInputRecordController = require('../controller/agrInputRecordController
const agrMatController = require('../controller/agrMatController');
router.post('/input/list', agrInputRecordController.list);
// router.post('/create', agrInputRecordController.create);
// router.post('/update', fileController.update);
// router.post('/upload', fileController.list);
......
......@@ -5,6 +5,7 @@ const router = express.Router();
const multer = require('multer');
const path = require('path');
const fs = require('fs');
const _ = require('lodash');
const moment = require('moment');
const mongoose = require('mongoose');
......@@ -38,9 +39,19 @@ router.post('/batch/upload', upload.array('files'), fileController.batchUpload);
// 文件访问: 起nginx用以处理文件服务器。
/**
* excel导
* excel导
*/
router.post('/:modelName/importExcel', upload.single('file'), fileController.importExcel);
router.post('/:modelName/importExcel', upload.single('file'), async (req, res, next) =>{
let modelName = req.params.modelName;
let controller = require(`../controller/${modelName}Controller`);
console.log(modelName,)
await controller.importExcel(req, res, next);
});
module.exports = router;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment