|
@@ -80,7 +80,7 @@ module.exports = app => {
|
|
|
' (SELECT * FROM '+ this.tableName + ' WHERE tid = ? And sid = ?) As Pos ' +
|
|
|
' INNER JOIN ( ' +
|
|
|
' SELECT MAX(`times` * ' + timesLen + ' + `order`) As `flow`, `pid`, `sid` From ' + this.tableName +
|
|
|
- ' WHERE `times` < ? OR (`times` = ? AND `order` <= ?) And tid = ? And sid = ?' + filterSql +
|
|
|
+ ' WHERE (`times` < ? OR (`times` = ? AND `order` <= ?)) And tid = ? And sid = ?' + filterSql +
|
|
|
' GROUP BY `pid`' +
|
|
|
' ) As MaxFilter ' +
|
|
|
' ON (Pos.times * ' + timesLen + ' + Pos.order) = MaxFilter.flow And Pos.pid = MaxFilter.pid And Pos.sid = MaxFilter.sid';
|
|
@@ -88,6 +88,42 @@ module.exports = app => {
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
|
+ async _filterLastestData(stagePos) {
|
|
|
+ const stagePosIndex = {};
|
|
|
+ for (const sp of stagePos) {
|
|
|
+ const key = 'sp-' + sp.pid;
|
|
|
+ const spi = stagePosIndex[key];
|
|
|
+ if (spi) {
|
|
|
+ if ((spi.times * timesLen + spi.order) < (sp.times * timesLen + spi.order)) stagePosIndex[key] = sp;
|
|
|
+ } else {
|
|
|
+ stagePosIndex[key] = spi;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const result = [];
|
|
|
+ for (const prop in stagePosIndex) {
|
|
|
+ if (stagePosIndex[prop] && stagePosIndex[prop].id) result.push(stagePosIndex[prop]);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ async getLastestStageData2(tid, sid, where) {
|
|
|
+ const filterSql = this._getPosFilterSql(where);
|
|
|
+ const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`' +
|
|
|
+ ' FROM ' + this.tableName +
|
|
|
+ ' WHERE tid = ? And sid = ? ' + filterSql;
|
|
|
+ const sqlParam = [tid, sid];
|
|
|
+ const stagePos = await this.db.query(sql, sqlParam);
|
|
|
+ return this._filterLastestData(stagePos);
|
|
|
+ }
|
|
|
+ async getAuditorStageData2(tid, sid, times, order, where) {
|
|
|
+ const filterSql = this._getPosFilterSql(where);
|
|
|
+ const sql = 'SELECT id, tid, sid, pid, lid, contract_qty, qc_qty, postil, `times`, `order`' +
|
|
|
+ ' FROM ' + this.tableName +
|
|
|
+ ' WHERE tid = ? And sid = ? And (`times` < ? OR (`times` = ? AND `order` <= ?)) ' + filterSql;
|
|
|
+ const sqlParam = [tid, sid, times, times, order];
|
|
|
+ const stagePos = await this.db.query(sql, sqlParam);
|
|
|
+ return this._filterLastestData(stagePos);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增部位明细数据(仅供updateStageData调用)
|
|
|
*
|
|
@@ -176,7 +212,7 @@ module.exports = app => {
|
|
|
const result = {ledger: [], pos: [], stageUpdate: true}, ledgerCalc = [];
|
|
|
const datas = data instanceof Array ? data : [data];
|
|
|
const orgPos = await this.ctx.service.pos.getPosDataByIds(this._.map(datas, 'pid'));
|
|
|
- const orgStagePos = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: this._.map(datas, 'pid')});
|
|
|
+ const orgStagePos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: this._.map(datas, 'pid')});
|
|
|
|
|
|
const transaction = await this.db.beginTransaction();
|
|
|
try {
|
|
@@ -325,7 +361,7 @@ module.exports = app => {
|
|
|
} else if (refreshData.pos.length > 0) {
|
|
|
result.pos.pos = await this.ctx.service.pos.getPosData({id: refreshData.pos});
|
|
|
if (refreshData.stageUpdate) {
|
|
|
- result.pos.curStageData = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: refreshData.pos});
|
|
|
+ result.pos.curStageData = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: refreshData.pos});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -336,7 +372,7 @@ module.exports = app => {
|
|
|
}
|
|
|
|
|
|
async updateChangeQuantity(transaction, pos, qty) {
|
|
|
- let orgPos = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
|
|
|
+ let orgPos = await this.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, {pid: pos.id});
|
|
|
if (orgPos.length > 1) {
|
|
|
throw '数据错误';
|
|
|
} else {
|