material_list_notjoin.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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: list.id,
  71. mid,
  72. mb_id: list.mb_id,
  73. gcl_id: list.gcl_id,
  74. xmj_id: list.xmj_id,
  75. mx_id: list.mx_id,
  76. in_time: new Date(),
  77. };
  78. notJoinlist.push(newLists);
  79. }
  80. // 复制上一期不参与调差的清单
  81. return await transaction.insert(this.tableName, notJoinlist);
  82. }
  83. }
  84. return MaterialListNotJoin;
  85. };