sys_model.js 6.5 KB

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