Quellcode durchsuchen

计量台账,获取期计量数据调整

MaiXinRong vor 3 Jahren
Ursprung
Commit
3096a740d7
3 geänderte Dateien mit 26 neuen und 2 gelöschten Zeilen
  1. 0 1
      app/controller/stage_controller.js
  2. 25 0
      app/extend/helper.js
  3. 1 1
      app/service/stage_bills.js

+ 0 - 1
app/controller/stage_controller.js

@@ -787,7 +787,6 @@ module.exports = app => {
                 const result = await ctx.service.stageDetailAtt.addFiles(this.ctx.stage, baseInfo, uploadFiles);
                 ctx.body = { err: 0, mgs: '', data: result };
             } catch (err) {
-                console.log(err);
                 // 失败需要消耗掉stream 以防卡死
                 if (stream) await sendToWormhole(stream);
                 ctx.log(err);

+ 25 - 0
app/extend/helper.js

@@ -1290,6 +1290,31 @@ module.exports = {
         return result;
     },
 
+    filterLastestData2(data, keyFields, timesField = 'times', orderField = 'order') {
+        const dataIndex = {};
+        for (const d of data) {
+            let key = 'd';
+            for (const kf of keyFields) {
+                key = key + '.' + (d[kf] || '');
+            }
+
+            if (!dataIndex[key]) dataIndex[key] = { index: 0, source: [] };
+            const di = dataIndex[key];
+            const curIndex = d[timesField] * timesLen + d[orderField];
+            if (curIndex === di.index) {
+                di.source.push(d);
+            } else if (curIndex > di.index) {
+                di.index = curIndex;
+                di.source = [d];
+            }
+        }
+        const result = [];
+        for (const prop in dataIndex) {
+            result.push(...dataIndex[prop].source);
+        }
+        return result;
+    },
+
     calcExpr(expr) {
         const validExpr = expr.replace('=', '').replace('%', '/100');
         return math.eval(validExpr);

+ 1 - 1
app/service/stage_bills.js

@@ -110,7 +110,7 @@ module.exports = app => {
                 '  Where tid = ? and sid = ? ' + filterSql;
 
             const result = await this.db.query(sql, [tid, sid]);
-            const stageBills = this.ctx.helper.filterLastestData(result, ['lid']);
+            const stageBills = this.ctx.helper.filterLastestData2(result, ['lid']);
             if (!lid || lid instanceof Array) return stageBills;
             return stageBills[0];
         }