明树Git Lab

Commit f52b6874 authored by zfp1's avatar zfp1

update: 公司信息、菜单、质检

parent 216111ef
async function findCompInfo(req, res, next) {
try {
return await DB.CompanyInfo.findOne({}).populate({path: "companyInfoImgs"}).lean().exec();
} catch (error) {
next(error);
}
}
async function updateCompInfo(req, res, next) {
try {
let body = req.body;
body.companyInfoImgs = (body.companyInfoImgs || []).map(o => {return o && o._id});
return await DB.CompanyInfo.findOneAndUpdate({_id: body._id},{body});
} catch (error) {
next(error);
}
}
module.exports = {
findCompInfo,
updateCompInfo,
}
\ No newline at end of file
...@@ -25,12 +25,14 @@ async function batchUpload(req, res, next) { ...@@ -25,12 +25,14 @@ async function batchUpload(req, res, next) {
let ret = []; let ret = [];
for (let index = 0; index < req.files.length; index++) { for (let index = 0; index < req.files.length; index++) {
const element = req.files[index]; const element = req.files[index];
let nginxpath = _.last(String(element.path).split('/mnt/vdb1'));
ret.push({ ret.push({
originalname: element.originalname, originalname: element.originalname,
mimetype: element.mimetype, mimetype: element.mimetype,
filename: element.filename, filename: element.filename,
path: element.path, path: element.path,
size: element.size, size: element.size,
nginxpath,
}) })
} }
let data = await DB.File.insertMany(ret); let data = await DB.File.insertMany(ret);
......
...@@ -49,6 +49,10 @@ async function updateMenu(req, res, next) { ...@@ -49,6 +49,10 @@ async function updateMenu(req, res, next) {
updateObj.parentId = req.body.parentId; updateObj.parentId = req.body.parentId;
updateObj.parentIds = parentIds; updateObj.parentIds = parentIds;
} }
if(req.body.del == 1) {
//删除,则删除其子菜单 TODO把所有的子删除:也就是数组里面包含当前id的都删除
}
let ret = await DB.Menu.findOneAndUpdate({ _id: req.body._id }, updateObj); let ret = await DB.Menu.findOneAndUpdate({ _id: req.body._id }, updateObj);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
......
...@@ -5,6 +5,7 @@ async function createDeepPlant(req, res, next) { ...@@ -5,6 +5,7 @@ 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});
let ret = await DB.ProductDeep.create(body); let ret = await DB.ProductDeep.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -21,7 +22,7 @@ async function listDeepPlant(req, res, next) { ...@@ -21,7 +22,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: "productPhotos"}).populate({path: "sourcePlantProduct"}).sort({_id: -1}).skip(skip).limit(pageSize); let list = await DB.ProductDeep.find(search).populate({path: "productPhotos"}).populate({path: "sourcePlantProduct"}).populate({path: "qualityInsReportImgs"}).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error); next(error);
......
...@@ -5,6 +5,7 @@ async function createDirectPlant(req, res, next) { ...@@ -5,6 +5,7 @@ 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});
let ret = await DB.ProductPlant.create(body); let ret = await DB.ProductPlant.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -22,7 +23,7 @@ async function listDirectPlant(req, res, next) { ...@@ -22,7 +23,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: "productPhotos"}).populate({path: "plantPlan"}).sort({_id: -1}).skip(skip).limit(pageSize); let list = await DB.ProductPlant.find(search).populate({path: "productPhotos"}).populate({path: "plantPlan"}).populate({path: "qualityInsReportImgs"}).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error); next(error);
......
...@@ -6,6 +6,7 @@ async function createPrePlant(req, res, next) { ...@@ -6,6 +6,7 @@ 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});
let ret = await DB.ProductPre.create(body); let ret = await DB.ProductPre.create(body);
res.sendData(ret); res.sendData(ret);
} catch (error) { } catch (error) {
...@@ -22,7 +23,7 @@ async function listPrePlant(req, res, next) { ...@@ -22,7 +23,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: "productPhotos"}).populate({path: "sourcePlantProduct"}).sort({_id: -1}).skip(skip).limit(pageSize); let list = await DB.ProductPre.find(search).populate({path: "productPhotos"}).populate({path: "sourcePlantProduct"}).populate({path: "qualityInsReportImgs"}).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error); next(error);
......
...@@ -82,7 +82,7 @@ async function getTraceCode(req, res, next) { ...@@ -82,7 +82,7 @@ async function getTraceCode(req, res, next) {
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"}).lean(); source = await DB.ProductPlant.findOne({_id: sourceId}).populate({path: "productPhotos"}).populate({path: "plantPlan"}).populate({path: "qualityInsReportImgs"}).lean();
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;
...@@ -90,13 +90,16 @@ async function getTraceCode(req, res, next) { ...@@ -90,13 +90,16 @@ async function getTraceCode(req, res, next) {
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"}).lean(); source = await DB.ProductPre.findOne({_id: sourceId}).populate({path: "productPhotos"}).populate({path: "qualityInsReportImgs"}).lean();
} else if(traccode.type && traccode.type == 3) { } else if(traccode.type && traccode.type == 3) {
source = await DB.ProductDeep.findOne({_id: sourceId}).populate({path: "productPhotos"}).lean(); source = await DB.ProductDeep.findOne({_id: sourceId}).populate({path: "productPhotos"}).populate({path: "qualityInsReportImgs"}).lean();
} }
console.log(source, "==") console.log(source, "==")
traccode.source = source; traccode.source = source;
//请求公司信息
let companyInfo = await DB.CompanyInfo.findOne({});
traccode.companyInfo = companyInfo || {};
res.sendData(traccode); res.sendData(traccode);
} catch (error) { } catch (error) {
next(error); next(error);
......
...@@ -75,6 +75,8 @@ const RequestLog = require('./models/systemRequestLog'); ...@@ -75,6 +75,8 @@ const RequestLog = require('./models/systemRequestLog');
const HeavyMetal = require('./models/letianHeavyMetal'); const HeavyMetal = require('./models/letianHeavyMetal');
const IndRawMatIn = require('./models/letianIndRawMatIn'); //工业-原料品投入 const IndRawMatIn = require('./models/letianIndRawMatIn'); //工业-原料品投入
const CompanyInfo = require('./models/letianCompanyInfo'); //公司信息 用作扫码处展示
global.DB = { global.DB = {
File, File,
User, User,
...@@ -122,7 +124,7 @@ global.DB = { ...@@ -122,7 +124,7 @@ global.DB = {
IndRawMatIn, IndRawMatIn,
HeavyMetal, HeavyMetal,
CompanyInfo,
} }
......
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const moment = require('moment');
/**
* 深加工成果产品 --- 关联初加工成果产品,关联初加工场地摄像头、深加工过程数据(工业信息采集数据)。
*/
const letianCompanyInfoSchema = new Schema({
name: {
type: mongoose.Types.ObjectId,
ref: 'ProductPre',
comment: "来源初加工产品 靠产品名称关联"
},
address: {
type: String,
comment: "深加工产品名称"
},
companyInfoImgs: {
type: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "公司信息介绍图"
}
]
},
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 CompanyInfo = mongoose.model('CompanyInfo', letianCompanyInfoSchema, 'letianCompanyInfo');
module.exports = CompanyInfo;
\ No newline at end of file
...@@ -51,6 +51,13 @@ const letianProductDeepSchema = new Schema({ ...@@ -51,6 +51,13 @@ const letianProductDeepSchema = new Schema({
type: String, type: String,
comment: "产品编号" comment: "产品编号"
}, },
qualityInsReportImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "质检报告图"
}
],
createdAt: { createdAt: {
type: Date, type: Date,
......
...@@ -45,6 +45,13 @@ const letianProductPlantSchema = new Schema({ ...@@ -45,6 +45,13 @@ const letianProductPlantSchema = new Schema({
type: Number, type: Number,
comment: "产品编号" comment: "产品编号"
}, },
qualityInsReportImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "质检报告图"
}
],
createdAt: { createdAt: {
type: Date, type: Date,
......
...@@ -33,7 +33,7 @@ const letianProductPreSchema = new Schema({ ...@@ -33,7 +33,7 @@ const letianProductPreSchema = new Schema({
ref: 'File', ref: 'File',
comment: "物品照片", comment: "物品照片",
default: null, default: null,
set: v => {if(!v) {return null;} else {return v;}} set: v => { if (!v) { return null; } else { return v; } }
}, },
introduction: { introduction: {
type: String, type: String,
...@@ -52,6 +52,13 @@ const letianProductPreSchema = new Schema({ ...@@ -52,6 +52,13 @@ const letianProductPreSchema = new Schema({
type: String, type: String,
comment: "产品编号" comment: "产品编号"
}, },
qualityInsReportImgs: [
{
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "质检报告图"
}
],
createdAt: { createdAt: {
type: Date, type: Date,
......
...@@ -61,8 +61,6 @@ async function getRoleMenus(roles, mobile) { ...@@ -61,8 +61,6 @@ async function getRoleMenus(roles, mobile) {
bMap[bpreId] = bMap[bpreId] || []; bMap[bpreId] = bMap[bpreId] || [];
bMap[bpreId].push(o); bMap[bpreId].push(o);
} }
} }
//获取用户有效的菜单 type : 1 //获取用户有效的菜单 type : 1
...@@ -72,7 +70,7 @@ async function getRoleMenus(roles, mobile) { ...@@ -72,7 +70,7 @@ async function getRoleMenus(roles, mobile) {
element.parentIds = element.parentIds || []; element.parentIds = element.parentIds || [];
for (let i = 0; i < element.parentIds.length; i++) { for (let i = 0; i < element.parentIds.length; i++) {
const par = element.parentIds[i]; const par = element.parentIds[i];
if (!nodeMap[par._id]) { if (!nodeMap[par._id] && par.del == 0 && par.enable) { // 父节点删除后 子节点没有联动删除(会有删除失败因素) 此处处理
par.buttons = bMap[par._id]; par.buttons = bMap[par._id];
par.permission = true par.permission = true
nodes.push(par); nodes.push(par);
......
const express = require('express');
const router = express.Router();
const companyInfoController = require('../controller/companyInfoController');
router.post('/info', companyInfoController.findCompInfo);
router.post('/update', companyInfoController.updateCompInfo);
module.exports = router;
\ No newline at end of file
...@@ -22,6 +22,7 @@ const flowRouter = require('./flowRouter'); ...@@ -22,6 +22,7 @@ const flowRouter = require('./flowRouter');
const excelrecordRouter = require('./excelrecordRouter'); const excelrecordRouter = require('./excelrecordRouter');
const inductryRouter = require('./inductryRouter'); const inductryRouter = require('./inductryRouter');
const heavyMetalRouter = require('./externalRouter'); const heavyMetalRouter = require('./externalRouter');
const compInfoRouter = require('./compInfoRouter');
router.use('/user', userRouter); // 用户 角色 router.use('/user', userRouter); // 用户 角色
...@@ -51,6 +52,8 @@ router.use('/excelrecord', excelrecordRouter); ...@@ -51,6 +52,8 @@ router.use('/excelrecord', excelrecordRouter);
// 工业 // 工业
router.use('/ind', inductryRouter); router.use('/ind', inductryRouter);
router.use('/company', compInfoRouter);
module.exports = router; module.exports = router;
\ 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