明树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
e3d6bb73
Commit
e3d6bb73
authored
Mar 18, 2025
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
ac87d65c
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
354 additions
and
57 deletions
+354
-57
statisticsController.js
controller/statisticsController.js
+88
-55
suppFactController.js
controller/suppFactController.js
+174
-0
index.js
db/index.js
+5
-0
letianSuppFact.js
db/models/letianSuppFact.js
+64
-0
fileRouter.js
router/fileRouter.js
+2
-0
index.js
router/index.js
+5
-2
nutrRouter.js
router/nutrRouter.js
+16
-0
No files found.
controller/statisticsController.js
View file @
e3d6bb73
This diff is collapsed.
Click to expand it.
controller/suppFactController.js
0 → 100644
View file @
e3d6bb73
const
ExcelJS
=
require
(
'exceljs'
);
const
_
=
require
(
'lodash'
);
const
fs
=
require
(
'fs'
);
async
function
list
(
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
;
if
(
req
.
body
.
name
)
{
search
.
name
=
req
.
body
.
name
;
}
let
count
=
await
DB
.
SuppFact
.
countDocuments
(
search
)
let
list
=
await
DB
.
SuppFact
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
sort
({
_id
:
-
1
}).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
lunbo
(
req
,
res
,
next
)
{
try
{
let
search
=
{
del
:
0
,
name
:
{
$exists
:
true
}
};
let
ret
=
await
DB
.
SuppFact
.
aggregate
([
{
$match
:
search
},
{
$group
:
{
_id
:
"$name"
,
}
}
]);
ret
=
ret
.
map
(
o
=>
{
return
o
.
_id
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
create
(
req
,
res
,
next
)
{
try
{
let
ret
=
await
DB
.
SuppFact
.
create
(
req
.
body
)
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
updateOne
(
req
,
res
,
next
)
{
try
{
let
updateInfo
=
{
...
req
.
body
,
}
let
ret
=
await
DB
.
SuppFact
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
updateInfo
);
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
deleteOne
(
req
,
res
,
next
)
{
try
{
let
ret
=
await
DB
.
SuppFact
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
del
:
1
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
deleteMany
(
req
,
res
,
next
)
{
try
{
let
_ids
=
req
.
body
.
_ids
;
if
(
_
.
isArray
(
_ids
)
&&
_ids
.
length
>
0
)
{
let
ret
=
await
DB
.
SuppFact
.
updateMany
({
_id
:
{
$in
:
_ids
}
},
{
del
:
1
});
res
.
sendData
(
ret
);
}
else
{
res
.
sendData
();
}
}
catch
(
error
)
{
next
(
error
)
}
}
async
function
importExcel
(
req
,
res
,
next
)
{
try
{
let
workbook
=
new
ExcelJS
.
Workbook
();
await
workbook
.
xlsx
.
readFile
(
req
.
file
.
path
);
let
worksheet
=
workbook
.
getWorksheet
(
1
);
let
arr
=
[];
for
(
let
index
=
2
;
index
<=
worksheet
.
actualRowCount
;
index
++
)
{
let
values
=
worksheet
.
getRow
(
index
).
values
;
let
obj
=
{
creator
:
req
.
user
.
_id
,
name
:
values
[
1
],
testItem
:
values
[
2
],
result
:
values
[
3
],
unit
:
values
[
4
],
nutrientReferenceValue
:
values
[
5
],
}
if
(
typeof
obj
.
indate
==
'number'
)
{
obj
.
indate
=
new
Date
(
1900
,
0
,
obj
.
indate
-
1
,
0
,
0
,
0
);
}
arr
.
push
(
obj
)
}
if
(
arr
.
length
)
{
await
DB
.
SuppFact
.
insertMany
(
arr
);
}
res
.
sendData
(
arr
);
}
catch
(
error
)
{
next
(
error
)
}
}
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
.
indate
=
search
.
indate
||
{};
search
.
indate
.
$gte
=
req
.
body
.
startTime
;
}
if
(
req
.
body
.
endTime
)
{
search
.
indate
=
search
.
indate
||
{};
search
.
indate
.
$lte
=
req
.
body
.
endTime
}
let
ret
=
await
DB
.
ExcelRecord
.
create
({
creator
:
req
.
user
.
_id
,
type
:
2
,
modleName
:
'SuppFact'
,
search
,
})
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
module
.
exports
=
{
list
,
create
,
importExcel
,
deleteOne
,
updateOne
,
exportExcel
,
deleteMany
,
lunbo
,
}
\ No newline at end of file
db/index.js
View file @
e3d6bb73
...
@@ -83,6 +83,9 @@ const RawMatReqList = require("./models/letianRawMatReqList");
...
@@ -83,6 +83,9 @@ const RawMatReqList = require("./models/letianRawMatReqList");
const
PackMatInList
=
require
(
"./models/letianPackMatInList"
);
const
PackMatInList
=
require
(
"./models/letianPackMatInList"
);
const
PackMatOutList
=
require
(
"./models/letianPackMatOutList"
);
const
PackMatOutList
=
require
(
"./models/letianPackMatOutList"
);
//营养成分表
const
SuppFact
=
require
(
"./models/letianSuppFact"
);
global
.
DB
=
{
global
.
DB
=
{
File
,
File
,
...
@@ -136,6 +139,8 @@ global.DB = {
...
@@ -136,6 +139,8 @@ global.DB = {
RawMatReqList
,
RawMatReqList
,
PackMatInList
,
PackMatInList
,
PackMatOutList
,
PackMatOutList
,
SuppFact
,
}
}
...
...
db/models/letianSuppFact.js
0 → 100644
View file @
e3d6bb73
const
mongoose
=
require
(
'mongoose'
);
const
Schema
=
mongoose
.
Schema
;
const
moment
=
require
(
'moment'
);
// const autoIncrement = require('mongoose-auto-increment');
// autoIncrement.initialize(mongoose.connection);
/**
* //营养成分表
*/
const
letianSuppFactSchema
=
new
Schema
({
name
:
{
type
:
String
,
comment
:
"名称"
,
},
testItem
:
{
type
:
String
,
comment
:
"检测项目"
,
},
result
:
{
type
:
String
,
comment
:
"结果"
,
},
unit
:
{
type
:
String
,
comment
:
"单位"
,
},
nutrientReferenceValue
:
{
type
:
String
,
comment
:
"营养素参考值%"
,
},
creator
:
{
type
:
mongoose
.
Types
.
ObjectId
,
ref
:
'User'
,
comment1
:
"创建人"
},
createdAt
:
{
type
:
Date
,
default
:
Date
.
now
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
},
updatedAt
:
{
type
:
Date
,
default
:
Date
.
now
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
},
del
:
{
type
:
Number
,
default
:
0
,
comment1
:
'默认0 , 1:表示删除, 若有其他隐藏业务 不要混用此字段。'
}
},
{
toJSON
:
{
getters
:
true
}
});
const
SuppFact
=
mongoose
.
model
(
'SuppFact'
,
letianSuppFactSchema
,
'letianSuppFact'
);
module
.
exports
=
SuppFact
;
\ No newline at end of file
router/fileRouter.js
View file @
e3d6bb73
...
@@ -63,6 +63,7 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
...
@@ -63,6 +63,7 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
'rawMatReq'
:
'rawMatReqlistController'
,
//原材料出库(领用)明细表
'rawMatReq'
:
'rawMatReqlistController'
,
//原材料出库(领用)明细表
'packMatIn'
:
'packMatInListController'
,
//包装材料入库(采购)明细表
'packMatIn'
:
'packMatInListController'
,
//包装材料入库(采购)明细表
'packMatOut'
:
'packMatOutListController'
,
//包装材料出库(领用)明细表
'packMatOut'
:
'packMatOutListController'
,
//包装材料出库(领用)明细表
'suppFact'
:
'suppFactController'
,
}
}
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
await
controller
.
importExcel
(
req
,
res
,
next
);
await
controller
.
importExcel
(
req
,
res
,
next
);
...
@@ -85,6 +86,7 @@ router.post('/:modelName/exportExcel', async (req, res, next) => {
...
@@ -85,6 +86,7 @@ router.post('/:modelName/exportExcel', async (req, res, next) => {
'rawMatReq'
:
'rawMatReqlistController'
,
//原材料出库(领用)明细表
'rawMatReq'
:
'rawMatReqlistController'
,
//原材料出库(领用)明细表
'packMatIn'
:
'packMatInListController'
,
//包装材料入库(采购)明细表
'packMatIn'
:
'packMatInListController'
,
//包装材料入库(采购)明细表
'packMatOut'
:
'packMatOutListController'
,
//包装材料出库(领用)明细表
'packMatOut'
:
'packMatOutListController'
,
//包装材料出库(领用)明细表
'suppFact'
:
'suppFactController'
,
}
}
console
.
log
(
modelMap
[
modelName
]);
console
.
log
(
modelMap
[
modelName
]);
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
let
controller
=
require
(
`../controller/
${
modelMap
[
modelName
]}
`
);
...
...
router/index.js
View file @
e3d6bb73
...
@@ -24,6 +24,7 @@ const inductryRouter = require('./inductryRouter');
...
@@ -24,6 +24,7 @@ const inductryRouter = require('./inductryRouter');
const
heavyMetalRouter
=
require
(
'./externalRouter'
);
const
heavyMetalRouter
=
require
(
'./externalRouter'
);
const
compInfoRouter
=
require
(
'./compInfoRouter'
);
const
compInfoRouter
=
require
(
'./compInfoRouter'
);
const
rawmatRouter
=
require
(
'./rawmatRouter'
);
const
rawmatRouter
=
require
(
'./rawmatRouter'
);
const
nutrRouter
=
require
(
'./nutrRouter'
);
router
.
use
(
'/user'
,
userRouter
);
// 用户 角色
router
.
use
(
'/user'
,
userRouter
);
// 用户 角色
...
@@ -53,9 +54,11 @@ router.use('/excelrecord', excelrecordRouter);
...
@@ -53,9 +54,11 @@ router.use('/excelrecord', excelrecordRouter);
// 工业
// 工业
router
.
use
(
'/ind'
,
inductryRouter
);
router
.
use
(
'/ind'
,
inductryRouter
);
router
.
use
(
'/company'
,
compInfoRouter
);
router
.
use
(
'/company'
,
compInfoRouter
);
//公司信息
router
.
use
(
'/mat'
,
rawmatRouter
);
router
.
use
(
'/mat'
,
rawmatRouter
);
//原材料 包材
router
.
use
(
'/nutrients'
,
nutrRouter
);
...
...
router/nutrRouter.js
0 → 100644
View file @
e3d6bb73
const
express
=
require
(
'express'
);
const
router
=
express
.
Router
();
const
suppFactController
=
require
(
'../controller/suppFactController'
);
router
.
post
(
'/suppFact/create'
,
suppFactController
.
create
);
router
.
post
(
'/suppFact/update'
,
suppFactController
.
updateOne
);
router
.
post
(
'/suppFact/delete'
,
suppFactController
.
deleteOne
);
router
.
post
(
'/suppFact/batchDelete'
,
suppFactController
.
deleteMany
);
router
.
post
(
'/suppFact/list'
,
suppFactController
.
list
);
router
.
post
(
'/suppFact/lunbo'
,
suppFactController
.
lunbo
);
module
.
exports
=
router
;
\ 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