明树Git Lab

Commit 197ccad1 authored by zengfanpei's avatar zengfanpei

update

parent 27254597
...@@ -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
...@@ -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: {
......
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`,
}]
};
...@@ -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: "POST", method: "GET",
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.data.length; pi++) { for (let pi = 0; pi < pData.length; pi++) {
const pir = preInRet.data[pi]; const pir = pData[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)
......
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};
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment