pos.js 24 KB

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