明树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
8d39aace
Commit
8d39aace
authored
Dec 23, 2024
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:溯源码
parent
5371570d
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
161 additions
and
0 deletions
+161
-0
productTracController.js
controller/productTracController.js
+94
-0
index.js
db/index.js
+2
-0
letianProTraceCode.js
db/models/letianProTraceCode.js
+57
-0
plantRouter.js
router/plantRouter.js
+8
-0
No files found.
controller/productTracController.js
0 → 100644
View file @
8d39aace
const
_
=
require
(
'lodash'
);
const
moment
=
require
(
'moment'
);
const
errorMessage
=
require
(
'../utils/errorMessage'
);
async
function
createTraceCode
(
req
,
res
,
next
)
{
try
{
//
const
body
=
req
.
body
;
body
.
creator
=
req
.
user
.
_id
;
let
ret
=
await
DB
.
ProTraceCode
.
create
(
body
);
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
listTraceCode
(
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
.
type
)
{
search
.
type
=
req
.
body
.
type
;
}
if
(
req
.
body
.
batchNumber
)
{
search
.
batchNumber
=
{
$regex
:
req
.
body
.
batchNumber
}
}
const
count
=
await
DB
.
ProTraceCode
.
countDocuments
(
search
);
let
list
=
await
DB
.
ProTraceCode
.
find
(
search
).
sort
({
_id
:
-
1
}).
skip
(
skip
).
limit
(
pageSize
);
res
.
sendData
({
count
,
list
});
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
deleteTraceCode
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
_id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
let
ret
=
await
DB
.
ProTraceCode
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
{
del
:
1
});
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
updateTraceCode
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
_id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
let
upInfo
=
{
...
req
.
body
,
_id
:
undefined
,
}
let
ret
=
await
DB
.
ProTraceCode
.
findOneAndUpdate
({
_id
:
req
.
body
.
_id
},
upInfo
);
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
async
function
getTraceCode
(
req
,
res
,
next
)
{
try
{
if
(
!
req
.
body
.
_id
)
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
let
traccode
=
await
DB
.
ProTraceCode
.
findOne
({
_id
:
req
.
body
.
_id
});
if
(
!
(
traccode
&&
traccode
.
_id
&&
traccode
.
source
))
{
return
res
.
sendError
(
errorMessage
.
resourceNotFound
);
}
let
sourceId
=
traccode
.
source
;
let
source
=
null
;
if
(
traccode
.
type
&&
traccode
.
type
==
1
)
{
source
=
await
DB
.
ProductPlant
.
findOne
({
_id
:
sourceId
}).
populate
({
path
:
"productPhotos"
}).
populate
({
path
:
"plantPlan"
}).
populate
({
path
:
"plantPlan.land"
});
}
else
if
(
traccode
.
type
&&
traccode
.
type
==
2
)
{
source
=
await
DB
.
ProductPre
.
findOne
({
_id
:
sourceId
});
}
else
if
(
traccode
.
type
&&
traccode
.
type
==
3
)
{
source
=
await
DB
.
ProductDeep
.
findOne
({
_id
:
sourceId
});
}
traccode
.
source
=
source
&&
sourceId
;
res
.
sendData
(
ret
);
}
catch
(
error
)
{
next
(
error
);
}
}
module
.
exports
=
{
createTraceCode
,
listTraceCode
,
deleteTraceCode
,
updateTraceCode
,
getTraceCode
,
}
\ No newline at end of file
db/index.js
View file @
8d39aace
...
...
@@ -56,6 +56,7 @@ const PlantPlan = require('./models/letianPlantPlan');
const
ProductPlant
=
require
(
'./models/letianProductPlant'
);
const
ProductPre
=
require
(
'./models/letianProductPre'
);
const
ProductDeep
=
require
(
'./models/letianProductDeep'
);
const
ProTraceCode
=
require
(
'./models/letianProTraceCode'
);
const
Device
=
require
(
'./models/collectDevice'
);
const
CollectSMC
=
require
(
'./models/collectSMC'
);
//土壤
...
...
@@ -103,6 +104,7 @@ global.DB = {
ProductPlant
,
ProductPre
,
ProductDeep
,
ProTraceCode
,
Device
,
CollectThreshold
,
...
...
db/models/letianProTraceCode.js
0 → 100644
View file @
8d39aace
const
mongoose
=
require
(
'mongoose'
);
const
Schema
=
mongoose
.
Schema
;
const
moment
=
require
(
'moment'
);
/**
* 溯源码
*/
const
letianProTraceCodeSchema
=
new
Schema
({
batchNumber
:
{
type
:
String
,
comment
:
"批次号"
},
manufactureDate
:
{
type
:
Date
,
default
:
Date
.
now
,
get
:
v
=>
moment
(
v
).
format
(
"YYYY-MM-DD HH:mm:ss"
),
comment
:
"生产日期"
},
type
:
{
type
:
Number
,
comment
:
"1 种植 2 轻加工 3 深加工"
},
source
:
{
type
:
mongoose
.
Types
.
ObjectId
,
comment
:
"源头productPre productDeep prodectPlant 三个"
},
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
,
comment
:
'默认0 , 1:表示删除,若有其他隐藏业务 不要混用此字段。'
}
},
{
toJSON
:
{
getters
:
true
}
});
const
ProTraceCode
=
mongoose
.
model
(
'ProTraceCode'
,
letianProTraceCodeSchema
,
'letianProTraceCode'
);
module
.
exports
=
ProTraceCode
;
\ No newline at end of file
router/plantRouter.js
View file @
8d39aace
...
...
@@ -6,6 +6,7 @@ const plantContoller = require('../controller/plantContoller.js');
const
productDirPlantController
=
require
(
'../controller/productDirPlantController.js'
);
const
productPreController
=
require
(
'../controller/productPreController.js'
);
const
productDeepController
=
require
(
'../controller/productDeepController.js'
);
const
productTracController
=
require
(
'../controller/productTracController.js'
);
// 生长周期
router
.
post
(
'/cycle/create'
,
plantContoller
.
createPlantCycle
);
...
...
@@ -39,4 +40,11 @@ router.post('/product/deep/list', productDeepController.listDeepPlant);
router
.
post
(
'/product/deep/delete'
,
productDeepController
.
deleteDeepPlant
);
router
.
post
(
'/product/deep/update'
,
productDeepController
.
updateDeepPlant
);
//溯源码
router
.
post
(
'/product/trace/create'
,
productTracController
.
createTraceCode
);
router
.
post
(
'/product/trace/list'
,
productTracController
.
listTraceCode
);
router
.
post
(
'/product/trace/delete'
,
productTracController
.
deleteTraceCode
);
router
.
post
(
'/product/trace/update'
,
productTracController
.
updateTraceCode
);
router
.
post
(
'/product/trace/info'
,
productTracController
.
getTraceCode
);
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