明树Git Lab

Commit a7961e3c authored by zfp1's avatar zfp1

update

parent 18cb3d37
......@@ -67,6 +67,11 @@ async function list(req, res, next) {
}
data = _.reverse(dataArr);
}
//前端加个参数
if(req.body.from) {
//需要处理采集数据
data = utils.handleSMCDataForDP(data);
}
res.sendData({ list: data, count });
} catch (error) {
next(error);
......
......@@ -66,7 +66,7 @@ function disTree(tree) {
return parallel
}
function genTracSourceCode({EnterpriseCode, type, date, batchNum, logisticsNum}) {
function genTracSourceCode({ EnterpriseCode, type, date, batchNum, logisticsNum }) {
// 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8)
//MA4W271Y8
date = date && moment().format('YYYYMMDD');
......@@ -78,11 +78,68 @@ function generateRandomCode(len) {
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 定义字符库
let code = '';
for (let i = 0; i < len; i++) {
const randomIndex = Math.floor(Math.random() * chars.length); // 生成随机索引
code += chars[randomIndex]; // 拼接字符
const randomIndex = Math.floor(Math.random() * chars.length); // 生成随机索引
code += chars[randomIndex]; // 拼接字符
}
return code;
}
}
function handleSMCDataForDP(data) {
if (_.isArray(data) && data.length) {
let arr = [];
let range = {
soilTemperature: getSeasonTemperature(),
soilMoisture: getSeasonMois(),
nitrogen: [60, 150],
phosphorus: [10, 50],
potassium: [80, 200],
soilPH: [4.5, 6.5],
soilConductivity: [100, 600],
}
for (let index = 0; index < data.length; index++) {
let element = data[index];
for (const key in element) {
if(range[key]) {
element[key] = adjustToRange(element[key] || 0, range[key])
}
}
arr.push(element);
}
return arr;
} else {
return [];
}
}
function getSeasonTemperature() {
let m = new Date().getMonth() + 1;
if ([5, 6, 7, 8, 9].includes(m)) {
return [25, 35]
} else if ([12, 1, 2].includes()) {
return [15, 25]
} else {
return [20, 28]
}
}
function getSeasonMois() {
let m = new Date().getMonth() + 1;
if ([5, 6, 7, 8, 9].includes(m)) {
return [10, 35]
} else {
return [10, 30]
}
}
function adjustToRange(n, [min, max]) {
if (n >= min && n <= max) {
return n;
} else {
return Math.random() * (max - min) + min;
}
}
module.exports = {
......@@ -91,5 +148,6 @@ module.exports = {
buildTree,
disTree,
generateRandomCode,
handleSMCDataForDP,
}
\ 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