| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 | 'use strict';/** * * * @author Zhong * @date 2018/5/24 * @version */import mongoose from 'mongoose';import schedule from 'node-schedule';import async from 'async';const projectModel = mongoose.model('projects');const projSettingModel = mongoose.model('proj_setting');const calcProgramModel = mongoose.model('calc_programs');const labourCoeModel = mongoose.model('labour_coes');const billsModel = mongoose.model('bills');const rationModel = mongoose.model('ration');const projGljModel = mongoose.model('glj_list');const rationGljModel = mongoose.model('ration_glj');const rationCoeMolde = mongoose.model('ration_coe');const installationModel = mongoose.model('installation_fee');const rationInstallationModel = mongoose.model('ration_installation');const rationTemplateModel  = mongoose.model('ration_template')const quantityDetailModel = mongoose.model('quantity_detail');const unitPriceFileModel = mongoose.model('unit_price_file');const unitPriceModel = mongoose.model('unit_price');const mixRatioModel = mongoose.model('mix_ratio');const feeRateFileModel = mongoose.model('fee_rate_file');const feeRateModel = mongoose.model('fee_rates');const compleRationSection = mongoose.model('complementary_ration_section_tree');//删除垃圾数据async function clearJunkData(callback){    let functions = [];    //获取彻底删除了的项目    let junkProjs = await projectModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});    let junkProjIds = [];    for(let jProj of junkProjs){        junkProjIds.push(jProj.ID);    }    if(junkProjIds.length > 0){        //清除proj_setting        functions.push(function(cb){            projSettingModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除calcProgram        functions.push(function(cb){            calcProgramModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除labourCoe        functions.push(function(cb){            labourCoeModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除bills        functions.push(function(cb){            billsModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除ration        functions.push(function(cb){            rationModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除project_glj        functions.push(function(cb){            projGljModel.remove({project_id: {$in: junkProjIds}}, cb);        });        //清除ration_glj        functions.push(function(cb){            rationGljModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除ration_coe        functions.push(function(cb){            rationCoeMolde.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除installation_fee        functions.push(function(cb){            installationModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除ration_installation        functions.push(function(cb){            rationInstallationModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除ration_installation        functions.push(function(cb){            rationTemplateModel.remove({projectID: {$in: junkProjIds}}, cb);        });        //清除quantity_detail        functions.push(function(cb){            quantityDetailModel.remove({projectID: {$in: junkProjIds}}, cb);        });    }    //彻底删除了的单价文件    let junkUFs = await unitPriceFileModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});    let junkUFIds = [];    for(let jUF of junkUFs){        junkUFIds.push(jUF.id);    }    if(junkUFIds.length > 0){        functions.push(function(cb){            unitPriceModel.remove({unit_price_file_id: {$in: junkUFIds}}, cb);        });        functions.push(function(cb){            mixRatioModel.remove({unit_price_file_id: {$in: junkUFIds}}, cb);        });    }    //彻底删除了的费率文件    let junkFFs = await feeRateFileModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});    let junkFFIds = [];    for(let jFF of junkFFs){        junkFFIds.push(jFF.feeRateID);    }    if(junkFFIds.length > 0){        functions.push(function(cb){            feeRateModel.remove({ID: {$in: junkFFIds}}, cb);        });    }    //清除    if(functions.length > 0){        async.parallel(functions, async function(err, result){            if(!err){                //清除项目                await projectModel.remove({ID: {$in: junkProjIds}});                //清除单价文件                await unitPriceFileModel.remove({id: {$in: junkUFIds}});                //清除费率文件                await feeRateFileModel.remove({feeRateID: {$in: junkFFIds}});            }            if(callback) callback(err);        });    }    else {       if(callback) callback(0);    }}//删除假删除数据/** 1.之前的删除造价书数据,都是做的假删除,这部分数据会一直存在并且随着项目重复使用越来越多,现要改为真删除,所以做这个清除功能。* 2.原假删除包括清单的所有类型(大项费用、分部、分项、补项、清单)、定额的所有类型(定额、数量单价、与定额同级的人材机)* */async function clearFakeData(callback) {    let functions = [];    //删除清单    functions.push(function (cb) {        billsModel.remove({deleteInfo: {$exists: true}}, cb);    });    //删除定额    functions.push(function (cb) {        rationModel.remove({deleteInfo: {$exists: true}}, cb);    });    //删除补充定额章节树    functions.push(function (cb) {        compleRationSection.remove({deleteInfo: {$exists: true}}, cb);    });    async.parallel(functions, async function(err, result){        if(callback){            callback(err);        }    });}const sysSchedule = {    clearJunkData,    clearFakeData};//export {sysSchedule as default}module.exports = sysSchedule;
 |