Просмотр исходного кода

feat: 添加weapp仪表盘控制器及相关统计功能,整合审计数据

caipin 1 месяц назад
Родитель
Сommit
b0c1f9fc7e

+ 1 - 0
app/controller/dashboard_controller.js

@@ -84,6 +84,7 @@ module.exports = app => {
                 },
             };
             let noticeList = [];
+            console.log(ctx.session.sessionUser.accountId);
             // 还要考虑功能关闭不展示对应类型情况
             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) {

+ 7 - 5
app/controller/weapp_controller.js

@@ -8,6 +8,7 @@
  * @version
  */
 
+const DashboardStats = require('../lib/dashboard_stats');
 
 module.exports = app => {
     class WeappController extends app.BaseController {
@@ -99,16 +100,17 @@ module.exports = app => {
                     userName: ctx.projectAccount.name,
                     mobile: mobile.slice(0, 3) + '****' + mobile.slice(-4),
                 };
-                ctx.body = { code: 0, msg: '', data: {
-                    userInfo: projectAccount,
-                } };
+                ctx.body = {
+                    code: 0, msg: '', data: {
+                        userInfo: projectAccount,
+                    }
+                };
             } catch (error) {
                 this.log(error);
                 ctx.body = { code: -1, msg: '', data: null };
             }
         }
-
-
     }
+
     return WeappController;
 };

+ 75 - 0
app/controller/weapp_dashboard_controller.js

@@ -0,0 +1,75 @@
+'use strict';
+
+const DashboardStats = require('../lib/dashboard_stats');
+
+module.exports = app => {
+    class WeappDashboardController extends app.BaseController {
+        async workspace(ctx) {
+            try {
+                const allAuditTenders = await ctx.service.ledgerAudit.getAuditTender(ctx.projectAccount.id);
+                const allAuditStages = await ctx.service.stageAudit.getAuditStage(ctx.projectAccount.id);
+                const allAuditChanges = await ctx.service.changeAudit.getAuditChange(ctx.projectAccount.id);
+                const allAuditRevise = await ctx.service.reviseAudit.getAuditRevise(ctx.projectAccount.id);
+                const allAuditMaterial = await ctx.service.materialAudit.getAuditMaterial(ctx.projectAccount.id);
+                const allAuditAdvance = await ctx.service.advanceAudit.getAuditAdvance(ctx.projectAccount.id);
+                const allAuditChangeProject = await ctx.service.changeProjectAudit.getAuditChangeProject(ctx.projectAccount.id);
+                const allAuditChangeApply = await ctx.service.changeApplyAudit.getAuditChangeApply(ctx.projectAccount.id);
+                const allAuditChangePlan = await ctx.service.changePlanAudit.getAuditChangePlan(ctx.projectAccount.id);
+                const allAuditPayments = await ctx.service.paymentDetailAudit.getAuditPayment(ctx.projectAccount.id);
+                const allAuditStageAss = await ctx.service.stageAuditAss.getAuditStageAss(ctx.projectAccount.id);
+                const allAuditFinancials = await ctx.service.financialPayAudit.getAuditFinancial(ctx.projectAccount.id);
+                const allAuditInspections = await ctx.service.qualityInspectionAudit.getAuditInspection(ctx.projectAccount.id);
+                const allAuditSafeInspections = await ctx.service.safeInspectionAudit.getAuditInspection(ctx.projectAccount.id);
+                const allAuditSafeStage = await ctx.service.safeStageAudit.getAuditStage(ctx.projectAccount.id);
+                const allAuditPhasePay = await ctx.service.phasePayAudit.getAuditStage(ctx.projectAccount.id);
+
+                const dashboardStatus = {
+                    all: 0,
+                    dashboard: 0,
+                    worry: 0,
+                    early: 0
+                };
+                const subProjects = await ctx.service.subProject.getSubProject(ctx.projectAccount.project_id, ctx.projectAccount.id, ctx.projectAccount.is_admin, true);
+                for (const subProject of subProjects) {
+                    subProject.page_show = ctx.service.subProject.getPageShow(subProject.page_show);
+                }
+
+                await DashboardStats.auditSet(ctx, allAuditTenders, subProjects, dashboardStatus, 'ledger');
+                await DashboardStats.auditSet(ctx, allAuditStages, subProjects, dashboardStatus, 'stage');
+                await DashboardStats.auditSet(ctx, allAuditChanges, subProjects, dashboardStatus, 'change');
+                await DashboardStats.auditSet(ctx, allAuditRevise, subProjects, dashboardStatus, 'revise');
+                await DashboardStats.auditSet(ctx, allAuditMaterial, subProjects, dashboardStatus, 'material');
+                await DashboardStats.auditSet(ctx, allAuditAdvance, subProjects, dashboardStatus, 'advance');
+                await DashboardStats.auditSet(ctx, allAuditChangeProject, subProjects, dashboardStatus, 'changeProject');
+                await DashboardStats.auditSet(ctx, allAuditChangeApply, subProjects, dashboardStatus, 'changeApply');
+                await DashboardStats.auditSet(ctx, allAuditChangePlan, subProjects, dashboardStatus, 'changePlan');
+                await DashboardStats.auditSet(ctx, allAuditPayments, subProjects, dashboardStatus, 'payment');
+                await DashboardStats.auditSet(ctx, allAuditStageAss, subProjects, dashboardStatus, 'stageAss');
+                await DashboardStats.auditSet(ctx, allAuditFinancials, subProjects, dashboardStatus, 'financial');
+                await DashboardStats.auditSet(ctx, allAuditInspections, subProjects, dashboardStatus, 'inspection');
+                await DashboardStats.auditSet(ctx, allAuditSafeInspections, subProjects, dashboardStatus, 'safeInspection');
+                await DashboardStats.auditSet(ctx, allAuditSafeStage, subProjects, dashboardStatus, 'safeStage');
+                await DashboardStats.auditSet(ctx, allAuditPhasePay, subProjects, dashboardStatus, 'phasePay');
+
+                ctx.body = {
+                    code: 0,
+                    msg: '获取成功',
+                    data: {
+                        dashboardStatus: {
+                            all: dashboardStatus.all,
+                            dashboard: dashboardStatus.dashboard,
+                            worry: dashboardStatus.worry,
+                            early: dashboardStatus.early
+                        }
+                    }
+                };
+            } catch (error) {
+                this.log(error);
+                ctx.body = { code: -1, msg: error.toString(), data: null };
+            }
+        }
+
+    }
+
+    return WeappDashboardController;
+};

+ 100 - 0
app/lib/dashboard_stats.js

@@ -0,0 +1,100 @@
+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;

+ 1 - 1
app/router.js

@@ -1240,5 +1240,5 @@ module.exports = app => {
     app.get('/wx/weapp/getCaptcha', 'weappController.getCaptcha');
     app.get('/wx/weapp/refresh', 'weappController.refresh');
     app.get('/wx/weapp/userInfo', weappAuth, 'weappController.getUserInfo');
-
+    app.get('/wx/weapp/dashboard', weappAuth, 'weappDashboardController.workspace');
 };

+ 23 - 21
app/service/sub_proj_permission.js

@@ -40,12 +40,12 @@ module.exports = app => {
                     rela: { title: '关联标段', value: 1 },
                 },
                 info: {
-                    view: { title: '查看', value: 1},
+                    view: { title: '查看', value: 1 },
                     edit: { title: '编辑', value: 2 },
                     editfile: { title: '编辑文件', value: 3 },
                 },
                 datacollect: {
-                    view: { title: '查看', value: 1},
+                    view: { title: '查看', value: 1 },
                 },
                 contract: {
                     edit: { title: '编辑节点', value: 1 },
@@ -75,7 +75,8 @@ module.exports = app => {
             this.PermissionBlock = [
                 { key: 'datacollect', name: '决策大屏', field: 'datacollect_permission' },
                 { key: 'info', name: '项目概况', field: 'info_permission' },
-                { key: 'contract', name: '项目合同', field: 'contract_permission', hint: ['1、编辑节点:编辑合同管理内页树结构',
+                {
+                    key: 'contract', name: '项目合同', field: 'contract_permission', hint: ['1、编辑节点:编辑合同管理内页树结构',
                         '2、添加合同:允许添加合同',
                         '3、编辑合同:编辑非自己上传的合同信息',
                         '4、添加支付:给非自己上传的合同添加合同支付',
@@ -83,7 +84,8 @@ module.exports = app => {
                         '6、授权节点下查看本单位合同:授权节点下查看本单位人员添加的所有合同',
                         '7、查看所有合同:未授权节点情况下可以查看包括其他单位人员添加的合同',
                         '注:查看合同第5、6、7必须选择其一,否则无法查看本项目合同管理',
-                    ] },
+                    ]
+                },
                 { key: 'file', name: '资料管理', field: 'file_permission' },
                 { key: 'budget', name: '项目进度', field: 'budget_permission' },
                 {
@@ -101,7 +103,7 @@ module.exports = app => {
                         const pConst = this.PermissionConst[c.key];
                         if (!pConst) continue;
                         for (const prop in pConst) {
-                            c.permission.push({ key: prop, ...pConst[prop]});
+                            c.permission.push({ key: prop, ...pConst[prop] });
                         }
                     }
                 } else {
@@ -109,7 +111,7 @@ module.exports = app => {
                     const pConst = this.PermissionConst[p.key];
                     if (!pConst) continue;
                     for (const prop in pConst) {
-                        p.permission.push({ key: prop, ...pConst[prop]});
+                        p.permission.push({ key: prop, ...pConst[prop] });
                     }
                 }
             }
@@ -126,7 +128,7 @@ module.exports = app => {
             }
         }
 
-        get adminPermission () {
+        get adminPermission() {
             return {
                 budget_permission: this.ctx.helper.mapAllSubField(this.PermissionConst.budget, 'value'),
                 file_permission: this.ctx.helper.mapAllSubField(this.PermissionConst.file, 'value'),
@@ -169,7 +171,7 @@ module.exports = app => {
                 x.contract_permission = x.contract_permission ? _.map(x.contract_permission.split(','), _.toInteger) : [];
                 x.fund_pay_permission = x.fund_pay_permission ? _.map(x.fund_pay_permission.split(','), _.toInteger) : [];
                 x.fund_trans_permission = x.fund_trans_permission ? _.map(x.fund_trans_permission.split(','), _.toInteger) : [];
-                x.filing_type = x.filing_type ? _.map(x.filing_type.split(','), _.toInteger): [];
+                x.filing_type = x.filing_type ? _.map(x.filing_type.split(','), _.toInteger) : [];
                 x.payment_permission = x.payment_permission ? _.map(x.payment_permission.split(','), _.toInteger) : [];
             });
         }
@@ -190,9 +192,9 @@ module.exports = app => {
             return result;
         }
 
-        async getUserPermission(pid, uid) {
+        async getUserPermission(pid = this.ctx.session.sessionProject.id, uid = this.ctx.session.sessionUser.accountId) {
             const result = await this.getAllDataByCondition({
-                where: { uid: this.ctx.session.sessionUser.accountId, pid: this.ctx.session.sessionProject.id }
+                where: { uid, pid }
             });
             this.parsePermission(result);
             return result;
@@ -334,7 +336,7 @@ module.exports = app => {
                 // }
                 await conn.updateRows(this.tableName, updateData);
                 await conn.commit();
-            } catch(err) {
+            } catch (err) {
                 await conn.rollback();
                 throw err;
             }
@@ -342,7 +344,7 @@ module.exports = app => {
         }
 
         async _copyUserPermission(copyData, force = false) {
-            const copyPermission = await this.getAllDataByCondition({ where: { spid: this.ctx.subProject.id, uid: copyData.uid }});
+            const copyPermission = await this.getAllDataByCondition({ where: { spid: this.ctx.subProject.id, uid: copyData.uid } });
             if (copyPermission.length === 0) throw '选择的用户不存在';
 
             const insertData = [], updateData = [];
@@ -489,13 +491,13 @@ module.exports = app => {
 
         async getContractPermission(cp) {
             const permission = {
-                permission_edit: cp.indexOf(1) !== -1 ? 1: 0,
-                permission_add: cp.indexOf(2) !== -1 ? 1: 0,
-                permission_edit_contract: cp.indexOf(7) !== -1 ? 1: 0,
-                permission_add_pay: cp.indexOf(8) !== -1 ? 1: 0,
-                permission_show_node: cp.indexOf(3) !== -1 ? 1: 0,
-                permission_show_unit: cp.indexOf(4) !== -1 ? 1: 0,
-                permission_att: cp.indexOf(6) !== -1 ? 1: 0,
+                permission_edit: cp.indexOf(1) !== -1 ? 1 : 0,
+                permission_add: cp.indexOf(2) !== -1 ? 1 : 0,
+                permission_edit_contract: cp.indexOf(7) !== -1 ? 1 : 0,
+                permission_add_pay: cp.indexOf(8) !== -1 ? 1 : 0,
+                permission_show_node: cp.indexOf(3) !== -1 ? 1 : 0,
+                permission_show_unit: cp.indexOf(4) !== -1 ? 1 : 0,
+                permission_att: cp.indexOf(6) !== -1 ? 1 : 0,
             };
             return permission;
         }
@@ -540,7 +542,7 @@ module.exports = app => {
             return permission;
         }
 
-        async savePaymentPermissionAudits(spid, uids, operation = 'add', transaction= null) {
+        async savePaymentPermissionAudits(spid, uids, operation = 'add', transaction = null) {
             const updateArr = [];
             const spAudits = await this.getAllDataByCondition({ where: { spid: spid, uid: uids } });
             for (const a of spAudits) {
@@ -598,7 +600,7 @@ module.exports = app => {
             return list;
         }
 
-        async saveDatacollectPermissionAudits(spid, uids, operation = 'add', transaction= null) {
+        async saveDatacollectPermissionAudits(spid, uids, operation = 'add', transaction = null) {
             const updateArr = [];
             const spAudits = await this.getAllDataByCondition({ where: { spid: spid, uid: uids } });
             for (const a of spAudits) {