明树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
0dc6afe3
Commit
0dc6afe3
authored
Dec 12, 2024
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
10fbc5f6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
11 deletions
+49
-11
plantWarnCron.js
cron/plantWarnCron.js
+47
-11
letianPlantPlan.js
db/models/letianPlantPlan.js
+2
-0
No files found.
cron/plantWarnCron.js
View file @
0dc6afe3
...
...
@@ -10,31 +10,54 @@ async function plantearlywarning(params) {
users
=
await
DB
.
User
.
find
({
roles
:
role
.
_id
}).
select
(
'_id'
);
}
//这里暂时不确定 收获周期的格式
let
plants
=
await
DB
.
PlantPlan
.
find
({
del
:
0
}).
populate
({
path
:
'plantCycle'
}).
lean
().
exec
();
let
plants
=
await
DB
.
PlantPlan
.
find
({
del
:
0
}).
populate
({
path
:
"land"
}).
populate
({
path
:
'plantCycle'
}).
lean
().
exec
();
let
exceeds
=
[];
console
.
log
(
plants
,
"===="
)
for
(
let
index
=
0
;
index
<
plants
.
length
;
index
++
)
{
const
element
=
plants
[
index
];
console
.
log
(
element
.
warning
,
"======"
)
let
cycles
=
element
.
plantCycle
||
[];
for
(
let
i
=
0
;
i
<
cycles
.
length
;
i
++
)
{
const
cyc
=
cycles
[
i
];
if
(
cyc
.
times
&&
cyc
.
times
.
length
)
{
if
(
cyc
.
times
&&
cyc
.
times
.
length
)
{
for
(
let
ii
=
0
;
ii
<
cyc
.
times
.
length
;
ii
++
)
{
const
ti
=
cyc
.
times
[
ii
];
if
(
ti
.
startTime
&&
ti
.
endTime
)
{
let
st
=
moment
().
diff
(
moment
(
ti
.
startTime
),
'days'
);
let
et
=
moment
().
diff
(
moment
(
ti
.
endTime
),
'days'
);
if
(
st
>=
0
&&
et
<=
0
)
{
element
.
warning
=
element
.
warning
||
[];
let
key
=
`
${
element
.
_id
}
_
${
cyc
.
_id
}
_
${
ti
.
_id
}
`
;
if
(
!
element
.
warning
.
includes
(
key
)
&&
ti
.
startTime
&&
ti
.
endTime
){
let
months
=
getMonthsBetweenDates
(
ti
.
startTime
,
ti
.
endTime
);
let
startMonth
=
new
Date
(
ti
.
startTime
).
getMonth
()
+
1
;
let
startDay
=
new
Date
(
ti
.
startTime
).
getDate
();
let
endMonth
=
new
Date
(
ti
.
endTime
).
getMonth
()
+
1
;
let
endDay
=
new
Date
(
ti
.
endTime
).
getDate
();
let
currentMonth
=
new
Date
().
getMonth
()
+
1
;
let
currentDay
=
new
Date
().
getDate
();
console
.
log
(
startMonth
,
currentMonth
,
startDay
,
currentDay
,
endMonth
,
endDay
)
if
(
months
.
includes
(
currentMonth
))
{
if
((
startMonth
==
currentMonth
)
&&
startDay
<=
currentDay
)
{
exceeds
.
push
({
...
cyc
,
})
...
element
,
});
element
.
warning
.
push
(
key
);
}
else
if
((
endMonth
==
currentMonth
)
&&
currentDay
<=
endDay
)
{
exceeds
.
push
({
...
element
,
});
element
.
warning
.
push
(
key
);
}
else
{
exceeds
.
push
({
...
element
,
});
element
.
warning
.
push
(
key
);
}
}
console
.
log
(
exceeds
,
"==============="
)
}
}
}
}
await
DB
.
PlantPlan
.
findOneAndUpdate
({
_id
:
element
.
_id
},
{
warning
:
element
.
warning
});
}
if
(
users
.
length
&&
exceeds
.
length
)
{
if
(
users
.
length
&&
exceeds
.
length
)
{
for
(
let
u
=
0
;
u
<
users
.
length
;
u
++
)
{
const
user
=
users
[
u
];
await
DB
.
Notice
.
create
({
...
...
@@ -49,6 +72,19 @@ async function plantearlywarning(params) {
}
}
function
getMonthsBetweenDates
(
startTime
,
endTime
)
{
let
months
=
[];
let
currentDate
=
new
Date
(
startTime
);
while
(
currentDate
<=
endTime
)
{
months
.
push
(
new
Date
(
currentDate
).
getMonth
()
+
1
);
currentDate
.
setMonth
(
currentDate
.
getMonth
()
+
1
);
}
return
months
;
}
module
.
exports
=
{
plantearlywarning
}
\ No newline at end of file
db/models/letianPlantPlan.js
View file @
0dc6afe3
...
...
@@ -83,6 +83,8 @@ const PlantPlanSchema = new Schema({
comment
:
"种植周期"
,
},
warning
:
[],
createdAt
:
{
...
...
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