Browse Source

1. 工作台、待办,安全计量,创建时间取值调整
2. 安全计量,报表数据源

MaiXinRong 1 day ago
parent
commit
f760274650

+ 134 - 0
app/lib/rm/safe_stage.js

@@ -0,0 +1,134 @@
+'use strict';
+
+/**
+ *
+ *
+ * @author Mai
+ * @date
+ * @version
+ */
+
+const RptMemBase = require('./base');
+const bindData = {};
+const Ledger = require('../ledger');
+
+class rptMemChange extends RptMemBase {
+    constructor(ctx) {
+        super(ctx, bindData);
+    }
+
+    async doCheckSafeStage(stage_id) {
+        if (this.ctx.safeStage) return;
+        this.ctx.safeStage = await this.ctx.service.safeStage.getDataById(stage_id);
+    }
+
+    async doCheckTender(tenderId) {
+        if (this.ctx.tender) return;
+        this.ctx.tender = { id: tenderId };
+        this.ctx.tender.data = await this.ctx.service.tender.getTender(tenderId);
+        this.ctx.tender.info = await this.ctx.service.tenderInfo.getTenderInfo(tenderId);
+    }
+
+    async doBeforeLoadReport(params) {
+        await this.doCheckSafeStage(params.safe_stage_id);
+        await this.doCheckTender(this.ctx.safeStage.tid);
+    }
+
+    async getSafeBills() {
+        const bills = this.ctx.detail.readOnly
+            ? await this.ctx.service.safeStageBills.getReadData(this.ctx.safeStage)
+            : await this.ctx.service.safeStageBills.getEditData(this.ctx.safeStage);
+        const setting = {
+            id: 'tree_id',
+            pid: 'tree_pid',
+            order: 'tree_order',
+            level: 'tree_level',
+            isLeaf: 'tree_is_leaf',
+            fullPath: 'tree_full_path',
+            rootId: -1,
+            calcFields: ['pre_tp', 'cur_tp', 'end_tp'],
+        };
+        const billsTree = new Ledger.billsTree(this.ctx, setting);
+        billsTree.loadDatas(bills);
+        billsTree.calculateAll();
+        return billsTree.getDefaultDatas();
+    }
+    _analysisCompareData(datas, roles){
+        const findHis = function (role, history) {
+            let his = null;
+            for (const h of history) {
+                if (h.times < role.times || (h.audit_times === role.audit_times && h.active_order <= role.active_order)) {
+                    his = h;
+                } else {
+                    break;
+                }
+            }
+            return his;
+        };
+        for (const d of datas) {
+            if (!d.tree_is_leaf) continue;
+            d.his_qty = [];
+            d.his_tp = [];
+            d.cur_his.sort((x, y) => { return x.audit_times === y.audit_times ? x.active_order - y.active_order : x.audit_times - y.audit_times; });
+            for (const r of roles) {
+                if (r.latest) {
+                    d[`r_qty_${r.order}`] = d.cur_qty;
+                    d[`r_tp_${r.order}`] = d.cur_tp;
+                    d.his_qty.push(d.cur_qty);
+                    d.his_tp.push(d.cur_tp);
+                } else {
+                    const rHis = findHis(r, d.cur_his);
+                    if (rHis) {
+                        d[`r_qty_${r.order}`] = rHis.qty;
+                        d[`r_tp_${r.order}`] = rHis.tp;
+                    }
+                    d.his_qty.push(rHis ? rHis.qty : 0);
+                    d.his_tp.push(rHis ? rHis.tp : 0);
+                }
+            }
+        }
+    }
+    async getSafeBillsCompare() {
+        const bills = await this.ctx.service.safeStageBills.getCompareData(this.ctx.safeStage);
+        const roles = await this.ctx.service.safeStageAudit.getViewFlow(this.ctx.safeStage);
+        this._analysisCompareData(bills, roles);
+        const setting = {
+            id: 'tree_id',
+            pid: 'tree_pid',
+            order: 'tree_order',
+            level: 'tree_level',
+            isLeaf: 'tree_is_leaf',
+            fullPath: 'tree_full_path',
+            rootId: -1,
+        };
+        setting.calcFields = roles.map(x => { return `r_tp_${x.order}`});
+        setting.calcFields.push('pre_tp');
+        const compareTree = new Ledger.billsTree(this.ctx, setting);
+        compareTree.loadDatas(bills);
+        compareTree.calculateAll();
+        return compareTree.getDefaultDatas();
+    }
+
+    getCommonData(params, tableName, fields, customDefine, customSelect) {
+        switch (tableName) {
+            case 'mem_project':
+                return this.ctx.service.project.getDataByCondition({ id: this.ctx.session.sessionProject.id });
+            case 'mem_tender':
+                return [this.ctx.tender.data];
+            case 'mem_tender_info':
+                return [this.ctx.tender.info];
+            case 'mem_safe_stage':
+                return [this.ctx.safeStage];
+            case 'mem_safe_stage_audit':
+                return this.ctx.service.safeStageAudit.getFinalUniqAuditors(this.ctx.safeStage);
+            case 'mem_safe_stage_bills':
+                return this.getSafeBills();
+            case 'mem_safe_stage_bills_compare':
+                return this.getSafeBillsCompare();
+            default:
+                return [];
+        }
+    }
+}
+
+module.exports = rptMemChange;

+ 8 - 0
app/service/report.js

@@ -796,6 +796,14 @@ module.exports = app => {
             return rptAdvance.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
         }
 
