明树Git Lab

Commit cd3d8a75 authored by zfp1's avatar zfp1

update

parent 0b9cdcf3
...@@ -5,11 +5,11 @@ async function createDeepPlant(req, res, next) { ...@@ -5,11 +5,11 @@ async function createDeepPlant(req, res, next) {
const body = req.body; const body = req.body;
let count = await DB.ProductDeep.countDocuments(); //没有真实删除 永远递增 let count = await DB.ProductDeep.countDocuments(); //没有真实删除 永远递增
body.productNumber = count; body.productNumber = count;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o}); // body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o}); // body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o}); body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o}); body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o}); // body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let ret = await DB.ProductDeep.create(body); let ret = await DB.ProductDeep.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -26,7 +26,7 @@ async function listDeepPlant(req, res, next) { ...@@ -26,7 +26,7 @@ async function listDeepPlant(req, res, next) {
search.preProductName = {$regex: req.body.name} search.preProductName = {$regex: req.body.name}
} }
const count = await DB.ProductDeep.countDocuments(search); const count = await DB.ProductDeep.countDocuments(search);
let list = await DB.ProductDeep.find(search).populate({path: "productPhotos2"}).populate({path: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "pesticidetImgs"}).populate({path: "homepageCarouselImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec(); let list = await DB.ProductDeep.find(search).populate({path: "productPhotos2"}).populate({path: "homepageCarouselImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error); next(error);
...@@ -49,11 +49,11 @@ async function updateDeepPlant(req, res, next) { ...@@ -49,11 +49,11 @@ async function updateDeepPlant(req, res, next) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let body = req.body; let body = req.body;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o}); // body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o}); // body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o}); body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o}); body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o}); // body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let upInfo = { let upInfo = {
...body, ...body,
_id: undefined, _id: undefined,
......
...@@ -5,11 +5,11 @@ async function createDirectPlant(req, res, next) { ...@@ -5,11 +5,11 @@ async function createDirectPlant(req, res, next) {
const body = req.body; const body = req.body;
let count = await DB.ProductPlant.countDocuments(); //没有真实删除 永远递增 let count = await DB.ProductPlant.countDocuments(); //没有真实删除 永远递增
body.productNumber = count; body.productNumber = count;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o}); // body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o}); // body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o});
// body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o}); body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o}); body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let ret = await DB.ProductPlant.create(body); let ret = await DB.ProductPlant.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -27,7 +27,7 @@ async function listDirectPlant(req, res, next) { ...@@ -27,7 +27,7 @@ async function listDirectPlant(req, res, next) {
} }
const count = await DB.ProductPlant.countDocuments(search); const count = await DB.ProductPlant.countDocuments(search);
let list = await DB.ProductPlant.find(search).populate({path: "plantPlan"}).populate({path: "pesticidetImgs"}).populate({path: "homepageCarouselImgs"}).populate({path: "productPhotos2"}).populate({path: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec(); let list = await DB.ProductPlant.find(search).populate({path: "plantPlan"}).populate({path: "homepageCarouselImgs"}).populate({path: "productPhotos2"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error); next(error);
...@@ -50,11 +50,11 @@ async function updateDirectPlant(req, res, next) { ...@@ -50,11 +50,11 @@ async function updateDirectPlant(req, res, next) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let body = req.body; let body = req.body;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o}); // body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o}); // body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o});
// body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o}); body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o}); body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let upInfo = { let upInfo = {
...body, ...body,
_id: undefined, _id: undefined,
......
...@@ -6,9 +6,9 @@ async function createPrePlant(req, res, next) { ...@@ -6,9 +6,9 @@ async function createPrePlant(req, res, next) {
const body = req.body; const body = req.body;
let count = await DB.ProductPre.countDocuments(); //没有真实删除 永远递增 let count = await DB.ProductPre.countDocuments(); //没有真实删除 永远递增
body.productNumber = count; body.productNumber = count;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o}); // body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o}); // body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o}); // body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o}); body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o}); body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
let ret = await DB.ProductPre.create(body); let ret = await DB.ProductPre.create(body);
...@@ -27,7 +27,7 @@ async function listPrePlant(req, res, next) { ...@@ -27,7 +27,7 @@ async function listPrePlant(req, res, next) {
search.preProductName = {$regex: req.body.name} search.preProductName = {$regex: req.body.name}
} }
const count = await DB.ProductPre.countDocuments(search); const count = await DB.ProductPre.countDocuments(search);
let list = await DB.ProductPre.find(search).populate({path: "productPhotos2"}).populate({path: "sourcePlantProduct"}).populate({path: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "pesticidetImgs"}).populate({path: "homepageCarouselImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec(); let list = await DB.ProductPre.find(search).populate({path: "productPhotos2"}).populate({path: "sourcePlantProduct"}).populate({path: "homepageCarouselImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error); next(error);
...@@ -50,9 +50,9 @@ async function updatePrePlant(req, res, next) { ...@@ -50,9 +50,9 @@ async function updatePrePlant(req, res, next) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let body = req.body; let body = req.body;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o}); // body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o}); // body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o}); // body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o}); body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o}); body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
let upInfo = { let upInfo = {
......
...@@ -14,6 +14,9 @@ async function createTraceCode(req, res, next) { ...@@ -14,6 +14,9 @@ async function createTraceCode(req, res, next) {
tcodeend = utils.generateRandomCode(4); tcodeend = utils.generateRandomCode(4);
body.tcodepre = tcodepre; body.tcodepre = tcodepre;
body.tcodeend = tcodeend; body.tcodeend = tcodeend;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => { return o && o._id || o });
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => { return o && o._id || o });
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => { return o && o._id || o });
let ret = await DB.ProTraceCode.create(body); let ret = await DB.ProTraceCode.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -33,7 +36,7 @@ async function listTraceCode(req, res, next) { ...@@ -33,7 +36,7 @@ async function listTraceCode(req, res, next) {
search.batchNumber = { $regex: req.body.batchNumber } search.batchNumber = { $regex: req.body.batchNumber }
} }
const count = await DB.ProTraceCode.countDocuments(search); const count = await DB.ProTraceCode.countDocuments(search);
let list = await DB.ProTraceCode.find(search).sort({ _id: -1 }).skip(skip).limit(pageSize).populate({path: "rawMatCul.proSteps.img"}).populate({path: "proProcess.proSteps.img"}).populate({path: "cjVideo"}).lean(); let list = await DB.ProTraceCode.find(search).sort({ _id: -1 }).skip(skip).limit(pageSize).populate({ path: "rawMatCul.proSteps.img" }).populate({ path: "proProcess.proSteps.img" }).populate({ path: "cjVideo" }).populate({path: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "pesticidetImgs"}).lean();
let ret = []; let ret = [];
for (let index = 0; index < list.length; index++) { for (let index = 0; index < list.length; index++) {
const element = list[index]; const element = list[index];
...@@ -67,8 +70,12 @@ async function updateTraceCode(req, res, next) { ...@@ -67,8 +70,12 @@ async function updateTraceCode(req, res, next) {
if (!req.body._id) { if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let body = req.body;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => { return o && o._id || o });
body.flourMerchantImgs = (body.flourMerchantImgs || []).map(o => { return o && o._id || o });
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => { return o && o._id || o });
let upInfo = { let upInfo = {
...req.body, ...body,
_id: undefined, _id: undefined,
} }
let ret = await DB.ProTraceCode.findOneAndUpdate({ _id: req.body._id }, upInfo); let ret = await DB.ProTraceCode.findOneAndUpdate({ _id: req.body._id }, upInfo);
...@@ -78,46 +85,46 @@ async function updateTraceCode(req, res, next) { ...@@ -78,46 +85,46 @@ async function updateTraceCode(req, res, next) {
} }
} }
async function getTraceCode(req, res, next) { async function getTraceCode(req, res, next) {
try { // try {
if (!req.body._id) { // if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); // return res.sendError(errorMessage.resourceNotFound);
} // }
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }).lean(); // let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }).lean();
if (!(traccode && traccode._id && traccode.source)) { // if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound); // return res.sendError(errorMessage.resourceNotFound);
} // }
let sourceId = traccode.source; // let sourceId = traccode.source;
let source = null; // let source = null;
if (traccode.type && traccode.type == 1) { // if (traccode.type && traccode.type == 1) {
source = await DB.ProductPlant.findOne({ _id: sourceId }).populate({ path: "productPhotos" }).populate({ path: "plantPlan" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).populate({ path: "monitorInfo.device" }).lean().exec(); // source = await DB.ProductPlant.findOne({ _id: sourceId }).populate({ path: "productPhotos" }).populate({ path: "plantPlan" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).populate({ path: "monitorInfo.device" }).lean().exec();
if (source && source.plantPlan && source.plantPlan.land) { // if (source && source.plantPlan && source.plantPlan.land) {
let devices = await DB.Device.find({ land: { $in: source.plantPlan.land }, deviceHQType: 5 }).lean(); // let devices = await DB.Device.find({ land: { $in: source.plantPlan.land }, deviceHQType: 5 }).lean();
source.devices = devices; // source.devices = devices;
} else { // } else {
source.devices = []; // source.devices = [];
} // }
} else if (traccode.type && traccode.type == 2) { // } else if (traccode.type && traccode.type == 2) {
source = await DB.ProductPre.findOne({ _id: sourceId }).populate({ path: "productPhotos" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).populate({ path: "monitorInfo.device" }).lean().exec(); // source = await DB.ProductPre.findOne({ _id: sourceId }).populate({ path: "productPhotos" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).populate({ path: "monitorInfo.device" }).lean().exec();
} else if (traccode.type && traccode.type == 3) { // } else if (traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({ _id: sourceId }).populate({ path: "productPhotos" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).populate({ path: "monitorInfo.device" }).lean().exec(); // source = await DB.ProductDeep.findOne({ _id: sourceId }).populate({ path: "productPhotos" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).populate({ path: "monitorInfo.device" }).lean().exec();
} // }
console.log(source, "==") // console.log(source, "==")
traccode.source = source; // traccode.source = source;
//请求公司信息 // //请求公司信息
let companyInfo = await DB.CompanyInfo.findOne({}).populate({ path: "companyInfoImgs" }).populate({ path: "addressInfo.img" }).lean().exec(); // let companyInfo = await DB.CompanyInfo.findOne({}).populate({ path: "companyInfoImgs" }).populate({ path: "addressInfo.img" }).lean().exec();
traccode.companyInfo = companyInfo || {}; // traccode.companyInfo = companyInfo || {};
res.sendData(traccode); // res.sendData(traccode);
} catch (error) { // } catch (error) {
next(error); // next(error);
} // }
} }
async function getTraceCode2(req, res, next) { async function getTraceCode2(req, res, next) {
try { try {
if (!req.body._id) { if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { workshop:1, manufactureDate:1, type: 1, source: 1,batchNumber:1, tcodepre: 1, tcodeend: 1, productSalUrl: 1,queryNum: 1, firstQueryTime: 1, _id: 1 }).lean(); let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { workshop: 1, manufactureDate: 1, type: 1, source: 1, batchNumber: 1, tcodepre: 1, tcodeend: 1, productSalUrl: 1, queryNum: 1, firstQueryTime: 1, _id: 1 }).lean();
if (!(traccode && traccode._id && traccode.source)) { if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
...@@ -151,7 +158,7 @@ async function getsuyuanBase(req, res, next) { ...@@ -151,7 +158,7 @@ async function getsuyuanBase(req, res, next) {
if (!req.body._id) { if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1, batchNumber:1,manufactureDate:1 ,rawMatCul: 1, proProcess: 1 }).populate({ path: "proProcess.proSteps.img" }).populate({ path: "rawMatCul.proSteps.img" }).lean(); let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1, batchNumber: 1, manufactureDate: 1, rawMatCul: 1, proProcess: 1 }).populate({ path: "proProcess.proSteps.img" }).populate({ path: "rawMatCul.proSteps.img" }).lean();
if (!(traccode && traccode._id && traccode.source)) { if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
...@@ -161,9 +168,9 @@ async function getsuyuanBase(req, res, next) { ...@@ -161,9 +168,9 @@ async function getsuyuanBase(req, res, next) {
if (traccode.type && traccode.type == 1) { if (traccode.type && traccode.type == 1) {
source = await DB.ProductPlant.findOne({ _id: sourceId }, { productName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, sellByDateUnit: 1, productPhotos2: 1 }).populate({ path: "productPhotos2" }).populate({ path: "homepageCarouselImgs" }).lean(); source = await DB.ProductPlant.findOne({ _id: sourceId }, { productName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, sellByDateUnit: 1, productPhotos2: 1 }).populate({ path: "productPhotos2" }).populate({ path: "homepageCarouselImgs" }).lean();
} else if (traccode.type && traccode.type == 2) { } else if (traccode.type && traccode.type == 2) {
source = await DB.ProductPre.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, sellByDateUnit: 1,productPhotos2: 1 }).populate({ path: "productPhotos2" }).populate({ path: "homepageCarouselImgs" }).lean(); source = await DB.ProductPre.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, sellByDateUnit: 1, productPhotos2: 1 }).populate({ path: "productPhotos2" }).populate({ path: "homepageCarouselImgs" }).lean();
} else if (traccode.type && traccode.type == 3) { } else if (traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, sellByDateUnit: 1,productPhotos2: 1 }).populate({ path: "productPhotos2" }).populate({ path: "homepageCarouselImgs" }).lean(); source = await DB.ProductDeep.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, sellByDateUnit: 1, productPhotos2: 1 }).populate({ path: "productPhotos2" }).populate({ path: "homepageCarouselImgs" }).lean();
} }
source.manufactureDate = traccode.manufactureDate || source.manufactureDate; source.manufactureDate = traccode.manufactureDate || source.manufactureDate;
source.batchNumber = traccode.batchNumber || source.batchNumber; source.batchNumber = traccode.batchNumber || source.batchNumber;
...@@ -178,7 +185,7 @@ async function getJiankong(req, res, next) { ...@@ -178,7 +185,7 @@ async function getJiankong(req, res, next) {
if (!req.body._id) { if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1, cjVideo: 1, agrOnOff: 1, indEnvOnOff: 1 }).populate({path: "cjVideo"}).lean(); let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1, cjVideo: 1, agrOnOff: 1, indEnvOnOff: 1 }).populate({ path: "cjVideo" }).lean();
if (!(traccode && traccode._id && traccode.source)) { if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
...@@ -186,18 +193,18 @@ async function getJiankong(req, res, next) { ...@@ -186,18 +193,18 @@ async function getJiankong(req, res, next) {
console.log(sourceId, "===") console.log(sourceId, "===")
let source = null; let source = null;
if (traccode.type && traccode.type == 1) { if (traccode.type && traccode.type == 1) {
source = await DB.ProductPlant.findOne({ _id: sourceId }, { monitorInfo: 1 ,monitorInfoForInt:1}).populate({ path: "monitorInfo.device" }).populate({ path: "monitorInfoForInt.device" }).lean(); source = await DB.ProductPlant.findOne({ _id: sourceId }, { monitorInfo: 1, monitorInfoForInt: 1 }).populate({ path: "monitorInfo.device" }).populate({ path: "monitorInfoForInt.device" }).lean();
} else if (traccode.type && traccode.type == 2) { } else if (traccode.type && traccode.type == 2) {
source = await DB.ProductPre.findOne({ _id: sourceId }, { monitorInfo: 1 ,monitorInfoForInt:1}).populate({ path: "monitorInfo.device" }).populate({ path: "monitorInfoForInt.device" }).lean(); source = await DB.ProductPre.findOne({ _id: sourceId }, { monitorInfo: 1, monitorInfoForInt: 1 }).populate({ path: "monitorInfo.device" }).populate({ path: "monitorInfoForInt.device" }).lean();
} else if (traccode.type && traccode.type == 3) { } else if (traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({ _id: sourceId }, { monitorInfo: 1 ,monitorInfoForInt:1}).populate({ path: "monitorInfo.device" }).populate({ path: "monitorInfoForInt.device" }).lean(); source = await DB.ProductDeep.findOne({ _id: sourceId }, { monitorInfo: 1, monitorInfoForInt: 1 }).populate({ path: "monitorInfo.device" }).populate({ path: "monitorInfoForInt.device" }).lean();
} }
//查询一下土壤采集数据 //查询一下土壤采集数据
if (traccode.agrOnOff) { if (traccode.agrOnOff) {
// 气象 土壤 // 气象 土壤
let ws = await DB.CollectWS.findOne().sort({time:-1}).lean(); let ws = await DB.CollectWS.findOne().sort({ time: -1 }).lean();
let smc = await DB.CollectSMC.findOne().sort({time:-1}).lean(); let smc = await DB.CollectSMC.findOne().sort({ time: -1 }).lean();
// //
let onlineArr = await deviceModule.getDeviceOnlineMap(); let onlineArr = await deviceModule.getDeviceOnlineMap();
smc.onLineState = onlineArr.includes(smc.deviceNumber) ? "1" : "0"; smc.onLineState = onlineArr.includes(smc.deviceNumber) ? "1" : "0";
...@@ -210,7 +217,7 @@ async function getJiankong(req, res, next) { ...@@ -210,7 +217,7 @@ async function getJiankong(req, res, next) {
// 工业环境 // 工业环境
} }
let companyInfo = await DB.CompanyInfo.findOne({}, {gcImg: 1, jdImg:1}).populate({ path: "gcImg" }).populate({ path: "jdImg" }); let companyInfo = await DB.CompanyInfo.findOne({}, { gcImg: 1, jdImg: 1 }).populate({ path: "gcImg" }).populate({ path: "jdImg" });
traccode.gcImg = companyInfo.gcImg; traccode.gcImg = companyInfo.gcImg;
traccode.jdImg = companyInfo.jdImg; traccode.jdImg = companyInfo.jdImg;
traccode.source = source; traccode.source = source;
...@@ -224,21 +231,10 @@ async function getZhijian(req, res, next) { ...@@ -224,21 +231,10 @@ async function getZhijian(req, res, next) {
if (!req.body._id) { if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1 }).lean(); let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1 , pesticidetImgs: 1, qualityInsReportImgs: 1, flourMerchantImgs: 1}).lean();
if (!(traccode && traccode._id && traccode.source)) { if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound); 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 }, { pesticidetImgs: 1, qualityInsReportImgs: 1, flourMerchantImgs: 1 }).populate({ path: "pesticidetImgs" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).lean();
} else if (traccode.type && traccode.type == 2) {
source = await DB.ProductPre.findOne({ _id: sourceId }, { pesticidetImgs: 1, qualityInsReportImgs: 1, flourMerchantImgs: 1 }).populate({ path: "pesticidetImgs" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).lean();
} else if (traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({ _id: sourceId }, { pesticidetImgs: 1, qualityInsReportImgs: 1, flourMerchantImgs: 1 }).populate({ path: "pesticidetImgs" }).populate({ path: "qualityInsReportImgs" }).populate({ path: "flourMerchantImgs" }).lean();
}
traccode.source = source;
res.sendData(traccode); res.sendData(traccode);
} catch (error) { } catch (error) {
next(error); next(error);
...@@ -248,14 +244,14 @@ async function batchAgrEnvOnOff(req, res, next) { ...@@ -248,14 +244,14 @@ async function batchAgrEnvOnOff(req, res, next) {
try { try {
let ids = req.body._ids; let ids = req.body._ids;
let search = {} let search = {}
if(ids && _.isArray(ids) && ids.length) { if (ids && _.isArray(ids) && ids.length) {
search = {_id: {$in: ids}} search = { _id: { $in: ids } }
} }
if(_.isBoolean(req.body.agrOnOff)) { if (_.isBoolean(req.body.agrOnOff)) {
await DB.ProTraceCode.updateMany(search, {agrOnOff: req.body.agrOnOff}); await DB.ProTraceCode.updateMany(search, { agrOnOff: req.body.agrOnOff });
} }
if(_.isBoolean(req.body.indEnvOnOff)) { if (_.isBoolean(req.body.indEnvOnOff)) {
await DB.ProTraceCode.updateMany(search, {indEnvOnOff: req.body.indEnvOnOff}); await DB.ProTraceCode.updateMany(search, { indEnvOnOff: req.body.indEnvOnOff });
} }
res.sendData(); res.sendData();
} catch (error) { } catch (error) {
......
...@@ -99,6 +99,28 @@ const letianProTraceCodeSchema = new Schema({ ...@@ -99,6 +99,28 @@ const letianProTraceCodeSchema = new Schema({
type: Boolean, type: Boolean,
}, },
flourMerchantImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "面粉商原料检测报告图"
}
],
qualityInsReportImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "质检报告图"
}
],
pesticidetImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "农残质检报告"
}
],
creator: { creator: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: 'User', ref: 'User',
......
...@@ -43,13 +43,6 @@ const letianProductDeepSchema = new Schema({ ...@@ -43,13 +43,6 @@ const letianProductDeepSchema = new Schema({
comment: "产品详情轮播图" comment: "产品详情轮播图"
} }
], ],
pesticidetImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "农残质检报告"
}
],
sellByDate: { sellByDate: {
type: String, type: String,
comment: "保质期" comment: "保质期"
...@@ -83,13 +76,6 @@ const letianProductDeepSchema = new Schema({ ...@@ -83,13 +76,6 @@ const letianProductDeepSchema = new Schema({
type: String, type: String,
comment: "产品编号" comment: "产品编号"
}, },
qualityInsReportImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "质检报告图"
}
],
monitorInfo: { monitorInfo: {
type: [ type: [
{ {
...@@ -164,14 +150,6 @@ const letianProductDeepSchema = new Schema({ ...@@ -164,14 +150,6 @@ const letianProductDeepSchema = new Schema({
get: v => moment(v).format("YYYY-MM-DD"), get: v => moment(v).format("YYYY-MM-DD"),
comment: "生产日期" comment: "生产日期"
}, },
flourMerchantImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "面粉商原料检测报告图"
}
],
createdAt: { createdAt: {
......
...@@ -70,20 +70,20 @@ const letianProductPlantSchema = new Schema({ ...@@ -70,20 +70,20 @@ const letianProductPlantSchema = new Schema({
type: Number, type: Number,
comment: "产品编号" comment: "产品编号"
}, },
qualityInsReportImgs: [ // qualityInsReportImgs: [
{ // {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
ref: 'File', // ref: 'File',
comment: "质检报告图" // comment: "质检报告图"
} // }
], // ],
pesticidetImgs: [ // pesticidetImgs: [
{ // {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
ref: 'File', // ref: 'File',
comment: "农残质检报告" // comment: "农残质检报告"
} // }
], // ],
monitorInfo: { monitorInfo: {
type: [ type: [
{ {
...@@ -145,13 +145,13 @@ const letianProductPlantSchema = new Schema({ ...@@ -145,13 +145,13 @@ const letianProductPlantSchema = new Schema({
get: v => moment(v).format("YYYY-MM-DD"), get: v => moment(v).format("YYYY-MM-DD"),
comment: "生产日期" comment: "生产日期"
}, },
flourMerchantImgs: [ // flourMerchantImgs: [
{ // {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
ref: 'File', // ref: 'File',
comment: "面粉商原料检测报告图" // comment: "面粉商原料检测报告图"
} // }
], // ],
createdAt: { createdAt: {
type: Date, type: Date,
......
...@@ -76,20 +76,20 @@ const letianProductPreSchema = new Schema({ ...@@ -76,20 +76,20 @@ const letianProductPreSchema = new Schema({
type: String, type: String,
comment: "产品编号" comment: "产品编号"
}, },
qualityInsReportImgs: [ // qualityInsReportImgs: [
{ // {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
ref: 'File', // ref: 'File',
comment: "质检报告图" // comment: "质检报告图"
} // }
], // ],
pesticidetImgs: [ // pesticidetImgs: [
{ // {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
ref: 'File', // ref: 'File',
comment: "农残质检报告" // comment: "农残质检报告"
} // }
], // ],
monitorInfo: { //农业 monitorInfo: { //农业
type: [ type: [
{ {
...@@ -152,13 +152,13 @@ const letianProductPreSchema = new Schema({ ...@@ -152,13 +152,13 @@ const letianProductPreSchema = new Schema({
get: v => moment(v).format("YYYY-MM-DD"), get: v => moment(v).format("YYYY-MM-DD"),
comment: "生产日期" comment: "生产日期"
}, },
flourMerchantImgs: [ // flourMerchantImgs: [
{ // {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
ref: 'File', // ref: 'File',
comment: "面粉商原料检测报告图" // comment: "面粉商原料检测报告图"
} // }
], // ],
createdAt: { createdAt: {
type: Date, type: Date,
......
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