|
@@ -10,6 +10,7 @@
|
|
|
|
|
|
const defaultPid = -1; // 非pid
|
|
|
const audit = require('../const/audit');
|
|
|
+const timesLen = 100;
|
|
|
|
|
|
module.exports = app => {
|
|
|
|
|
@@ -258,13 +259,13 @@ 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`) As `stimes`, MAX(`sorder`) As `sorder`, `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 = m.stimes And c.sorder = m.sorder 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`' +
|
|
|
' WHERE cb.cid = ?' +
|
|
|
' GROUP By c.`cbid`';
|
|
|
const sqlParam = [tid, cid, cid];
|
|
@@ -286,11 +287,11 @@ module.exports = app => {
|
|
|
' p.name As `p_name`, p.drawing_code As `p_drawing_code`, p.`quantity` As `p_qty`' +
|
|
|
' FROM ' + this.tableName + ' As c ' +
|
|
|
' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `cbid` From ' + this.tableName +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid` From ' + this.tableName +
|
|
|
' WHERE sid = ? And cid = ?' +
|
|
|
' GROUP By `lid`, `pid`, `cbid`' +
|
|
|
' ) As m ' +
|
|
|
- ' ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' As l ON c.lid = l.id' +
|
|
|
' LEFT JOIN ' + this.ctx.service.pos.tableName + ' As p ON c.pid = p.id';
|
|
|
const sqlParam = [sid, cid];
|
|
@@ -305,15 +306,15 @@ module.exports = app => {
|
|
|
async getStageUsedChangeId(sid) {
|
|
|
const sql = 'SELECT c.`cid` FROM ' + this.tableName + ' As c' +
|
|
|
' INNER JOIN (' +
|
|
|
- ' SELECT MAX(`stimes`) As `stimes`, MAX(`sorder`) As `sorder`, `lid`, `pid`, `cbid` From ' + this.tableName +
|
|
|
- ' WHERE sid = ? And not ISNULL(qty)' +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid` From ' + this.tableName +
|
|
|
+ ' WHERE sid = ?' +
|
|
|
' GROUP By `lid`, `pid`, `cbid`' +
|
|
|
' ) As m' +
|
|
|
- ' ON c.stimes = m.stimes And c.sorder = m.sorder And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid' +
|
|
|
' GROUP BY c.`cid`';
|
|
|
const sqlParam = [sid];
|
|
|
const result = await this.db.query(sql, sqlParam);
|
|
|
- return this._.map(result, 'cid');
|
|
|
+ return this._.map(this._.filter(result, 'qty'), 'cid');
|
|
|
}
|
|
|
}
|
|
|
|