+        // params = { safe_stage_id: uuid }
+        async safe_stage(params, sourceFilters, memFieldKeys, customDefine, customSelect) {
+            const RptSafeStage = require('../lib/rm/safe_stage');
+            const rptSafeStage = new RptSafeStage(this.ctx);
+
+            return rptSafeStage.getReportData(params, sourceFilters, memFieldKeys, customDefine, customSelect);
+        }
+
         async getReportData(source_type, params, sourceFilters, memFieldKeys, customDefine, customSelect) {
             this.clearReportCache();
             const sourceType = sourceTypeConst.sourceTypeData.find(x => { return x.id === source_type; });

+ 16 - 2
app/service/safe_stage_audit.js

@@ -43,7 +43,17 @@ module.exports = app => {
             const auditors = await this.getAuditors(safeStage.id, safeStage.audit_times); // 全部参与的审批人
             const result = [];
             auditors.forEach(x => {
-                if (result.findIndex(r => { return x.audit_id === r.audit_id && x.audit_order === x.audit_order; }) < 0) {
+                if (result.findIndex(r => { return x.audit_id === r.audit_id && x.audit_order === r.audit_order; }) < 0) {
+                    result.push(x);
+                }
+            });
+            return result;
+        }
+        async getFinalUniqAuditors(safeStage) {
+            const auditors = await this.getAuditors(safeStage.id, safeStage.audit_times); // 全部参与的审批人
+            const result = [];
+            auditors.forEach(x => {
+                if (auditors.findIndex(r => { return x.audit_id === r.audit_id && x.audit_order === x.audit_order && x.active_order > r.active_order}) < 0) {
                     result.push(x);
                 }
             });
@@ -118,7 +128,7 @@ module.exports = app => {
         async getAuditStage(auditorId, spid = '') {
             const spSql = spid ? ' and t.`spid` = "' + spid + '"' : '';
             const sql =
-                'SELECT sa.`audit_id`, sa.`audit_times`, sa.`audit_order`, sa.`tid`, sa.`stage_id`,' +
+                'SELECT sa.`audit_id`, sa.`audit_times`, sa.`audit_order`, sa.active_order, sa.`tid`, sa.`stage_id`,' +
                 '    s.`stage_order`, s.`stage_code`, s.`stage_date`, s.create_time,' +
                 '    t.`name`, t.`project_id`, t.`type`, t.`user_id`, t.`spid` ' +
                 `  FROM ${this.tableName} AS sa ` +
@@ -128,6 +138,10 @@ module.exports = app => {
                 '  ORDER BY sa.`create_time` DESC';
             const sqlParam = [auditorId, auditConst.common.status.checking];
             const result = await this.db.query(sql, sqlParam);
+            for (const r of result) {
+                const preAuditTime = await this.db.queryOne(`SELECT Max(audit_time) as audit_time FROM ${this.tableName} where stage_id = ? and audit_times = ? and active_order = ?`, [r.stage_id, r.audit_times, r.active_order]);
+                r.begin_time = preAuditTime.audit_time;
+            }
             return result;
         }
         /**

+ 1 - 1
app/view/dashboard/index.ejs

@@ -347,7 +347,7 @@
                                             <td><span class="bg-new-inspection text-new-payment badge text-width">安全计量</span></td>
                                             <td><a href="/sp/<%- ass.spid %>/safe/tender/<%- ass.tid %>/stage"><%- ass.name %></a> <a href="/sp/<%- ass.spid %>/safe/tender/<%- ass.tid %>/stage/<%- ass.stage_order %>/bills">第<%- ass.stage_order %>期</a></td>
                                             <td>第<%- ass.stage_order %>期</td>
-                                            <td><%- (ass.create_time ? ctx.moment(ass.create_time).format('YYYY/MM/DD HH:mm') : '') %></td>
+                                            <td><%- (ass.begin_time ? ctx.moment(ass.begin_time).format('YYYY/MM/DD HH:mm') : '') %></td>
                                             <td><a href="/sp/<%- ass.spid %>/safe/tender/<%- ass.tid %>/stage/<%- ass.stage_order %>/bills" class="btn btn-sm btn-table <%- (ass.audit_order === 0 ? 'btn-outline-warning text-warning' : 'btn-outline-primary') %>" role="button"><%- (ass.audit_order === 0 ? '重新上报' : '审批')%></a></td>
                                         </tr>
                                         <% } %>

+ 1 - 1
app/view/dashboard/workspace.ejs

@@ -455,7 +455,7 @@
                                                             <td><a href="/sp/<%- am.spid %>/dashboard"><%- am.sp_name %></a></td>
                                                             <td><a href="/sp/<%- am.spid %>/safe/tender/<%- am.tid %>/stage"><%- am.name %></a> <a href="/sp/<%- am.spid %>/safe/tender/<%- am.tid %>/stage/<%- am.stage_order %>/bills">第<%- am.stage_order %>期</a></td>
                                                             <td>第<%- am.stage_order %>期</td>
-                                                            <td><%- (am.create_time ? ctx.moment(am.create_time).format('YYYY/MM/DD HH:mm') : '') %></td>
+                                                            <td><%- (am.begin_time ? ctx.moment(am.begin_time).format('YYYY/MM/DD HH:mm') : '') %></td>
                                                             <td><a href="/sp/<%- am.spid %>/safe/tender/<%- am.tid %>/stage/<%- am.stage_order %>/bills" class="btn btn-sm btn-table <%- (am.audit_order === 0 ? 'btn-outline-warning text-warning' : 'btn-outline-primary') %>" role="button"><%- (am.audit_order === 0 ? '重新上报' : '审批')%></a></td>
                                                         </tr>
                                                     <% } %>