明树Git Lab

Commit e467eeee authored by zengfanpei's avatar zengfanpei

update

parent 1e34c1bc
......@@ -38,6 +38,6 @@
"getAllDevice": false,
"collectDeviceInfo": false,
"collectDeviceInfo4": false,
"excel": true
"excel": false
}
}
\ No newline at end of file
const ExcelJS = require('exceljs');
const _ = require('lodash');
const fs = require('fs');
async function list(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
let count = await DB.AgrInputDetail.countDocuments(search)
let list = await DB.AgrInputDetail.find(search).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error)
}
}
async function create(req, res, next) {
try {
let ret = await DB.AgrInputDetail.create(req.body)
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function updateOne(req, res, next) {
try {
let updateInfo = {
...req.body,
}
let ret = await DB.AgrInputDetail.findOneAndUpdate({_id: req.body._id}, updateInfo);
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function deleteOne(req, res, next) {
try {
let ret = await DB.AgrInputDetail.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function importExcel(req, res, next) {
try {
let workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
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],
totalCost: values[7],
dilutionRatio: values[8],
waterConsumption: values[9],
area: values[10],
dosage: values[11],
land: values[12],
notes: values[13],
}
if(obj.time && obj.agrProName) {
arr.push(obj)
}
}
if(arr.length) {
await DB.AgrInputDetail.insertMany(arr);
}
res.sendData(arr);
} catch (error) {
next(error)
}
}
module.exports = {
list,
create,
importExcel,
deleteOne,
updateOne
}
\ No newline at end of file
const ExcelJS = require('exceljs');
const _ = require('lodash');
const fs = require('fs');
async function list(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
let count = await DB.AgrInputEmploy.countDocuments(search)
let list = await DB.AgrInputEmploy.find(search).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error)
}
}
async function create(req, res, next) {
try {
let ret = await DB.AgrInputEmploy.create(req.body)
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function updateOne(req, res, next) {
try {
let updateInfo = {
...req.body,
}
let ret = await DB.AgrInputEmploy.findOneAndUpdate({_id: req.body._id}, updateInfo);
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function deleteOne(req, res, next) {
try {
let ret = await DB.AgrInputEmploy.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function importExcel(req, res, next) {
try {
let workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
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],
totalCost: values[7],
dilutionRatio: values[8],
waterConsumption: values[9],
area: values[10],
dosage: values[11],
land: values[12],
notes: values[13],
}
if(obj.time && obj.agrProName) {
arr.push(obj)
}
}
if(arr.length) {
await DB.AgrInputEmploy.insertMany(arr);
}
res.sendData(arr);
} catch (error) {
next(error)
}
}
module.exports = {
list,
create,
importExcel,
deleteOne,
updateOne
}
\ No newline at end of file
const ExcelJS = require('exceljs');
const _ = require('lodash');
const fs = require('fs');
async function list(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
let count = await DB.AgrInputOther.countDocuments(search)
let list = await DB.AgrInputOther.find(search).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error)
}
}
async function create(req, res, next) {
try {
let ret = await DB.AgrInputOther.create(req.body)
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function updateOne(req, res, next) {
try {
let updateInfo = {
...req.body,
}
let ret = await DB.AgrInputOther.findOneAndUpdate({_id: req.body._id}, updateInfo);
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function deleteOne(req, res, next) {
try {
let ret = await DB.AgrInputOther.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function importExcel(req, res, next) {
try {
let workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
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],
totalCost: values[7],
dilutionRatio: values[8],
waterConsumption: values[9],
area: values[10],
dosage: values[11],
land: values[12],
notes: values[13],
}
if(obj.time && obj.agrProName) {
arr.push(obj)
}
}
if(arr.length) {
await DB.AgrInputOther.insertMany(arr);
}
res.sendData(arr);
} catch (error) {
next(error)
}
}
module.exports = {
list,
create,
importExcel,
deleteOne,
updateOne
}
\ No newline at end of file
......@@ -4,6 +4,7 @@
const ExcelJS = require('exceljs');
const _ = require('lodash');
const fs = require('fs');
......@@ -32,17 +33,37 @@ async function create(req, res, next) {
}
}
async function updateOne(req, res, next) {
try {
let updateInfo = {
...req.body,
}
let ret = await DB.AgrInputRecord.findOneAndUpdate({_id: req.body._id}, updateInfo);
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function deleteOne(req, res, next) {
try {
let ret = await DB.AgrInputRecord.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error)
}
}
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++) {
for (let index = 2; index <= worksheet.actualRowCount; index++) {
let values = worksheet.getRow(index).values;
let obj = {
creator: req.user._id,
......@@ -52,11 +73,17 @@ async function importExcel(req, res, next) {
type: values[4],
total: values[5],
unit: values[6],
land: values[7],
area: values[8],
dosage: values[9],
totalCost: values[7],
dilutionRatio: values[8],
waterConsumption: values[9],
area: values[10],
dosage: values[11],
land: values[12],
notes: values[13],
}
if(obj.time && obj.agrProName) {
arr.push(obj)
}
arr.push(obj)
}
if(arr.length) {
await DB.AgrInputRecord.insertMany(arr);
......@@ -82,5 +109,7 @@ async function importExcel(req, res, next) {
module.exports = {
list,
create,
importExcel
importExcel,
deleteOne,
updateOne
}
\ No newline at end of file
......@@ -15,6 +15,9 @@ async function list(req, res, next) {
if (req.body.name) {
search.name = { $regex: req.body.name };
}
if(req.body.deviceHQType) {
search.deviceHQType = req.body.deviceHQType;
}
const count = await DB.Device.countDocuments(search);
let list = await DB.Device.find(search).skip(skip).limit(pageSize).populate({path: "land"}).lean().exec();
let deviceNumbers = [];
......
......@@ -5,7 +5,7 @@ const dbURI = sysConfig.dbURI || 'mongodb://localhost:27017/letian';
// 连接数据库
console.log(dbURI, "000-0-0-0-0-0-0")
mongoose.connect(dbURI, {useNewUrlParser: true, useUnifiedTopology: true})
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));
......@@ -41,12 +41,14 @@ const FlowDefRelation = require('./models/systemFlowDefRelation');
const Land = require('./models/letianLand');
const Zone = require('./models/letianZone');
const AgrInputRecord = require('./models/letianAgrInputRecord');
const AreaRecord = require('./models/letianAreaRecord');
const AgrInputDetail = require('./models/letianAgrInputDetail');
const AgrInputEmploy = require('./models/letianAgrInputEmploy');
const AgrInputOther = require('./models/letianAgrInputOther');
const AgrMatType = require('./models/letianAgrMatType');
const AgrMatApproval = require('./models/letianAgrMatApproval');
const AgrMatInOut = require('./models/letianAgrMatInOut');
const FileTemplate = require('./models/letianFileTemplate');
const AreaRecord = require('./models/letianAreaRecord');
const ExcelRecord = require('./models/letianExcelRecord');
......@@ -57,7 +59,6 @@ const CollectIPS = require('./models/collectIPS');
const CollectIPSResult = require('./models/collectIPSResult');
const CollectIPSType = require('./models/collectIPSType');
const CollectIPSPlan = require('./models/collectIPSPlan');
const CollectWS = require('./models/collectWS');
const CollectAttribute = require('./models/collectAttribute');
const CollectThreshold = require('./models/collectThreshold');
......@@ -69,11 +70,9 @@ global.DB = {
User,
Role,
Menu,
Device,
Depart,
Notice,
FlowDef,
FlowDefNode,
FlowDefRelation,
......@@ -81,22 +80,24 @@ global.DB = {
Land,
Zone,
AgrInputRecord,
AreaRecord,
AgrInputDetail,
AgrInputEmploy,
AgrInputOther,
AgrMatType,
AgrMatApproval,
AgrMatInOut,
FileTemplate,
AreaRecord,
ExcelRecord,
Device,
CollectThreshold,
CollectSMC,
CollectIPS,
CollectIPSResult,
CollectIPSType,
CollectIPSPlan,
CollectAttribute,
CollectWS,
RequestLog,
......
......@@ -80,6 +80,10 @@ const deviceSchema = new Schema({
comment: "设备上次清洁时间",
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
channel: {
type: Number,
comment: "频道号"
},
/* -------------设备与地块的信息----------------- */
......@@ -97,7 +101,7 @@ const deviceSchema = new Schema({
// },
deviceHQType: {
type: Number,
comment: "用来获取数据的设备类型-(接口文档): 1.土壤温湿度、土壤氮磷钾, 2土壤ph、土壤电导率, 3 气象站, 4虫情",
comment: "用来获取数据的设备类型-(接口文档): 1.土壤温湿度、土壤氮磷钾, 2土壤ph、土壤电导率, 3 气象站, 4虫情, 5摄像头",
},
deviceDPType: {
type: Number,
......
// 购买日期 产品名称 规格 单位 成分 购买数量 单位 单价(元) 合计金额(元) 总购买量 单位 代理商 备注
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const moment = require('moment');
/**
* 乐田 农资投入详情表
*/
const letianAgrInputDetailSchema = new Schema({
time: {
type: Date,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
comment: "购买日期",
},
name: {
type: String,
commnet: "产品名称",
},
spec: {
type: String,
commnet: "规格",
},
proUnit: {
type: String,
comment: "单位"
},
component: {
type: String,
comment: "成分"
},
buyNum: {
type: Number,
comment: "购买数量"
},
buyUnti: {
type: String,
comment: "单位"
},
unitPrice: {
type: Number,
comment: "单价(元)"
},
totalAmount: {
type: Number,
comment: "合计金额(元)"
},
totalBuyNum: {
type: Number,
comment: "总购买量"
},
totalBuyUnit: {
type: String,
comment: "单位"
},
agent: {
type: String,
comment: "代理商"
},
notes: {
type: String,
comment: "备注"
},
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
comment1: "创建人"
},
createdAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
updatedAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
del: {
type: Number,
default: 0,
comment1: '默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
}, {
id: false,
toJSON: {
getters: true,
}
});
const AgrInputDetail = mongoose.model('letianAgrInputDetail', letianAgrInputDetailSchema, 'letianAgrInputDetail');
module.exports = AgrInputDetail;
\ No newline at end of file
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const moment = require('moment');
/**
* 乐田 农场其他投入品记录表
* 日期 类别/名称 规格 数量 单位 单价 税额 总额 代理商/厂家 备注
*/
const letianAgrInputEmploySchema = new Schema({
time: {
type: Date,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
comment: "日期",
},
name: {
type: String,
commnet: "类别/名称",
},
spec: {
type: String,
commnet: "规格",
},
buyNum: {
type: Number,
comment: "数量"
},
unitPrice: {
type: Number,
comment: "单价(元)"
},
taxAmount: {
type: Number,
comment: "税额(元)"
},
totalAmount: {
type: Number,
comment: "总额(元)"
},
agent: {
type: String,
comment: "代理商/厂家"
},
notes: {
type: String,
comment: "备注"
},
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
comment1: "创建人"
},
createdAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
updatedAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
del: {
type: Number,
default: 0,
comment1: '默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
}, {
id: false,
toJSON: {
getters: true,
}
});
const AgrInputEmploy = mongoose.model('letianAgrInputEmploy', letianAgrInputEmploySchema, 'letianAgrInputEmploy');
module.exports = AgrInputEmploy;
\ No newline at end of file
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const moment = require('moment');
/**
* 乐田 农场其他投入品记录表
* 日期 类别/名称 规格 数量 单位 单价 税额 总额 代理商/厂家 备注
*/
const letianAgrInputOtherSchema = new Schema({
time: {
type: Date,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
comment: "日期",
},
name: {
type: String,
commnet: "类别/名称",
},
spec: {
type: String,
commnet: "规格",
},
buyNum: {
type: Number,
comment: "数量"
},
unitPrice: {
type: Number,
comment: "单价(元)"
},
taxAmount: {
type: Number,
comment: "税额(元)"
},
totalAmount: {
type: Number,
comment: "总额(元)"
},
agent: {
type: String,
comment: "代理商/厂家"
},
notes: {
type: String,
comment: "备注"
},
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
comment1: "创建人"
},
createdAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
updatedAt: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
del: {
type: Number,
default: 0,
comment1: '默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
}, {
id: false,
toJSON: {
getters: true,
}
});
const AgrInputOther = mongoose.model('letianAgrInputOther', letianAgrInputOtherSchema, 'letianAgrInputOther');
module.exports = AgrInputOther;
\ No newline at end of file
......@@ -3,7 +3,7 @@ const Schema = mongoose.Schema;
const moment = require('moment');
/**
* 乐田 农业投入品 出入库记录表 时间 生产投入品名称 投入品类别 总投入品使用数量 单位
* 乐田 生产投入品使用详情表
*/
const letianAgrInputRecordSchema = new Schema({
......@@ -32,19 +32,36 @@ const letianAgrInputRecordSchema = new Schema({
type: String,
commnet: "单位",
},
land: {
totalCost: {
type: String,
comment: "作业区"
comment: "总投入品成本(元)"
},
dilutionRatio: {
type: String,
comment: "稀释倍数/倍"
},
waterConsumption: {
type: String,
comment: "用水量"
},
area: {
type: String,
comment: "面积/亩"
},
dosage: {
type: String,
comment: "用量/亩"
},
land: {
type: String,
comment: "作业区"
},
notes: {
type: String,
comment: "备注"
},
......
......@@ -3,11 +3,40 @@ const express = require('express');
const router = express.Router();
const agrInputRecordController = require('../controller/agrInputRecordController');
const agrMatController = require('../controller/agrMatController');
const agrInputOtherController = require('../controller/agrInputOtherController');
const agrInputDetailController = require('../controller/agrInputDetailController');
const agrInputEmployController = require('../controller/agrInputEmployController');
// excel采集信息上传 甲方要求
//1. 青皮柚农业投入品使用情况
router.post('/input/list', agrInputRecordController.list);
// router.post('/update', fileController.update);
// router.post('/upload', fileController.list);
router.post('/inputRecord/update', agrInputRecordController.updateOne);
router.post('/inputRecord/delete', agrInputRecordController.deleteOne);
router.post('/inputRecord/create', agrInputRecordController.create);
//2. 农场其他投入品使用情况
router.post('/inputOther/list', agrInputOtherController.list);
router.post('/inputOther/update', agrInputOtherController.updateOne);
router.post('/inputOther/delete', agrInputOtherController.deleteOne);
router.post('/inputOther/create', agrInputOtherController.create);
//3. 农资投入详情
router.post('/inputDetail/list', agrInputDetailController.list);
router.post('/inputDetail/update', agrInputDetailController.updateOne);
router.post('/inputDetail/delete', agrInputDetailController.deleteOne);
router.post('/inputDetail/create', agrInputDetailController.create);
//4. 用工明细
router.post('/inputEmploy/list', agrInputEmployController.list);
router.post('/inputEmploy/update', agrInputEmployController.updateOne);
router.post('/inputEmploy/delete', agrInputEmployController.deleteOne);
router.post('/inputEmploy/create', agrInputEmployController.create);
const agrMatController = require('../controller/agrMatController');
/**
* 农资
......
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