pos.js 24 KB

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