明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
L
letian_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
letian_backend
Commits
a7961e3c
Commit
a7961e3c
authored
May 23, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
18cb3d37
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
4 deletions
+67
-4
collectSMCController.js
controller/collectSMCController.js
+5
-0
index.js
utils/index.js
+62
-4
No files found.
controller/collectSMCController.js
View file @
a7961e3c
...
@@ -67,6 +67,11 @@ async function list(req, res, next) {
...
@@ -67,6 +67,11 @@ async function list(req, res, next) {
}
}
data
=
_
.
reverse
(
dataArr
);
data
=
_
.
reverse
(
dataArr
);
}
}
//前端加个参数
if
(
req
.
body
.
from
)
{
//需要处理采集数据
data
=
utils
.
handleSMCDataForDP
(
data
);
}
res
.
sendData
({
list
:
data
,
count
});
res
.
sendData
({
list
:
data
,
count
});
}
catch
(
error
)
{
}
catch
(
error
)
{
next
(
error
);
next
(
error
);
...
...
utils/index.js
View file @
a7961e3c
...
@@ -66,7 +66,7 @@ function disTree(tree) {
...
@@ -66,7 +66,7 @@ function disTree(tree) {
return
parallel
return
parallel
}
}
function
genTracSourceCode
({
EnterpriseCode
,
type
,
date
,
batchNum
,
logisticsNum
})
{
function
genTracSourceCode
({
EnterpriseCode
,
type
,
date
,
batchNum
,
logisticsNum
})
{
// 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8)
// 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8)
//MA4W271Y8
//MA4W271Y8
date
=
date
&&
moment
().
format
(
'YYYYMMDD'
);
date
=
date
&&
moment
().
format
(
'YYYYMMDD'
);
...
@@ -82,7 +82,64 @@ function generateRandomCode(len) {
...
@@ -82,7 +82,64 @@ function generateRandomCode(len) {
code
+=
chars
[
randomIndex
];
// 拼接字符
code
+=
chars
[
randomIndex
];
// 拼接字符
}
}
return
code
;
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
=
{
module
.
exports
=
{
...
@@ -91,5 +148,6 @@ module.exports = {
...
@@ -91,5 +148,6 @@ module.exports = {
buildTree
,
buildTree
,
disTree
,
disTree
,
generateRandomCode
,
generateRandomCode
,
handleSMCDataForDP
,
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment