明树Git Lab

Commit 47580fc1 authored by zengfanpei's avatar zengfanpei

update

parent 417de00f
...@@ -104,7 +104,31 @@ async function test(req, res, next) { ...@@ -104,7 +104,31 @@ async function test(req, res, next) {
async function exportExcel(req, res, next) {
try {
let search = {del: 0};
if(req.body.name) {
search.name = {$regex: req.body.name}
}
if(req.body.startTime) {
search.time = search.time || {};
search.time.$gte = req.body.startTime;
}
if(req.body.endTime) {
search.time = search.time || {};
search.time.$lte = req.body.endTime
}
if(_.isArray(req.body.time) && req.body.time.length == 2) {
search.time = {
$lte: req.body.time[1],
$gte: req.body.time[0]
}
}
} catch (error) {
next(error);
}
}
...@@ -116,4 +140,5 @@ module.exports = { ...@@ -116,4 +140,5 @@ module.exports = {
queryInfo, queryInfo,
updateInfo, updateInfo,
delInfo, delInfo,
exportExcel
} }
\ No newline at end of file
const moment = require('moment');
const mongoose = require('mongoose');
async function init(req, res) {
// 1. 初始化数据采集属性
let attrs = [
{ deviceKey: "温度", dbKey: "soilTemperature", name: "土壤温度" },
{ deviceKey: "湿度", dbKey: "soilMoisture", name: "土壤湿度" },
{ deviceKey: "氮", dbKey: "nitrogen", name: "氮" },
{ deviceKey: "磷", dbKey: "phosphorus", name: "磷" },
{ deviceKey: "钾", dbKey: "potassium", name: "钾" },
{ deviceKey: "PH", dbKey: "soilPH", name: "土壤PH值" },
{ deviceKey: "电导率", dbKey: "soilConductivity", name: "土壤电导率" },
{ deviceKey: "风速", dbKey: "windSpeed", name: "风速" },
{ deviceKey: "风向", dbKey: "windDirection", name: "风向" },
{ deviceKey: "雨量", dbKey: "rainfall", name: "雨量" },
{ deviceKey: "信号强度", dbKey: "signalSterngth", name: "信号强度" },
{ deviceKey: "错误码", dbKey: "errorCode", name: "错误码" },
{ deviceKey: "版本号", dbKey: "version", name: "版本号" },
]
for (let index = 0; index < attrs.length; index++) {
const element = attrs[index];
await DB.CollectAttribute.findOneAndUpdate({ dbKey: element.dbKey }, element, { upsert: true });
}
// // 土壤
// for (let index = 0; index < 20; index++) {
// await DB.CollectSMC.findOneAndUpdate({ time: moment('2024-08-26').add(index, 'day') }, {
// id: 8746,
// name: "设备名称修改测试",
// deviceNumber: "16A67205BA3A",
// time: moment('2024-08-26').add(index, 'day'),
// soilTemperature: 11 + Math.floor(Math.random() * 20),
// soilMoisture: 11 + Math.floor(Math.random() * 20),
// nitrogen: 11 + Math.floor(Math.random() * 20),
// phosphorus: 11 + Math.floor(Math.random() * 20),
// potassium: 11 + Math.floor(Math.random() * 20),
// soilPH: 11 + Math.floor(Math.random() * 20),
// soilConductivity: 11 + Math.floor(Math.random() * 20),
// }, { upsert: true })
// }
//气象
// for (let index = 0; index < 20; index++) {
// await DB.CollectWS.findOneAndUpdate({ time: moment('2024-08-26').add(index, 'day') }, {
// id: 8746,
// name: "气象站",
// deviceNumber: "1111111111111",
// time: moment('2024-08-26').add(index, 'day'),
// windSpeed: 11 + Math.floor(Math.random() * 20),
// windDirection: 11 + Math.floor(Math.random() * 20),
// rainfall: 11 + Math.floor(Math.random() * 20),
// }, { upsert: true })
// }
// 虫情
// for (let index = 0; index < 20; index++) {
// let dataId = new mongoose.Types.ObjectId()
// let data = await DB.CollectIPS.create({
// _id: dataId,
// id: 8746,
// name: "虫情系统",
// deviceNumber: "FF35d4072d53",
// time: moment('2024-08-26').add(index, 'day'),
// downloadUrl: "pictures/FF35D4072D53/2024-08-20-15-03-43.jpg",
// newTime: moment('2024-08-26').add(index, 'day'),
// newCount: 11 + Math.floor(Math.random() * 20)
// });
// let typeId = new mongoose.Types.ObjectId()
// let type = await DB.CollectIPSType.create({ _id: typeId, name: "虫子" + index });
// let planId = new mongoose.Types.ObjectId()
// let plan = await DB.CollectIPSPlan.create({ _id: planId, name: "虫子" + index, controlPlan: "防治建议" + index });
// await DB.CollectIPSResult.findOneAndUpdate({ data: dataId }, {
// deviceNumber: "FF35d4072d53",
// name: "虫子" + index,
// count: 1 + Math.floor(Math.random() * 10),
// time: moment('2024-08-26').add(index, 'day'),
// type: typeId,
// plan: planId,
// data: dataId,
// }, { upsert: true });
// }
res.sendData({})
}
module.exports = {
init
}
\ No newline at end of file
...@@ -17,6 +17,7 @@ router.post('/IPS/list', collectIPSController.list); // 翻页列表 ...@@ -17,6 +17,7 @@ router.post('/IPS/list', collectIPSController.list); // 翻页列表
router.post('/IPS/show', collectIPSController.queryInfo); // 查询详情 router.post('/IPS/show', collectIPSController.queryInfo); // 查询详情
router.post('/IPS/update', collectIPSController.updateInfo); // 更新 router.post('/IPS/update', collectIPSController.updateInfo); // 更新
router.post('/IPS/del', collectIPSController.delInfo); // 删除 router.post('/IPS/del', collectIPSController.delInfo); // 删除
router.post('/IPS/exportExcel', collectIPSController.exportExcel); // 删除
......
...@@ -20,9 +20,6 @@ const statisticsRouter = require('./statisticsRouter'); ...@@ -20,9 +20,6 @@ const statisticsRouter = require('./statisticsRouter');
const flowRouter = require('./flowRouter'); const flowRouter = require('./flowRouter');
const initController = require('../controller/initController')
router.post('/init', initController.init); // 后续删除
router.use('/user', userRouter); // 用户 角色 router.use('/user', userRouter); // 用户 角色
router.use('/depart', departRouter); // 部门 router.use('/depart', departRouter); // 部门
router.use('/menu', menuRouter); //菜单 按钮 router.use('/menu', menuRouter); //菜单 按钮
......
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