明树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
2aa06d51
Commit
2aa06d51
authored
Nov 26, 2024
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
a4881d4d
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
270 additions
and
32 deletions
+270
-32
agrMatController.js
controller/agrMatController.js
+134
-10
plantWarnCron.js
cron/plantWarnCron.js
+41
-0
db.zip
db.zip
+0
-0
index.js
db/index.js
+5
-2
letianAgrMat.js
db/models/letianAgrMat.js
+26
-3
letianAgrMatApproval.js
db/models/letianAgrMatApproval.js
+10
-10
letianAgrMatInOut.js
db/models/letianAgrMatInOut.js
+7
-1
letianPlantCycle.js
db/models/letianPlantCycle.js
+7
-0
letianPlantPlan.js
db/models/letianPlantPlan.js
+26
-3
systemNotice.js
db/models/systemNotice.js
+1
-1
agrRouter.js
router/agrRouter.js
+12
-2
fileRouter.js
router/fileRouter.js
+1
-0
No files found.
controller/agrMatController.js
View file @
2aa06d51
...
...
@@ -3,6 +3,7 @@ const moment = require('moment');
const
errorMessage
=
require
(
'../utils/errorMessage'
);
const
mongoose
=
require
(
'mongoose'
);
const
agrMatModule
=
require
(
'../module/agrMatModule'
);
const
ExcelJS
=
require
(
'exceljs'
);
/* ----------------农资类型--------------------- */
...
...
@@ -78,17 +79,17 @@ async function queryMatType(req, res, next) {
async
function
queryMatApprList
(
req
,
res
,
next
)
{
try
{
let
search
=
{
del
:
0
};
if
(
req
.
body
.
type
)
{
if
(
req
.
body
.
type
)
{
search
.
type
=
req
.
body
.
type
;
}
if
(
req
.
body
.
name
)
{
search
.
name
=
{
$regex
:
req
.
body
.
name
}
if
(
req
.
body
.
name
)
{
search
.
name
=
{
$regex
:
req
.
body
.
name
}
}
let
page
=
req
.
body
.
page
||
1
;
let
pageSize
=
req
.
body
.
pageSize
||
10
;
let
skip
=
(
page
-
1
)
*
pageSize
;
let
count
=
await
DB
.
AgrMatApproval
.
countDocuments
(
search
)
let
list
=
await
DB
.
AgrMatApproval
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
populate
({
path
:
'materials'
,
match
:
{
del
:
0
},
select
:
''
}).
lean
().
exec
();
let
list
=
await
DB
.
AgrMatApproval
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
populate
({
path
:
'materials'
,
match
:
{
del
:
0
},
select
:
''
}).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
)
...
...
@@ -144,7 +145,7 @@ async function saveMatAppr(req, res, next) {
if
(
!
existsMatApr
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
for
(
let
index
=
0
;
index
<
materials
.
length
;
index
++
)
{
const
element
=
materials
[
index
];
if
(
element
.
name
&&
element
.
type
&&
_
.
isNumber
(
element
.
count
)
&&
element
.
count
>
0
)
{
...
...
@@ -196,17 +197,17 @@ async function saveMatAppr(req, res, next) {
async
function
deleteMatAppr
(
req
,
res
,
next
)
{
try
{
//
let
check
=
await
DB
.
AgrMatApproval
.
findOne
({
_id
:
req
.
body
.
_id
});
if
(
!
(
check
&&
check
.
_id
))
{
let
check
=
await
DB
.
AgrMatApproval
.
findOne
({
_id
:
req
.
body
.
_id
});
if
(
!
(
check
&&
check
.
_id
))
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
if
(
check
&&
check
.
flows
&&
check
.
flows
.
length
>
0
)
{
if
(
check
&&
check
.
flows
&&
check
.
flows
.
length
>
0
)
{
return
res
.
sendError
(
errorMessage
.
agrMatHaveFlow
);
}
// 删除清单。
await
DB
.
AgrMatInOut
.
updateMany
({
approval
:
check
.
_id
},
{
del
:
1
});
await
DB
.
AgrMatInOut
.
updateMany
({
approval
:
check
.
_id
},
{
del
:
1
});
// 删除单据
await
DB
.
AgrMatApproval
.
updateOne
({
_id
:
check
.
_id
},
{
del
:
1
});
await
DB
.
AgrMatApproval
.
updateOne
({
_id
:
check
.
_id
},
{
del
:
1
});
return
res
.
sendData
({});
}
catch
(
error
)
{
next
(
error
)
...
...
@@ -220,11 +221,126 @@ async function deleteMatAppr(req, res, next) {
/* ---------------------------------------------库存---------------------------------------------------------- */
async
function
queryMatList
(
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
.
AgrMat
.
countDocuments
(
search
)
let
list
=
await
DB
.
AgrMat
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
addMat
(
req
,
res
,
next
)
{
try
{
let
creator
=
req
.
user
.
_id
;
let
info
=
{
...
req
.
body
,
creator
,
}
// if (req.body.name) {
// let check = await DB.AgrMat.findOne({ name: req.body.name });
// if (check) {
// return res.sendError(errorMessage.nameDuplicated);
// }
// }
let
ret
=
await
DB
.
AgrMat
.
findOneAndUpdate
({
name
:
info
.
name
},
info
,
{
upsert
:
true
,
returnOriginal
:
false
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
deleteMat
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
_id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
await
DB
.
AgrMat
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
del
:
1
});
res
.
sendData
({})
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
updateMat
(
req
,
res
,
next
)
{
try
{
// if (req.body.name) {
// let check = await DB.AgrMat.findOne({ name: req.body.name, _id: {$ne: req.body._id} });
// if (check) {
// return res.sendError(errorMessage.nameDuplicated);
// }
// }
let
ret
=
await
DB
.
AgrMat
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
...
req
.
body
,
_id
:
undefined
,
},
{
returnOriginal
:
false
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
importExcel
(
req
,
res
,
next
)
{
let
workbook
=
new
ExcelJS
.
Workbook
();
await
workbook
.
xlsx
.
readFile
(
req
.
file
.
path
);
let
worksheet
=
workbook
.
getWorksheet
(
1
);
let
arr
=
[];
worksheet
.
eachRow
({
includeEmpty
:
false
},
function
(
row
,
rowNumber
)
{
console
.
log
(
rowNumber
)
const
rowData
=
{};
row
.
eachCell
({
includeEmpty
:
true
},
function
(
cell
,
colNumber
)
{
console
.
log
(
'colNumber: '
,
colNumber
)
rowData
[
cell
.
value
]
=
cell
.
value
;
});
// rowsData.push(rowData);
arr
.
push
(
rowData
);
});
res
.
sendData
(
arr
)
}
async
function
inMat
(
req
,
res
,
next
)
{
try
{
let
body
=
req
.
body
;
let
creator
=
req
.
user
.
_id
;
let
materials
=
body
.
materials
||
[];
let
inApprovalId
=
new
mongoose
.
Types
.
ObjectId
();
let
inApproval
=
{
_id
:
inApprovalId
,
type
:
1
,
name
:
"入库单"
,
creator
,
}
let
m_arr
=
[];
for
(
let
index
=
0
;
index
<
materials
.
length
;
index
++
)
{
const
element
=
materials
[
index
];
if
(
element
.
count
>
0
)
{
m_arr
.
push
({
...
element
,
approval
:
inApprovalId
,
});
}
}
//创建单据
//创建列表
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
outMat
(
req
,
res
,
next
)
{
try
{
}
catch
(
error
)
{
next
(
error
);
}
}
...
...
@@ -249,4 +365,12 @@ module.exports = {
queryMatApprList
,
saveMatAppr
,
deleteMatAppr
,
queryMatList
,
addMat
,
deleteMat
,
updateMat
,
importExcel
,
inMat
,
outMat
,
}
\ No newline at end of file
cron/plantWarnCron.js
View file @
2aa06d51
...
...
@@ -4,7 +4,48 @@ const httpRequest = require('../utils/httpRequest');
const
_
=
require
(
'lodash'
);
async
function
plantearlywarning
(
params
)
{
let
role
=
await
DB
.
Role
.
findOne
({
key
:
"notice_role"
});
let
users
=
[]
if
(
role
&&
role
.
_id
)
{
users
=
await
DB
.
User
.
find
({
roles
:
role
.
_id
}).
select
(
'_id'
);
}
//这里暂时不确定 收获周期的格式
let
plants
=
await
DB
.
PlantPlan
.
find
({
del
:
0
}).
populate
({
path
:
'plantiCycle'
}).
lean
().
exec
();
let
exceeds
=
[];
for
(
let
index
=
0
;
index
<
plants
.
length
;
index
++
)
{
const
element
=
plants
[
index
];
let
cycles
=
element
.
plantCycle
||
[];
for
(
let
i
=
0
;
i
<
cycles
.
length
;
i
++
)
{
const
cyc
=
cycles
[
i
];
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
)
{
exceeds
.
push
({
...
cyc
,
})
}
}
}
}
}
}
if
(
users
.
length
&&
exceeds
.
length
)
{
for
(
let
u
=
0
;
u
<
users
.
length
;
u
++
)
{
const
user
=
users
[
u
];
await
DB
.
Notice
.
create
({
sendUser
:
"66d6c4099f8480c6db53ce13"
,
receiveUser
:
user
.
_id
,
content
:
""
,
exceeds
,
title
:
"农事预警"
,
type
:
5
,
});
}
}
}
module
.
exports
=
{
...
...
db.zip
deleted
100644 → 0
View file @
a4881d4d
File deleted
db/index.js
View file @
2aa06d51
...
...
@@ -41,14 +41,16 @@ const AgrInputRecord = require('./models/letianAgrInputRecord');
const
AgrInputDetail
=
require
(
'./models/letianAgrInputDetail'
);
const
AgrInputEmploy
=
require
(
'./models/letianAgrInputEmploy'
);
const
AgrInputOther
=
require
(
'./models/letianAgrInputOther'
);
const
AgrMat
=
require
(
'./models/letianAgrMat'
);
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'
);
const
PlantCycle
=
require
(
'./models/letianPlantCycle'
);
const
PlantPlan
=
require
(
'./models/letianPlantPlan'
);
const
ProductPlant
=
require
(
'./models/letianProductPlant'
);
const
ProductPre
=
require
(
'./models/letianProductPre'
);
...
...
@@ -81,13 +83,14 @@ global.DB = {
AgrInputDetail
,
AgrInputEmploy
,
AgrInputOther
,
AgrMat
,
AgrMatType
,
AgrMatApproval
,
AgrMatInOut
,
FileTemplate
,
AreaRecord
,
ExcelRecord
,
PlantCycle
,
PlantPlan
,
ProductPlant
,
...
...
db/models/letianAgrMat.js
View file @
2aa06d51
...
...
@@ -8,7 +8,8 @@ const moment = require('moment');
const
AgrMaterialSchema
=
new
Schema
({
type
:
{
type
:
mongoose
.
Types
.
ObjectId
,
// type: mongoose.Types.ObjectId,
type
:
String
,
comment
:
"农资类型"
},
name
:
{
...
...
@@ -16,12 +17,34 @@ const AgrMaterialSchema = new Schema({
type
:
String
,
comment
:
"农资名称"
},
img
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'File'
,
comment
:
"物品照片"
,
default
:
null
,
set
:
v
=>
{
if
(
!
v
)
{
return
null
;}
else
{
return
v
;}}
},
totalCount
:
{
type
:
Number
,
comment
:
"农资库存数量"
},
unit
:
{
type
:
String
,
comment
:
"农资单位"
},
comment
:
{
type
:
String
,
comment
:
"备注"
},
spec
:
{
type
:
String
,
commnet
:
"规格"
,
},
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
,
comment1
:
"创建人"
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
,
...
...
db/models/letianAgrMatApproval.js
View file @
2aa06d51
...
...
@@ -21,12 +21,12 @@ const AgrMaterialApprovalSchema = new Schema({
type
:
String
,
comment
:
"单据名称"
},
materials
:
{
type
:
[
mongoose
.
Types
.
ObjectId
],
ref
:
'AgrMatInOut'
,
comment
:
"出入库记录清单"
,
default
:
[]
},
//
materials: {
//
type: [mongoose.Types.ObjectId],
//
ref: 'AgrMatInOut',
//
comment: "出入库记录清单",
//
default: []
//
},
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
,
...
...
@@ -38,10 +38,10 @@ const AgrMaterialApprovalSchema = new Schema({
comment
:
"单据状态 1.未提交 3.待审批 5.审批通过 7.审批不通过"
,
default
:
1
,
},
flow
:
{
type
:
[
mongoose
.
Types
.
ObjectId
],
comment
:
"审批流程记录 不通过后再提交即为一次新的审批流程"
},
//
flow: {
//
type: [mongoose.Types.ObjectId],
//
comment: "审批流程记录 不通过后再提交即为一次新的审批流程"
//
},
createdAt
:
{
type
:
Date
,
...
...
db/models/letianAgrMatInOut.js
View file @
2aa06d51
...
...
@@ -8,7 +8,8 @@ const moment = require('moment');
const
AgrMaterialInOutSchema
=
new
Schema
({
type
:
{
type
:
mongoose
.
Types
.
ObjectId
,
// type: mongoose.Types.ObjectId,
type
:
String
,
comment
:
"农资类型"
,
required
:
true
,
...
...
@@ -27,6 +28,11 @@ const AgrMaterialInOutSchema = new Schema({
comment
:
"单据id"
,
required
:
true
,
},
status
:
{
type
:
Number
,
comment
:
"入库状态 1 新增入库 2 追加入库 "
,
default
:
1
,
},
createdAt
:
{
...
...
db/models/letianPlantCycle.js
View file @
2aa06d51
...
...
@@ -19,6 +19,13 @@ const PlantCycleSchema = new Schema({
type
:
String
,
comment
:
"内容 : 注意事项"
},
img
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'File'
,
comment
:
"物品照片"
,
default
:
null
,
set
:
v
=>
{
if
(
!
v
)
{
return
null
;}
else
{
return
v
;}}
},
times
:
{
type
:
[
{
...
...
db/models/letianPlantPlan.js
View file @
2aa06d51
...
...
@@ -6,7 +6,7 @@ const moment = require('moment');
* 种植计划
*/
const
PlantPlanSchema
=
new
Schema
({
plantType
:
{
type
:
String
,
comment
:
"作物类型"
,
...
...
@@ -43,11 +43,34 @@ const PlantPlanSchema = new Schema({
comment
:
"种植状态 采收、结束种植"
,
},
plantiCycle
:
{
type
:
mongoose
.
Types
.
ObjectId
,
type
:
[
mongoose
.
Types
.
ObjectId
],
// type: [{
// cycleName: {
// type: String,
// comment: "周期名称",
// },
// content: {
// type: String,
// comment: "内容 : 注意事项"
// },
// times: {
// type: [
// {
// startTime: {
// type: Date,
// },
// endTime: {
// type: Date,
// },
// }
// ],
// },
// }],
ref
:
"PlantCycle"
,
comment
:
"种植周期"
,
},
createdAt
:
{
...
...
db/models/systemNotice.js
View file @
2aa06d51
...
...
@@ -29,7 +29,7 @@ const Noticechema = new Schema({
type
:
{
type
:
Number
,
comment
:
"通知类型 3. 采集数据预警通知。"
,
comment
:
"通知类型 3. 采集数据预警通知。
5. 农事预警
"
,
},
exceeds
:[],
createdAt
:
{
...
...
router/agrRouter.js
View file @
2aa06d51
...
...
@@ -37,10 +37,20 @@ router.post('/inputEmploy/create', agrInputEmployController.create);
const
agrMatController
=
require
(
'../controller/agrMatController'
);
router
.
post
(
'/mat/list'
,
agrMatController
.
queryMatList
);
router
.
post
(
'/mat/add'
,
agrMatController
.
addMat
);
router
.
post
(
'/mat/delete'
,
agrMatController
.
deleteMat
);
router
.
post
(
'/mat/update'
,
agrMatController
.
updateMat
);
//入库
router
.
post
(
'/mat/in'
,
agrMatController
.
inMat
);
//出库
router
.
post
(
'/mat/out'
,
agrMatController
.
outMat
);
/**
* 农资
* 农资
审批记录--- 202411 ---- 不要审批过程 废弃
*/
router
.
post
(
'/mat/approval/list'
,
agrMatController
.
queryMatApprList
);
//获取农资审批记录列表
router
.
post
(
'/mat/approval/save'
,
agrMatController
.
saveMatAppr
);
//获取农资审批记录列表
...
...
@@ -49,7 +59,7 @@ router.post('/mat/approval/delete', agrMatController.deleteMatAppr); //获取农
/**
* 农资类型
* 农资类型
--- 不要类型 --- 不方便导入
*/
router
.
post
(
'/mat/type/create'
,
agrMatController
.
createMatType
);
router
.
post
(
'/mat/type/delete'
,
agrMatController
.
deleteMatType
);
...
...
router/fileRouter.js
View file @
2aa06d51
...
...
@@ -54,6 +54,7 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
'agrInputOther'
:
"agrInputOtherController"
,
'agrInputDetail'
:
"agrInputDetailController"
,
'agrInputEmploy'
:
"agrInputEmployController"
,
'agrMat'
:
'agrMatController'
,
}
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
await
controller
.
importExcel
(
req
,
res
,
next
);
...
...
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