dashboard_stats.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. const auditConst = require('../const/audit');
  2. class DashboardStats {
  3. static async auditSet(ctx, allAudits, subProjects, dashboardStatus, type) {
  4. const audits = [];
  5. for (const t of allAudits) {
  6. const sp = subProjects.find(sp => sp.id === t.spid);
  7. if (sp) {
  8. t.sp_name = sp.name;
  9. t.start_audit = 0;
  10. let calcTime;
  11. let closeType = false;
  12. switch (type) {
  13. case 'ledger':
  14. calcTime = t.ledger_status === auditConst[type].status.checking ? t.begin_time : t.end_time;
  15. break;
  16. case 'revise':
  17. calcTime = t.status === auditConst[type].status.checking ? t.begin_time : t.end_time;
  18. break;
  19. case 'stage':
  20. calcTime = t.sstatus === auditConst[type].status.checkNo ? t.end_time : t.begin_time;
  21. break;
  22. case 'stageAss':
  23. calcTime = t.begin_time;
  24. break;
  25. case 'change':
  26. calcTime = t.begin_time ? t.begin_time : t.cin_time ? new Date(ctx.moment.unix(t.cin_time).format('YYYY-MM-DD HH:mm:ss')) : '';
  27. break;
  28. case 'changeProject':
  29. if (!sp.page_show.openChangeProject) closeType = true;
  30. calcTime = t.status !== auditConst[type].status.back ? t.begin_time : t.end_time;
  31. break;
  32. case 'changeApply':
  33. if (!sp.page_show.openChangeApply) closeType = true;
  34. calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
  35. break;
  36. case 'changePlan':
  37. if (!sp.page_show.openChangePlan) closeType = true;
  38. calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
  39. break;
  40. case 'material':
  41. if (!sp.page_show.openMaterial) closeType = true;
  42. calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
  43. break;
  44. case 'advance':
  45. calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.create_time : t.end_time;
  46. break;
  47. case 'payment':
  48. if (!sp.page_show.openPayment) closeType = true;
  49. calcTime = t.sstatus !== auditConst.stage.status.checkNo ? t.begin_time : t.end_time;
  50. break;
  51. case 'financial':
  52. if (!sp.page_show.openFinancial) closeType = true;
  53. calcTime = t.fpcstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
  54. break;
  55. case 'inspection':
  56. if (!sp.page_show.qualityInspection) closeType = true;
  57. calcTime = t.status !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
  58. break;
  59. case 'safeInspection':
  60. if (!sp.page_show.safeInspection) closeType = true;
  61. calcTime = t.status !== auditConst.inspection.status.checkNo ? t.begin_time : t.end_time;
  62. break;
  63. case 'safeStage':
  64. if (!sp.page_show.safePayment) closeType = true;
  65. calcTime = t.create_time;
  66. break;
  67. case 'phasePay':
  68. if (!sp.page_show.phasePay) closeType = true;
  69. calcTime = t.create_time;
  70. break;
  71. default:
  72. closeType = true;
  73. }
  74. if (closeType) continue;
  75. if (sp.page_show.openStageAudit) {
  76. const now = new Date();
  77. const calcDay = ctx.helper.calculateDaysBetween(now, calcTime);
  78. if (sp.page_show.stageAuditWorry && calcDay >= sp.page_show.stageAuditWorry) {
  79. t.start_audit = 2;
  80. dashboardStatus.worry += 1;
  81. } else if (sp.page_show.stageAuditEarly && calcDay >= sp.page_show.stageAuditEarly) {
  82. t.start_audit = 1;
  83. dashboardStatus.early += 1;
  84. }
  85. }
  86. const calcType = type === 'stageAss' ? 'stage' : type;
  87. dashboardStatus.shenpi[calcType] += 1;
  88. t.shenpi_time = calcTime;
  89. t.shenpi_type = type;
  90. dashboardStatus.dashboard += 1;
  91. audits.push(t);
  92. }
  93. }
  94. return audits;
  95. }
  96. }
  97. module.exports = DashboardStats;