1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /**
- * Created by jimiz on 2017/4/1.
- */
- var mongoose = require("mongoose");
- var db = require("../db/project_db");
- var subSchema = require("./billsSubSchemas");
- var Schema = mongoose.Schema;
- var rationSchema = new Schema({
- ID: Number,
- projectID: Number,
- billsItemID: Number,
- serialNo: Number,
- libID: Number,
- code: String,
- name: String,
- maskName: String,
- unit: String,
- quantity: String, // Decimal
- programId: Number,
- content: String,
- rationProjName: String,
- comments: String,
- // 费用字段
- fees: [subSchema.feesSchema],
- // 标记字段
- flags: [subSchema.flagsSchema]
- });
- var ration = db.model("rations", rationSchema);
- var rationDAO = function(){};
- rationDAO.prototype.getData = function(projectId, callback){
- rations.find({projectID: projectId}, function(err, datas){
- if (!err) {
- callback(0, '', datas);
- } else {
- callback(1, '', null);
- }
- });
- };
- 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);
- };
- };
- };
- rationDAO.prototype.getItemTemplate = function(callback){
- var data = new ration;
- /* to do: 需要根据标准配置库填充fees和flags字段,是否需要更多的参数? */
- 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;
- callback(0, '', {lowID: lowID, highID: highID});
- });
- };
- module.exports = new rationDAO();
|