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

feat: 项目详情增加预警查询的逻辑

lanjianrong 6 дней назад
Родитель
Сommit
80a75ff950

+ 19 - 3
app/controller/weapp_subp_controller.js

@@ -9,7 +9,7 @@
  */
 
 
-const measureType = require('../const/tender').measureType;
+const DashboardStats = require('../lib/dashboard_stats');
 
 module.exports = app => {
     class WeappSubpController extends app.BaseController {
@@ -41,7 +41,7 @@ module.exports = app => {
                     ctx.body = { code: -1, msg: '子项目不存在', data: null };
                     return;
                 }
-                const pageShow = subProject.page_show ? JSON.parse(subProject.page_show) : {};
+                const pageShow = ctx.service.subProject.getPageShow(subProject.page_show);
                 const auditList = [];
                 // 获取待审批的计量期列表
                 const auditStages = await ctx.service.stageAudit.getAuditStageByWap(ctx.session.sessionUser.id, subProjectId);
@@ -87,12 +87,28 @@ module.exports = app => {
                 //     const safeInspectionList = await ctx.service.safeInspectionAudit.getAuditInspectionByWap(ctx.session.sessionUser.id, subProjectId);
                 //     auditList.push(...(safeInspectionList.map(item => ({ ...item, type: 'safeInspection', subType: 'safeInspection' }))));
                 // }
+                // 与主页复用审批计时和预警阈值,避免前后端分别计算产生差异。
+                const dashboardStatus = { dashboard: 0, worry: 0, early: 0, shenpi: {} };
+                const pendingAudits = [];
+                const auditGroups = ctx.helper._.groupBy(auditList, 'subType');
+                for (const subType of Object.keys(auditGroups)) {
+                    dashboardStatus.shenpi[subType] = 0;
+                    const audits = await DashboardStats.auditSet(
+                        ctx,
+                        auditGroups[subType],
+                        [{ ...subProject, page_show: pageShow }],
+                        dashboardStatus,
+                        subType
+                    );
+                    pendingAudits.push(...audits);
+                }
+
                 // 获取消息列表
                 const msgList = await ctx.service.message.getMsgList(ctx.session.sessionProject.id, subProjectId, 1);
 
                 ctx.body = {
                     code: 0, msg: '', data: {
-                      auditList: ctx.helper._.orderBy(auditList, ['begin_time'], ['desc', 'asc']),
+                      auditList: ctx.helper._.orderBy(pendingAudits, ['start_audit', 'shenpi_time'], ['desc', 'asc']),
                       msgList,
                     },
                 };

+ 2 - 2
app/service/advance_audit.js

@@ -801,9 +801,9 @@ module.exports = app => {
         async getAuditAdvanceByWap(auditorId, spid = '') {
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
-                'SELECT ad.`id`, ad.`tid`, ad.`pay_ratio`, ad.`cur_amount`, ad.`prev_amount`, ad.`prev_total_amount`, ad.`type`, ad.`order`, ' +
+                'SELECT ad.`id`, ad.`tid`, ad.`pay_ratio`, ad.`cur_amount`, ad.`prev_amount`, ad.`prev_total_amount`, ad.`type`, ad.`order`, ad.`status` As `mstatus`, aa.`create_time`, aa.`end_time`, ' +
                 // '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
-                '    t.`name`, t.`project_id`, t.`user_id`,' +
+                '    t.`name`, t.`project_id`, t.`user_id`, t.`spid`,' +
                 '    ti.`deal_info`, ti.`deal_param` ' +
                 '  FROM ?? AS aa, ?? AS ad, ?? As t, ?? AS ti ' +
                 '  WHERE aa.`audit_id` = ? and aa.`status` = ?' +

+ 1 - 1
app/service/change_apply_audit.js

@@ -1406,7 +1406,7 @@ module.exports = app => {
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`caid`,' +
-                '    s.*,' +
+                '    s.*, s.`status` As `mstatus`, sa.`begin_time`, sa.`end_time`,' +
                 '    t.`name` as `t_name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid`, ' +
                 '    ti.`deal_info`, ti.`decimal` ' +
                 '  FROM ?? AS sa' +

+ 2 - 2
app/service/change_audit.js

@@ -332,8 +332,8 @@ module.exports = app => {
         async getAuditChangeByWap(uid, spid = '') {
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql = 'SELECT ca.`uid`, ca.`times`, ca.`usite`, ca.`usort`, ca.`tid`, ca.`cid`, ca.`sin_time`, ca.`begin_time`, ca.`name` As `caname`, ' +
-                '    c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`quality`, c.`total_price`,' +
-                '    t.`name`, t.`type`, t.`user_id`, ' +
+                '    c.`code` As `ccode`, c.`name` As `cname`, c.`status` As `cstatus`, c.`quality`, c.`total_price`, c.`cin_time`,' +
+                '    t.`name`, t.`type`, t.`user_id`, t.`spid`, ' +
                 '    ti.`deal_info`, ti.`decimal` ' +
                 '  FROM ?? AS ca, ?? AS c, ?? As t, ?? AS ti ' +
                 '  WHERE ca.`uid` = ? and ca.`status` = ? and (c.`status` = ? or c.`status` = ?)' +

+ 1 - 1
app/service/change_plan_audit.js

@@ -738,7 +738,7 @@ module.exports = app => {
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`cpid`,' +
-                '    s.*,' +
+                '    s.*, s.`status` As `mstatus`, sa.`begin_time`, sa.`end_time`,' +
                 '    t.`name` as `t_name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid`,' +
                 '    ti.`deal_info`, ti.`decimal` ' +
                 '  FROM ?? AS sa' +

+ 1 - 1
app/service/change_project_audit.js

@@ -1550,7 +1550,7 @@ module.exports = app => {
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`cpid`,' +
-                '    s.*,' +
+                '    s.*, s.`status` As `mstatus`, sa.`begin_time`, sa.`end_time`,' +
                 '    t.`name` as `t_name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid`,' +
                 '    ti.`deal_info`, ti.`decimal` ' +
                 '  FROM ?? AS sa' +

+ 1 - 1
app/service/material_audit.js

@@ -1172,7 +1172,7 @@ module.exports = app => {
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`mid`,' +
                 // '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
-                '    s.*,' +
+                '    s.*, s.`status` As `mstatus`, sa.`begin_time`, sa.`end_time`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid`,' +
                 '    ti.`deal_info` ' +
                 '  FROM ?? AS sa' +

+ 1 - 1
app/service/stage_audit.js

@@ -1901,7 +1901,7 @@ module.exports = app => {
             const sql =
                 'SELECT sa.`aid`, sa.`times`, sa.`begin_time`, sa.`end_time`, sa.`tid`, sa.`sid`,' +
                 // '    s.`order` As `sorder`, s.`status` As `sstatus`, s.`s_time`, s.`contract_tp`, s.`qc_tp`, s.`pre_contract_tp`, s.`pre_qc_tp`, s.`yf_tp`, s.`pre_yf_tp`, ' +
-                '    s.*,' +
+                '    s.*, s.`status` As `sstatus`, sa.`begin_time`, sa.`end_time`,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid`,' +
                 '    ti.`deal_info` ' +
                 '  FROM ?? AS sa' +