| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- const auditConst = require('../const/audit');
- class DashboardStats {
- static async auditSet(ctx, allAudits, subProjects, dashboardStatus, type) {
- const audits = [];
- for (const t of allAudits) {
- const sp = subProjects.find(sp => sp.id === t.spid);
- if (sp) {
- t.sp_name = sp.name;
- t.start_audit = 0;
- let calcTime;
- let closeType = false;
- switch (type) {
- case 'ledger':
- calcTime = t.ledger_status === auditConst[type].status.checking ? t.begin_time : t.end_time;
- break;
- case 'revise':
- calcTime = t.status === auditConst[type].status.checking ? t.begin_time : t.end_time;
- break;
- case 'stage':
- calcTime = t.sstatus === auditConst[type].status.checkNo ? t.end_time : t.begin_time;
- break;
- case 'stageAss':
- calcTime = t.begin_time;
- break;
- case 'change':
- 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')) : '';
- break;
- case 'changeProject':
- if (!sp.page_show.openChangeProject) closeType = true;
- calcTime = t.status !== auditConst[type].status.back ? t.begin_time : t.end_time;
- break;
- case 'changeApply':
- if (!sp.page_show.openChangeApply) closeType = true;
- calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'changePlan':
- if (!sp.page_show.openChangePlan) closeType = true;
- calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'material':
- if (!sp.page_show.openMaterial) closeType = true;
- calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'advance':
- calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.create_time : t.end_time;
- break;
- case 'payment':
- if (!sp.page_show.openPayment) closeType = true;
- calcTime = t.sstatus !== auditConst.stage.status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'financial':
- if (!sp.page_show.openFinancial) closeType = true;
- calcTime = t.fpcstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'inspection':
- if (!sp.page_show.qualityInspection) closeType = true;
- calcTime = t.status !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'safeInspection':
- if (!sp.page_show.safeInspection) closeType = true;
- calcTime = t.status !== auditConst.inspection.status.checkNo ? t.begin_time : t.end_time;
- break;
- case 'safeStage':
- if (!sp.page_show.safePayment) closeType = true;
- calcTime = t.create_time;
- break;
- case 'phasePay':
- if (!sp.page_show.phasePay) closeType = true;
- calcTime = t.create_time;
- break;
- default:
- closeType = true;
- }
- if (closeType) continue;
- if (sp.page_show.openStageAudit) {
- const now = new Date();
- const calcDay = ctx.helper.calculateDaysBetween(now, calcTime);
- if (sp.page_show.stageAuditWorry && calcDay >= sp.page_show.stageAuditWorry) {
- t.start_audit = 2;
- dashboardStatus.worry += 1;
- } else if (sp.page_show.stageAuditEarly && calcDay >= sp.page_show.stageAuditEarly) {
- t.start_audit = 1;
- dashboardStatus.early += 1;
- }
- }
- const calcType = type === 'stageAss' ? 'stage' : type;
- dashboardStatus.shenpi[calcType] += 1;
- t.shenpi_time = calcTime;
- t.shenpi_type = type;
- dashboardStatus.dashboard += 1;
- audits.push(t);
- }
- }
- return audits;
- }
- }
- module.exports = DashboardStats;
|