unit_price_file.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Created by jimiz on 2017/5/12.
  3. */
  4. var mongoose = require("mongoose");
  5. var db = require("../db/unitPriceFile_db");
  6. var Schema = mongoose.Schema;
  7. var deleteSchema = require('../../../public/models/delete_schema');
  8. var consts = require('../../main/models/projectConsts');
  9. var projectConsts = consts.projectConst;
  10. var commonConsts = consts.commonConst;
  11. var GLJList = require('./GLJList');
  12. var unitPriceFileSchema = new Schema({
  13. ID: Number,
  14. name: String,
  15. version: Number,
  16. projects: Array,
  17. deleteInfo: deleteSchema
  18. });
  19. var unitPriceFile = db.model("unitPriceFile", unitPriceFileSchema, "unitPriceFile");
  20. var unitPriceFileDAO = function(){};
  21. unitPriceFileDAO.prototype.getData = function(fileID, callback){
  22. unitPriceFile.find({'$or': [{fileID: fileID, deleteInfo: null}, {fileID: fileID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
  23. if (!err) {
  24. callback(0, projectConsts.UNITPRICEFILE, datas);
  25. } else {
  26. callback(1, '', null);
  27. }
  28. });
  29. };
  30. unitPriceFileDAO.prototype.save = function(fileId, datas, callback){
  31. function changed(err, changedDatas){
  32. sync(fileId, changedDatas, callback);
  33. }
  34. GLJList.save(fileID, datas, changed);
  35. };
  36. unitPriceFileDAO.prototype.sync = function(fileID, datas, callback){
  37. unitPriceFile.find({'$or': [{ID: fileID, deleteInfo: null}, {ID: fileID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
  38. if (!err) {
  39. datas[0].projects
  40. callback(0, projectConsts.UNITPRICEFILE, datas);
  41. } else {
  42. callback(1, '', null);
  43. }
  44. });
  45. };
  46. unitPriceFileDAO.prototype.add = function(fileID, count, callback){
  47. GLJList.add(fileID, count, callback);
  48. };
  49. unitPriceFileDAO.prototype.newFile = function(data, callback){
  50. };
  51. unitPriceFileDAO.prototype.useFile = function(fileID, projectID, callback){
  52. };
  53. unitPriceFileDAO.prototype.unuseFile = function(fileID, projectID, callback){
  54. };
  55. module.exports = new unitPriceFileDAO();