material_list_notjoin.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. 'use strict';
  2. /**
  3. * 不参与调差-清单关联表 数据模型
  4. *
  5. * @author Mai
  6. * @date 2018/8/13
  7. * @version
  8. */
  9. module.exports = app => {
  10. class MaterialListNotJoin extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'material_list_notjoin';
  20. }
  21. /**
  22. * 添加不参与调差的清单
  23. * @return {void}
  24. */
  25. async add(data) {
  26. if (!this.ctx.tender || !this.ctx.material) {
  27. throw '数据错误';
  28. }
  29. const newListNotJoin = {
  30. tid: this.ctx.tender.id,
  31. mid: this.ctx.material.id,
  32. gcl_id: data.gcl_id,
  33. xmj_id: data.id,
  34. mx_id: data.mx_id !== undefined ? data.mx_id : '',
  35. in_time: new Date(),
  36. };
  37. // 新增不参与调差清单
  38. const result = await this.db.insert(this.tableName, newListNotJoin);
  39. if (result.affectedRows === 0) {
  40. throw '新增不参与调差清单数据失败';
  41. }
  42. return await this.getDataById(result.insertId);
  43. }
  44. /**
  45. * 删除不参与调差的清单
  46. * @param {int} id 工料id
  47. * @return {void}
  48. */
  49. async del(id) {
  50. if (!this.ctx.tender || !this.ctx.material) {
  51. throw '数据错误';
  52. }
  53. // 判断是否可删
  54. return await this.deleteById(id);
  55. }
  56. /**
  57. * 复制上一期不参与调差的清单到下一期中
  58. * @param {Object} transaction - 新增一期的事务
  59. * @param {Object} list 上期清单
  60. * @param {int} mid 工料id
  61. * @return {void}
  62. */
  63. async copyNewStageNotJoinList(transaction, list, mid) {
  64. if (!this.ctx.tender) {
  65. throw '数据错误';
  66. }
  67. const notJoinlist = [];
  68. for (const mb of list) {
  69. const newLists = {
  70. tid: mb.tid,
  71. mid,
  72. gcl_id: mb.gcl_id,
  73. xmj_id: mb.xmj_id,
  74. mx_id: mb.mx_id,
  75. in_time: new Date(),
  76. };
  77. notJoinlist.push(newLists);
  78. }
  79. // 复制上一期不参与调差的清单
  80. return await transaction.insert(this.tableName, notJoinlist);
  81. }
  82. }
  83. return MaterialListNotJoin;
  84. };