quality_gongxu.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. 'use strict';
  2. /**
  3. * 质量管理 - 工程质量
  4. *
  5. * @author Mai
  6. * @date 2024/7/22
  7. * @version
  8. */
  9. module.exports = app => {
  10. class QualityGongxu extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'quality_gongxu';
  20. }
  21. async add(filter, name) {
  22. let quality = await this.ctx.service.quality.getQuality(filter);
  23. const conn = await this.db.beginTransaction();
  24. try {
  25. if (!quality) {
  26. quality = await this.ctx.service.quality.saveQuality(quality, filter, {}, conn);
  27. }
  28. const newGongxu = {
  29. id: this.uuid.v4(), tid: quality.tid, quality_id: quality.id, name, user_id: this.ctx.session.sessionUser.accountId,
  30. };
  31. await conn.insert(this.tableName, newGongxu);
  32. await conn.commit();
  33. } catch (err) {
  34. this.ctx.log(err);
  35. await conn.rollback();
  36. throw '新增工序失败';
  37. }
  38. }
  39. async update(id, name) {
  40. const gongxu = await this.getDataById(id);
  41. if (!gongxu) throw '工序不存在';
  42. await this.db.update(this.tableName, { id, name });
  43. }
  44. async del(id) {
  45. const gongxu = await this.getDataById(id);
  46. if (!gongxu) throw '工序不存在';
  47. const conn = await this.db.beginTransaction();
  48. try {
  49. await conn.delete(this.tableName, { id });
  50. await conn.update(this.ctx.service.qualityFile.tableName, { is_deleted: 1 }, { where: { tid: gongxu.tid, quality_id: gongxu.quality_id, block_type: 'gongxu', block_id: id } });
  51. await conn.commit();
  52. } catch (err) {
  53. this.ctx.log(err);
  54. await conn.rollback();
  55. throw '删除工序失败';
  56. }
  57. }
  58. }
  59. return QualityGongxu;
  60. };