land_facade.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Created by zhang on 2018/9/10.
  3. */
  4. import mongoose from "mongoose";
  5. const uuidV1 = require('uuid/v1');
  6. let moment = require("moment");
  7. let landModel = mongoose.model('std_land_libs');
  8. let compilationModel = mongoose.model("compilation");
  9. const _ = require('lodash');
  10. let landLib = {
  11. findByCondition: async function (conditions, options, single = true) {
  12. if (single == true) {
  13. return await landModel.findOne(conditions, options);
  14. } else {
  15. return await landModel.find(conditions, options);
  16. }
  17. },
  18. addLib: async function (data) {
  19. let now = new Date().getTime();
  20. let dateStr = moment(now).format('YYYY-MM-DD HH:mm:ss');
  21. //取编办信息
  22. let compilation = await compilationModel.findOne({ _id: data.compilationId });
  23. if (compilation) {
  24. let newLib = {
  25. creator: data.userAccount,
  26. createDate: now,
  27. recentOpr: [{ operator: data.userAccount, operateDate: dateStr }],
  28. libName: data.name,
  29. compilationId: data.compilationId,
  30. compilationName: compilation.name,
  31. };
  32. newLib.ID = uuidV1();
  33. return await landModel.create(newLib);
  34. } else {
  35. throw new Error("没有找到该编办!");
  36. }
  37. },
  38. saveLib: async function (param) {
  39. return await landModel.findOneAndUpdate(param.query, param.data, { new: true });
  40. },
  41. deleteLibByID: async function (ID) {
  42. return await landModel.deleteOne({ ID: ID });
  43. },
  44. };
  45. export default landLib