明树Git Lab

Commit 9377401a authored by zfp1's avatar zfp1

update

parent 258f71f6
......@@ -5,7 +5,7 @@
async function findCompInfo(req, res, next) {
try {
let ret = await DB.CompanyInfo.findOne({}).populate({path: "companyInfoImgs"}).populate({path: "addressInfo.img"}).lean().exec();
let ret = await DB.CompanyInfo.findOne({}).populate({path: "companyInfoImgs"}).populate({path: "qualiCertiImgs"}).populate({path: "addressInfo.img"}).lean().exec();
return res.sendData(ret);
} catch (error) {
next(error);
......@@ -16,6 +16,7 @@ async function updateCompInfo(req, res, next) {
try {
let body = req.body;
body.companyInfoImgs = (body.companyInfoImgs || []).map(o => {return o && o._id || o});
body.qualiCertiImgs = (body.qualiCertiImgs || []).map(o => {return o && o._id || o});
body.addressInfo = body.addressInfo || [];
let newAdr = [];
for (let index = 0; index < body.addressInfo.length; index++) {
......
......@@ -7,6 +7,9 @@ async function createDeepPlant(req, res, next) {
body.productNumber = count;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).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.homepageCarouselImgs = (body.homepageCarouselImgs || []).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);
res.sendData(ret);
} catch (error) {
......@@ -23,7 +26,7 @@ async function listDeepPlant(req, res, next) {
search.preProductName = {$regex: req.body.name}
}
const count = await DB.ProductDeep.countDocuments(search);
let list = await DB.ProductDeep.find(search).populate({path: "productPhotos"}).populate({path: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).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: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "pesticidetImgs"}).populate({path: "homepageCarouselImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error);
......@@ -45,6 +48,11 @@ async function updateDeepPlant(req, res, next) {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).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.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let upInfo = {
...req.body,
_id: undefined,
......
......@@ -7,6 +7,9 @@ async function createDirectPlant(req, res, next) {
body.productNumber = count;
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).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.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let ret = await DB.ProductPlant.create(body);
res.sendData(ret);
} catch (error) {
......@@ -24,7 +27,7 @@ async function listDirectPlant(req, res, next) {
}
const count = await DB.ProductPlant.countDocuments(search);
let list = await DB.ProductPlant.find(search).populate({path: "productPhotos"}).populate({path: "plantPlan"}).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: "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();
res.sendData({ count, list });
} catch (error) {
next(error);
......@@ -46,6 +49,11 @@ async function updateDirectPlant(req, res, next) {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
body.qualityInsReportImgs = (body.qualityInsReportImgs || []).map(o => {return o && o._id || o});
body.flourMerchantImgs = (body.flourMerchantImgs || []).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.pesticidetImgs = (body.pesticidetImgs || []).map(o => {return o && o._id || o});
let upInfo = {
...req.body,
_id: undefined,
......
......@@ -8,6 +8,9 @@ async function createPrePlant(req, res, next) {
body.productNumber = count;
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});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).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);
res.sendData(ret);
} catch (error) {
......@@ -24,7 +27,7 @@ async function listPrePlant(req, res, next) {
search.preProductName = {$regex: req.body.name}
}
const count = await DB.ProductPre.countDocuments(search);
let list = await DB.ProductPre.find(search).populate({path: "productPhotos"}).populate({path: "sourcePlantProduct"}).populate({path: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).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: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "pesticidetImgs"}).populate({path: "homepageCarouselImgs"}).populate({path: "monitorInfo.device"}).sort({_id: -1}).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error);
......@@ -46,6 +49,11 @@ async function updatePrePlant(req, res, next) {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
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});
body.homepageCarouselImgs = (body.homepageCarouselImgs || []).map(o => {return o && o._id || o});
body.productPhotos2 = (body.productPhotos2 || []).map(o => {return o && o._id || o});
let upInfo = {
...req.body,
_id: undefined,
......
......@@ -7,6 +7,25 @@ async function createTraceCode(req, res, next) {
//
const body = req.body;
body.creator = req.user._id;
// 生成溯源码:
let tcode = `271Y8U00${body.type || 1}`;
let batchNumber;
if (!body.batchNumber) {
let source;
if (body.source && body.type == 1) {
source = await DB.ProductPlant.findOne({ _id: body.source }).lean();
} else if (body.source && body.type == 2) {
source = await DB.ProductPre.findOne({ _id: body.source }).lean();
} else if (body.source && body.type == 3) {
source = await DB.ProductDeep.findOne({ _id: body.source }).lean();
}
batchNumber = source.batchNumber;
} else {
batchNumber = body.batchNumber;
}
tcode = tcode + batchNumber;
tcode = tcode + utils.generateRandomCode(4);
body.tcode = tcode;
let ret = await DB.ProTraceCode.create(body);
res.sendData(ret);
} catch (error) {
......@@ -19,23 +38,23 @@ async function listTraceCode(req, res, next) {
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
if(req.body.type) {
if (req.body.type) {
search.type = req.body.type;
}
if(req.body.batchNumber) {
search.batchNumber = {$regex: req.body.batchNumber}
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).lean();
let list = await DB.ProTraceCode.find(search).sort({ _id: -1 }).skip(skip).limit(pageSize).lean();
let ret = [];
for (let index = 0; index < list.length; index++) {
const element = list[index];
if(element.source && element.type == 1) {
element.source = await DB.ProductPlant.findOne({_id: element.source}).lean();
} else if(element.source && element.type == 2) {
element.source = await DB.ProductPre.findOne({_id: element.source}).lean();
if (element.source && element.type == 1) {
element.source = await DB.ProductPlant.findOne({ _id: element.source }).lean();
} else if (element.source && element.type == 2) {
element.source = await DB.ProductPre.findOne({ _id: element.source }).lean();
} else if (element.source && element.type == 3) {
element.source = await DB.ProductDeep.findOne({_id: element.source}).lean();
element.source = await DB.ProductDeep.findOne({ _id: element.source }).lean();
}
ret.push(element);
}
......@@ -46,10 +65,10 @@ async function listTraceCode(req, res, next) {
}
async function deleteTraceCode(req, res, next) {
try {
if(!req.body._id) {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProTraceCode.findOneAndUpdate({_id: req.body._id}, {del: 1});
let ret = await DB.ProTraceCode.findOneAndUpdate({ _id: req.body._id }, { del: 1 });
res.sendData(ret);
} catch (error) {
next(error);
......@@ -57,14 +76,14 @@ async function deleteTraceCode(req, res, next) {
}
async function updateTraceCode(req, res, next) {
try {
if(!req.body._id) {
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);
let ret = await DB.ProTraceCode.findOneAndUpdate({ _id: req.body._id }, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
......@@ -72,39 +91,161 @@ async function updateTraceCode(req, res, next) {
}
async function getTraceCode(req, res, next) {
try {
if(!req.body._id) {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let traccode = await DB.ProTraceCode.findOne({_id: req.body._id}).lean();
if(!(traccode && traccode._id && traccode.source)) {
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }).lean();
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: "qualityInsReportImgs"}).populate({path: "flourMerchantImgs"}).populate({path: "monitorInfo.device"}).lean().exec();
if(source && source.plantPlan && source.plantPlan.land) {
let devices = await DB.Device.find({land: {$in: source.plantPlan.land}, deviceHQType: 5}).lean();
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();
if (source && source.plantPlan && source.plantPlan.land) {
let devices = await DB.Device.find({ land: { $in: source.plantPlan.land }, deviceHQType: 5 }).lean();
source.devices = devices;
} else {
source.devices = [];
}
} 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();
} 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();
} 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();
} 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();
}
console.log(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 || {};
res.sendData(traccode);
} catch (error) {
next(error);
}
}
async function getTraceCode2(req, res, next) {
try {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, tcode: 1, queryNum: 1, firstQueryTime: 1, _id: 1 }).lean();
if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound);
}
let sourceId = traccode.source;
console.log(sourceId, "===")
let source = null;
if (traccode.type && traccode.type == 1) {
source = await DB.ProductPlant.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, agrPlantBase: 1, homepageCarouselImgs: 1 }).populate({ path: "homepageCarouselImgs" }).lean();
} else if (traccode.type && traccode.type == 2) {
source = await DB.ProductPre.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, agrPlantBase: 1, homepageCarouselImgs: 1 }).populate({ path: "homepageCarouselImgs" }).lean();
} else if (traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, agrPlantBase: 1, homepageCarouselImgs: 1 }).populate({ path: "homepageCarouselImgs" }).lean();
}
traccode.source = source;
/**
* 查询一次则给这条数据加1
*/
traccode.queryNum = (traccode.queryNum || 0) + 1;
traccode.firstQueryTime = traccode.firstQueryTime ? traccode.firstQueryTime : new Date();
await await DB.ProTraceCode.findOneAndUpdate({ _id: req.body._id }, { queryNum: traccode.queryNum, firstQueryTime: traccode.firstQueryTime });
res.sendData(traccode);
} catch (error) {
next(error);
}
}
async function getsuyuanBase(req, res, next) {
try {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1, rawMatCul: 1, proProcess: 1 }).populate({ path: "proProcess.proSteps.img" }).populate({ path: "rawMatCul.proSteps.img" }).lean();
if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound);
}
let sourceId = traccode.source;
console.log(sourceId, "===")
let source = null;
if (traccode.type && traccode.type == 1) {
source = await DB.ProductPlant.findOne({ _id: sourceId }, { preProductName: 1, productSpec: 1, manufactureDate: 1, batchNumber: 1, qualityInspector: 1, productUnit: 1, sellByDate: 1, productPhotos2: 1 }).populate({ path: "homepageCarouselImgs" }).lean();
} 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, productPhotos2: 1 }).populate({ path: "homepageCarouselImgs" }).lean();
} 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, productPhotos2: 1 }).populate({ path: "homepageCarouselImgs" }).lean();
}
traccode.source = source;
res.sendData(traccode);
} catch (error) {
next(error);
}
}
async function getJiankong(req, res, next) {
try {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1, jdImg: 1, gcImg: 1, agrOnOff: 1, indEnvOnOff: 1 }).populate({ path: "gcImg" }).populate({ path: "jdImg" }).lean();
if (!(traccode && traccode._id && traccode.source)) {
return res.sendError(errorMessage.resourceNotFound);
}
let sourceId = traccode.source;
console.log(sourceId, "===")
let source = null;
if (traccode.type && traccode.type == 1) {
source = await DB.ProductPlant.findOne({ _id: sourceId }, { monitorInfo: 1 }).populate({ path: "monitorInfo.device" }).lean();
} else if (traccode.type && traccode.type == 2) {
source = await DB.ProductPre.findOne({ _id: sourceId }, { monitorInfo: 1 }).populate({ path: "monitorInfo.device" }).lean();
} else if (traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({ _id: sourceId }, { monitorInfo: 1 }).populate({ path: "monitorInfo.device" }).lean();
}
//查询一下土壤采集数据
if (traccode.agrOnOff) {
// 气象 土壤
let ws = await DB.CollectWS.findOne({});
let smc = await DB.CollectSMC.findOne();
traccode.ws = ws;
traccode.smc = smc;
}
if (traccode.indEnvOnOff) {
// 工业环境
}
traccode.source = source;
res.sendData(traccode);
} catch (error) {
next(error);
}
}
async function getZhijian(req, res, next) {
try {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let traccode = await DB.ProTraceCode.findOne({ _id: req.body._id }, { type: 1, source: 1, _id: 1 }).lean();
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 }, { 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);
} catch (error) {
next(error);
}
}
......@@ -114,4 +255,8 @@ module.exports = {
deleteTraceCode,
updateTraceCode,
getTraceCode,
getTraceCode2,
getsuyuanBase,
getJiankong,
getZhijian,
}
\ No newline at end of file
......@@ -3,7 +3,7 @@ const Schema = mongoose.Schema;
const moment = require('moment');
/**
* 深加工成果产品 --- 关联初加工成果产品,关联初加工场地摄像头、深加工过程数据(工业信息采集数据)。
* 公司信息
*/
const letianCompanyInfoSchema = new Schema({
......@@ -23,6 +23,13 @@ const letianCompanyInfoSchema = new Schema({
comment: "公司信息介绍图"
}
],
qualiCertiImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "资质证书"
}
],
addressInfo: {
type: [{
name: String,
......
......@@ -10,7 +10,32 @@ const letianProTraceCodeSchema = new Schema({
// type: String,
// comment: "产品名称"
// },
tcode: String, // 溯源码
jdImg: { // 基地总览图片
type: mongoose.Types.ObjectId,
ref: 'File',
},
gcImg: { //工厂总览图
type: mongoose.Types.ObjectId,
ref: 'File',
},
type: {
type: Number,
comment: "1 种植农产品 2 轻加工 3 深加工"
},
workshop: {
type: String,
comment: "生产车间"
},
source: {
type: mongoose.Types.ObjectId,
comment: "产品名称: 源头productPre productDeep prodectPlant 三个"
},
brand: String, //品牌
batchNumber: {
type: String,
comment: "生产批次"
},
proInDate: {
type: Date,
default: Date.now,
......@@ -29,18 +54,56 @@ const letianProTraceCodeSchema = new Schema({
get: v => moment(v).format("YYYY-MM-DD"),
comment: "产品生产日期"
},
type: {
productSalUrl: String, //第三方页面地址,前端当有这个地址时,直接打开此地址,没有则跳转自己的地址
queryNum: {
type: Number,
comment: "1 种植 2 轻加工 3 深加工"
default: 0,
comment: "查询次数",
},
source: {
type: mongoose.Types.ObjectId,
comment: "产品名称: 源头productPre productDeep prodectPlant 三个"
firstQueryTime: {
type: Date,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
comment: "首次查询时间",
},
workshop: {
type: String,
comment: "生产车间"
rawMatCul: { //原料种植
proName: String,
proAdr: String,
manager: String,
proSteps: [
{
name: String,
time: Date,
img: {
type: mongoose.Types.ObjectId,
ref: 'File',
}
}
]
},
proProcess: { //产品加工
proName: String,
proAdr: String,
manager: String,
proSteps: [
{
name: String,
time: Date,
img: {
type: mongoose.Types.ObjectId,
ref: 'File',
}
}
]
},
agrOnOff: { // 农业数据开关
type: Boolean,
default: true,
},
indEnvOnOff: { //工业环境开关
type: Boolean,
default: true,
},
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
......
......@@ -29,10 +29,38 @@ const letianProductDeepSchema = new Schema({
// type: String,
// comment: "库存量"
// },
productPhotos: {
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "产品照片"
homepageCarouselImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "溯源码产品首页轮播图"
}
],
productPhotos2: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "产品详情轮播图"
}
],
pesticidetImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "农残质检报告"
}
],
sellByDate: {
type: String,
comment: "保质期"
},
qualityInspector: {
type: String,
comment: "质检员"
},
productUnit: {
type: String,
comment: "生产单位"
},
// introduction: {
// type: String,
......@@ -124,6 +152,8 @@ const letianProductDeepSchema = new Schema({
}
],
createdAt: {
type: Date,
default: Date.now,
......
......@@ -15,19 +15,40 @@ const letianProductPlantSchema = new Schema({
type: String,
comment: "品种"
},
productPhotos: {
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "产品照片"
},
productIntro: {
homepageCarouselImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "溯源码产品首页轮播图"
}
],
productPhotos2: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "产品详情轮播图"
}
],
sellByDate: {
type: String,
comment: "产品介绍"
comment: "保质期"
},
qualityInfor: {
qualityInspector: {
type: String,
comment: "质量信息"
comment: "质检员"
},
productUnit: {
type: String,
comment: "生产单位"
},
// productIntro: {
// type: String,
// comment: "产品介绍"
// },
// qualityInfor: {
// type: String,
// comment: "质量信息"
// },
yield: {
type: Number,
comment: "产量",
......@@ -52,6 +73,13 @@ const letianProductPlantSchema = new Schema({
comment: "质检报告图"
}
],
pesticidetImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "农残质检报告"
}
],
monitorInfo: {
type: [
{
......
......@@ -28,26 +28,46 @@ const letianProductPreSchema = new Schema({
type: String,
comment: "库存量"
},
productPhotos: {
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "物品照片",
default: null,
set: v => { if (!v) { return null; } else { return v; } }
homepageCarouselImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "溯源码产品首页轮播图"
}
],
productPhotos2: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "产品详情轮播图"
}
],
sellByDate: {
type: String,
comment: "保质期"
},
qualityInspector: {
type: String,
comment: "质检员"
},
introduction: {
productUnit: {
type: String,
comment: "介绍内容"
comment: "生产单位"
},
// introduction: {
// type: String,
// comment: "介绍内容"
// },
processTime: {
type: Date,
default: Date.now,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
},
qualityInfo: {
type: String,
comment: "质量信息"
},
// qualityInfo: {
// type: String,
// comment: "质量信息"
// },
productNumber: {
type: String,
comment: "产品编号"
......@@ -59,6 +79,13 @@ const letianProductPreSchema = new Schema({
comment: "质检报告图"
}
],
pesticidetImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "农残质检报告"
}
],
monitorInfo: {
type: [
{
......
......@@ -46,5 +46,9 @@ 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);
router.post('/product/trace/info2', productTracController.getTraceCode2); //溯源首页
router.post('/product/trace/suyuan', productTracController.getsuyuanBase); // 溯源信息
router.post('/product/trace/jiankong', productTracController.getJiankong); // 实时监控
router.post('/product/trace/zhijian', productTracController.getZhijian); // 质量检测报告
module.exports = router;
\ No newline at end of file
......@@ -74,11 +74,22 @@ function genTracSourceCode({EnterpriseCode, type, date, batchNum, logisticsNum})
}
function generateRandomCode(len) {
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; // 定义字符库
let code = '';
for (let i = 0; i < len; i++) {
const randomIndex = Math.floor(Math.random() * chars.length); // 生成随机索引
code += chars[randomIndex]; // 拼接字符
}
return code;
}
module.exports = {
saltHashPassword,
checkUserPassword,
buildTree,
disTree,
generateRandomCode,
}
\ No newline at end of file
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