sys_model.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. const shareListModel = mongoose.model('share_list');
  34. //删除垃圾数据
  35. async function clearJunkData(callback){
  36. let functions = [];
  37. //获取彻底删除了的项目
  38. let junkProjs = await projectModel.find({'deleteInfo.deleted': true, 'deleteInfo.completeDeleted': true}, '-_id ID').lean();
  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 shareListModel.remove({projectID: {$in: junkProjIds}});
  138. //清除单价文件
  139. await unitPriceFileModel.remove({id: {$in: junkUFIds}});
  140. //清除费率文件
  141. await feeRateFileModel.remove({feeRateID: {$in: junkFFIds}});
  142. } else {
  143. console.log(err);
  144. }
  145. if(callback) callback(err);
  146. });
  147. }
  148. else {
  149. if(callback) callback(0);
  150. }
  151. }
  152. //删除假删除数据
  153. /*
  154. * 1.之前的删除造价书数据,都是做的假删除,这部分数据会一直存在并且随着项目重复使用越来越多,现要改为真删除,所以做这个清除功能。
  155. * 2.原假删除包括清单的所有类型(大项费用、分部、分项、补项、清单)、定额的所有类型(定额、数量单价、与定额同级的人材机)
  156. * */
  157. async function clearFakeData(callback) {
  158. let functions = [];
  159. //删除清单
  160. functions.push(function (cb) {
  161. billsModel.remove({deleteInfo: {$exists: true}}, cb);
  162. });
  163. //删除定额
  164. functions.push(function (cb) {
  165. rationModel.remove({deleteInfo: {$exists: true}}, cb);
  166. });
  167. //删除补充定额章节树
  168. functions.push(function (cb) {
  169. compleRationSection.remove({deleteInfo: {$exists: true}}, cb);
  170. });
  171. async.parallel(functions, async function(err, result){
  172. if(callback){
  173. callback(err);
  174. }
  175. });
  176. }
  177. const sysSchedule = {
  178. clearJunkData,
  179. clearFakeData
  180. };
  181. //export {sysSchedule as default}
  182. module.exports = sysSchedule;