|
@@ -5,6 +5,11 @@ var mongoose = require("mongoose");
|
|
|
var db = require("../db/project_db");
|
|
|
var subSchema = require("./billsSubSchemas");
|
|
|
var Schema = mongoose.Schema;
|
|
|
+var deleteSchema = require('../../../public/models/deleteSchema');
|
|
|
+var counter = require("../../../public/counter/counter.js");
|
|
|
+var consts = require('./projectConsts');
|
|
|
+var projectConsts = consts.projectConst;
|
|
|
+var commonConsts = consts.commonConst;
|
|
|
|
|
|
var rationSchema = new Schema({
|
|
|
ID: Number,
|
|
@@ -17,24 +22,26 @@ var rationSchema = new Schema({
|
|
|
maskName: String,
|
|
|
unit: String,
|
|
|
quantity: String, // Decimal
|
|
|
- programId: Number,
|
|
|
+ programID: Number,
|
|
|
+ adjustState: String,
|
|
|
content: String,
|
|
|
rationProjName: String,
|
|
|
comments: String,
|
|
|
// 费用字段
|
|
|
fees: [subSchema.feesSchema],
|
|
|
// 标记字段
|
|
|
- flags: [subSchema.flagsSchema]
|
|
|
+ flags: [subSchema.flagsSchema],
|
|
|
+ deleteInfo: deleteSchema
|
|
|
});
|
|
|
|
|
|
-var ration = db.model("rations", rationSchema);
|
|
|
+var ration = db.model("ration", rationSchema, "ration");
|
|
|
|
|
|
var rationDAO = function(){};
|
|
|
|
|
|
-rationDAO.prototype.getData = function(projectId, callback){
|
|
|
- rations.find({projectID: projectId}, function(err, datas){
|
|
|
+rationDAO.prototype.getData = function(projectID, callback){
|
|
|
+ ration.find({'$or': [{projectID: projectID, deleteInfo: null}, {projectID: projectID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
|
|
|
if (!err) {
|
|
|
- callback(0, '', datas);
|
|
|
+ callback(0, projectConsts.RATION, datas);
|
|
|
} else {
|
|
|
callback(1, '', null);
|
|
|
}
|
|
@@ -42,32 +49,32 @@ rationDAO.prototype.getData = function(projectId, callback){
|
|
|
};
|
|
|
|
|
|
rationDAO.prototype.save = function(projectId, datas, callback){
|
|
|
- var data, errList = [], updateLength = 0;
|
|
|
- var updateFunc = function (err, errData) {
|
|
|
- if (err){
|
|
|
- errList.push(errData);
|
|
|
- };
|
|
|
- };
|
|
|
- if (datas){
|
|
|
- for (var i = 0; i < datas.length; i++){
|
|
|
- data = datas[i];
|
|
|
- if (data.updateType === 'update') {
|
|
|
- delete data.updateType;
|
|
|
- data.save(updateFunc);
|
|
|
- } else if (data.updateType === 'create') {
|
|
|
- delete data.updateType;
|
|
|
- data.save(updateFunc);
|
|
|
- } else if (data.updateType === 'delete') {
|
|
|
- delete data.updateType;
|
|
|
- data.remove(updateFunc);
|
|
|
- };
|
|
|
- };
|
|
|
- if (errList.length > 0){
|
|
|
- callback(1, 'update error.', errList);
|
|
|
- } else {
|
|
|
- callback(0, '', null);
|
|
|
- };
|
|
|
- };
|
|
|
+ var functions = [];
|
|
|
+ var data;
|
|
|
+
|
|
|
+ function saveOne(data) {
|
|
|
+ return function (cb) {
|
|
|
+ switch (doc.updateType) {
|
|
|
+ case commonConsts.UT_UPDATE:
|
|
|
+ ration.update({ID: doc.ID}, doc, cb);
|
|
|
+ break;
|
|
|
+ case commonConsts.UT_CREATE:
|
|
|
+ ration.create(doc, cb);
|
|
|
+ break;
|
|
|
+ case commonConsts.UT_DELETE:
|
|
|
+ /* 假删除
|
|
|
+ var item = new ration(doc);
|
|
|
+ item.remove(cb);
|
|
|
+ */
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (var i = 0; i < datas.length; i++){
|
|
|
+ data = datas[i];
|
|
|
+ functions.push(saveOne(data));
|
|
|
+ }
|
|
|
+
|
|
|
+ async.parallel(functions, callback);
|
|
|
};
|
|
|
|
|
|
rationDAO.prototype.getItemTemplate = function(callback){
|
|
@@ -76,9 +83,6 @@ rationDAO.prototype.getItemTemplate = function(callback){
|
|
|
callback(0, '', data);
|
|
|
};
|
|
|
|
|
|
-const
|
|
|
- IDStep = 50, IDModule = 'rations';
|
|
|
-
|
|
|
rationDAO.prototype.allocIDs = function(IDStep, callback){
|
|
|
counter.counterDAO.getIDAfterCount(counter.moduleName.ration, IDStep, function(err, highID){
|
|
|
var lowID = highID - IDStep + 1;
|