| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- /**
- * Created by zhang on 2018/8/22.
- */
- import mongoose from "mongoose";
- const uuidV1 = require('uuid/v1');
- let moment = require("moment");
- let compilationModel = mongoose.model("compilation");
- let materialLibModel = mongoose.model("std_material_replace_lib");
- let StdBillsLib = mongoose.model('std_bills_lib_list');
- let materialReplaceLib = {
- findByCondition:async function(conditions,options,single=true){
- if(single == true){
- return await materialLibModel.findOne(conditions,options);
- }else {
- return await materialLibModel.find(conditions,options);
- }
- },
- addLib : async function (data){
- let now = new Date().getTime();
- let dateStr = moment(now).format('YYYY-MM-DD HH:mm:ss');
- //取编办信息
- let compilation = await compilationModel.findOne({_id:data.compilationId});
- //取清单规则信息
- let billLib = await StdBillsLib.findOne({billsLibId:data.billsLibId});
- if(compilation && billLib){
- let newLib = {
- creator: data.userAccount,
- createDate: now,
- recentOpr: [{operator: data.userAccount, operateDate: dateStr}],
- name: data.name,
- compilationId: data.compilationId,
- compilationName: compilation.name,
- billsLibId:billLib.billsLibId,
- billsLibName:billLib.billsLibName,
- deleted: false
- };
- newLib.ID = uuidV1();
- return await materialLibModel.create(newLib);
- }else {
- throw new Error("编办或清单规则有误!");
- }
- },
- saveLib:async function(param) {
- return await materialLibModel.findOneAndUpdate(param.query,param.data,{new:true});
- },
- deleteLibByID:async function(ID){
- return materialLibModel.deleteOne({ID:ID});
- }
- }
- export default materialReplaceLib
|