quality_yinbi.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use strict';
  2. /**
  3. * 质量管理 - 工程质量
  4. *
  5. * @author Mai
  6. * @date 2024/7/22
  7. * @version
  8. */
  9. module.exports = app => {
  10. class QualityYinbi 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_yinbi';
  20. }
  21. async add(filter, data) {
  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.saveQuality(quality, filter, {}, conn);
  27. }
  28. const newYinbi = {
  29. id: this.uuid.v4(), tid: quality.tid, quality_id: quality.id, user_id: this.ctx.session.sessionUser.accountId,
  30. name: data.name, gongxu_id: data.gongxu_id || '', gcbw: data.gcbw || '', content: data.content,
  31. };
  32. await conn.insert(this.tableName, newYinbi);
  33. await conn.commit();
  34. } catch (err) {
  35. this.ctx.log(err);
  36. await conn.rollback();
  37. throw '新增工序失败';
  38. }
  39. }
  40. async update(id, data) {
  41. const yinbi = await this.getDataById(id);
  42. if (!yinbi) throw '隐蔽工程不存在';
  43. const updateData = { id: yinbi.id, name: data.name, gongxu_id: data.gongxu_id || '', gcbw: data.gcbw || '', content: data.content };
  44. await this.db.update(this.tableName, updateData);
  45. }
  46. async del(id) {
  47. const yinbi = await this.getDataById(id);
  48. if (!yinbi) throw '工序不存在';
  49. const conn = await this.db.beginTransaction();
  50. try {
  51. await conn.delete(this.tableName, { id });
  52. await conn.update(this.ctx.service.qualityFile.tableName, { is_deleted: 1 }, { where: { tid: yinbi.tid, quality_id: yinbi.quality_id, block_type: 'yinbi', block_id: id } });
  53. await conn.commit();
  54. } catch (err) {
  55. this.ctx.log(err);
  56. await conn.rollback();
  57. throw '删除工序失败';
  58. }
  59. }
  60. }
  61. return QualityYinbi;
  62. };