pos.js 24 KB

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