sys_model.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/5/24
  7. * @version
  8. */
  9. import mongoose from 'mongoose';
  10. import schedule from 'node-schedule';
  11. import async from 'async';
  12. const projectModel = mongoose.model('projects');
  13. const projSettingModel = mongoose.model('proj_setting');
  14. const calcProgramModel = mongoose.model('calc_programs');
  15. const labourCoeModel = mongoose.model('labour_coes');
  16. const billsModel = mongoose.model('bills');
  17. const rationModel = mongoose.model('ration');
  18. const projGljModel = mongoose.model('glj_list');
  19. const rationGljModel = mongoose.model('ration_glj');
  20. const rationCoeMolde = mongoose.model('ration_coe');
  21. const installationModel = mongoose.model('installation_fee');
  22. const rationInstallationModel = mongoose.model('ration_installation');
  23. const rationTemplateModel = mongoose.model('ration_template');
  24. const quantityDetailModel = mongoose.model('quantity_detail');
  25. const unitPriceFileModel = mongoose.model('unit_price_file');
  26. const unitPriceModel = mongoose.model('unit_price');
  27. const mixRatioModel = mongoose.model('mix_ratio');
  28. const feeRateFileModel = mongoose.model('fee_rate_file');
  29. const feeRateModel = mongoose.model('fee_rates');
  30. const compleRationSection = mongoose.model('complementary_ration_section_tree');
  31. const evaluateListModel = mongoose.model("evaluate_list");
  32. const bidListModel = mongoose.model("bid_evaluation_list");
  33. //删除垃圾数据
  34. async function clearJunkData(callback){
  35. let functions = [];
  36. //获取彻底删除了的项目
  37. let junkProjs = await projectModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});
  38. let junkProjIds = [];
  39. for(let jProj of junkProjs){
  40. junkProjIds.push(jProj.ID);
  41. }
  42. if(junkProjIds.length > 0){
  43. //清除proj_setting
  44. functions.push(function(cb){
  45. projSettingModel.remove({projectID: {$in: junkProjIds}}, cb);
  46. });
  47. //清除calcProgram
  48. functions.push(function(cb){
  49. calcProgramModel.remove({projectID: {$in: junkProjIds}}, cb);
  50. });
  51. //清除labourCoe
  52. functions.push(function(cb){
  53. labourCoeModel.remove({projectID: {$in: junkProjIds}}, cb);
  54. });
  55. //清除bills
  56. functions.push(function(cb){
  57. billsModel.remove({projectID: {$in: junkProjIds}}, cb);
  58. });
  59. //清除ration
  60. functions.push(function(cb){
  61. rationModel.remove({projectID: {$in: junkProjIds}}, cb);
  62. });
  63. //清除project_glj
  64. functions.push(function(cb){
  65. projGljModel.remove({project_id: {$in: junkProjIds}}, cb);
  66. });
  67. //清除ration_glj
  68. functions.push(function(cb){
  69. rationGljModel.remove({projectID: {$in: junkProjIds}}, cb);
  70. });
  71. //清除ration_coe
  72. functions.push(function(cb){
  73. rationCoeMolde.remove({projectID: {$in: junkProjIds}}, cb);
  74. });
  75. //清除installation_fee
  76. functions.push(function(cb){
  77. installationModel.remove({projectID: {$in: junkProjIds}}, cb);
  78. });
  79. //清除ration_installation
  80. functions.push(function(cb){
  81. rationInstallationModel.remove({projectID: {$in: junkProjIds}}, cb);
  82. });
  83. //清除ration_installation
  84. functions.push(function(cb){
  85. rationTemplateModel.remove({projectID: {$in: junkProjIds}}, cb);
  86. });
  87. //清除quantity_detail
  88. functions.push(function(cb){
  89. quantityDetailModel.remove({projectID: {$in: junkProjIds}}, cb);
  90. });
  91. //清除暂估材料
  92. functions.push(function(cb){
  93. evaluateListModel.remove({projectID: {$in: junkProjIds}}, cb);
  94. });
  95. //清除评标材料
  96. functions.push(function(cb){
  97. bidListModel.remove({projectID: {$in: junkProjIds}}, cb);
  98. });
  99. }
  100. //彻底删除了的单价文件
  101. let junkUFs = await unitPriceFileModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});
  102. let junkUFIds = [];
  103. for(let jUF of junkUFs){
  104. junkUFIds.push(jUF.id);
  105. }
  106. if(junkUFIds.length > 0){
  107. functions.push(function(cb){
  108. unitPriceModel.remove({unit_price_file_id: {$in: junkUFIds}}, cb);
  109. });
  110. functions.push(function(cb){
  111. mixRatioModel.remove({unit_price_file_id: {$in: junkUFIds}}, cb);
  112. });
  113. }
  114. //彻底删除了的费率文件
  115. let junkFFs = await feeRateFileModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});
  116. let junkFFIds = [];
  117. for(let jFF of junkFFs){
  118. junkFFIds.push(jFF.feeRateID);
  119. }
  120. if(junkFFIds.length > 0){
  121. functions.push(function(cb){
  122. feeRateModel.remove({ID: {$in: junkFFIds}}, cb);
  123. });
  124. }
  125. //清除
  126. if(functions.length > 0){
  127. async.parallel(functions, async function(err, result){
  128. if(!err){
  129. //清除项目
  130. await projectModel.remove({ID: {$in: junkProjIds}});
  131. //清除单价文件
  132. await unitPriceFileModel.remove({id: {$in: junkUFIds}});
  133. //清除费率文件
  134. await feeRateFileModel.remove({feeRateID: {$in: junkFFIds}});
  135. }
  136. if(callback) callback(err);
  137. });
  138. }
  139. else {
  140. if(callback) callback(0);
  141. }
  142. }
  143. //删除假删除数据
  144. /*
  145. * 1.之前的删除造价书数据,都是做的假删除,这部分数据会一直存在并且随着项目重复使用越来越多,现要改为真删除,所以做这个清除功能。
  146. * 2.原假删除包括清单的所有类型(大项费用、分部、分项、补项、清单)、定额的所有类型(定额、数量单价、与定额同级的人材机)
  147. * */
  148. async function clearFakeData(callback) {
  149. let functions = [];
  150. //删除清单
  151. functions.push(function (cb) {
  152. billsModel.remove({deleteInfo: {$exists: true}}, cb);
  153. });
  154. //删除定额
  155. functions.push(function (cb) {
  156. rationModel.remove({deleteInfo: {$exists: true}}, cb);
  157. });
  158. //删除补充定额章节树
  159. functions.push(function (cb) {
  160. compleRationSection.remove({deleteInfo: {$exists: true}}, cb);
  161. });
  162. async.parallel(functions, async function(err, result){
  163. if(callback){
  164. callback(err);
  165. }
  166. });
  167. }
  168. const sysSchedule = {
  169. clearJunkData,
  170. clearFakeData
  171. };
  172. //export {sysSchedule as default}
  173. module.exports = sysSchedule;