|
@@ -27,6 +27,249 @@ module.exports = app => {
|
|
|
* @param {Object} ctx - egg全局变量
|
|
|
* @return {void}
|
|
|
*/
|
|
|
+ async workspace(ctx) {
|
|
|
+ const allAuditTenders = await ctx.service.ledgerAudit.getAuditTender(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditStages = await ctx.service.stageAudit.getAuditStage(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditChanges = await ctx.service.changeAudit.getAuditChange(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditRevise = await ctx.service.reviseAudit.getAuditRevise(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditMaterial = await ctx.service.materialAudit.getAuditMaterial(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditAdvance = await ctx.service.advanceAudit.getAuditAdvance(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditChangeProject = await ctx.service.changeProjectAudit.getAuditChangeProject(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditChangeApply = await ctx.service.changeApplyAudit.getAuditChangeApply(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditChangePlan = await ctx.service.changePlanAudit.getAuditChangePlan(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditPayments = await ctx.service.paymentDetailAudit.getAuditPayment(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditStageAss = await ctx.service.stageAuditAss.getAuditStageAss(ctx.session.sessionUser.accountId);
|
|
|
+ const allAuditFinancials = await ctx.service.financialPayAudit.getAuditFinancial(ctx.session.sessionUser.accountId);
|
|
|
+ const pa = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiTenders = await ctx.service.ledgerAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiStages = await ctx.service.stageAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiChanges = await ctx.service.changeAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiRevise = await ctx.service.reviseAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiMaterial = await ctx.service.materialAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiAdvance = await ctx.service.advanceAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiChangeProject = await ctx.service.changeProjectAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiChangeApply = await ctx.service.changeApplyAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiChangePlan = await ctx.service.changePlanAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiPayment = await ctx.service.paymentDetailAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const auditShenpiFinancial = await ctx.service.financialPayAudit.getDonesByAudit(ctx.session.sessionUser.accountId);
|
|
|
+ const dashboardStatus = {
|
|
|
+ all: 0,
|
|
|
+ dashboard: 0,
|
|
|
+ worry: 0,
|
|
|
+ early: 0,
|
|
|
+ };
|
|
|
+ let noticeList = [];
|
|
|
+ // 还要考虑功能关闭不展示对应类型情况
|
|
|
+ const subProjects = await ctx.service.subProject.getSubProject(ctx.session.sessionProject.id, ctx.session.sessionUser.accountId, ctx.session.sessionUser.is_admin, true);
|
|
|
+ for (const subProject of subProjects) {
|
|
|
+ subProject.page_show = ctx.service.subProject.getPageShow(subProject.page_show);
|
|
|
+ const spTenders = ctx.helper._.filter(auditShenpiTenders, { spid: subProject.id });
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spTenders, 'shenpi_type', 'ledger'));
|
|
|
+ const spStages = ctx.helper._.filter(auditShenpiStages, { spid: subProject.id });
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spStages, 'shenpi_type', 'stage'));
|
|
|
+ const spChanges = ctx.helper._.filter(auditShenpiChanges, { spid: subProject.id });
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spChanges, 'shenpi_type', 'change'));
|
|
|
+ const spRevise = ctx.helper._.filter(auditShenpiRevise, { spid: subProject.id });
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spRevise, 'shenpi_type', 'revise'));
|
|
|
+ const spMaterial = subProject.page_show.openMaterial ? ctx.helper._.filter(auditShenpiMaterial, { spid: subProject.id }) : [];
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spMaterial, 'shenpi_type', 'material'));
|
|
|
+ const spAdvance = ctx.helper._.filter(auditShenpiAdvance, { spid: subProject.id });
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spAdvance, 'shenpi_type', 'advance'));
|
|
|
+ const spChangeProject = subProject.page_show.openChangeProject ? ctx.helper._.filter(auditShenpiChangeProject, { spid: subProject.id }) : [];
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spChangeProject, 'shenpi_type', 'changeProject'));
|
|
|
+ const spChangeApply = subProject.page_show.openChangeApply ? ctx.helper._.filter(auditShenpiChangeApply, { spid: subProject.id }) : [];
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spChangeApply, 'shenpi_type', 'changeApply'));
|
|
|
+ const spChangePlan = subProject.page_show.openChangePlan ? ctx.helper._.filter(auditShenpiChangePlan, { spid: subProject.id }) : [];
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spChangePlan, 'shenpi_type', 'changePlan'));
|
|
|
+ const spPayment = subProject.page_show.openPayment ? ctx.helper._.filter(auditShenpiPayment, { spid: subProject.id }) : [];
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spPayment, 'shenpi_type', 'payment'));
|
|
|
+ const spFinancial = subProject.page_show.openFinancial ? ctx.helper._.filter(auditShenpiFinancial, { spid: subProject.id }) : [];
|
|
|
+ noticeList.push(...ctx.helper.addKeyValue4ObjArray(spFinancial, 'shenpi_type', 'financial'));
|
|
|
+ }
|
|
|
+ const noticeDayList = [];
|
|
|
+ noticeList = ctx.helper._.orderBy(noticeList, ['shenpi_time'], ['desc']);
|
|
|
+ for (const notice of noticeList) {
|
|
|
+ const noticeDay = moment(new Date(notice.shenpi_time)).format('YYYY-MM-DD');
|
|
|
+ if (noticeDayList.indexOf(noticeDay) === -1) noticeDayList.push(noticeDay);
|
|
|
+ }
|
|
|
+ // 审批时间状态提示,0:无预警,1,预警(当前时间大于创建时间常高于stageAuditEarly天时,触发提示),2,紧急(当前时间大于审批发起时常高于stageAuditWorry天时,触发提示)
|
|
|
+ const auditTenders = await this.auditSet(ctx, allAuditTenders, subProjects, dashboardStatus, 'ledger');
|
|
|
+ const auditStages = await this.auditSet(ctx, allAuditStages, subProjects, dashboardStatus, 'stage');
|
|
|
+ const auditChanges = await this.auditSet(ctx, allAuditChanges, subProjects, dashboardStatus, 'change');
|
|
|
+ const auditRevise = await this.auditSet(ctx, allAuditRevise, subProjects, dashboardStatus, 'revise');
|
|
|
+ const auditMaterial = await this.auditSet(ctx, allAuditMaterial, subProjects, dashboardStatus, 'material');
|
|
|
+ const auditAdvance = await this.auditSet(ctx, allAuditAdvance, subProjects, dashboardStatus, 'advance');
|
|
|
+ const auditChangeProject = await this.auditSet(ctx, allAuditChangeProject, subProjects, dashboardStatus, 'changeProject');
|
|
|
+ const auditChangeApply = await this.auditSet(ctx, allAuditChangeApply, subProjects, dashboardStatus, 'changeApply');
|
|
|
+ const auditChangePlan = await this.auditSet(ctx, allAuditChangePlan, subProjects, dashboardStatus, 'changePlan');
|
|
|
+ const auditPayments = await this.auditSet(ctx, allAuditPayments, subProjects, dashboardStatus, 'payment');
|
|
|
+ const auditStageAss = await this.auditSet(ctx, allAuditStageAss, subProjects, dashboardStatus, 'stageAss');
|
|
|
+ const auditFinancials = await this.auditSet(ctx, allAuditFinancials, subProjects, dashboardStatus, 'financial');
|
|
|
+ const projectData = await ctx.service.project.getDataById(ctx.session.sessionProject.id);
|
|
|
+ // 获取销售人员数据
|
|
|
+ const salesmanData = await ctx.service.manager.getDataById(projectData.manager_id);
|
|
|
+ const officeName = officeList[salesmanData.office];
|
|
|
+ // 获取版本信息
|
|
|
+ const versionList = await ctx.service.version.getAllDataByCondition({ orders: [['id', 'desc']], limit: 5, offset: 0 });
|
|
|
+ // 获取项目通知
|
|
|
+ const msgList = await ctx.service.message.getMsgList(ctx.session.sessionProject.id);
|
|
|
+ // 获取系统通知
|
|
|
+ const sysMsgList = await ctx.service.message.getMsgList(ctx.session.sessionProject.id, '', 1, 0, 2);
|
|
|
+ // 获取系统维护信息
|
|
|
+ const maintainData = await ctx.service.maintain.getDataById(1);
|
|
|
+ const renderData = {
|
|
|
+ auditTenders,
|
|
|
+ auditStages,
|
|
|
+ auditChanges,
|
|
|
+ auditRevise,
|
|
|
+ auditMaterial,
|
|
|
+ auditAdvance,
|
|
|
+ auditChangeProject,
|
|
|
+ auditChangeApply,
|
|
|
+ auditChangePlan,
|
|
|
+ auditPayments,
|
|
|
+ auditStageAss,
|
|
|
+ auditFinancials,
|
|
|
+ dashboardStatus,
|
|
|
+ role: pa.role,
|
|
|
+ authMobile: pa.auth_mobile,
|
|
|
+ acLedger: auditConst.ledger,
|
|
|
+ acStage: auditConst.stage,
|
|
|
+ acChange: auditConst.change,
|
|
|
+ acRevise: auditConst.revise,
|
|
|
+ acMaterial: auditConst.material,
|
|
|
+ acAdvance: auditConst.advance,
|
|
|
+ acChangeProject: auditConst.changeProject,
|
|
|
+ acChangeApply: auditConst.changeApply,
|
|
|
+ acChangePlan: auditConst.changeApply,
|
|
|
+ acFinancial: auditConst.financial,
|
|
|
+ noticeList,
|
|
|
+ noticeDayList,
|
|
|
+ pushType: auditConst.pushType,
|
|
|
+ projectData,
|
|
|
+ salesmanData,
|
|
|
+ officeName,
|
|
|
+ versionList: JSON.parse(JSON.stringify(versionList).replace(/\\r\\n/g, '<br>').replace(/\\"/g, '"').replace(/'/g, ''').replace(/\\t/g, '	')),
|
|
|
+ msgList: JSON.parse(JSON.stringify(msgList).replace(/\\r\\n/g, '<br>').replace(/\\"/g, '"').replace(/'/g, ''').replace(/\\t/g, '	')),
|
|
|
+ sysMsgList: JSON.parse(JSON.stringify(sysMsgList).replace(/\\r\\n/g, '<br>').replace(/\\"/g, '"').replace(/'/g, ''').replace(/\\t/g, '	')),
|
|
|
+ uid: ctx.session.sessionUser.accountId,
|
|
|
+ maintainData,
|
|
|
+ maintainConst,
|
|
|
+ typeColMap,
|
|
|
+ jsFiles: this.app.jsFiles.common.concat(this.app.jsFiles.dashboard.workspace),
|
|
|
+ };
|
|
|
+ await this.layout('dashboard/workspace.ejs', renderData, 'dashboard/modal.ejs');
|
|
|
+ await ctx.service.projectAccount.defaultUpdate({
|
|
|
+ id: this.ctx.session.sessionUser.accountId,
|
|
|
+ last_notice: new Date(),
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ async loadTenders(ctx) {
|
|
|
+ try {
|
|
|
+ const responseData = { err: 0, msg: '', data: {} };
|
|
|
+ const subProjects = await ctx.service.subProject.getSubProject(ctx.session.sessionProject.id, ctx.session.sessionUser.accountId, ctx.session.sessionUser.is_admin, true);
|
|
|
+ const tenders = [];
|
|
|
+ const accountInfo = await ctx.service.projectAccount.getDataById(ctx.session.sessionUser.accountId);
|
|
|
+ const userPermission = accountInfo !== undefined && accountInfo.permission !== '' ? JSON.parse(accountInfo.permission) : null;
|
|
|
+ for (const subProject of subProjects) {
|
|
|
+ subProject.page_show = ctx.service.subProject.getPageShow(subProject.page_show);
|
|
|
+ // 获取每个项目下参与的标段
|
|
|
+ const subProjectTenders = await ctx.service.tender.getList('', userPermission, ctx.session.sessionUser.is_admin, '', subProject);
|
|
|
+ tenders.push(...subProjectTenders);
|
|
|
+ }
|
|
|
+ for (const t of tenders) {
|
|
|
+ // 用标段管理的方法获取t数据
|
|
|
+ await this.ctx.service.tenderCache.loadTenderCache(t, '');
|
|
|
+ t.total_price = t.ledger_tp && t.ledger_tp.total_price ? t.ledger_tp.total_price : 0;
|
|
|
+ // [t.change_tp, t.change_p_tp, t.change_n_tp, t.change_valuation_tp, t.change_unvaluation_tp] = await ctx.service.change.getChangeTp(t.id);
|
|
|
+ }
|
|
|
+ responseData.data.tenderList = tenders;
|
|
|
+ ctx.body = responseData;
|
|
|
+ } catch (err) {
|
|
|
+ this.log(err);
|
|
|
+ ctx.body = { err: 1, msg: err.toString(), data: null };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ 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 ? ctx.moment.unix(t.cin_time).format('YYYY/MM/DD HH:mm') : '';
|
|
|
+ break;
|
|
|
+ case 'changeProject':
|
|
|
+ if (!sp.page_show.openChangeProject) return [];
|
|
|
+ calcTime = t.status !== auditConst[type].status.back ? t.begin_time : t.end_time;
|
|
|
+ break;
|
|
|
+ case 'changeApply':
|
|
|
+ if (!sp.page_show.openChangeApply) return [];
|
|
|
+ calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
|
|
|
+ break;
|
|
|
+ case 'changePlan':
|
|
|
+ if (!sp.page_show.openChangePlan) return [];
|
|
|
+ calcTime = t.mstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
|
|
|
+ break;
|
|
|
+ case 'material':
|
|
|
+ if (!sp.page_show.openMaterial) return [];
|
|
|
+ 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) return [];
|
|
|
+ calcTime = t.sstatus !== auditConst.stage.status.checkNo ? t.begin_time : t.end_time;
|
|
|
+ break;
|
|
|
+ case 'financial':
|
|
|
+ if (!sp.page_show.openFinancial) return [];
|
|
|
+ calcTime = t.fpcstatus !== auditConst[type].status.checkNo ? t.begin_time : t.end_time;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dashboardStatus.dashboard += 1;
|
|
|
+ audits.push(t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return audits;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制面板页面
|
|
|
+ *
|
|
|
+ * @param {Object} ctx - egg全局变量
|
|
|
+ * @return {void}
|
|
|
+ */
|
|
|
async index(ctx) {
|
|
|
const auditTenders = await ctx.service.ledgerAudit.getAuditTender(ctx.session.sessionUser.accountId, ctx.subProject.id);
|
|
|
const auditStages = await ctx.service.stageAudit.getAuditStage(ctx.session.sessionUser.accountId, ctx.subProject.id);
|