明树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
c513d055
Commit
c513d055
authored
Sep 23, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
de023961
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
121 additions
and
68 deletions
+121
-68
agrMatController.js
controller/agrMatController.js
+80
-52
fileController.js
controller/fileController.js
+1
-1
letianAgrMatApproval.js
db/models/letianAgrMatApproval.js
+0
-11
letianAgrMatInOut.js
db/models/letianAgrMatInOut.js
+1
-1
agrMatModule.js
module/agrMatModule.js
+24
-0
agrRouter.js
router/agrRouter.js
+1
-0
server.js
server.js
+6
-3
errorMessage.js
utils/errorMessage.js
+8
-0
No files found.
controller/agrMatController.js
View file @
c513d055
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
errorMessage
=
require
(
'../utils/errorMessage'
);
const
{
default
:
mongoose
}
=
require
(
'mongoose'
);
const
mongoose
=
require
(
'mongoose'
);
const
agrMatModule
=
require
(
'../module/agrMatModule'
);
/* ----------------农资类型--------------------- */
...
...
@@ -12,7 +13,7 @@ async function createMatType(req, res, next) {
...
req
.
body
,
creator
,
}
let
ret
=
await
DB
.
AgrMatType
.
findOneAndUpdate
({
name
:
info
.
name
},
info
,
{
upsert
:
true
});
let
ret
=
await
DB
.
AgrMatType
.
findOneAndUpdate
({
name
:
info
.
name
},
info
,
{
upsert
:
true
,
returnOriginal
:
false
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
...
...
@@ -21,10 +22,10 @@ async function createMatType(req, res, next) {
async
function
deleteMatType
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
_id
)
{
if
(
!
req
.
body
.
_id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
await
DB
.
AgrMatType
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
del
:
1
});
await
DB
.
AgrMatType
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
del
:
1
});
res
.
sendData
({})
}
catch
(
error
)
{
next
(
error
);
...
...
@@ -33,13 +34,13 @@ async function deleteMatType(req, res, next) {
async
function
updateMatType
(
req
,
res
,
next
)
{
try
{
if
(
req
.
body
.
name
)
{
let
check
=
await
DB
.
AgrMatType
.
findOne
({
name
:
req
.
body
.
name
});
if
(
check
)
{
if
(
req
.
body
.
name
)
{
let
check
=
await
DB
.
AgrMatType
.
findOne
({
name
:
req
.
body
.
name
});
if
(
check
)
{
return
res
.
sendError
(
errorMessage
.
nameDuplicated
);
}
}
let
ret
=
await
DB
.
AgrMatType
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{...
req
.
body
,
_id
:
undefined
,},
{
returnOriginal
:
false
});
let
ret
=
await
DB
.
AgrMatType
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
...
req
.
body
,
_id
:
undefined
,
},
{
returnOriginal
:
false
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
...
...
@@ -54,7 +55,7 @@ async function queryMatType(req, res, next) {
let
skip
=
(
page
-
1
)
*
pageSize
;
let
count
=
await
DB
.
AgrMatType
.
countDocuments
(
search
)
let
list
=
await
DB
.
AgrMatType
.
find
(
search
).
skip
(
skip
).
limit
(
pageSize
).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
);
}
...
...
@@ -77,12 +78,18 @@ async function queryMatType(req, res, next) {
async
function
queryMatApprList
(
req
,
res
,
next
)
{
try
{
let
search
=
{
del
:
0
};
if
(
req
.
body
.
type
)
{
search
.
type
=
req
.
body
.
type
;
}
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
).
lean
().
exec
();
res
.
sendData
({
count
,
list
});
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
)
}
...
...
@@ -92,95 +99,115 @@ async function queryMatApprList(req, res, next) {
*创建审批--入库、出库、归还 ,保存 不发起流程
*/
async
function
saveMatAppr
(
req
,
res
,
next
)
{
let
{
_id
,
materials
}
=
req
.
body
;
let
user
=
req
.
user
;
let
matInOutList
=
[],
matIds
=
[],
matType
=
[];
try
{
let
{
_id
,
type
,
materials
}
=
req
.
body
;
if
(
!
_id
)
{
let
matApr
;
if
(
!
_id
)
{
// 创建
let
matAprId
=
new
mongoose
.
Types
.
ObjectId
();
let
matInOutList
=
[],
matIds
=
[];
for
(
let
index
=
0
;
index
<
materials
.
length
;
index
++
)
{
const
element
=
materials
[
index
];
if
(
element
.
name
&&
element
.
type
&&
_
.
isNumber
(
element
.
count
)
&&
element
.
count
>
0
)
{
if
(
element
.
name
&&
element
.
type
&&
_
.
isNumber
(
element
.
count
)
&&
element
.
count
>
0
)
{
let
mioId
=
new
mongoose
.
Types
.
ObjectId
();
matIds
.
push
(
mioId
);
let
eleType
=
element
&&
element
.
type
&&
element
.
type
.
_id
||
element
&&
element
.
type
;
matType
.
push
(
eleType
)
matInOutList
.
push
({
_id
:
mioId
,
type
:
ele
ment
&&
element
.
_id
||
element
,
//种类的id
type
:
ele
Type
,
//种类的id
name
:
element
.
name
,
count
:
element
.
count
,
approval
:
matAprId
,
creator
:
user
.
_id
,
});
}
}
if
(
matInOutList
.
length
>
0
)
{
//判断重复
if
(
_
.
uniq
(
matType
).
length
!==
matType
.
length
)
{
res
.
sendError
(
errorMessage
.
agrMatDuplicated
);
}
if
(
matInOutList
.
length
>
0
)
{
await
DB
.
AgrMatInOut
.
insertMany
(
matInOutList
);
// 插入清单
}
let
matApr
=
await
DB
.
AgrMatApproval
.
create
({
// 创建单据
matApr
=
await
DB
.
AgrMatApproval
.
create
({
// 创建单据
...
req
.
body
,
_id
:
matAprId
,
type
:
type
,
materials
:
matIds
,
creator
:
user
.
_id
,
});
return
res
.
sendData
(
matApr
);
}
else
{
// 更新
let
existsMatApr
=
await
DB
.
AgrMatApproval
.
findOne
({
_id
:
req
.
body
.
_id
});
if
(
!
existsMatApr
)
{
let
existsMatApr
=
await
DB
.
AgrMatApproval
.
findOne
({
_id
});
if
(
!
existsMatApr
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
let
matInOutList
=
[],
matIds
=
[],
matExistsIds
=
[];
for
(
let
index
=
0
;
index
<
materials
.
length
;
index
++
)
{
const
element
=
materials
[
index
];
if
(
element
.
name
&&
element
.
type
&&
_
.
isNumber
(
element
.
count
)
&&
element
.
count
>
0
)
{
if
(
element
.
name
&&
element
.
type
&&
_
.
isNumber
(
element
.
count
)
&&
element
.
count
>
0
)
{
let
mioId
=
element
.
_id
;
if
(
!
mioId
)
{
if
(
!
mioId
)
{
mioId
=
new
mongoose
.
Types
.
ObjectId
();
}
matIds
.
push
(
mioId
);
matInOutList
.
push
(
DB
.
AgrMatInOut
.
findOneAndUpdate
({
_id
:
mioId
},
{
type
:
element
&&
element
.
_id
||
element
,
//种类的id
name
:
element
.
name
,
count
:
element
.
count
,
approval
:
_id
,
},
{
upsert
:
true
}));
}
matIds
.
push
(
mioId
);
let
eleType
=
element
&&
element
.
type
&&
element
.
type
.
_id
||
element
&&
element
.
type
;
matType
.
push
(
eleType
)
matInOutList
.
push
(
DB
.
AgrMatInOut
.
findOneAndUpdate
({
_id
:
mioId
},
{
type
:
eleType
,
//种类的id
name
:
element
.
name
,
count
:
element
.
count
,
approval
:
_id
,
creator
:
user
.
_id
,
},
{
upsert
:
true
}));
}
}
//判断重复
if
(
_
.
uniq
(
matType
).
length
!==
matType
.
length
)
{
res
.
sendError
(
errorMessage
.
agrMatDuplicated
);
}
//1. 删除不在传递进来的materials里、在数据库里面的数据
if
(
matIds
.
length
>
0
)
{
await
DB
.
AgrMatInOut
.
updateMany
({
approval
:
_id
,
_id
:
{
$nin
:
matIds
}},
{
del
:
1
});
if
(
matIds
.
length
>
0
)
{
await
DB
.
AgrMatInOut
.
updateMany
({
approval
:
_id
,
_id
:
{
$nin
:
matIds
}
},
{
del
:
1
});
}
//2. 更新或插入materials
if
(
matInOutList
.
length
>
0
)
{
if
(
matInOutList
.
length
>
0
)
{
await
Promise
.
all
(
matInOutList
);
}
let
matApr
=
await
DB
.
AgrMatApproval
.
findOneAndUpdate
({
_id
},{
type
:
type
,
matApr
=
await
DB
.
AgrMatApproval
.
findOneAndUpdate
({
_id
},
{
...
req
.
body
,
type
:
existsMatApr
.
type
,
materials
:
matIds
,
});
return
res
.
sendData
(
matApr
);
},
{
returnOriginal
:
false
});
}
res
.
sendData
(
matApr
);
}
catch
(
error
)
{
next
(
error
)
}
}
/**
* 更新审批--入库、出库、归还 ,保存 不发起流程
*/
async
function
createMatAppr
(
req
,
res
,
next
)
{
try
{
//
}
catch
(
error
)
{
next
(
error
)
}
}
/**
* 删除审批--入库、出库、归还 ,已发起流程不能删除。
*/
async
function
crea
teMatAppr
(
req
,
res
,
next
)
{
async
function
dele
teMatAppr
(
req
,
res
,
next
)
{
try
{
//
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
)
{
return
res
.
sendError
(
errorMessage
.
agrMatHaveFlow
);
}
// 删除清单。
await
DB
.
AgrMatInOut
.
updateMany
({
approval
:
check
.
_id
},
{
del
:
1
});
// 删除单据
await
DB
.
AgrMatApproval
.
updateOne
({
_id
:
check
.
_id
},
{
del
:
1
});
return
res
.
sendData
({});
}
catch
(
error
)
{
next
(
error
)
}
...
...
@@ -221,4 +248,5 @@ module.exports = {
queryMatApprList
,
saveMatAppr
,
deleteMatAppr
,
}
\ No newline at end of file
controller/fileController.js
View file @
c513d055
...
...
@@ -53,7 +53,7 @@ async function importExcel(req, res, next) {
let
workbook
=
new
ExcelJS
.
Workbook
();
console
.
log
(
req
.
file
)
await
workbook
.
xlsx
.
readFile
(
req
.
file
.
path
);
let
worksheet
=
workbook
.
getWorksheet
(
4
);
let
worksheet
=
workbook
.
getWorksheet
(
1
);
console
.
log
(
workbook
.
_worksheets
.
length
);
let
values
=
worksheet
.
getRow
(
1
).
values
;
// 示例:读取第一行
// for (let index = 1; index < worksheet.actualRowCount; index++) {
...
...
db/models/letianAgrMatApproval.js
View file @
c513d055
...
...
@@ -19,7 +19,6 @@ const AgrMaterialApprovalSchema = new Schema({
},
name
:
{
type
:
String
,
set
:
setNameToApproval
,
comment
:
"单据名称"
},
materials
:
{
...
...
@@ -66,15 +65,5 @@ const AgrMaterialApprovalSchema = new Schema({
}
});
function
setNameToApproval
(
v
)
{
let
map
=
{
1
:
"入库单"
,
2
:
"出库单"
,
3
:
"归还单"
,
}
return
map
[
this
.
_update
.
type
];
}
const
AgrMatApproval
=
mongoose
.
model
(
'AgrMatApproval'
,
AgrMaterialApprovalSchema
,
'letianAgrMaterialApproval'
);
module
.
exports
=
AgrMatApproval
;
\ No newline at end of file
db/models/letianAgrMatInOut.js
View file @
c513d055
...
...
@@ -52,5 +52,5 @@ const AgrMaterialInOutSchema = new Schema({
});
const
AgrMatInOut
=
mongoose
.
model
(
'AgrMatInOut'
,
AgrMaterialInOutSchema
,
'letianAgrMatInOut'
);
const
AgrMatInOut
=
mongoose
.
model
(
'AgrMatInOut'
,
AgrMaterialInOutSchema
,
'letianAgrMat
erial
InOut'
);
module
.
exports
=
AgrMatInOut
;
\ No newline at end of file
module/agrMatModule.js
0 → 100644
View file @
c513d055
const
mongoose
=
require
(
'mongoose'
);
const
_
=
require
(
'lodash'
);
async
function
saveMatAppr
({
_id
,
materials
,
type
},
user
)
{
}
module
.
exports
=
{
saveMatAppr
}
\ No newline at end of file
router/agrRouter.js
View file @
c513d055
...
...
@@ -15,6 +15,7 @@ router.post('/input/list', agrInputRecordController.list);
*/
router
.
post
(
'/mat/approval/list'
,
agrMatController
.
queryMatApprList
);
//获取农资审批记录列表
router
.
post
(
'/mat/approval/save'
,
agrMatController
.
saveMatAppr
);
//获取农资审批记录列表
router
.
post
(
'/mat/approval/delete'
,
agrMatController
.
deleteMatAppr
);
//获取农资审批记录列表
...
...
server.js
View file @
c513d055
...
...
@@ -53,7 +53,7 @@ app.use(function(req, res, next) {
// error handler
app
.
use
(
function
(
err
,
req
,
res
,
next
)
{
console
.
log
(
err
)
console
.
log
(
err
.
code
,
err
.
status
)
// 记录下错误日志
requestLogModule
.
createRequestLog
({
url
:
req
.
path
,
...
...
@@ -63,10 +63,13 @@ app.use(function (err, req, res, next) {
...
req
.
params
,
}),
user
:
req
.
user
,
status
:
err
.
status
||
500
,
status
:
err
.
status
||
err
.
code
||
500
,
msg
:
err
.
message
||
'server error'
});
return
res
.
status
(
err
.
status
||
500
).
send
({
code
:
err
.
status
||
500
,
msg
:
err
.
message
||
'server error'
});
if
(
err
.
code
&&
err
.
message
)
{
return
res
.
sendError
(
err
);
}
return
res
.
status
(
err
.
status
||
500
).
send
({
code
:
err
.
status
||
500
,
msg
:
err
.
message
||
'server error'
});
});
...
...
utils/errorMessage.js
View file @
c513d055
...
...
@@ -11,6 +11,14 @@ module.exports = {
code
:
40003
,
message
:
"名称重复"
},
agrMatDuplicated
:
{
code
:
40004
,
message
:
"入库物品种类重复,请检查!"
},
agrMatHaveFlow
:
{
code
:
40005
,
message
:
"入库物品种类重复,请检查!"
},
databaseQueryError
:
{
...
...
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