sys_model.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2018/5/24
  7. * @version
  8. */
  9. import mongoose from 'mongoose';
  10. import async from 'async';
  11. const projectModel = mongoose.model('projects');
  12. const projSettingModel = mongoose.model('proj_setting');
  13. const calcProgramModel = mongoose.model('calc_programs');
  14. const labourCoeModel = mongoose.model('labour_coes');
  15. const billsModel = mongoose.model('bills');
  16. const rationModel = mongoose.model('ration');
  17. const projGljModel = mongoose.model('glj_list');
  18. const rationGljModel = mongoose.model('ration_glj');
  19. const rationCoeMolde = mongoose.model('ration_coe');
  20. const installationModel = mongoose.model('installation_fee');
  21. const rationInstallationModel = mongoose.model('ration_installation');
  22. const rationTemplateModel = mongoose.model('ration_template');
  23. const quantityDetailModel = mongoose.model('quantity_detail');
  24. const unitPriceFileModel = mongoose.model('unit_price_file');
  25. const unitPriceModel = mongoose.model('unit_price');
  26. const mixRatioModel = mongoose.model('mix_ratio');
  27. const feeRateFileModel = mongoose.model('fee_rate_file');
  28. const feeRateModel = mongoose.model('fee_rates');
  29. const compleRationSection = mongoose.model('complementary_ration_section_tree');
  30. const evaluateListModel = mongoose.model("evaluate_list");
  31. const bidListModel = mongoose.model("bid_evaluation_list");
  32. const contractorListModel = mongoose.model("contractor_list");
  33. //删除垃圾数据
  34. async function clearJunkData(callback){
  35. let functions = [];
  36. //获取彻底删除了的项目
  37. let junkProjs = await projectModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true}, '-_id ID').lean();
  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. functions.push(function(cb){
  101. contractorListModel.remove({projectID: {$in: junkProjIds}}, cb);
  102. });
  103. }
  104. //彻底删除了的单价文件
  105. let junkUFs = await unitPriceFileModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});
  106. let junkUFIds = [];
  107. for(let jUF of junkUFs){
  108. junkUFIds.push(jUF.id);
  109. }
  110. if(junkUFIds.length > 0){
  111. functions.push(function(cb){
  112. unitPriceModel.remove({unit_price_file_id: {$in: junkUFIds}}, cb);
  113. });
  114. functions.push(function(cb){
  115. mixRatioModel.remove({unit_price_file_id: {$in: junkUFIds}}, cb);
  116. });
  117. }
  118. //彻底删除了的费率文件
  119. let junkFFs = await feeRateFileModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true});
  120. let junkFFIds = [];
  121. for(let jFF of junkFFs){
  122. junkFFIds.push(jFF.feeRateID);
  123. }
  124. if(junkFFIds.length > 0){
  125. functions.push(function(cb){
  126. feeRateModel.remove({ID: {$in: junkFFIds}}, cb);
  127. });
  128. }
  129. //清除
  130. if(functions.length > 0){
  131. async.parallel(functions, async function(err, result){
  132. if(!err){
  133. //清除项目
  134. await projectModel.remove({ID: {$in: junkProjIds}});
  135. //清除单价文件
  136. await unitPriceFileModel.remove({id: {$in: junkUFIds}});
  137. //清除费率文件
  138. await feeRateFileModel.remove({feeRateID: {$in: junkFFIds}});
  139. } else {
  140. console.log(err);
  141. }
  142. if(callback) callback(err);
  143. });
  144. }
  145. else {
  146. if(callback) callback(0);
  147. }
  148. }
  149. //删除假删除数据
  150. /*
  151. * 1.之前的删除造价书数据,都是做的假删除,这部分数据会一直存在并且随着项目重复使用越来越多,现要改为真删除,所以做这个清除功能。
  152. * 2.原假删除包括清单的所有类型(大项费用、分部、分项、补项、清单)、定额的所有类型(定额、数量单价、与定额同级的人材机)
  153. * */
  154. async function clearFakeData(callback) {
  155. let functions = [];
  156. //删除清单
  157. functions.push(function (cb) {
  158. billsModel.remove({deleteInfo: {$exists: true}}, cb);
  159. });
  160. //删除定额
  161. functions.push(function (cb) {
  162. rationModel.remove({deleteInfo: {$exists: true}}, cb);
  163. });
  164. //删除补充定额章节树
  165. functions.push(function (cb) {
  166. compleRationSection.remove({deleteInfo: {$exists: true}}, cb);
  167. });
  168. async.parallel(functions, async function(err, result){
  169. if(callback){
  170. callback(err);
  171. }
  172. });
  173. }
  174. const sysSchedule = {
  175. clearJunkData,
  176. clearFakeData
  177. };
  178. //export {sysSchedule as default}
  179. module.exports = sysSchedule;