Browse Source

变更概况页面,统计计算错误

maixinrong 5 years ago
parent
commit
b3fce2e1ca
2 changed files with 6 additions and 5 deletions
  1. 1 1
      app/service/change.js
  2. 5 4
      app/service/stage_change.js

+ 1 - 1
app/service/change.js

@@ -865,7 +865,7 @@ module.exports = app => {
                 '        WHERE sChange.tid = ?' + filter +
                 '        GROUP By `lid`, `pid`, `cbid`, `sid`' +
                 '    ) As m' +
-                '    ON sc.stimes = m.stimes And sc.sorder = m.sorder And sc.`cbid` = m.`cbid` AND sc.`sid` = m.`sid`' +
+                '    ON sc.stimes = m.stimes And sc.sorder = m.sorder And sc.`cbid` = m.`cbid` AND sc.`sid` = m.`sid` And sc.`lid` = m.`lid` And sc.`pid` = m.`pid`' +
                 '    LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As cb ON sc.cbid = cb.id' +
                 '    GROUP By sc.`cbid`' +
                 '  ) As U ON C.cid = U.cid' +

+ 5 - 4
app/service/stage_change.js

@@ -86,7 +86,7 @@ module.exports = app => {
                 '      WHERE tid = ? And sid = ?' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid`' +
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid` And c.lid = m.lid And c.pid = m.pid' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
                 '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid];
@@ -102,7 +102,7 @@ module.exports = app => {
                 '      WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
                 '      GROUP By `lid`, `pid`' +
                 '  ) As m ' +
-                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid`' +
+                '  ON c.stimes = m.stimes And c.sorder = m.sorder And c.`sid` = m.`sid` And c.lid = m.lid And c.pid = m.pid' +
                 '  LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
                 '  ON c.cid = oc.cid';
             const sqlParam = [tid, sid, times, times, order];
@@ -299,17 +299,18 @@ module.exports = app => {
                         '  FROM ' + this.ctx.service.changeAuditList.tableName + ' As cb' +
                         '  LEFT JOIN ' + this.tableName + ' As c ON cb.id = c.cbid ' +
                         '  INNER JOIN (' +
-                        '    SELECT  MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, sChange.`sid`, `cid` ' +
+                        '    SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, sChange.`sid`, `cid` ' +
                         '      FROM ' + this.tableName + ' As sChange' +
                         '      LEFT JOIN ' + this.ctx.service.stage.tableName + ' As s ON sChange.sid = s.id' +
                         '      WHERE sChange.tid = ? AND cid = ?' + filter +
                         '      GROUP By `lid`, `pid`, `cbid`, sChange.`sid`' +
                         '  ) As m' +
-                        '  ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.`cbid` = m.`cbid` AND c.`sid` = m.`sid` And c.`cid` = m.`cid`' +
+                        '  ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.`cbid` = m.`cbid` AND c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`lid` = m.`lid` And c.`pid` = m.`pid`' +
                         '  WHERE cb.cid = ?' +
                         '  GROUP By c.`cbid`';
             const sqlParam = [tid, cid, cid];
 
+            console.log(this.db.format(sql, sqlParam));
             return await this.db.query(sql, sqlParam);
         }