明树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
197ccad1
Commit
197ccad1
authored
Sep 04, 2024
by
zengfanpei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
27254597
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
167 additions
and
81 deletions
+167
-81
.gitignore
.gitignore
+1
-0
collectIPS.js
db/models/collectIPS.js
+3
-2
ecosystem.config.js
ecosystem.config.js
+18
-0
collectIPSModule.js
module/collectIPSModule.js
+137
-74
httpRequest.js
utils/httpRequest.js
+8
-5
No files found.
.gitignore
View file @
197ccad1
...
@@ -3,4 +3,5 @@ node_modules/
...
@@ -3,4 +3,5 @@ node_modules/
package-lock.json
package-lock.json
.vscode
.vscode
test/
test/
test.js
public/avatar
public/avatar
\ No newline at end of file
db/models/collectIPS.js
View file @
197ccad1
...
@@ -89,9 +89,10 @@ const collectInsectPestSituationSchema = new Schema({
...
@@ -89,9 +89,10 @@ const collectInsectPestSituationSchema = new Schema({
comment
:
"上一次标注后的图片(压缩后)"
,
comment
:
"上一次标注后的图片(压缩后)"
,
},
},
/*
图片识别结果
*/
/*
识别结果 不管哪一种形式,只要结果确认有效则写入,为空则表示此条数据无效,后续需要根据业务定期处理这类数据
*/
cameraRecognition
:
{
cameraRecognition
:
{
type
:
String
type
:
String
,
default
:
null
,
},
},
createdAt
:
{
createdAt
:
{
...
...
ecosystem.config.js
0 → 100644
View file @
197ccad1
let
curDate
=
new
Date
();
let
curDateStr
=
curDate
.
getFullYear
()
+
""
+
String
(
curDate
.
getMonth
()
+
1
).
padStart
(
2
,
'0'
)
+
""
+
curDate
.
getDate
();
module
.
exports
=
{
apps
:
[{
name
:
"letian"
,
script
:
'server.js'
,
watch
:
true
,
ignore_watch
:
[
'node_modules'
,
'logs'
],
env_dev
:
{
NODE_ENV
:
"dev"
},
log_date_format
:
"YYYY-MM-DD HH:mm:ss"
,
out_file
:
`logs/
${
curDateStr
}
.log`
,
error_file
:
`logs/
${
curDateStr
}
.log`
,
}]
};
module/collectIPSModule.js
View file @
197ccad1
...
@@ -40,31 +40,90 @@ async function insertHQData(data) {
...
@@ -40,31 +40,90 @@ async function insertHQData(data) {
}
}
}
}
/**
* 复杂版本 直接上传图片 获取结果
* @param {*} data
*/
// async function handleIPSResult(data) {
// try {
// const url = sysConfig.device.getInsectNewCollectionResult;
// const token = sysConfig.device.token;
// const userName = sysConfig.device.userName;
// // 1. 上传结果照片 获取结果
// let formData = new FormData();
// let imgUrl = sysConfig.device.fileBaseUrl + data.downloadUrl;
// formData.append('token', token);
// formData.append('userName', userName);
// formData.append('deviceNumber', data.deviceNumber);
// let imgStream = await httpRequest({ url: imgUrl, method: 'GET', responseType: "stream" });
// console.log(imgStream)
// if (imgStream.status) {
// formData.append('img', imgStream.data);
// const result = await httpRequest({
// url,
// method: "POST",
// headers: { "Content-Type": "mutipart/form-data" },
// data: formData
// });
// if (result.status) {
// // 需要处理一张识别的种类表 获取其对应的方案 成功
// // await DB.CollectIPS.updateOne({_id: data._id}, {cameraRecognition});
// let retData = result.data && result.data.data || "";
// let retArr = retData && retData.results.split(',') || [];
// for (let index = 0; index < retArr.length; index++) {
// const element = retArr[index];
// let eleArr = element.split(':');
// let name = String(eleArr[0]).trim();
// // 记录虫子类型
// let bugType = await DB.CollectIPSType.findOneAndUpdate({ name }, { name }, { upsert: true });
// //获取防止建议---此处建议不从远端取,在本系统根据虫子种类维护建议即可
// let preInRet = await httpRequest({
// url: sysConfig.device.getPreventionToInsectName,
// method: "GET",
// params: { token, userName, name },
// });
// let plan;
// if (preInRet && preInRet.status) {
// let pData = preInRet.data && preInRet.data.data || [];
// for (let pi = 0; pi < pData.length; pi++) {
// const pir = pData[pi];
// plan = await DB.CollectIPSPlan.findOneAndUpdate({ name }, pir, { upsert: true });
// }
// }
// // 记录识别的每一次识别的 虫子 的种类 和 数量
// // 此处暂时 每一次单独记录 不是对每一天做累加
// await DB.CollectIPSResult.create({
// deviceNumber: data.deviceNumber,
// name,
// // $inc: {count: 11},
// count: element.newCount,
// time: data.time || data.newTime,
// type: bugType && bugType._id,
// plan: plan && plan._id,
// data: data._id,
// });
// }
// await DB.CollectIPS.updateOne({ _id: data._id }, { cameraRecognition: JSON.stringify(result) });
// }
// }
// } catch (error) {
// console.log(error)
// }
// }
/**
* 直接利用硬件的信息结果
* @param {*} data
*/
async
function
handleIPSResult
(
data
)
{
async
function
handleIPSResult
(
data
)
{
try
{
try
{
const
url
=
sysConfig
.
device
.
getInsectNewCollectionResult
;
const
url
=
sysConfig
.
device
.
getInsectNewCollectionResult
;
const
token
=
sysConfig
.
device
.
token
;
const
token
=
sysConfig
.
device
.
token
;
const
userName
=
sysConfig
.
device
.
userName
;
const
userName
=
sysConfig
.
device
.
userName
;
// 1. 上传结果照片 获取结果
if
(
data
.
results
!=
"数据提取成功"
&&
data
.
results
.
includes
(
":"
))
{
let
formData
=
new
FormData
();
let
retArr
=
data
.
results
.
split
(
','
)
||
[];
let
imgUrl
=
sysConfig
.
device
.
fileBaseUrl
+
data
.
downloadUrl
;
formData
.
append
(
'token'
,
token
);
formData
.
append
(
'userName'
,
userName
);
formData
.
append
(
'deviceNumber'
,
data
.
deviceNumber
);
let
imgStream
=
await
httpRequest
({
url
:
imgUrl
,
method
:
'GET'
,
responseType
:
"stream"
});
if
(
imgStream
.
status
)
{
formData
.
append
(
'img'
,
imgStream
);
const
result
=
await
httpRequest
({
url
,
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"mutipart/form-data"
},
data
:
formData
});
if
(
result
.
status
)
{
// 需要处理一张识别的种类表 获取其对应的方案 成功
// await DB.CollectIPS.updateOne({_id: data._id}, {cameraRecognition});
let
retData
=
result
.
data
;
let
retArr
=
retData
.
split
(
','
);
for
(
let
index
=
0
;
index
<
retArr
.
length
;
index
++
)
{
for
(
let
index
=
0
;
index
<
retArr
.
length
;
index
++
)
{
const
element
=
retArr
[
index
];
const
element
=
retArr
[
index
];
let
eleArr
=
element
.
split
(
':'
);
let
eleArr
=
element
.
split
(
':'
);
...
@@ -74,14 +133,15 @@ async function handleIPSResult(data) {
...
@@ -74,14 +133,15 @@ async function handleIPSResult(data) {
//获取防止建议---此处建议不从远端取,在本系统根据虫子种类维护建议即可
//获取防止建议---此处建议不从远端取,在本系统根据虫子种类维护建议即可
let
preInRet
=
await
httpRequest
({
let
preInRet
=
await
httpRequest
({
url
:
sysConfig
.
device
.
getPreventionToInsectName
,
url
:
sysConfig
.
device
.
getPreventionToInsectName
,
method
:
"POS
T"
,
method
:
"GE
T"
,
data
:
{
token
,
userName
,
name
},
params
:
{
token
,
userName
,
name
},
});
});
console
.
log
(
"000"
,
preInRet
)
let
plan
;
let
plan
;
if
(
preInRet
&&
preInRet
.
status
)
{
if
(
preInRet
&&
preInRet
.
status
)
{
preInRet
.
data
=
preInRet
.
data
||
[];
let
pData
=
preInRet
.
data
&&
preInRet
.
data
.
data
||
[];
for
(
let
pi
=
0
;
pi
<
preInRet
.
d
ata
.
length
;
pi
++
)
{
for
(
let
pi
=
0
;
pi
<
pD
ata
.
length
;
pi
++
)
{
const
pir
=
preInRet
.
d
ata
[
pi
];
const
pir
=
pD
ata
[
pi
];
plan
=
await
DB
.
CollectIPSPlan
.
findOneAndUpdate
({
name
},
pir
,
{
upsert
:
true
});
plan
=
await
DB
.
CollectIPSPlan
.
findOneAndUpdate
({
name
},
pir
,
{
upsert
:
true
});
}
}
}
}
...
@@ -89,6 +149,7 @@ async function handleIPSResult(data) {
...
@@ -89,6 +149,7 @@ async function handleIPSResult(data) {
// 记录识别的每一次识别的 虫子 的种类 和 数量
// 记录识别的每一次识别的 虫子 的种类 和 数量
// 此处暂时 每一次单独记录 不是对每一天做累加
// 此处暂时 每一次单独记录 不是对每一天做累加
await
DB
.
CollectIPSResult
.
create
({
await
DB
.
CollectIPSResult
.
create
({
deviceNumber
:
data
.
deviceNumber
,
name
,
name
,
// $inc: {count: 11},
// $inc: {count: 11},
count
:
element
.
newCount
,
count
:
element
.
newCount
,
...
@@ -98,8 +159,9 @@ async function handleIPSResult(data) {
...
@@ -98,8 +159,9 @@ async function handleIPSResult(data) {
data
:
data
.
_id
,
data
:
data
.
_id
,
});
});
}
}
await
DB
.
CollectIPS
.
updateOne
({
_id
:
data
.
_id
},
{
cameraRecognition
:
data
.
results
});
}
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
)
console
.
log
(
error
)
}
}
...
@@ -107,29 +169,30 @@ async function handleIPSResult(data) {
...
@@ -107,29 +169,30 @@ async function handleIPSResult(data) {
setTimeout
(()
=>
{
// setTimeout(() => {
handleIPSResult
({
// handleIPSResult({
downloadUrl
:
'pictures/FF355138D5C3/2024-05-29-05-59-43.jpg'
,
// downloadUrl: 'pictures/FF355138D5C3/2024-05-29-05-59-43.jpg',
taggingImgUrl
:
'picturesResult/FF355138D5C3/2024-05-29-05-59-43.jpg'
,
// taggingImgUrl: 'picturesResult/FF355138D5C3/2024-05-29-05-59-43.jpg',
downloadUrlCompress
:
'picturesCompress/FF355138D5C3/orgin_2024-05-29-05-59-43.jpg'
,
// downloadUrlCompress: 'picturesCompress/FF355138D5C3/orgin_2024-05-29-05-59-43.jpg',
taggingImgUrlCompress
:
'picturesCompress/FF355138D5C3/result_2024-05-29-05-59-43.jpg'
,
// taggingImgUrlCompress: 'picturesCompress/FF355138D5C3/result_2024-05-29-05-59-43.jpg',
deviceNumber
:
'FF355138D5C3'
,
// deviceNumber: 'FF355138D5C3',
newTime
:
'2024-05-29 05:59:43'
,
// newTime: '2024-05-29 05:59:43',
results
:
'飞蛾:2'
,
// results: '飞蛾:2',
newCount
:
2
,
// newCount: 2,
typeCount
:
1
,
// typeCount: 1,
oldCount
:
0
,
// oldCount: 0,
oldTime
:
null
,
// oldTime: null,
oldResults
:
null
,
// oldResults: null,
oldTypeCount
:
0
,
// oldTypeCount: 0,
oldDownloadUrl
:
'pictures/FF355138D5C3/2024-05-29-05-59-43.jpg'
,
// oldDownloadUrl: 'pictures/FF355138D5C3/2024-05-29-05-59-43.jpg',
oldTaggingImgUrl
:
'picturesResult/FF355138D5C3/2024-05-29-05-59-43.jpg'
,
// oldTaggingImgUrl: 'picturesResult/FF355138D5C3/2024-05-29-05-59-43.jpg',
oldDownloadUrlCompress
:
null
,
// oldDownloadUrlCompress: null,
oldTaggingImgUrlCompress
:
'picturesCompress/FF355138D5C3/result_2024-05-29-05-59-43.jpg'
,
// oldTaggingImgUrlCompress: 'picturesCompress/FF355138D5C3/result_2024-05-29-05-59-43.jpg',
name
:
undefined
,
// name: undefined,
time
:
'2024-05-29 05:59:43'
// time: '2024-05-29 05:59:43',
})
// "_id": "66d6d20cdc4220c02affe05d"
},
5000
)
// })
// }, 5000)
...
...
utils/httpRequest.js
View file @
197ccad1
const
axios
=
require
(
'axios'
);
const
axios
=
require
(
'axios'
);
const
requestLogModule
=
require
(
"../module/requestLogModule"
);
const
requestLogModule
=
require
(
"../module/requestLogModule"
);
async
function
httpRequest
({
url
,
method
,
data
,
params
,
headers
,
responseType
})
{
async
function
httpRequest
({
url
,
method
,
data
,
params
,
headers
=
{},
responseType
})
{
console
.
log
(
`
${
url
}
,
${
JSON
.
stringify
(
data
)}
,
${
JSON
.
stringify
(
params
)}
`
)
try
{
try
{
let
opt
=
{
let
opt
=
{
url
,
url
,
...
@@ -18,11 +17,13 @@ async function httpRequest ({url, method, data, params, headers, responseType})
...
@@ -18,11 +17,13 @@ async function httpRequest ({url, method, data, params, headers, responseType})
requestLogModule
.
createRequestLog
({
requestLogModule
.
createRequestLog
({
url
,
url
,
method
,
method
,
params
:
JSON
.
stringify
(
params
)
+
JSON
.
stringify
(
data
),
params
:
JSON
.
stringify
(
params
)
+
JSON
.
stringify
(
(
headers
[
"Content-Type"
]
==
"mutipart/form-data"
?
""
:
data
)
),
headers
:
JSON
.
stringify
(
headers
),
headers
:
JSON
.
stringify
(
headers
),
type
:
"device"
,
type
:
"device"
,
status
:
ret
&&
ret
.
status
,
status
:
ret
&&
ret
.
status
,
result
:
JSON
.
stringify
(
ret
.
data
)
result
:
responseType
==
'stream'
?
""
:
JSON
.
stringify
(
ret
.
data
)
}).
catch
(
error
=>
{
console
.
log
(
error
);
});
});
if
(
ret
&&
ret
.
status
==
200
)
{
if
(
ret
&&
ret
.
status
==
200
)
{
...
@@ -36,10 +37,12 @@ async function httpRequest ({url, method, data, params, headers, responseType})
...
@@ -36,10 +37,12 @@ async function httpRequest ({url, method, data, params, headers, responseType})
requestLogModule
.
createRequestLog
({
requestLogModule
.
createRequestLog
({
url
,
url
,
method
,
method
,
params
:
JSON
.
stringify
(
params
)
+
JSON
.
stringify
(
data
),
params
:
JSON
.
stringify
(
params
)
+
JSON
.
stringify
(
(
headers
[
"Content-Type"
]
==
"mutipart/form-data"
?
""
:
data
)
),
headers
:
JSON
.
stringify
(
headers
),
headers
:
JSON
.
stringify
(
headers
),
type
:
"device"
,
type
:
"device"
,
msg
:
error
.
message
,
msg
:
error
.
message
,
}).
catch
(
error
=>
{
console
.
log
(
error
);
});
});
return
{
data
:
null
,
status
:
false
};
return
{
data
:
null
,
status
:
false
};
}
}
...
...
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