|
@@ -36,22 +36,24 @@ module.exports = app => {
|
|
|
* @param {Number} pid - 部位明细id
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getLastestStageData(tid, sid, lid, pid) {
|
|
|
+ async getLastestStageData(tid, sid, lid, pid, noValue) {
|
|
|
+ const filter = noValue !== undefined ? 'And no_value = ?' : '';
|
|
|
const sql = 'SELECT c.*,' +
|
|
|
' oc.p_code As c_code, oc.new_code As c_new_code' +
|
|
|
' FROM ' + this.tableName + ' As c ' +
|
|
|
' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
- ' WHERE tid = ? And sid = ? And lid = ? And pid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`, `cid`, `cbid`' +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
|
|
|
+ ' WHERE tid = ? And sid = ? And lid = ? And pid = ?' + filter +
|
|
|
+ ' GROUP By `lid`, `pid`, `cid`, `cbid`, `no_value`' +
|
|
|
' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
' ON c.cid = oc.cid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
|
' ON c.cbid = ocb.id' +
|
|
|
' WHERE not ISNULL(ocb.id)';
|
|
|
const sqlParam = [tid, sid, lid, pid ? pid : -1];
|
|
|
+ if (noValue !== undefined) sqlParam.push(noValue);
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -65,22 +67,24 @@ module.exports = app => {
|
|
|
* @param {Number} pid - 部位明细id
|
|
|
* @return {Promise<*>}
|
|
|
*/
|
|
|
- async getAuditorStageData(tid, sid, times, order, lid, pid) {
|
|
|
+ async getAuditorStageData(tid, sid, times, order, lid, pid, noValue) {
|
|
|
+ const filter = noValue !== undefined ? 'And no_value = ?' : '';
|
|
|
const sql = 'SELECT c.*,' +
|
|
|
' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
|
|
|
' FROM ' + this.tableName + ' As c ' +
|
|
|
' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
- ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`, cid, cbid' +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
|
|
|
+ ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' + filter +
|
|
|
+ ' GROUP By `lid`, `pid`, cid, cbid, no_value' +
|
|
|
' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
' ON c.cid = oc.cid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
|
' ON c.cbid = ocb.id' +
|
|
|
' WHERE not ISNULL(ocb.id)';
|
|
|
const sqlParam = [tid, sid, times, times, order, lid, pid ? pid : -1];
|
|
|
+ if (noValue !== undefined) sqlParam.push(noValue);
|
|
|
return await this.db.query(sql, sqlParam);
|
|
|
}
|
|
|
|
|
@@ -89,11 +93,11 @@ module.exports = app => {
|
|
|
' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
|
|
|
' FROM ' + this.tableName + ' As c ' +
|
|
|
' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
|
|
|
' WHERE tid = ? And sid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`, cid, cbid' +
|
|
|
+ ' GROUP By `lid`, `pid`, cid, cbid, no_value' +
|
|
|
' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
' ON c.cid = oc.cid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
@@ -108,11 +112,11 @@ module.exports = app => {
|
|
|
' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
|
|
|
' FROM ' + this.tableName + ' As c ' +
|
|
|
' INNER JOIN ( ' +
|
|
|
- ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid` From ' + this.tableName +
|
|
|
+ ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
|
|
|
' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
|
|
|
- ' GROUP By `lid`, `pid`, cid, cbid' +
|
|
|
+ ' GROUP By `lid`, `pid`, cid, cbid, no_value' +
|
|
|
' ) As m ' +
|
|
|
- ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid`' +
|
|
|
+ ' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.progress And c.lid = m.lid And c.pid = m.pid And c.`sid` = m.`sid` And c.`cid` = m.`cid` And c.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
|
|
|
' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
|
|
|
' ON c.cid = oc.cid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
|
|
@@ -129,15 +133,15 @@ module.exports = app => {
|
|
|
* @param {Array} changes - 调用的变更令
|
|
|
* @return {Promise<void>}
|
|
|
*/
|
|
|
- async billsChange(bills, changes) {
|
|
|
+ async billsChange(bills, noValue, changes) {
|
|
|
const self = this;
|
|
|
- function getNewChange(cid, cbid, times, order, qty, minus) {
|
|
|
+ function getNewChange(cid, cbid, times, order, qty, minus, no_value) {
|
|
|
return {
|
|
|
tid: self.ctx.tender.id, sid: self.ctx.stage.id,
|
|
|
lid: bills.id, pid: -1,
|
|
|
cid, cbid,
|
|
|
stimes: times, sorder: order,
|
|
|
- qty, minus
|
|
|
+ qty, minus, no_value,
|
|
|
};
|
|
|
}
|
|
|
const ledgerBills = await this.ctx.service.ledger.getDataById(bills.id);
|
|
@@ -146,7 +150,7 @@ module.exports = app => {
|
|
|
}
|
|
|
const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
|
|
|
// 获取原变更令
|
|
|
- const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, bills.id, -1);
|
|
|
+ const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, bills.id, -1, noValue);
|
|
|
// 获取更新数据
|
|
|
const updateChanges = [],
|
|
|
newChanges = [];
|
|
@@ -155,7 +159,7 @@ module.exports = app => {
|
|
|
const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
|
|
|
if (!nc || nc.qty !== oc.qty) {
|
|
|
const qty = nc ? this.round(nc.qty, precision.value) : null;
|
|
|
- const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus);
|
|
|
+ const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus, noValue);
|
|
|
billsQty = this.ctx.helper.add(billsQty, change.qty);
|
|
|
if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
|
|
|
change.id = oc.id;
|
|
@@ -170,7 +174,7 @@ module.exports = app => {
|
|
|
for (const c of changes) {
|
|
|
const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
|
|
|
if (!nc) {
|
|
|
- const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus);
|
|
|
+ const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus, noValue);
|
|
|
billsQty = this.ctx.helper.add(billsQty, change.qty);
|
|
|
newChanges.push(change);
|
|
|
}
|
|
@@ -185,7 +189,8 @@ module.exports = app => {
|
|
|
await transaction.update(this.tableName, c);
|
|
|
}
|
|
|
const stageBills = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, bills.id);
|
|
|
- await this.ctx.service.stageBills.updateStageBillsQty(transaction, ledgerBills, stageBills, { qc_qty: billsQty });
|
|
|
+ const sbUpdate = noValue ? {qc_minus_qty: billsQty} : {qc_qty: billsQty};
|
|
|
+ await this.ctx.service.stageBills.updateStageBillsQty(transaction, ledgerBills, stageBills, sbUpdate);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -202,15 +207,15 @@ module.exports = app => {
|
|
|
* @param {Array} changes - 调用的变更令
|
|
|
* @return {Promise<{}>}
|
|
|
*/
|
|
|
- async posChange(pos, changes) {
|
|
|
+ async posChange(pos, noValue, changes) {
|
|
|
const self = this;
|
|
|
- function getNewChange(cid, cbid, times, order, qty, minus) {
|
|
|
+ function getNewChange(cid, cbid, times, order, qty, minus, no_value) {
|
|
|
return {
|
|
|
tid: self.ctx.tender.id, sid: self.ctx.stage.id,
|
|
|
lid: pos.lid, pid: pos.id,
|
|
|
cid, cbid,
|
|
|
stimes: times, sorder: order,
|
|
|
- qty, minus
|
|
|
+ qty, minus, no_value,
|
|
|
};
|
|
|
}
|
|
|
const ledgerBills = await this.ctx.service.ledger.getDataById(pos.lid);
|
|
@@ -219,7 +224,7 @@ module.exports = app => {
|
|
|
}
|
|
|
const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
|
|
|
// 获取原变更令
|
|
|
- const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, pos.lid, pos.id);
|
|
|
+ const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, pos.lid, pos.id, noValue);
|
|
|
const updateChanges = [],
|
|
|
newChanges = [];
|
|
|
let posQty = 0;
|
|
@@ -227,7 +232,7 @@ module.exports = app => {
|
|
|
const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
|
|
|
if (!nc || nc.qty !== oc.qty) {
|
|
|
const qty = nc ? this.round(nc.qty, precision.value) : null;
|
|
|
- const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus);
|
|
|
+ const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus, noValue);
|
|
|
posQty = this.ctx.helper.add(posQty, change.qty);
|
|
|
if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
|
|
|
change.id = oc.id;
|
|
@@ -242,7 +247,7 @@ module.exports = app => {
|
|
|
for (const c of changes) {
|
|
|
const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
|
|
|
if (!nc) {
|
|
|
- const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus);
|
|
|
+ const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus, noValue);
|
|
|
posQty = this.ctx.helper.add(posQty, change.qty);
|
|
|
newChanges.push(change);
|
|
|
}
|
|
@@ -252,7 +257,7 @@ module.exports = app => {
|
|
|
try {
|
|
|
if (newChanges.length > 0) await transaction.insert(this.tableName, newChanges);
|
|
|
if (updateChanges.length > 0) await transaction.updateRows(this.tableName, updateChanges);
|
|
|
- await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty);
|
|
|
+ await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty, noValue);
|
|
|
await transaction.commit();
|
|
|
} catch (err) {
|
|
|
await transaction.rollback();
|
|
@@ -292,7 +297,7 @@ module.exports = app => {
|
|
|
const pre = await this.db.query(preSql, [tid, cid, this.ctx.stage.order]);
|
|
|
const sql = 'SELECT * FROM ' + this.tableName + ' WHERE sid = ?';
|
|
|
const curAll = await this.db.query(sql, [this.ctx.stage.id]);
|
|
|
- const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cid', 'cbid'], 'stimes', 'sorder');
|
|
|
+ const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
|
|
|
return [...pre, ...cur];
|
|
|
}
|
|
|
}
|
|
@@ -317,7 +322,7 @@ module.exports = app => {
|
|
|
const pre = await this.db.query(preSql, [tid, cid, stage.order]);
|
|
|
const sql = 'SELECT * FROM ' + this.tableName + ' WHERE sid = ? and cid = ?';
|
|
|
const curAll = await this.db.query(sql, [stage.id, cid]);
|
|
|
- const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cid', 'cbid'], 'stimes', 'sorder');
|
|
|
+ const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
|
|
|
return [...pre, ...cur];
|
|
|
}
|
|
|
}
|
|
@@ -338,7 +343,7 @@ module.exports = app => {
|
|
|
' INNER JOIN ( ' +
|
|
|
' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `flow`, `lid`, `pid`, `cbid`, `sid` From ' + this.tableName +
|
|
|
' WHERE sid = ? And cid = ?' +
|
|
|
- ' GROUP By `lid`, `pid`, `cbid`' +
|
|
|
+ ' GROUP By `lid`, `pid`, `cbid`, `no_value`' +
|
|
|
' ) As m ' +
|
|
|
' ON (c.stimes * ' + timesLen + ' + c.sorder) = m.flow And c.lid = m.lid And c.pid = m.pid And c.cbid = m.cbid And c.sid = m.sid' +
|
|
|
' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' As l ON c.lid = l.id' +
|
|
@@ -355,13 +360,13 @@ module.exports = app => {
|
|
|
async getStageUsedChangeId(sid) {
|
|
|
const sql = 'SELECT lid, pid, cid, cbid, qty, stimes, sorder FROM ' + this.tableName + ' WHERE sid = ?';
|
|
|
const curAll = await this.db.query(sql, [sid]);
|
|
|
- const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cid', 'cbid'], 'stimes', 'sorder');
|
|
|
+ const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
|
|
|
return this._.map(this._.filter(cur, 'qty'), 'cid');
|
|
|
}
|
|
|
|
|
|
async getFinalStageData(tid, sid) {
|
|
|
const data = await this.getAllDataByCondition({ where: { tid, sid } });
|
|
|
- return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cid', 'cbid'], 'stimes', 'sorder');
|
|
|
+ return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
|
|
|
}
|
|
|
|
|
|
async getSumLoadFinalData(sid) {
|
|
@@ -370,7 +375,7 @@ module.exports = app => {
|
|
|
' Left Join ' + this.ctx.service.change.tableName + ' c ON cf.cid = c.cid' +
|
|
|
' Where cf.sid = ?';
|
|
|
const result = await this.db.query(sql, [sid]);
|
|
|
- return this.ctx.helper.filterLastestData(result, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
|
|
|
+ return this.ctx.helper.filterLastestData(result, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
|
|
|
}
|
|
|
|
|
|
async _getTender(stage) {
|
|
@@ -425,7 +430,7 @@ module.exports = app => {
|
|
|
const pre = await this.db.query(preSql, [stage.tid, stage.order]);
|
|
|
const sql = 'SELECT * FROM ' + this.tableName + ' WHERE sid = ? AND (stimes * 100 + sorder) <= (? * 100 + ?)';
|
|
|
const curAll = await this.db.query(sql, [stage.id, stage.curTimes, stage.curOrder]);
|
|
|
- const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cid', 'cbid'], 'stimes', 'sorder');
|
|
|
+ const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
|
|
|
return [...pre, ...cur];
|
|
|
}
|
|
|
}
|