//这个好像没有用到了，先注释掉，运行如无错误后删除
/*
/!**
 * Created by jimiz on 2017/5/10.
 * 单价文件的GLJ列表，注意与项目GLJ区分
 *!/
var mongoose = require("mongoose");
var db = require("../db/unit_price_file_db");
var Schema = mongoose.Schema;
var deleteSchema = require('../../../public/models/delete_schema');
var counter = require("../../../public/counter/counter.js");
var consts = require('../../main/models/project_consts');
var projectConsts = consts.projectConst;
var commonConsts = consts.commonConst;

var GLJListSchema = new Schema({
    ID: Number,
    fileID: Number,
    code: String,
    name: String,
    specs: String,
    unit: String,
    type: Number,
    adjustPrice: String,
    rationPrice: String,
    price: String, //Decimal
    deleteInfo: deleteSchema
});

var GLJList = db.model("GLJList", GLJListSchema, "GLJList");

var GLJListDAO = function(){};

GLJListDAO.prototype.getData = function(fileID, callback){
    var me = this;
    GLJList.find({'$or': [{fileID: fileID, deleteInfo: null}, {fileID: fileID, 'deleteInfo.deleted': {$in: [null, false]}}]}, '-_id', function(err, datas){
        if (!err) {
            callback(0, projectConsts.GLJLIST, datas);
        } else {
            callback(1, '', null);
        }
    });
};

// 单价文件中的工料机不在这里新增，只能由add方法新增，删除需要在前端projectGLJ判断：1、是新工料机；2、没有定额引用，才可以删除
GLJListDAO.prototype.save = function(fileId, datas, callback){
    var functions = [];
    var data;

    // cb中返回doc，以便进行同步
    function saveOne(doc) {
        return function (cb) {
            function updateCallback(err, data){
                cb(err, doc);
            }
            switch (doc.updateType) {
                case commonConsts.UT_UPDATE:
                    ration.update({ID: doc.ID}, doc, updateCallback);
                    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);
};

GLJListDAO.prototype.add = function(fileID, count, callback){

    function newCallback(err, lowID, highID){
        if (!err) {
            var datas = [];
            for (var i = lowID; i <= highID; i++){
                var GLJ = new GLJList;
                GLJ.ID = i;
                GLJ.fileID = fileID;
                datas.push(GLJ);
            }
            callback(err, datas);

        }
        else{
            callback(err, null);
        }
    }

    counter.counterDAO.getIDAfterCount(COUNTER_MODULE_NAME.unitPriceGLJ, IDStep, function(err, highID){
        var lowID = highID - IDStep + 1;
        newCallback(err, lowID, highID);
    });
};

module.exports = new GLJListDAO();*/
