unit_price_file.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * Created by jimiz on 2017/5/12.
  3. */
  4. var mongoose = require("mongoose");
  5. var db = require("../db/unit_price_file_db");
  6. var Schema = mongoose.Schema;
  7. var deleteSchema = require('../../../public/models/delete_schema');
  8. var consts = require('../../main/models/project_consts');
  9. var projectConsts = consts.projectConst;
  10. var commonConsts = consts.commonConst;
  11. var GLJList = require('./glj_list');
  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. var data;
  23. unitPriceFile.find({'$or': [{fileID: fileID, deleteInfo: null}, {fileID: fileID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
  24. if (!err) {
  25. GLJList.getData(fileID, function(err, gljList){
  26. data['properties'] = datas[0];
  27. data['glj_list'] = gljList;
  28. callback(0, projectConsts.UNITPRICEFILE, data);
  29. });
  30. } else {
  31. callback(1, '', null);
  32. }
  33. });
  34. };
  35. unitPriceFileDAO.prototype.save = function(fileId, datas, callback){
  36. function changed(err, changedDatas){
  37. sync(fileId, changedDatas, callback);
  38. }
  39. GLJList.save(fileID, datas, changed);
  40. };
  41. unitPriceFileDAO.prototype.sync = function(fileID, datas, callback){
  42. unitPriceFile.find({'$or': [{ID: fileID, deleteInfo: null}, {ID: fileID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
  43. if (!err) {
  44. // to do
  45. callback(0, projectConsts.UNITPRICEFILE, datas);
  46. } else {
  47. callback(1, '', null);
  48. }
  49. });
  50. };
  51. unitPriceFileDAO.prototype.add = function(fileID, count, callback){
  52. GLJList.add(fileID, count, callback);
  53. };
  54. unitPriceFileDAO.prototype.newFile = function(data, callback){
  55. };
  56. unitPriceFileDAO.prototype.useFile = function(fileID, projectID, callback){
  57. };
  58. unitPriceFileDAO.prototype.unuseFile = function(fileID, projectID, callback){
  59. };
  60. module.exports = new unitPriceFileDAO();