pos.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. 'use strict';
  2. /**
  3. * 部位明细
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. module.exports = app => {
  10. class Pos extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'pos';
  20. }
  21. async getPosData(condition) {
  22. return await this.db.select(this.tableName, {
  23. where: condition,
  24. columns: ['id', 'tid', 'lid', 'name', 'quantity', 'position', 'drawing_code', 'sgfh_qty', 'sjcl_qty',
  25. 'qtcl_qty', 'in_time', 'porder', 'add_stage', 'sgfh_expr', 'sjcl_expr', 'qtcl_expr', 'real_qty',
  26. 'dagl_status', 'dagl_url', 'gxby_status'],
  27. order: [['porder', 'ASC']],
  28. });
  29. }
  30. async getPosDataWithAddStageOrder(condition) {
  31. const sql = 'SELECT p.id, p.tid, p.lid, p.name, p.quantity, p.position, p.drawing_code,' +
  32. ' p.sgfh_qty, p.sjcl_qty, p.qtcl_qty, p.porder, p.add_stage, p.add_times, p.add_user, s.order As add_stage_order,' +
  33. ' p.sgfh_expr, p.sjcl_expr, p.qtcl_expr, p.real_qty, p.gxby_status, p.dagl_status, p.dagl_url' +
  34. ' FROM ' + this.tableName + ' p ' +
  35. ' LEFT JOIN ' + this.ctx.service.stage.tableName + ' s' +
  36. ' ON p.add_stage = s.id'
  37. + this.ctx.helper.whereSql(condition, 'p');
  38. return await this.db.query(sql);
  39. }
  40. async getPosDataByIds(ids) {
  41. if (ids instanceof Array && ids.length > 0) {
  42. const sql = 'SELECT id, tid, lid, name, quantity, position, drawing_code,' +
  43. ' sgfh_qty, sjcl_qty, qtcl_qty, add_stage, add_times, add_user, sgfh_expr, sjcl_expr, qtcl_expr, real_qty,' +
  44. ' dagl_status, p.dagl_url, gxby_status' +
  45. ' FROM ' + this.tableName +
  46. ' WHERE id in (' + this.ctx.helper.getInArrStrSqlFilter(ids) + ')';
  47. return await this.db.query(sql, []);
  48. } else {
  49. return [];
  50. }
  51. // this.initSqlBuilder();
  52. // this.sqlBuilder.setAndWhere('id', {
  53. // operate: 'in',
  54. // value: ids
  55. // });
  56. // this.sqlBuilder.columns = ['id', 'tid', 'lid', 'name', 'quantity', 'drawing_code', 'sgfh_qty', 'sjcl_qty', 'qtcl_qty'];
  57. // const [sql, sqlParam] = this.sqlBuilder.build(this.tableName)
  58. // return await this.db.query(sql, sqlParam);
  59. }
  60. async getPosDataByUnits(tenderId, units) {
  61. const sql = 'SELECT p.id, p.lid, p.sgfh_qty, p.sjcl_qty, p.qtcl_qty' +
  62. ' FROM ' + this.tableName + ' p' +
  63. ' LEFT JOIN ' + this.ctx.service.ledger.tableName + ' b' +
  64. ' ON p.lid = b.id ' +
  65. ' WHERE p.tid = ? and b.unit IN (?)';
  66. const sqlParam = [tenderId, units];
  67. return await this.db.query(sql, sqlParam);
  68. }
  69. async _insertPosData(transaction, data, tid) {
  70. data.id = this.uuid.v4();
  71. data.tid = tid;
  72. // todo 新增期
  73. data.add_stage = 0;
  74. data.add_times = 0;
  75. data.in_time = new Date();
  76. data.add_user = this.ctx.session.sessionUser.accountId;
  77. if (data.quantity) {
  78. const bills = await this.ctx.service.ledger.getDataById(data.lid);
  79. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  80. data.quantity = this.round(data.quantity, precision.value);
  81. }
  82. if (transaction) {
  83. const addRst = await transaction.insert(this.tableName, data);
  84. } else {
  85. const addRst = await this.db.insert(this.tableName, data);
  86. }
  87. }
  88. async _completeInsertPosData(tid, data) {
  89. data.id = this.uuid.v4();
  90. data.tid = tid;
  91. // todo 新增期
  92. data.add_stage = 0;
  93. data.add_times = 0;
  94. data.in_time = new Date();
  95. data.add_user = this.ctx.session.sessionUser.accountId;
  96. }
  97. async _getUpdateBills(data) {
  98. const datas = data instanceof Array ? data : [data];
  99. const bills = await this.ctx.service.ledger.getDataById(datas[0].lid);
  100. const billsPos = await this.getAllDataByCondition({where: {tid: bills.tender_id, lid: bills.id} });
  101. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  102. const updateBills = {id: bills.id};
  103. for (const bp of billsPos) {
  104. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  105. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  106. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  107. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  108. }
  109. for (const d of datas) {
  110. if (d.sgfh_qty) {
  111. d.sgfh_qty = this.ctx.helper.round(d.sgfh_qty, precision.value);
  112. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
  113. }
  114. if (d.sjcl_qty) {
  115. d.sjcl_qty = this.ctx.helper.round(d.sjcl_qty, precision.value);
  116. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
  117. }
  118. if (d.qtcl_qty) {
  119. d.qtcl_qty = this.ctx.helper.round(d.qtcl_qty, precision.value);
  120. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
  121. }
  122. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  123. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
  124. }
  125. const info = this.ctx.tender.info;
  126. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  127. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  128. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  129. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  130. return updateBills;
  131. }
  132. async _addPosData(tid, data) {
  133. let updateBills = null;
  134. if (data instanceof Array) {
  135. for (const d of data) {
  136. this._completeInsertPosData(tid, d);
  137. }
  138. if (data[0].sgfh_qty !== undefined || data[0].sjcl_qty !== undefined || data[0].qtcl_qty !== undefined) {
  139. updateBills = await this._getUpdateBills(data);
  140. }
  141. } else {
  142. this._completeInsertPosData(tid, data);
  143. if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
  144. updateBills = await this._getUpdateBills(data);
  145. }
  146. }
  147. if (updateBills) {
  148. const transaction = await this.db.beginTransaction();
  149. try {
  150. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  151. updateBills.ledger_id = bills.ledger_id;
  152. await transaction.commit();
  153. } catch (err) {
  154. await transaction.rollback();
  155. throw err;
  156. }
  157. return {
  158. ledger: { update: [updateBills] },
  159. pos: data,
  160. }
  161. } else {
  162. await this.db.insert(this.tableName, data);
  163. return { pos: data }
  164. }
  165. }
  166. async _updatePosData(tid, data) {
  167. if (data.sgfh_qty !== undefined || data.sjcl_qty !== undefined || data.qtcl_qty !== undefined) {
  168. const op = await this.getDataById(data.id);
  169. const bills = await this.ctx.service.ledger.getDataById(op.lid);
  170. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
  171. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  172. if (data.sgfh_qty !== undefined) {
  173. data.sgfh_qty = this.round(data.sgfh_qty, precision.value);
  174. } else if (op) {
  175. data.sgfh_qty = op.sgfh_qty;
  176. }
  177. if (data.sjcl_qty !== undefined) {
  178. data.sjcl_qty = this.round(data.sjcl_qty, precision.value);
  179. } else if (op) {
  180. data.sjcl_qty = op.sjcl_qty;
  181. }
  182. if (data.qtcl_qty !== undefined) {
  183. data.qtcl_qty = this.round(data.qtcl_qty, precision.value);
  184. } else if (op) {
  185. data.qtcl_qty = op.qtcl_qty;
  186. }
  187. data.quantity = this.ctx.helper.sum([data.sgfh_qty, data.qtcl_qty, data.sjcl_qty]);
  188. const updateBills = {id: bills.id};
  189. for (const bp of billsPos) {
  190. const calcData = bp.id === data.id ? data : bp;
  191. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, calcData.sgfh_qty);
  192. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, calcData.sjcl_qty);
  193. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, calcData.qtcl_qty);
  194. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, calcData.quantity);
  195. }
  196. const info = this.ctx.tender.info;
  197. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  198. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  199. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  200. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  201. const transaction = await this.db.beginTransaction();
  202. try {
  203. await transaction.update(this.tableName, data);
  204. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  205. await transaction.commit();
  206. updateBills.ledger_id = bills.ledger_id;
  207. return {
  208. ledger: { update: [updateBills] },
  209. pos: data,
  210. }
  211. } catch(err) {
  212. await transaction.rollback();
  213. throw err;
  214. }
  215. } else {
  216. await this.db.update(this.tableName, data);
  217. return {pos: data};
  218. }
  219. }
  220. async _updatePosDatas(tid, data) {
  221. if (data.length === 0) return;
  222. const op = await this.getDataById(data[0].id);
  223. const bills = await this.ctx.service.ledger.getDataById(op.lid);
  224. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: op.lid} });
  225. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  226. let needUpdateBills;
  227. for (const d of data) {
  228. if (d.sgfh_qty !== undefined || d.sjcl_qty !== undefined || d.qtcl_qty !== undefined) {
  229. if (d.sgfh_qty !== undefined) {
  230. d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
  231. } else if (op) {
  232. d.sgfh_qty = op.sgfh_qty;
  233. }
  234. if (d.sjcl_qty !== undefined) {
  235. d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
  236. } else if (op) {
  237. d.sjcl_qty = op.sjcl_qty;
  238. }
  239. if (d.qtcl_qty !== undefined) {
  240. d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
  241. } else if (op) {
  242. d.qtcl_qty = op.qtcl_qty;
  243. }
  244. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  245. needUpdateBills = true;
  246. }
  247. }
  248. const updateBills = {id: bills.id};
  249. if (needUpdateBills) {
  250. for (const bp of billsPos) {
  251. const newPos = data.find(function (x) { return x.id === bp.id });
  252. updateBills.sgfh_qty = newPos && newPos.sgfh_qty !== undefined
  253. ? this.ctx.helper.add(updateBills.sgfh_qty, newPos.sgfh_qty)
  254. : this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  255. updateBills.sjcl_qty = newPos && newPos.sjcl_qty !== undefined
  256. ? this.ctx.helper.add(updateBills.sjcl_qty, newPos.sjcl_qty)
  257. : this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  258. updateBills.qtcl_qty = newPos && newPos.qtcl_qty !== undefined
  259. ? this.ctx.helper.add(updateBills.qtcl_qty, newPos.qtcl_qty)
  260. : this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  261. updateBills.quantity = newPos && newPos.quantity !== undefined
  262. ? this.ctx.helper.add(updateBills.quantity, newPos.quantity)
  263. : this.ctx.helper.add(updateBills.quantity, bp.quantity);
  264. }
  265. const info = this.ctx.tender.info;
  266. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  267. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  268. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  269. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  270. }
  271. const transaction = await this.db.beginTransaction();
  272. try {
  273. for (const d of data) {
  274. await transaction.update(this.tableName, d);
  275. }
  276. if (needUpdateBills) await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  277. await transaction.commit();
  278. updateBills.ledger_id = bills.ledger_id;
  279. return {
  280. ledger: { update: [updateBills] },
  281. pos: data,
  282. }
  283. } catch(err) {
  284. await transaction.rollback();
  285. throw err;
  286. }
  287. }
  288. async _deletePosData(tid, data) {
  289. if (!data || data.length === 0) {
  290. throw '提交数据错误';
  291. }
  292. const pos = await this.getPosData({tid: tid, id: data});
  293. const bills = await this.ctx.service.ledger.getDataById(pos[0].lid);
  294. const billsPos = await this.getAllDataByCondition({ where: {tid: tid, lid: bills.id} });
  295. const updateBills = {id: bills.id, sgfh_qty: null, sjcl_qty: null, qtcl_qty: null, quantity: null};
  296. for (const bp of billsPos) {
  297. if (data.indexOf(bp.id) >= 0) continue;
  298. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  299. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  300. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  301. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  302. }
  303. const info = this.ctx.tender.info;
  304. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  305. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  306. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  307. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  308. const transaction = await this.db.beginTransaction();
  309. try {
  310. await transaction.delete(this.tableName, {tid: tid, id: data});
  311. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  312. await transaction.commit();
  313. updateBills.ledger_id = bills.ledger_id;
  314. return { ledger: { update: [updateBills] }, pos: data };
  315. } catch(err) {
  316. await transaction.rollback();
  317. throw err;
  318. }
  319. }
  320. /**
  321. * 保存部位明细数据
  322. * @param data
  323. * @param {Number} tid - 标段id
  324. * @returns {Promise<{ledger: {}, pos: null}>}
  325. */
  326. async savePosData(data, tid) {
  327. switch (data.updateType) {
  328. case 'add':
  329. return await this._addPosData(tid, data.updateData);
  330. case 'update':
  331. if (data.updateData instanceof Array) {
  332. return await this._updatePosDatas(tid, data.updateData);
  333. } else {
  334. return await this._updatePosData(tid, data.updateData);
  335. }
  336. case 'delete':
  337. return await this._deletePosData(tid, data.updateData);
  338. }
  339. }
  340. /**
  341. * 复制粘贴 部位明细数据
  342. * @param {Array} data - 复制粘贴的数据
  343. * @param {Number} tid - 标段id
  344. * @returns {Promise<{ledger: {}, pos: null}>}
  345. */
  346. async pastePosData(data, tid) {
  347. if (!(data instanceof Array)) {
  348. throw '提交数据错误';
  349. }
  350. const transaction = await this.db.beginTransaction();
  351. const result = { ledger: {}, pos: null };
  352. const bills = await this.ctx.service.ledger.getDataById(data[0].lid);
  353. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  354. const updateBills = {id: bills.id};
  355. const billsPos = await this.getAllDataByCondition({where: {tid: tid, lid: bills.id} });
  356. for (const bp of billsPos) {
  357. const d = data.find(function (x) {
  358. return bp.id ? x.id === bp.id : false;
  359. });
  360. if (d) continue;
  361. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, bp.sgfh_qty);
  362. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, bp.sjcl_qty);
  363. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, bp.qtcl_qty);
  364. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, bp.quantity);
  365. }
  366. try {
  367. for (const d of data) {
  368. const op = d.id ? this._.find(billsPos, {id: d.id}) : null;
  369. if (d.sgfh_qty !== undefined) {
  370. d.sgfh_qty = this.round(d.sgfh_qty, precision.value);
  371. } else if (op) {
  372. d.sgfh_qty = op.sgfh_qty;
  373. }
  374. updateBills.sgfh_qty = this.ctx.helper.add(updateBills.sgfh_qty, d.sgfh_qty);
  375. if (d.sjcl_qty !== undefined) {
  376. d.sjcl_qty = this.round(d.sjcl_qty, precision.value);
  377. } else if (op) {
  378. d.sjcl_qty = op.sjcl_qty;
  379. }
  380. updateBills.sjcl_qty = this.ctx.helper.add(updateBills.sjcl_qty, d.sjcl_qty);
  381. if (d.qtcl_qty) {
  382. d.qtcl_qty = this.round(d.qtcl_qty, precision.value);
  383. } else if (op) {
  384. d.qtcl_qty = op.qtcl_qty;
  385. }
  386. updateBills.qtcl_qty = this.ctx.helper.add(updateBills.qtcl_qty, d.qtcl_qty);
  387. d.quantity = this.ctx.helper.sum([d.sgfh_qty, d.qtcl_qty, d.sjcl_qty]);
  388. updateBills.quantity = this.ctx.helper.add(updateBills.quantity, d.quantity);
  389. if (d.id) {
  390. await transaction.update(this.tableName, d);
  391. } else {
  392. this._completeInsertPosData(tid, d);
  393. await transaction.insert(this.tableName, d);
  394. }
  395. }
  396. const info = this.ctx.tender.info;
  397. updateBills.sgfh_tp = this.ctx.helper.mul(updateBills.sgfh_qty, bills.unit_price, info.decimal.tp);
  398. updateBills.sjcl_tp = this.ctx.helper.mul(updateBills.sjcl_qty, bills.unit_price, info.decimal.tp);
  399. updateBills.qtcl_tp = this.ctx.helper.mul(updateBills.qtcl_qty, bills.unit_price, info.decimal.tp);
  400. updateBills.total_price = this.ctx.helper.mul(updateBills.quantity, bills.unit_price, info.decimal.tp);
  401. await transaction.update(this.ctx.service.ledger.tableName, updateBills);
  402. updateBills.ledger_id = bills.ledger_id;
  403. await transaction.commit();
  404. } catch (err) {
  405. await transaction.rollback();
  406. throw err;
  407. }
  408. result.pos = data;
  409. result.ledger.update = [updateBills];
  410. return result;
  411. }
  412. /**
  413. * 删除清单下部位明细数据(删除清单时调用)
  414. *
  415. * @param transaction - 事务
  416. * @param tid - 标段id
  417. * @param lid - 清单id
  418. * @returns {Promise<void>}
  419. */
  420. async deletePosData(transaction, tid, lid) {
  421. await transaction.delete(this.tableName, {tid: tid, lid: lid});
  422. }
  423. /**
  424. * 复制整块 拷贝部位明细数据
  425. * @param {Number} orgLid - 拷贝的部位明细所属台账id
  426. * @param {Number} newLid - 新的台账id
  427. * @param transaction - 复制整块事务
  428. * @returns {Promise<void>}
  429. */
  430. async copyBillsPosData(lid, transaction) {
  431. const lidArr = lid instanceof Array ? lid : [lid];
  432. const pasteData = [];
  433. for (const id of lidArr) {
  434. const posData = await this.getAllDataByCondition({ where: { lid: id.org } });
  435. if (posData.length > 0) {
  436. for (const pd of posData) {
  437. pd.id = this.uuid.v4();
  438. pd.lid = id.new;
  439. pd.tid = this.ctx.tender.id;
  440. pd.in_time = new Date();
  441. pasteData.push(pd);
  442. }
  443. }
  444. }
  445. await transaction.insert(this.tableName, pasteData);
  446. }
  447. /**
  448. * 批量插入部位数据 - 仅供批量插入清单部位调用
  449. * @param transaction - 所属事务
  450. * @param {Number} tid - 标段id
  451. * @param {Number} lid - 台账id
  452. * @param {Array} data - 新增数据
  453. * @returns {Promise<void>}
  454. */
  455. async insertLedgerPosData(transaction, tid, bills, data) {
  456. const precision = this.ctx.helper.findPrecision(this.ctx.tender.info.precision, bills.unit);
  457. const insertDatas = [];
  458. for (const d of data) {
  459. const inD = {
  460. id: this.uuid.v4(), tid: tid, lid: bills.id,
  461. add_stage: 0, add_times: 0, add_user: this.ctx.session.sessionUser.accountId,
  462. in_time: new Date(), porder: data.indexOf(d) + 1,
  463. name: d.name, drawing_code: d.drawing_code,
  464. };
  465. if (d.quantity) {
  466. inD.sgfh_qty = this.round(d.quantity, precision.value);
  467. inD.quantity = inD.sgfh_qty;
  468. }
  469. insertDatas.push(inD);
  470. }
  471. await transaction.insert(this.tableName, insertDatas);
  472. }
  473. }
  474. return Pos;
  475. };