Sfoglia il codice sorgente

变更清单,统计已使用数量sql调整

maixinrong 5 anni fa
parent
commit
31b1fca55a
1 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. 5 3
      app/service/change.js

+ 5 - 3
app/service/change.js

@@ -794,6 +794,7 @@ module.exports = app => {
          * @returns {Promise<*>} - 可用的变更令列表
          */
         async getValidChanges(tid, bills, pos) {
+            const timesLen = 100;
             const filter = 'cb.`code` = ' + this.db.escape(bills.b_code) + (pos ? ' And cb.`bwmx` = ' + this.db.escape(pos.name) : '');
             const sql = 'SELECT c.cid, c.code, c.name, c.w_code, c.p_code, c.peg, c.org_name, c.org_code, c.new_name, c.new_code,' +
                         '    c.content, c.basis, c.memo, c.type, c.class, c.quality, c.company, c.charge, ' +
@@ -804,17 +805,18 @@ module.exports = app => {
                         '  Left Join (' +
                         '    SELECT SUM(sc.qty) As used_amount, sc.cbid' +
                         '      FROM ' + this.ctx.service.stageChange.tableName + ' As sc' +
-                        '      INNER JOIN (SELECT Max(stimes) As `stimes`, Max(sorder) As `sorder`, cbid ' +
+                        '      INNER JOIN (SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, cbid, sid ' +
                         '        FROM ' + this.ctx.service.stageChange.tableName +
                         '        WHERE tid = ?' +
-                        '        GROUP BY cbid' +
+                        '        GROUP BY cbid, sid' +
                         '      ) As MF' +
-                        '      ON sc.stimes = MF.stimes And sc.sorder = MF.sorder And sc.cbid = MF.cbid' +
+                        '      ON (sc.stimes * ' + timesLen + ' + sc.sorder) = MF.flow And sc.cbid = MF.cbid And sc.sid = MF.sid' +
                         '    GROUP BY sc.cbid' +
                         '  ) As scb ON cb.id = scb.cbid' +
                         '  WHERE c.tid = ? And c.status = ? And c.valid And ' + filter +
                         '  ORDER BY c.in_time';
             const sqlParam = [tid, tid, audit.flow.status.checked];
+            console.log(this.db.format(sql, sqlParam));
             const changes = await this.db.query(sql, sqlParam);
             for (const c of changes) {
                 const aSql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +