明树Git Lab

Commit 2aa06d51 authored by zfp1's avatar zfp1

update

parent a4881d4d
...@@ -3,6 +3,7 @@ const moment = require('moment'); ...@@ -3,6 +3,7 @@ const moment = require('moment');
const errorMessage = require('../utils/errorMessage'); const errorMessage = require('../utils/errorMessage');
const mongoose = require('mongoose'); const mongoose = require('mongoose');
const agrMatModule = require('../module/agrMatModule'); const agrMatModule = require('../module/agrMatModule');
const ExcelJS = require('exceljs');
/* ----------------农资类型--------------------- */ /* ----------------农资类型--------------------- */
...@@ -78,17 +79,17 @@ async function queryMatType(req, res, next) { ...@@ -78,17 +79,17 @@ async function queryMatType(req, res, next) {
async function queryMatApprList(req, res, next) { async function queryMatApprList(req, res, next) {
try { try {
let search = { del: 0 }; let search = { del: 0 };
if(req.body.type) { if (req.body.type) {
search.type = req.body.type; search.type = req.body.type;
} }
if(req.body.name) { if (req.body.name) {
search.name = {$regex: req.body.name} search.name = { $regex: req.body.name }
} }
let page = req.body.page || 1; let page = req.body.page || 1;
let pageSize = req.body.pageSize || 10; let pageSize = req.body.pageSize || 10;
let skip = (page - 1) * pageSize; let skip = (page - 1) * pageSize;
let count = await DB.AgrMatApproval.countDocuments(search) let count = await DB.AgrMatApproval.countDocuments(search)
let list = await DB.AgrMatApproval.find(search).skip(skip).limit(pageSize).populate({path: 'materials', match: {del: 0}, select: ''}).lean().exec(); let list = await DB.AgrMatApproval.find(search).skip(skip).limit(pageSize).populate({ path: 'materials', match: { del: 0 }, select: '' }).lean().exec();
res.sendData({ count, list }); res.sendData({ count, list });
} catch (error) { } catch (error) {
next(error) next(error)
...@@ -196,17 +197,17 @@ async function saveMatAppr(req, res, next) { ...@@ -196,17 +197,17 @@ async function saveMatAppr(req, res, next) {
async function deleteMatAppr(req, res, next) { async function deleteMatAppr(req, res, next) {
try { try {
// //
let check = await DB.AgrMatApproval.findOne({_id: req.body._id}); let check = await DB.AgrMatApproval.findOne({ _id: req.body._id });
if(!(check && check._id)) { if (!(check && check._id)) {
return res.sendError(errorMessage.resourceNotFound); return res.sendError(errorMessage.resourceNotFound);
} }
if(check && check.flows && check.flows.length > 0) { if (check && check.flows && check.flows.length > 0) {
return res.sendError(errorMessage.agrMatHaveFlow); return res.sendError(errorMessage.agrMatHaveFlow);
} }
// 删除清单。 // 删除清单。
await DB.AgrMatInOut.updateMany({approval: check._id}, {del: 1}); await DB.AgrMatInOut.updateMany({ approval: check._id }, { del: 1 });
// 删除单据 // 删除单据
await DB.AgrMatApproval.updateOne({_id: check._id}, {del: 1}); await DB.AgrMatApproval.updateOne({ _id: check._id }, { del: 1 });
return res.sendData({}); return res.sendData({});
} catch (error) { } catch (error) {
next(error) next(error)
...@@ -220,11 +221,126 @@ async function deleteMatAppr(req, res, next) { ...@@ -220,11 +221,126 @@ async function deleteMatAppr(req, res, next) {
/* ---------------------------------------------库存---------------------------------------------------------- */
async function queryMatList(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;
let count = await DB.AgrMat.countDocuments(search)
let list = await DB.AgrMat.find(search).skip(skip).limit(pageSize).lean().exec();
res.sendData({ count, list });
} catch (error) {
next(error)
}
}
async function addMat(req, res, next) {
try {
let creator = req.user._id;
let info = {
...req.body,
creator,
}
// if (req.body.name) {
// let check = await DB.AgrMat.findOne({ name: req.body.name });
// if (check) {
// return res.sendError(errorMessage.nameDuplicated);
// }
// }
let ret = await DB.AgrMat.findOneAndUpdate({ name: info.name }, info, { upsert: true, returnOriginal: false });
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function deleteMat(req, res, next) {
try {
if (!req.body._id) {
return res.sendError(errorMessage.resourceNotFound);
}
await DB.AgrMat.findOneAndUpdate({ _id: req.body._id }, { del: 1 });
res.sendData({})
} catch (error) {
next(error)
}
}
async function updateMat(req, res, next) {
try {
// if (req.body.name) {
// let check = await DB.AgrMat.findOne({ name: req.body.name, _id: {$ne: req.body._id} });
// if (check) {
// return res.sendError(errorMessage.nameDuplicated);
// }
// }
let ret = await DB.AgrMat.findOneAndUpdate({ _id: req.body._id }, { ...req.body, _id: undefined, }, { returnOriginal: false });
res.sendData(ret);
} catch (error) {
next(error)
}
}
async function importExcel(req, res, next) {
let workbook = new ExcelJS.Workbook();
await workbook.xlsx.readFile(req.file.path);
let worksheet = workbook.getWorksheet(1);
let arr = [];
worksheet.eachRow({ includeEmpty: false }, function (row, 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);
});
res.sendData(arr)
}
async function inMat(req, res, next) {
try {
let body = req.body;
let creator = req.user._id;
let materials = body.materials || [];
let inApprovalId = new mongoose.Types.ObjectId();
let inApproval = {
_id: inApprovalId,
type: 1,
name: "入库单",
creator,
}
let m_arr = [];
for (let index = 0; index < materials.length; index++) {
const element = materials[index];
if(element.count > 0) {
m_arr.push({
...element,
approval: inApprovalId,
});
}
}
//创建单据
//创建列表
} catch (error) {
next(error);
}
}
async function outMat(req, res, next) {
try {
} catch (error) {
next(error);
}
}
...@@ -249,4 +365,12 @@ module.exports = { ...@@ -249,4 +365,12 @@ module.exports = {
queryMatApprList, queryMatApprList,
saveMatAppr, saveMatAppr,
deleteMatAppr, deleteMatAppr,
queryMatList,
addMat,
deleteMat,
updateMat,
importExcel,
inMat,
outMat,
} }
\ No newline at end of file
...@@ -4,7 +4,48 @@ const httpRequest = require('../utils/httpRequest'); ...@@ -4,7 +4,48 @@ const httpRequest = require('../utils/httpRequest');
const _ = require('lodash'); const _ = require('lodash');
async function plantearlywarning(params) { async function plantearlywarning(params) {
let role = await DB.Role.findOne({ key: "notice_role" });
let users = []
if (role && role._id) {
users = await DB.User.find({ roles: role._id }).select('_id');
}
//这里暂时不确定 收获周期的格式 //这里暂时不确定 收获周期的格式
let plants = await DB.PlantPlan.find({del: 0}).populate({path: 'plantiCycle'}).lean().exec();
let exceeds = [];
for (let index = 0; index < plants.length; index++) {
const element = plants[index];
let cycles = element.plantCycle || [];
for (let i = 0; i < cycles.length; i++) {
const cyc = cycles[i];
if(cyc.times && cyc.times.length) {
for (let ii = 0; ii < cyc.times.length; ii++) {
const ti = cyc.times[ii];
if(ti.startTime && ti.endTime) {
let st = moment().diff(moment(ti.startTime), 'days');
let et = moment().diff(moment(ti.endTime), 'days');
if(st >= 0 && et <= 0) {
exceeds.push({
...cyc,
})
}
}
}
}
}
}
if(users.length && exceeds.length) {
for (let u = 0; u < users.length; u++) {
const user = users[u];
await DB.Notice.create({
sendUser: "66d6c4099f8480c6db53ce13",
receiveUser: user._id,
content: "",
exceeds,
title: "农事预警",
type: 5,
});
}
}
} }
module.exports = { module.exports = {
......
File deleted
...@@ -41,14 +41,16 @@ const AgrInputRecord = require('./models/letianAgrInputRecord'); ...@@ -41,14 +41,16 @@ const AgrInputRecord = require('./models/letianAgrInputRecord');
const AgrInputDetail = require('./models/letianAgrInputDetail'); const AgrInputDetail = require('./models/letianAgrInputDetail');
const AgrInputEmploy = require('./models/letianAgrInputEmploy'); const AgrInputEmploy = require('./models/letianAgrInputEmploy');
const AgrInputOther = require('./models/letianAgrInputOther'); const AgrInputOther = require('./models/letianAgrInputOther');
const AgrMat = require('./models/letianAgrMat');
const AgrMatType = require('./models/letianAgrMatType'); const AgrMatType = require('./models/letianAgrMatType');
const AgrMatApproval = require('./models/letianAgrMatApproval'); const AgrMatApproval = require('./models/letianAgrMatApproval');
const AgrMatInOut = require('./models/letianAgrMatInOut'); const AgrMatInOut = require('./models/letianAgrMatInOut');
const FileTemplate = require('./models/letianFileTemplate'); const FileTemplate = require('./models/letianFileTemplate');
const AreaRecord = require('./models/letianAreaRecord'); const AreaRecord = require('./models/letianAreaRecord');
const ExcelRecord = require('./models/letianExcelRecord'); const ExcelRecord = require('./models/letianExcelRecord');
const PlantCycle = require('./models/letianPlantCycle');
const PlantPlan = require('./models/letianPlantPlan'); const PlantPlan = require('./models/letianPlantPlan');
const ProductPlant = require('./models/letianProductPlant'); const ProductPlant = require('./models/letianProductPlant');
const ProductPre = require('./models/letianProductPre'); const ProductPre = require('./models/letianProductPre');
...@@ -81,13 +83,14 @@ global.DB = { ...@@ -81,13 +83,14 @@ global.DB = {
AgrInputDetail, AgrInputDetail,
AgrInputEmploy, AgrInputEmploy,
AgrInputOther, AgrInputOther,
AgrMat,
AgrMatType, AgrMatType,
AgrMatApproval, AgrMatApproval,
AgrMatInOut, AgrMatInOut,
FileTemplate, FileTemplate,
AreaRecord, AreaRecord,
ExcelRecord, ExcelRecord,
PlantCycle,
PlantPlan, PlantPlan,
ProductPlant, ProductPlant,
......
...@@ -8,7 +8,8 @@ const moment = require('moment'); ...@@ -8,7 +8,8 @@ const moment = require('moment');
const AgrMaterialSchema = new Schema({ const AgrMaterialSchema = new Schema({
type: { type: {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
type: String,
comment: "农资类型" comment: "农资类型"
}, },
name: { name: {
...@@ -16,12 +17,34 @@ const AgrMaterialSchema = new Schema({ ...@@ -16,12 +17,34 @@ const AgrMaterialSchema = new Schema({
type: String, type: String,
comment: "农资名称" comment: "农资名称"
}, },
img: {
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "物品照片",
default: null,
set: v => {if(!v) {return null;} else {return v;}}
},
totalCount: { totalCount: {
type: Number, type: Number,
comment: "农资库存数量" comment: "农资库存数量"
}, },
unit: {
type: String,
comment: "农资单位"
},
comment: {
type: String,
comment: "备注"
},
spec: {
type: String,
commnet: "规格",
},
creator: {
type: mongoose.Types.ObjectId,
ref: 'User',
comment1: "创建人"
},
createdAt: { createdAt: {
type: Date, type: Date,
default: Date.now, default: Date.now,
......
...@@ -21,12 +21,12 @@ const AgrMaterialApprovalSchema = new Schema({ ...@@ -21,12 +21,12 @@ const AgrMaterialApprovalSchema = new Schema({
type: String, type: String,
comment: "单据名称" comment: "单据名称"
}, },
materials: { // materials: {
type: [mongoose.Types.ObjectId], // type: [mongoose.Types.ObjectId],
ref: 'AgrMatInOut', // ref: 'AgrMatInOut',
comment: "出入库记录清单", // comment: "出入库记录清单",
default: [] // default: []
}, // },
creator: { creator: {
type: mongoose.Types.ObjectId, type: mongoose.Types.ObjectId,
ref: 'User', ref: 'User',
...@@ -38,10 +38,10 @@ const AgrMaterialApprovalSchema = new Schema({ ...@@ -38,10 +38,10 @@ const AgrMaterialApprovalSchema = new Schema({
comment: "单据状态 1.未提交 3.待审批 5.审批通过 7.审批不通过", comment: "单据状态 1.未提交 3.待审批 5.审批通过 7.审批不通过",
default: 1, default: 1,
}, },
flow: { // flow: {
type: [mongoose.Types.ObjectId], // type: [mongoose.Types.ObjectId],
comment: "审批流程记录 不通过后再提交即为一次新的审批流程" // comment: "审批流程记录 不通过后再提交即为一次新的审批流程"
}, // },
createdAt: { createdAt: {
type: Date, type: Date,
......
...@@ -8,7 +8,8 @@ const moment = require('moment'); ...@@ -8,7 +8,8 @@ const moment = require('moment');
const AgrMaterialInOutSchema = new Schema({ const AgrMaterialInOutSchema = new Schema({
type: { type: {
type: mongoose.Types.ObjectId, // type: mongoose.Types.ObjectId,
type: String,
comment: "农资类型", comment: "农资类型",
required: true, required: true,
...@@ -27,6 +28,11 @@ const AgrMaterialInOutSchema = new Schema({ ...@@ -27,6 +28,11 @@ const AgrMaterialInOutSchema = new Schema({
comment: "单据id", comment: "单据id",
required: true, required: true,
}, },
status: {
type: Number,
comment: "入库状态 1 新增入库 2 追加入库 ",
default: 1,
},
createdAt: { createdAt: {
......
...@@ -19,6 +19,13 @@ const PlantCycleSchema = new Schema({ ...@@ -19,6 +19,13 @@ const PlantCycleSchema = new Schema({
type: String, type: String,
comment: "内容 : 注意事项" comment: "内容 : 注意事项"
}, },
img: {
type: mongoose.Types.ObjectId,
ref: 'File',
comment: "物品照片",
default: null,
set: v => {if(!v) {return null;} else {return v;}}
},
times: { times: {
type: [ type: [
{ {
......
...@@ -43,7 +43,30 @@ const PlantPlanSchema = new Schema({ ...@@ -43,7 +43,30 @@ const PlantPlanSchema = new Schema({
comment: "种植状态 采收、结束种植", comment: "种植状态 采收、结束种植",
}, },
plantiCycle: { plantiCycle: {
type: mongoose.Types.ObjectId, type: [mongoose.Types.ObjectId],
// type: [{
// cycleName: {
// type: String,
// comment: "周期名称",
// },
// content: {
// type: String,
// comment: "内容 : 注意事项"
// },
// times: {
// type: [
// {
// startTime: {
// type: Date,
// },
// endTime: {
// type: Date,
// },
// }
// ],
// },
// }],
ref: "PlantCycle", ref: "PlantCycle",
comment: "种植周期", comment: "种植周期",
}, },
......
...@@ -29,7 +29,7 @@ const Noticechema = new Schema({ ...@@ -29,7 +29,7 @@ const Noticechema = new Schema({
type: { type: {
type: Number, type: Number,
comment: "通知类型 3. 采集数据预警通知。", comment: "通知类型 3. 采集数据预警通知。5. 农事预警",
}, },
exceeds:[], exceeds:[],
createdAt: { createdAt: {
......
...@@ -37,10 +37,20 @@ router.post('/inputEmploy/create', agrInputEmployController.create); ...@@ -37,10 +37,20 @@ router.post('/inputEmploy/create', agrInputEmployController.create);
const agrMatController = require('../controller/agrMatController'); const agrMatController = require('../controller/agrMatController');
router.post('/mat/list', agrMatController.queryMatList);
router.post('/mat/add', agrMatController.addMat);
router.post('/mat/delete', agrMatController.deleteMat);
router.post('/mat/update', agrMatController.updateMat);
//入库
router.post('/mat/in', agrMatController.inMat);
//出库
router.post('/mat/out', agrMatController.outMat);
/** /**
* 农资 * 农资审批记录--- 202411 ---- 不要审批过程 废弃
*/ */
router.post('/mat/approval/list', agrMatController.queryMatApprList); //获取农资审批记录列表 router.post('/mat/approval/list', agrMatController.queryMatApprList); //获取农资审批记录列表
router.post('/mat/approval/save', agrMatController.saveMatAppr); //获取农资审批记录列表 router.post('/mat/approval/save', agrMatController.saveMatAppr); //获取农资审批记录列表
...@@ -49,7 +59,7 @@ router.post('/mat/approval/delete', agrMatController.deleteMatAppr); //获取农 ...@@ -49,7 +59,7 @@ router.post('/mat/approval/delete', agrMatController.deleteMatAppr); //获取农
/** /**
* 农资类型 * 农资类型 --- 不要类型 --- 不方便导入
*/ */
router.post('/mat/type/create', agrMatController.createMatType); router.post('/mat/type/create', agrMatController.createMatType);
router.post('/mat/type/delete', agrMatController.deleteMatType); router.post('/mat/type/delete', agrMatController.deleteMatType);
......
...@@ -54,6 +54,7 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n ...@@ -54,6 +54,7 @@ router.post('/:modelName/importExcel', upload.single('file'), async (req, res, n
'agrInputOther': "agrInputOtherController", 'agrInputOther': "agrInputOtherController",
'agrInputDetail': "agrInputDetailController", 'agrInputDetail': "agrInputDetailController",
'agrInputEmploy': "agrInputEmployController", 'agrInputEmploy': "agrInputEmployController",
'agrMat': 'agrMatController',
} }
let controller = require(`../controller/${modelMap[modelName]}`); let controller = require(`../controller/${modelMap[modelName]}`);
await controller.importExcel(req, res, next); await controller.importExcel(req, res, next);
......
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