明树Git Lab

Commit 160d5a87 authored by zfp1's avatar zfp1

update

parent 1eca7605
......@@ -303,14 +303,16 @@ async function importExcel(req, res, next) {
let arr = [];
worksheet.eachRow({ includeEmpty: false }, function (row, rowNumber) {
console.log(rowNumber)
// console.log(rowNumber)
const rowData = {};
row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
console.log('colNumber: ', colNumber)
rowData[cell.value] = cell.value;
});
// rowsData.push(rowData);
arr.push(rowData);
if(rowNumber > 1) {
let keys = ['type', 'name', 'count', 'spec', 'comment'];
row.eachCell({ includeEmpty: true }, function (cell, colNumber) {
// console.log('colNumber: ', colNumber)
rowData[keys[colNumber - 1]] = cell.value;
});
arr.push(rowData);
}
});
res.sendData({
......@@ -350,6 +352,8 @@ async function inMat(req, res, next) {
status: 1,
currentTotalCount: check.totalCount,
actualCount: element.count,
spec: element.spec,
comment: element.comment,
});
} else {
await DB.AgrMat.create({
......@@ -365,7 +369,8 @@ async function inMat(req, res, next) {
status: 2,
currentTotalCount: 0,
actualCount: element.count,
spec: element.spec,
comment: element.comment,
});
}
}
......@@ -380,14 +385,14 @@ async function outMat(req, res, next) {
let body = req.body;
let creator = req.user._id;
let materials = body.materials || [];
// let fileInfo = body.fileInfo;
let fileInfo = body.fileInfo;
let inApprovalId = new mongoose.Types.ObjectId();
let inApproval = {
_id: inApprovalId,
type: 2,
name: "出库单",
creator,
// file: fileInfo && fileInfo._id,
file: fileInfo && fileInfo._id,
}
//创建单据
await DB.AgrMatApproval.create(inApproval);
......
......@@ -122,161 +122,9 @@ async function updatePlan(req, res, next) {
}
}
/**--------------------------------------------直接种植--------------------------------------------------------- */
async function createDirectPlant(req, res, next) {
try {
//
const body = req.body;
let ret = await DB.ProductPlant.create(body);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function listDirectPlant(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
const count = await DB.ProductPlant.countDocuments(search);
let list = await DB.ProductPlant.find(search).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list });
} catch (error) {
next(error);
}
}
async function deleteDirectPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProductPlant.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function updateDirectPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let upInfo = {
...req.body,
_id: undefined,
}
let ret = await DB.ProductPlant.findOneAndUpdate({_id: req.body._id}, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
}
}
/**--------------------------------------------初加工--------------------------------------------------------- */
async function createPrePlant(req, res, next) {
try {
//
const body = req.body;
let ret = await DB.ProductPre.create(body);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function listPrePlant(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
const count = await DB.ProductPre.countDocuments(search);
let list = await DB.ProductPre.find(search).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list });
} catch (error) {
next(error);
}
}
async function deletePrePlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProductPre.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function updatePrePlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let upInfo = {
...req.body,
_id: undefined,
}
let ret = await DB.ProductPre.findOneAndUpdate({_id: req.body._id}, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
}
}
/**--------------------------------------------深加工--------------------------------------------------------- */
async function createDeepPlant(req, res, next) {
try {
//
const body = req.body;
let ret = await DB.ProductDeep.create(body);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function listDeepPlant(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
const count = await DB.ProductDeep.countDocuments(search);
let list = await DB.ProductDeep.find(search).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list });
} catch (error) {
next(error);
}
}
async function deleteDeepPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProductDeep.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function updateDeepPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let upInfo = {
...req.body,
_id: undefined,
}
let ret = await DB.ProductDeep.findOneAndUpdate({_id: req.body._id}, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
}
}
......@@ -289,18 +137,6 @@ module.exports = {
createPlan,
listPlan,
deletePlan,
updatePlan,
createDirectPlant,
listDirectPlant,
deleteDirectPlant,
updateDirectPlant,
createPrePlant,
listPrePlant,
deletePrePlant,
updatePrePlant,
createDeepPlant,
listDeepPlant,
deleteDeepPlant,
updateDeepPlant,
updatePlan
}
\ No newline at end of file
/**--------------------------------------------深加工--------------------------------------------------------- */
async function createDeepPlant(req, res, next) {
try {
//
const body = req.body;
let count = await DB.ProductDeep.count(); //没有真实删除 永远递增
body.productNumber = count;
let ret = await DB.ProductDeep.create(body);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function listDeepPlant(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
const count = await DB.ProductDeep.countDocuments(search);
let list = await DB.ProductDeep.find(search).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list });
} catch (error) {
next(error);
}
}
async function deleteDeepPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProductDeep.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function updateDeepPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let upInfo = {
...req.body,
_id: undefined,
}
let ret = await DB.ProductDeep.findOneAndUpdate({_id: req.body._id}, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
}
}
module.exports = {
createDeepPlant,
listDeepPlant,
deleteDeepPlant,
updateDeepPlant,
}
\ No newline at end of file
/**--------------------------------------------直接种植--------------------------------------------------------- */
async function createDirectPlant(req, res, next) {
try {
//
const body = req.body;
let count = await DB.ProductPlant.count(); //没有真实删除 永远递增
body.productNumber = count;
let ret = await DB.ProductPlant.create(body);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function listDirectPlant(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
const count = await DB.ProductPlant.countDocuments(search);
let list = await DB.ProductPlant.find(search).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list });
} catch (error) {
next(error);
}
}
async function deleteDirectPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProductPlant.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function updateDirectPlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let upInfo = {
...req.body,
_id: undefined,
}
let ret = await DB.ProductPlant.findOneAndUpdate({_id: req.body._id}, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function importExcel(req, res, next) {
try {
throw new Error('不适合做解析,直接录入');
let workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
let arr = [];
for (let index = 2; index <= worksheet.actualRowCount; index++) {
let values = worksheet.getRow(index).values;
let obj = {
creator: req.user._id,
productName: values[1],
varieties: values[2],
productIntro: values[3],
qualityInfor: values[4],
}
if(typeof obj.time == 'number') {
obj.time = new Date(1900, 0, obj.time - 1, 0, 0, 0);
}
if (obj.time && obj.agrProName) {
arr.push(obj)
}
}
if (arr.length) {
await DB.AgrInputRecord.insertMany(arr);
}
res.sendData(arr);
} catch (error) {
next(error)
}
}
module.exports = {
createDirectPlant,
listDirectPlant,
deleteDirectPlant,
updateDirectPlant,
importExcel,
}
\ No newline at end of file
/**--------------------------------------------初加工--------------------------------------------------------- */
async function createPrePlant(req, res, next) {
try {
//
const body = req.body;
let count = await DB.ProductPre.count(); //没有真实删除 永远递增
body.productNumber = count;
let ret = await DB.ProductPre.create(body);
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function listPrePlant(req, res, next) {
try {
let search = { del: 0 };
let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize;
const count = await DB.ProductPre.countDocuments(search);
let list = await DB.ProductPre.find(search).sort({_id: -1}).skip(skip).limit(pageSize);
res.sendData({ count, list });
} catch (error) {
next(error);
}
}
async function deletePrePlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let ret = await DB.ProductPre.findOneAndUpdate({_id: req.body._id}, {del: 1});
res.sendData(ret);
} catch (error) {
next(error);
}
}
async function updatePrePlant(req, res, next) {
try {
if(!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
let upInfo = {
...req.body,
_id: undefined,
}
let ret = await DB.ProductPre.findOneAndUpdate({_id: req.body._id}, upInfo);
res.sendData(ret);
} catch (error) {
next(error);
}
}
module.exports = {
createPrePlant,
listPrePlant,
deletePrePlant,
updatePrePlant,
}
\ No newline at end of file
......@@ -31,6 +31,18 @@ const AgrMaterialInOutSchema = new Schema({
type: Number,
comment: "实际出入库数量--计算依据",
},
unit: {
type: String,
comment: "农资单位"
},
comment: {
type: String,
comment: "备注"
},
spec: {
type: String,
commnet: "规格",
},
approval: {
type: mongoose.Types.ObjectId,
......
......@@ -45,6 +45,10 @@ const letianProductDeepSchema = new Schema({
type: String,
comment: "质量信息"
},
productNumber: {
type: String,
comment: "产品编号"
},
createdAt: {
type: Date,
......
......@@ -16,7 +16,8 @@ const letianProductPlantSchema = new Schema({
comment: "品种"
},
productPhotos: {
type: String,
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "产品照片"
},
productIntro: {
......@@ -32,6 +33,10 @@ const letianProductPlantSchema = new Schema({
ref: 'PlantPlan',
comment: "种植规划 关联信息 按照农作物的名称关联"
},
productNumber: {
type: String,
comment: "产品编号"
},
createdAt: {
type: Date,
......
......@@ -44,6 +44,10 @@ const letianProductPreSchema = new Schema({
type: String,
comment: "质量信息"
},
productNumber: {
type: String,
comment: "产品编号"
},
createdAt: {
type: Date,
......
......@@ -54,7 +54,10 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
'agrInputOther': "agrInputOtherController",
'agrInputDetail': "agrInputDetailController",
'agrInputEmploy': "agrInputEmployController",
'agrMat': 'agrMatController',
'agrMat': 'agrMatController', //库存解析
// 'productDirPlant': 'productDirPlantController', //直接种植
// 'productPre': 'productPreController', //初加工
// 'productDeep': 'productDeepController', // 深加工
}
let controller = require(`../controller/${modelMap[modelName]}`);
await controller.importExcel(req, res, next);
......
......@@ -46,6 +46,9 @@ router.use('/statistics', statisticsRouter); // 统计 大屏
router.use('/flow', flowRouter);
router.use('/excelrecord', excelrecordRouter);
// 工业
......
......@@ -3,6 +3,9 @@ const express = require('express');
const router = express.Router();
const plantContoller = require('../controller/plantContoller.js');
const productDirPlantController = require('../controller/productDirPlantController.js');
const productPreController = require('../controller/productPreController.js');
const productDeepController = require('../controller/productDeepController.js');
// 生长周期
router.post('/cycle/create', plantContoller.createPlantCycle);
......@@ -17,21 +20,21 @@ router.post('/plan/delete', plantContoller.deletePlan);
router.post('/plan/update', plantContoller.updatePlan);
// 直接种植
router.post('/product/direct/create', plantContoller.createDirectPlant);
router.post('/product/direct/list', plantContoller.listDirectPlant);
router.post('/product/direct/delete', plantContoller.deleteDirectPlant);
router.post('/product/direct/update', plantContoller.updateDirectPlant);
router.post('/product/direct/create', productDirPlantController.createDirectPlant);
router.post('/product/direct/list', productDirPlantController.listDirectPlant);
router.post('/product/direct/delete', productDirPlantController.deleteDirectPlant);
router.post('/product/direct/update', productDirPlantController.updateDirectPlant);
// 初加工
router.post('/product/pre/create', plantContoller.createPrePlant);
router.post('/product/pre/list', plantContoller.listPrePlant);
router.post('/product/pre/delete', plantContoller.deletePrePlant);
router.post('/product/pre/update', plantContoller.updatePrePlant);
router.post('/product/pre/create', productPreController.createPrePlant);
router.post('/product/pre/list', productPreController.listPrePlant);
router.post('/product/pre/delete', productPreController.deletePrePlant);
router.post('/product/pre/update', productPreController.updatePrePlant);
// 深加工
router.post('/product/deep/create', plantContoller.createDeepPlant);
router.post('/product/deep/list', plantContoller.listDeepPlant);
router.post('/product/deep/delete', plantContoller.deleteDeepPlant);
router.post('/product/deep/update', plantContoller.updateDeepPlant);
router.post('/product/deep/create', productDeepController.createDeepPlant);
router.post('/product/deep/list', productDeepController.listDeepPlant);
router.post('/product/deep/delete', productDeepController.deleteDeepPlant);
router.post('/product/deep/update', productDeepController.updateDeepPlant);
module.exports = router;
\ No newline at end of file
......@@ -66,6 +66,13 @@ function disTree(tree) {
return parallel
}
function genTracSourceCode({EnterpriseCode, type, date, batchNum, logisticsNum}) {
// 企业代码(9) MA4W271Y8 + 产品代码【种植、初加工、深加工】(6)+ 生产/出厂日期(8)) + 批次号(8)+ 物流码 + 校验码(8)
//MA4W271Y8
date = date && moment().format('YYYYMMDD');
return `${EnterpriseCode}${type}${date}${batchNum}${logisticsNum}`;
}
module.exports = {
......
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