stage_change.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. 'use strict';
  2. /**
  3. * 期 - 变更数据
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. const defaultPid = -1; // 非pid
  10. const audit = require('../const/audit');
  11. const timesLen = audit.stage.timesLen;
  12. const changeConst = require('../const/change');
  13. class autoUseChange {
  14. constructor(helper, info, settleStatus) {
  15. this.helper = helper;
  16. this.precision = info.precision;
  17. this.decimal = info.decimal;
  18. this.settleStatus = settleStatus;
  19. this.insertBills = [];
  20. this.insertPos = [];
  21. this.updateBills = [];
  22. this.updatePos = [];
  23. this.insertChange = [];
  24. this.updateChange = [];
  25. this.changeBills = {};
  26. this.changePos = {};
  27. this.changeDetail = [];
  28. }
  29. init(source) {
  30. this.default = source.default;
  31. const LedgerModel = require('../lib/ledger');
  32. this.ledgerTree = new LedgerModel.billsTree(this.ctx, {
  33. id: 'ledger_id', pid: 'ledger_pid', order: 'order', level: 'level', rootId: -1, calcFields: [],
  34. });
  35. this.pos = new LedgerModel.pos({ id: 'id', ledgerId: 'lid' });
  36. this.ledgerTree.loadDatas(source.ledgerData);
  37. this.pos.loadDatas(source.posData);
  38. this.stageBills = source.stageBills;
  39. this.stagePos = source.stagePos;
  40. this.stageChange = source.stageChange || [];
  41. }
  42. findBillsPos(changeBills){
  43. if (changeBills.gcl_id) {
  44. const node = this.ledgerTree.datas.find(x => {return x.id === changeBills.gcl_id});
  45. if (node.settle_status === this.settleStatus.finish) return null;
  46. const posData = this.pos.getLedgerPos(node.id) || [];
  47. const changePos = posData.find(x => { return x.name === changeBills.bwmx; });
  48. if (changePos.settle_status) return null;
  49. let defaultPos;
  50. if (posData.length > 0) {
  51. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  52. if (!defaultPos) return null;
  53. } else {
  54. defaultPos = { id: '-1' };
  55. }
  56. return { bills: node, lid: node.id, pid: changePos ? changePos.id : defaultPos.id };
  57. } else {
  58. const cb = {
  59. b_code: changeBills.code || '',
  60. name: changeBills.name || '',
  61. unit: changeBills.unit || '',
  62. unit_price: changeBills.unit_price || 0,
  63. is_tp: false,
  64. };
  65. for (const node of this.ledgerTree.nodes) {
  66. if (node.children && node.children.length > 0) continue;
  67. if (node.settle_status === this.settleStatus.finish) return null;
  68. const b = {
  69. b_code: node.b_code || '',
  70. name: node.name || '',
  71. unit: node.unit || '',
  72. unit_price: node.unit_price || 0,
  73. is_tp: !!node.is_tp,
  74. };
  75. if (this.helper._.isMatch(cb, b)) {
  76. const posData = this.pos.getLedgerPos(node.id) || [];
  77. let defaultPos;
  78. if (posData.length > 0) {
  79. defaultPos = posData.length > 0 ? posData.find(x => { return !x.settle_status}) : null;
  80. if (!defaultPos) return null;
  81. } else {
  82. defaultPos = { id: '-1' };
  83. }
  84. return { bills: node, lid: node.id, pid: defaultPos.id };
  85. }
  86. }
  87. return null;
  88. }
  89. }
  90. useBills(bills) {
  91. if (bills.billsPos) bills.billsPos.bills = this.ledgerTree.datas.find(x => {return x.id === bills.billsPos.lid; });
  92. const billsPos = bills.billsPos || this.findBillsPos(bills);
  93. if (!billsPos) return;
  94. const bamount = parseFloat(bills.samount);
  95. const minus = bamount < 0;
  96. this.changeDetail.push({
  97. tid: this.default.tid, sid: this.default.sid,
  98. lid: billsPos.lid, pid: billsPos.pid + '', cid: bills.cid, cbid: bills.id,
  99. qty: bills.valid_qty, stimes: 1, sorder: 0, unit_price: bills.unit_price, minus, no_value: !bills.is_valuation,
  100. });
  101. if (!bills.is_valuation) return;
  102. if (billsPos.pid !== '-1') {
  103. let cp = this.changePos[billsPos.pid];
  104. if (!cp) {
  105. cp = { lid: billsPos.lid, pid: billsPos.pid, qty: 0, bills: billsPos.bills };
  106. this.changePos[billsPos.pid] = cp
  107. }
  108. cp.qty = this.helper.add(cp.qty, bills.valid_qty);
  109. if (minus) {
  110. cp.negative_qc_qty = cp.qty;
  111. } else {
  112. cp.positive_qc_qty = cp.qty;
  113. }
  114. } else {
  115. let cb = this.changeBills[billsPos.lid];
  116. if (!cb) {
  117. cb = { lid: billsPos.lid, qty: 0, bills: billsPos.bills };
  118. this.changeBills[billsPos.lid] = cb;
  119. }
  120. cb.qty = this.helper.add(cb.qty, bills.valid_qty);
  121. if (minus) {
  122. cb.negative_qc_qty = this.helper.add(cb.negative_qc_qty, bills.valid_qty);
  123. } else {
  124. cb.positive_qc_qty = this.helper.add(cb.positive_qc_qty, bills.valid_qty);
  125. }
  126. }
  127. }
  128. calculateAll() {
  129. for (const cd of this.changeDetail) {
  130. const sci = this.stageChange.findIndex(x => {
  131. return x.lid === cd.lid && x.pid === cd.pid && x.cbid === cd.cbid;
  132. });
  133. const sc = this.stageChange[sci];
  134. if (sc) {
  135. this.updateChange.push({ id: sc.id, qty: cd.qty });
  136. this.stageChange.splice(sci, 1);
  137. } else {
  138. this.insertChange.push(cd);
  139. }
  140. }
  141. for (const sc of this.stageChange) {
  142. if (sc.no_value) continue;
  143. const cp = this.changePos[sc.pid];
  144. if (cp) {
  145. cp.qty = this.helper.add(cp.qty, sc.qty);
  146. if (sc.minus) {
  147. cp.negative_qc_qty = this.helper.add(cp.negative_qc_qty, sc.qty);
  148. } else {
  149. cp.positive_qc_qty = this.helper.add(cp.positive_qc_qty, sc.qty);
  150. }
  151. }
  152. }
  153. for (const pid in this.changePos) {
  154. const cp = this.changePos[pid];
  155. if (!cp) continue;
  156. const precision = this.helper.findPrecision(this.precision, cp.bills.unit);
  157. const qc_qty = this.helper.round(cp.qty, precision.value);
  158. const positive_qc_qty = this.helper.round(cp.positive_qc_qty || 0, precision.value);
  159. const negative_qc_qty = this.helper.round(cp.negative_qc_qty || 0, precision.value);
  160. const sp = this.stagePos.find(x => {return x.pid === pid});
  161. if (sp) {
  162. this.updatePos.push({ id: sp.id, qc_qty, positive_qc_qty, negative_qc_qty });
  163. } else {
  164. this.insertPos.push({
  165. tid: this.default.tid, sid: this.default.sid, said: this.default.said,
  166. lid: cp.lid, pid, qc_qty, positive_qc_qty, negative_qc_qty, times: 1, order: 0
  167. });
  168. }
  169. const cb = this.changeBills[cp.lid];
  170. if (!cb) {
  171. this.changeBills[cp.lid] = { lid: cp.lid, qty: qc_qty, positive_qc_qty, negative_qc_qty, bills: cp.bills };
  172. } else {
  173. cb.qty = this.helper.add(cb.qty, qc_qty);
  174. cb.positive_qc_qty = this.helper.add(cb.positive_qc_qty, positive_qc_qty);
  175. cb.negative_qc_qty = this.helper.add(cb.negative_qc_qty, negative_qc_qty);
  176. }
  177. }
  178. for (const sc of this.stageChange) {
  179. if (sc.no_value) continue;
  180. const cp = this.changePos[sc.pid];
  181. if (cp) continue;
  182. const cb = this.changeBills[sc.lid];
  183. if (cb) {
  184. cb.qty = this.helper.add(cb.qty, sc.qty);
  185. if (sc.minus) {
  186. cb.negative_qc_qty = this.helper.add(cb.negative_qc_qty, sc.qty);
  187. } else {
  188. cb.positive_qc_qty = this.helper.add(cb.positive_qc_qty, sc.qty);
  189. }
  190. }
  191. }
  192. for (const lid in this.changeBills) {
  193. const cb = this.changeBills[lid];
  194. if (!cb) continue;
  195. const precision = this.helper.findPrecision(this.precision, cb.bills.unit);
  196. const qc_qty = this.helper.round(cb.qty, precision.value);
  197. const qc_tp = this.helper.mul(cb.qty, cb.bills.unit_price, this.decimal.tp);
  198. const positive_qc_qty = this.helper.round(cb.positive_qc_qty || 0, precision.value);
  199. const positive_qc_tp = this.helper.mul(positive_qc_qty, cb.bills.unit_price, this.decimal.tp);
  200. const negative_qc_qty = this.helper.round(cb.negative_qc_qty || 0, precision.value);
  201. const negative_qc_tp = this.helper.mul(negative_qc_qty, cb.bills.unit_price, this.decimal.tp);
  202. const sb = this.stageBills.find(x => {return x.lid === lid});
  203. if (sb) {
  204. this.updateBills.push({ id: sb.id, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp });
  205. } else {
  206. this.insertBills.push({
  207. tid: this.default.tid, sid: this.default.sid, said: this.default.said,
  208. lid, qc_qty, qc_tp, positive_qc_qty, positive_qc_tp, negative_qc_qty, negative_qc_tp, times: 1, order: 0
  209. });
  210. }
  211. }
  212. }
  213. use(source, validChangeBills) {
  214. this.init(source);
  215. for (const bills of validChangeBills) {
  216. this.useBills(bills);
  217. }
  218. this.calculateAll();
  219. }
  220. }
  221. module.exports = app => {
  222. class StageChange extends app.BaseService {
  223. /**
  224. * 构造函数
  225. *
  226. * @param {Object} ctx - egg全局变量
  227. * @return {void}
  228. */
  229. constructor(ctx) {
  230. super(ctx);
  231. this.tableName = 'stage_change';
  232. }
  233. /**
  234. * 查询 调用的变更令 最新数据
  235. * @param {Number} tid - 标段id
  236. * @param {Number} sid - 期id
  237. * @param {Number} lid - 台账节点id
  238. * @param {Number} pid - 部位明细id
  239. * @return {Promise<*>}
  240. */
  241. async getLastestStageData(tid, sid, lid, pid, noValue) {
  242. const filter = noValue !== undefined ? ' And no_value = ?' : '';
  243. const sql = 'SELECT c.*,' +
  244. ' oc.p_code As c_code, oc.new_code As c_new_code' +
  245. ' FROM ' + this.tableName + ' As c ' +
  246. ' INNER JOIN ( ' +
  247. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
  248. ' WHERE tid = ? And sid = ? And lid = ? And pid = ?' + filter +
  249. ' GROUP By `lid`, `pid`, `cbid`, `no_value`' +
  250. ' ) As m ' +
  251. ' 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.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
  252. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  253. ' ON c.cid = oc.cid' +
  254. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  255. ' ON c.cbid = ocb.id' +
  256. ' WHERE not ISNULL(ocb.id)';
  257. const sqlParam = [tid, sid, lid, pid ? pid : -1];
  258. if (noValue !== undefined) sqlParam.push(noValue);
  259. return await this.db.query(sql, sqlParam);
  260. }
  261. /**
  262. * 查询 调用的变更令 某轮 某人的数据
  263. * @param {Number} tid - 标段id
  264. * @param {Number} sid - 期id
  265. * @param {Number} times - 第几轮
  266. * @param {Number} order - 第几人
  267. * @param {Number} lid - 台账节点id
  268. * @param {Number} pid - 部位明细id
  269. * @return {Promise<*>}
  270. */
  271. async getAuditorStageData(tid, sid, times, order, lid, pid, noValue) {
  272. const filter = noValue !== undefined ? ' And no_value = ?' : '';
  273. const sql = 'SELECT c.*,' +
  274. ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
  275. ' FROM ' + this.tableName + ' As c ' +
  276. ' INNER JOIN ( ' +
  277. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
  278. ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?)) And lid = ? And pid = ?' + filter +
  279. ' GROUP By `lid`, `pid`, cbid, no_value' +
  280. ' ) As m ' +
  281. ' 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.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
  282. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  283. ' ON c.cid = oc.cid' +
  284. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  285. ' ON c.cbid = ocb.id' +
  286. ' WHERE not ISNULL(ocb.id)';
  287. const sqlParam = [tid, sid, times, times, order, lid, pid ? pid : -1];
  288. if (noValue !== undefined) sqlParam.push(noValue);
  289. return await this.db.query(sql, sqlParam);
  290. }
  291. async getLastestAllStageData(tid, sid) {
  292. const sql = 'SELECT c.*,' +
  293. ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
  294. ' FROM ' + this.tableName + ' As c ' +
  295. ' INNER JOIN ( ' +
  296. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
  297. ' WHERE tid = ? And sid = ?' +
  298. ' GROUP By `lid`, `pid`, cbid, no_value' +
  299. ' ) As m ' +
  300. ' 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.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
  301. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  302. ' ON c.cid = oc.cid' +
  303. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  304. ' ON c.cbid = ocb.id' +
  305. ' WHERE not ISNULL(ocb.id)';
  306. const sqlParam = [tid, sid];
  307. return await this.db.query(sql, sqlParam);
  308. }
  309. async getAuditorAllStageData(tid, sid, times, order) {
  310. const sql = 'SELECT c.*, ' +
  311. ' oc.p_code As c_code, oc.new_code As c_new_code, oc.quality, ocb.code as b_code, ocb.name, ocb.unit' +
  312. ' FROM ' + this.tableName + ' As c ' +
  313. ' INNER JOIN ( ' +
  314. ' SELECT MAX(`stimes` * ' + timesLen + ' + `sorder`) As `progress`, `lid`, `pid`, `sid`, `cid`, `cbid`, `no_value` From ' + this.tableName +
  315. ' WHERE tid = ? And sid = ? And (`stimes` < ? OR (`stimes` = ? AND `sorder` <= ?))' +
  316. ' GROUP By `lid`, `pid`, cbid, no_value' +
  317. ' ) As m ' +
  318. ' 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.`cbid` = m.`cbid` And c.`no_value` = m.`no_value`' +
  319. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' As oc' +
  320. ' ON c.cid = oc.cid' +
  321. ' LEFT JOIN ' + this.ctx.service.changeAuditList.tableName + ' As ocb' +
  322. ' ON c.cbid = ocb.id' +
  323. ' WHERE not ISNULL(ocb.id)';
  324. const sqlParam = [tid, sid, times, times, order];
  325. return await this.db.query(sql, sqlParam);
  326. }
  327. /**
  328. * 台账,调用变更令
  329. *
  330. * @param {Object} bills - 台账节点数据
  331. * @param {Array} changes - 调用的变更令
  332. * @return {Promise<void>}
  333. */
  334. async billsChange(bills, noValue, changes) {
  335. const self = this;
  336. function getNewChange(cid, cbid, times, order, qty, minus, no_value) {
  337. return {
  338. tid: self.ctx.tender.id, sid: self.ctx.stage.id,
  339. lid: bills.id, pid: -1,
  340. cid, cbid,
  341. stimes: times, sorder: order,
  342. qty, minus, no_value,
  343. };
  344. }
  345. const ledgerBills = await this.ctx.service.ledger.getCompleteDataById(bills.id);
  346. if (!ledgerBills || ledgerBills.tender_id !== this.ctx.tender.id) {
  347. throw '提交数据错误';
  348. }
  349. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
  350. // 获取原变更令
  351. const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, bills.id, -1, noValue);
  352. // 获取更新数据
  353. const updateChanges = [],
  354. newChanges = [];
  355. let billsQty = 0, billsPositiveQty = 0, billsNegativeQty = 0;
  356. for (const oc of oldChanges) {
  357. const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
  358. if (!nc || nc.qty !== oc.qty) {
  359. const qty = nc ? this.round(nc.qty, precision.value) : null;
  360. const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus, noValue);
  361. change.unit_price = ledgerBills.unit_price;
  362. billsQty = this.ctx.helper.add(billsQty, change.qty);
  363. if (change.minus) {
  364. billsNegativeQty = this.ctx.helper.add(billsNegativeQty, change.qty);
  365. } else {
  366. billsPositiveQty = this.ctx.helper.add(billsPositiveQty, change.qty);
  367. }
  368. if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
  369. change.id = oc.id;
  370. updateChanges.push(change);
  371. } else {
  372. newChanges.push(change);
  373. }
  374. } else {
  375. billsQty = this.ctx.helper.add(billsQty, oc.qty);
  376. if (oc.minus) {
  377. billsNegativeQty = this.ctx.helper.add(billsNegativeQty, oc.qty);
  378. } else {
  379. billsPositiveQty = this.ctx.helper.add(billsPositiveQty, oc.qty);
  380. }
  381. }
  382. }
  383. for (const c of changes) {
  384. const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
  385. if (!nc) {
  386. const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus, noValue);
  387. change.unit_price = ledgerBills.unit_price;
  388. billsQty = this.ctx.helper.add(billsQty, change.qty);
  389. if (change.minus) {
  390. billsNegativeQty = this.ctx.helper.add(billsNegativeQty, change.qty);
  391. } else {
  392. billsPositiveQty = this.ctx.helper.add(billsPositiveQty, change.qty);
  393. }
  394. newChanges.push(change);
  395. }
  396. }
  397. // 更新数据
  398. const transaction = await this.db.beginTransaction();
  399. try {
  400. if (newChanges.length > 0) await transaction.insert(this.tableName, newChanges);
  401. if (updateChanges.length > 0) await transaction.updateRows(this.tableName, updateChanges);
  402. const stageBills = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, bills.id);
  403. const sbUpdate = noValue
  404. ? { qc_minus_qty: billsQty }
  405. : { qc_qty: billsQty, positive_qc_qty: billsPositiveQty, negative_qc_qty: billsNegativeQty };
  406. await this.ctx.service.stageBills.updateStageBillsQty(transaction, ledgerBills, stageBills, sbUpdate);
  407. await transaction.commit();
  408. } catch (err) {
  409. await transaction.rollback();
  410. throw err;
  411. }
  412. const result = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, [bills.id]);
  413. return { bills: { curStageData: result } };
  414. }
  415. /**
  416. * 部位明细,调用变更令
  417. *
  418. * @param {Object} pos - 部位明细数据
  419. * @param {Array} changes - 调用的变更令
  420. * @return {Promise<{}>}
  421. */
  422. async posChange(pos, noValue, changes) {
  423. const self = this;
  424. function getNewChange(cid, cbid, times, order, qty, minus, no_value) {
  425. return {
  426. tid: self.ctx.tender.id, sid: self.ctx.stage.id,
  427. lid: pos.lid, pid: pos.id,
  428. cid, cbid,
  429. stimes: times, sorder: order,
  430. qty, minus, no_value,
  431. };
  432. }
  433. const ledgerBills = await this.ctx.service.ledger.getCompleteDataById(pos.lid);
  434. if (!ledgerBills || ledgerBills.tender_id !== this.ctx.tender.id) {
  435. throw '提交数据错误';
  436. }
  437. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, ledgerBills.unit);
  438. // 获取原变更令
  439. const oldChanges = await this.getLastestStageData(this.ctx.tender.id, this.ctx.stage.id, pos.lid, pos.id, noValue);
  440. const updateChanges = [],
  441. newChanges = [];
  442. let posQty = 0, posPositiveQty = 0, posNegativeQty = 0;
  443. for (const oc of oldChanges) {
  444. const nc = this._.find(changes, { cid: oc.cid, cbid: oc.cbid });
  445. if (!nc || nc.qty !== oc.qty) {
  446. const qty = nc ? this.round(nc.qty, precision.value) : null;
  447. const change = getNewChange(oc.cid, oc.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, qty, nc ? nc.minus : oc.minus, noValue);
  448. change.unit_price = ledgerBills.unit_price;
  449. posQty = this.ctx.helper.add(posQty, change.qty);
  450. if (change.minus) {
  451. posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);
  452. } else {
  453. posPositiveQty = this.ctx.helper.add(posPositiveQty, change.qty);
  454. }
  455. if (oc.stimes === this.ctx.stage.curTimes && oc.sorder === this.ctx.stage.curOrder) {
  456. change.id = oc.id;
  457. updateChanges.push(change);
  458. } else {
  459. newChanges.push(change);
  460. }
  461. } else {
  462. posQty = this.ctx.helper.add(posQty, oc.qty);
  463. if (oc.minus) {
  464. posNegativeQty = this.ctx.helper.add(posNegativeQty, oc.qty);
  465. } else {
  466. posPositiveQty = this.ctx.helper.add(posPositiveQty, oc.qty);
  467. }
  468. }
  469. }
  470. for (const c of changes) {
  471. const nc = this._.find(oldChanges, { cid: c.cid, cbid: c.cbid });
  472. if (!nc) {
  473. const change = getNewChange(c.cid, c.cbid, this.ctx.stage.curTimes, this.ctx.stage.curOrder, this.round(c.qty, precision.value), c.minus, noValue);
  474. change.unit_price = ledgerBills.unit_price;
  475. posQty = this.ctx.helper.add(posQty, change.qty);
  476. if (change.minus) {
  477. posNegativeQty = this.ctx.helper.add(posNegativeQty, change.qty);
  478. } else {
  479. posPositiveQty = this.ctx.helper.add(posPositiveQty, change.qty);
  480. }
  481. newChanges.push(change);
  482. }
  483. }
  484. // 更新数据
  485. const transaction = await this.db.beginTransaction();
  486. try {
  487. if (newChanges.length > 0) await transaction.insert(this.tableName, newChanges);
  488. if (updateChanges.length > 0) await transaction.updateRows(this.tableName, updateChanges);
  489. await this.ctx.service.stagePos.updateChangeQuantity(transaction, pos, posQty, noValue, posPositiveQty, posNegativeQty);
  490. await transaction.commit();
  491. } catch (err) {
  492. await transaction.rollback();
  493. throw err;
  494. }
  495. // 获取返回数据
  496. try {
  497. const data = { bills: {}, pos: {} };
  498. data.bills.curStageData = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, [pos.lid]);
  499. data.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, { pid: pos.id });
  500. return data;
  501. } catch (err) {
  502. throw '获取数据错误,请刷新页面';
  503. }
  504. }
  505. /**
  506. * 获取 变更令 - 变更清单 使用情况
  507. * @param {Number} sid - 查询期id
  508. * @param {uuid} cid - 变更令id
  509. * @return {Promise<void>}
  510. */
  511. async getUsedData(tid, cid) {
  512. if (this.ctx.stage.status === audit.stage.status.checked) {
  513. const sql = 'SELECT scf.* ' +
  514. ' FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
  515. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
  516. ' WHERE scf.tid = ? And scf.cid = ? And s.order <= ?';
  517. const result = await this.db.query(sql, [tid, cid, this.ctx.stage.order]);
  518. return result;
  519. } else {
  520. const preSql = 'SELECT scf.* ' +
  521. ' FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
  522. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
  523. ' WHERE scf.tid = ? And scf.cid = ? And s.order < ?';
  524. const pre = await this.db.query(preSql, [tid, cid, this.ctx.stage.order]);
  525. const sql = 'SELECT * FROM ' + this.tableName + ' WHERE sid = ?';
  526. const curAll = await this.db.query(sql, [this.ctx.stage.id]);
  527. const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
  528. return [...pre, ...cur];
  529. }
  530. }
  531. async getFinalUsedData(tid, cid) {
  532. const stage = await this.ctx.service.stage.getLastestStage(tid, true);
  533. if (!stage) { // 防止未创建期时调用
  534. return [];
  535. }
  536. if (stage.status === audit.stage.status.checked) {
  537. const sql = 'SELECT scf.* ' +
  538. ' FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
  539. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
  540. this.ctx.helper.whereSql({ tid, cid }, 'scf') + ' And s.order <= ?';
  541. const result = await this.db.query(sql, [stage.order]);
  542. return result;
  543. } else {
  544. const preSql = 'SELECT scf.* ' +
  545. ' FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
  546. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
  547. this.ctx.helper.whereSql({ tid, cid }, 'scf') + ' And s.order < ?';
  548. const pre = await this.db.query(preSql, [stage.order]);
  549. const sql = 'SELECT * FROM ' + this.tableName + this.ctx.helper.whereSql({ sid: stage.id, cid });
  550. const curAll = await this.db.query(sql);
  551. const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
  552. return [...pre, ...cur];
  553. }
  554. }
  555. /**
  556. * 获取 变更令 - 变更清单 当期使用情况
  557. * @param {Number} sid - 查询期id
  558. * @param {uuid} cid - 变更令id
  559. * @return {Promise<*>}
  560. */
  561. async getStageUsedData(sid, cid) {
  562. const data = await this.getAllDataByCondition({ where: { sid, cid } });
  563. const _ = this.ctx.helper._;
  564. const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
  565. if (filter.length === 0) return filter;
  566. const bills = await this.ctx.service.ledger.getAllDataByCondition({
  567. where: { id: _.uniq(_.map(filter, 'lid')) }
  568. });
  569. const pos = await this.ctx.service.pos.getAllDataByCondition({
  570. where: { id: _.uniq(_.map(filter, 'pid')) }
  571. });
  572. return filter.map(x => {
  573. const b = bills.find(y => { return y.id === x.lid });
  574. const rela_b = b
  575. ? {ledger_id: b ? b.ledger_id : -1, l_code: b.b_code, l_name: b.name, l_unit: b.unit, l_up: b.unit_price,
  576. l_deal_qty: b.deal_qty, l_deal_tp: b.deal_tp, l_qty: b.quantity, l_tp: b.total_price, l_drawing_code: b.drawing_code}
  577. : { ledger_id: -1, l_code: '', l_name: '', l_unit: '', l_up: 0, l_deal_qty: 0, l_deal_tp: 0, l_qty: 0, l_tp: 0, l_drawing_code: '' };
  578. const p = pos.find(y => { return y.id === x.pid });
  579. const rela_p = p ? { p_name: p.name, p_drawing_code: p.drawing_code, p_qty: p.quantity } : { p_name: '', p_drawing_code: '', p_qty: 0 };
  580. return { ...x, ...rela_b, ...rela_p };
  581. });
  582. }
  583. /**
  584. * 获取 本期 使用的变更令
  585. * @param sid
  586. * @return {Promise<void>}
  587. */
  588. async getStageUsedChangeId(sid) {
  589. const sql = 'SELECT lid, pid, cid, cbid, qty, stimes, sorder FROM ' + this.tableName + ' WHERE sid = ?';
  590. const curAll = await this.db.query(sql, [sid]);
  591. const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
  592. return this._.map(this._.filter(cur, 'qty'), 'cid');
  593. }
  594. async getFinalStageData(tid, sid) {
  595. const data = await this.getAllDataByCondition({ where: { tid, sid } });
  596. return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
  597. }
  598. async getSumLoadFinalData(sid) {
  599. const sql = 'Select cf.tid, cf.sid, cf.lid, cf.pid, cf.cid, cf.cbid, cf.qty, cf.stimes, cf.sorder, cf.minus, cf.no_value, c.code As c_code' +
  600. ' FROM ' + this.tableName + ' cf' +
  601. ' Left Join ' + this.ctx.service.change.tableName + ' c ON cf.cid = c.cid' +
  602. ' Where cf.sid = ?';
  603. const result = await this.db.query(sql, [sid]);
  604. return this.ctx.helper.filterLastestData(result, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
  605. }
  606. async _getTender(stage) {
  607. if (this.ctx.tender) return this.ctx.tender;
  608. const tender = { id: stage.tid };
  609. tender.data = await this.ctx.service.tender.getTender(stage.tid);
  610. tender.info = await this.service.tenderInfo.getTenderInfo(tender.id);
  611. return tender;
  612. }
  613. async getSubtotal(stage) {
  614. const helper = this.ctx.helper;
  615. const tender = await this._getTender(stage);
  616. const sql = 'SELECT sc.*, c.quality FROM ' + this.tableName + ' sc' +
  617. ' LEFT JOIN ' + this.ctx.service.change.tableName + ' c ON sc.cid = c.cid' +
  618. ' WHERE sid = ? ' + (stage.readOnly ? ` and (stimes < ${stage.curTimes} or (stimes = ${stage.curTimes} and sorder <= ${stage.curOrder}))` : '');
  619. let data = await this.db.query(sql, [stage.id]);
  620. data = helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
  621. const bqData = [];
  622. for (const d of data) {
  623. if (!d.qty || d.no_value) continue;
  624. let bd = bqData.find(x => { return x.lid === d.lid && x.quality === d.quality; });
  625. if (!bd) {
  626. bd = { lid: d.lid, quality: d.quality, unit_price: d.unit_price };
  627. bqData.push(bd);
  628. }
  629. const tp = this.ctx.helper.mul(d.qty, bd.unit_price, tender.info.decimal.tp);
  630. bd.tp = this.ctx.helper.add(bd.tp, tp);
  631. }
  632. const result = {};
  633. result.common = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.common.value; }), 'tp'));
  634. result.more = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.more.value; }), 'tp'));
  635. result.great = helper.sum(helper._.map(bqData.filter(x => {return x.quality === changeConst.quality.great.value; }), 'tp'));
  636. return result;
  637. }
  638. async getChangeBillsWithUsedInfo(stage) {
  639. if (stage.status === audit.stage.status.checked) {
  640. const sql = 'SELECT scf.* ' +
  641. ' FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
  642. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
  643. ' WHERE scf.tid = ? And s.order <= ?';
  644. const result = await this.db.query(sql, [stage.tid, stage.order]);
  645. return result;
  646. } else {
  647. const preSql = 'SELECT scf.* ' +
  648. ' FROM ' + this.ctx.service.stageChangeFinal.tableName + ' scf ' +
  649. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s ON scf.sid = s.id' +
  650. ' WHERE scf.tid = ? And s.order < ?';
  651. const pre = await this.db.query(preSql, [stage.tid, stage.order]);
  652. const sql = 'SELECT * FROM ' + this.tableName + ' WHERE sid = ? AND (stimes * 100 + sorder) <= (? * 100 + ?)';
  653. const curAll = await this.db.query(sql, [stage.id, stage.curTimes, stage.curOrder]);
  654. const cur = this.ctx.helper.filterLastestData(curAll, ['lid', 'pid', 'cbid', 'no_value'], 'stimes', 'sorder');
  655. return [...pre, ...cur];
  656. }
  657. }
  658. async getChangeWithUsedInfo(stage) {
  659. const change = await this.ctx.service.change.getAllDataByCondition({
  660. where: { tid: stage.tid, status: audit.flow.status.checked },
  661. orders: [['code', 'asc']],
  662. });
  663. if (change.length === 0) return [];
  664. const changeBills = await this.ctx.service.changeAuditList.getAllDataByCondition({
  665. where: { cid: change.map(x => { return x.cid; }) }
  666. });
  667. const changeBillsIndex = {}, changeBillsPart = {};
  668. for (const cb of changeBills) {
  669. changeBillsIndex[cb.id] = cb;
  670. if (!changeBillsPart[cb.cid]) changeBillsPart[cb.cid] = [];
  671. changeBillsPart[cb.cid].push(cb);
  672. }
  673. const stageChangeBills = await this.getChangeBillsWithUsedInfo(stage);
  674. for (const scb of stageChangeBills) {
  675. if (!scb.qty) continue;
  676. const cb = changeBillsIndex[scb.cbid];
  677. if (cb) cb.used_qty = this.ctx.helper.add(cb.used_qty, scb.qty);
  678. }
  679. for (const cid in changeBillsPart) {
  680. const c = change.find(x => { return x.cid === cid });
  681. if (!c) continue;
  682. for (const cb of changeBillsPart[cid]) {
  683. cb.tp = this.ctx.helper.mul(cb.spamount, cb.unit_price, c.tp_decimal || this.ctx.tender.info.decimal.tp);
  684. cb.used_tp = this.ctx.helper.mul(cb.used_qty, cb.unit_price, this.ctx.tender.info.decimal.tp);
  685. c.used_tp = this.ctx.helper.add(c.used_tp, cb.used_tp);
  686. if (cb.spamount > 0) {
  687. c.p_tp = this.ctx.helper.add(c.p_tp, cb.tp);
  688. c.p_used_tp = this.ctx.helper.add(c.p_used_tp, cb.used_tp);
  689. } else if (cb.spamount < 0){
  690. c.n_tp = this.ctx.helper.add(c.n_tp, cb.tp);
  691. c.n_used_tp = this.ctx.helper.add(c.n_used_tp, cb.used_tp);
  692. }
  693. }
  694. c.used_pt = c.total_price ? this.ctx.helper.mul(this.ctx.helper.div(c.used_tp, c.total_price, 4), 100) : 0;
  695. c.p_used_pt = c.p_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.p_used_tp, c.p_tp, 4), 100) : 0;
  696. c.n_used_pt = c.n_tp ? this.ctx.helper.mul(this.ctx.helper.div(c.n_used_tp, c.n_tp, 4), 100) : 0;
  697. }
  698. return change;
  699. }
  700. async getStageMinusChange(stage) {
  701. const data = await this.getAllDataByCondition({ where: { sid: stage.id, minus: 1 } });
  702. return this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
  703. };
  704. async getBillsMinusQty(stage, lid) {
  705. const data = await this.getAllDataByCondition({ where: { sid: stage.id, lid, minus: 1 } });
  706. const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
  707. return { lid, qty: this.ctx.helper.sum(filter.map(x => { return x.qty; })) };
  708. };
  709. async getPosMinusQty(stage, pid) {
  710. const data = await this.getAllDataByCondition({ where: { sid: stage.id, pid, minus: 1 } });
  711. const filter = this.ctx.helper.filterLastestData(data, ['lid', 'pid', 'cbid'], 'stimes', 'sorder');
  712. return { pid, qty: this.ctx.helper.sum(filter.map(x => { return x.qty; })) };
  713. };
  714. async autoUseChangeBills(tender, stage, data) {
  715. const lid = [], cbid = [];
  716. data.forEach(x => {
  717. lid.push(x.lid);
  718. cbid.push(x.cbid);
  719. });
  720. const validChangeBills = await this.ctx.service.stageChangeFinal.getListChangeBillsValidQty(tender.id, cbid);
  721. validChangeBills.forEach(x => {
  722. x.billsPos = data.find(y => { return x.id === y.cbid; });
  723. });
  724. const ledgerData = await this.ctx.service.ledger.getAllDataByCondition({
  725. columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price'],
  726. where: { id: lid },
  727. });
  728. const extraData = await this.ctx.service.ledgerExtra.getData(this.ctx.tender.id, ['is_tp']);
  729. this.ctx.helper.assignRelaData(ledgerData, [
  730. { data: extraData, fields: ['is_tp'], prefix: '', relaId: 'id' },
  731. ]);
  732. const posData = await this.ctx.service.pos.getAllDataByCondition({
  733. columns: ['id', 'lid', 'name', 'porder'],
  734. where: { lid },
  735. });
  736. const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
  737. const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
  738. const stageChange = await this.ctx.service.stageChange.getAllDataByCondition({ where: { sid: stage.id, lid }});
  739. const useModal = new autoUseChange(this.ctx.helper, tender.info);
  740. useModal.use({ledgerData, posData, stageBills, stagePos, stageChange, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills);
  741. const conn = await this.db.beginTransaction();
  742. try {
  743. if (useModal.insertBills.length > 0) await conn.insert(this.ctx.service.stageBills.tableName, useModal.insertBills);
  744. if (useModal.updateBills.length > 0) await conn.updateRows(this.ctx.service.stageBills.tableName, useModal.updateBills);
  745. if (useModal.insertPos.length > 0) await conn.insert(this.ctx.service.stagePos.tableName, useModal.insertPos);
  746. if (useModal.updatePos.length > 0) await conn.updateRows(this.ctx.service.stagePos.tableName, useModal.updatePos);
  747. if (useModal.insertChange.length > 0) await conn.insert(this.tableName, useModal.insertChange);
  748. if (useModal.updateChange.length > 0) await conn.updateRows(this.tableName, useModal.updateChange);
  749. await conn.commit();
  750. } catch (err) {
  751. await conn.rollback();
  752. this.ctx.log(err);
  753. throw '保存导入数据失败';
  754. }
  755. const rst = { bills: {}, pos: {} };
  756. rst.bills.curStageData = await this.ctx.service.stageBills.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, lid);
  757. rst.pos.curStageData = await this.ctx.service.stagePos.getLastestStageData2(this.ctx.tender.id, this.ctx.stage.id, { lid });
  758. return rst;
  759. };
  760. async autoUseAllChange(tender, stage) {
  761. const validChangeBills = await this.ctx.service.stageChangeFinal.getAllChangeBillsValidQty(tender.id);
  762. const ledgerData = await this.ctx.service.ledger.getAllDataByCondition({
  763. columns: ['id', 'ledger_id', 'ledger_pid', 'level', 'order', 'full_path', 'is_leaf', 'code', 'b_code', 'name', 'unit', 'unit_price'],
  764. where: { tender_id: stage.tid },
  765. });
  766. const extraData = await this.ctx.service.ledgerExtra.getData(this.ctx.tender.id, ['is_tp']);
  767. const settleStatusBills = stage.readySettle ? await this.ctx.service.settleBills.getAllDataByCondition({ where: { settle_id: stage.readySettle.id }}) : [];
  768. this.ctx.helper.assignRelaData(ledgerData, [
  769. { data: extraData, fields: ['is_tp'], prefix: '', relaId: 'id' },
  770. { data: settleStatusBills, fields: ['settle_status'], prefix: '', relaId: 'lid' },
  771. ]);
  772. const posData = await this.ctx.service.pos.getAllDataByCondition({
  773. columns: ['id', 'lid', 'name', 'porder'],
  774. where: { tid: stage.tid },
  775. });
  776. const settleStatusPos = stage.readySettle ? await this.ctx.service.settlePos.getAllDataByCondition({ where: { settle_id: stage.readySettle.id }}) : [];
  777. this.ctx.helper.assignRelaData(posData, [
  778. { data: settleStatusPos, fields: ['settle_status'], prefix: '', relaId: 'pid' },
  779. ]);
  780. const stageBills = await this.ctx.service.stageBills.getAllDataByCondition({ where: { sid: stage.id } });
  781. const stagePos = await this.ctx.service.stagePos.getAllDataByCondition({ where: { sid: stage.id } });
  782. const useModal = new autoUseChange(this.ctx.helper, tender.info, this.ctx.service.settle.settleStatus);
  783. useModal.use({ledgerData, posData, stageBills, stagePos, default: { tid: stage.tid, sid: stage.id, said: this.ctx.session.sessionUser.accountId } }, validChangeBills);
  784. // if (useModal.insertChange.length === 0) return '无可调用的清单或计量单元';
  785. const conn = await this.db.beginTransaction();
  786. try {
  787. if (useModal.insertBills.length > 0) await conn.insert(this.ctx.service.stageBills.tableName, useModal.insertBills);
  788. if (useModal.updateBills.length > 0) await conn.updateRows(this.ctx.service.stageBills.tableName, useModal.updateBills);
  789. if (useModal.insertPos.length > 0) await conn.insert(this.ctx.service.stagePos.tableName, useModal.insertPos);
  790. if (useModal.updatePos.length > 0) await conn.updateRows(this.ctx.service.stagePos.tableName, useModal.updatePos);
  791. await conn.delete(this.tableName, { sid: stage.id });
  792. if (useModal.insertChange.length > 0) await conn.insert(this.tableName, useModal.insertChange);
  793. await conn.commit();
  794. } catch (err) {
  795. await conn.rollback();
  796. this.ctx.log(err);
  797. throw '保存导入数据失败';
  798. }
  799. }
  800. async updateStageChange4CheckCancel(sid, newTimes, newOrder, oldTimes, oldOrder, transaction) {
  801. const oldSBLists = await this.getAllDataByCondition({ where: { sid, stimes: oldTimes, sorder: oldOrder } });
  802. const newSBLists = await this.getAllDataByCondition({ where: { sid, stimes: newTimes, sorder: newOrder } });
  803. const delidList = [];
  804. for (const o of oldSBLists) {
  805. const newSBInfo = this._.find(newSBLists, { lid: o.lid });
  806. if (newSBInfo) {
  807. // 删除
  808. delidList.push(newSBInfo.id);
  809. }
  810. }
  811. if (delidList.length > 0) await transaction.delete(this.tableName, { id: delidList });
  812. if (oldSBLists.length > 0) {
  813. await transaction.update(this.tableName, {
  814. stimes: newTimes,
  815. sorder: newOrder,
  816. }, { where: { id: this._.map(oldSBLists, 'id') } });
  817. }
  818. }
  819. }
  820. return StageChange;
  821. };