'use strict'; /** * 质量管理 - 工程质量 * * @author Mai * @date 2024/7/22 * @version */ module.exports = app => { class QualityGongxu extends app.BaseService { /** * 构造函数 * * @param {Object} ctx - egg全局变量 * @return {void} */ constructor(ctx) { super(ctx); this.tableName = 'quality_gongxu'; } async add(filter, name) { let quality = await this.ctx.service.quality.getQuality(filter); const conn = await this.db.beginTransaction(); try { if (!quality) { quality = await this.ctx.service.quality.saveQuality(quality, filter, {}, conn); } const newGongxu = { id: this.uuid.v4(), tid: quality.tid, quality_id: quality.id, name, user_id: this.ctx.session.sessionUser.accountId, }; await conn.insert(this.tableName, newGongxu); await conn.commit(); } catch (err) { this.ctx.log(err); await conn.rollback(); throw '新增工序失败'; } } async update(id, name) { const gongxu = await this.getDataById(id); if (!gongxu) throw '工序不存在'; await this.db.update(this.tableName, { id, name }); } async del(id) { const gongxu = await this.getDataById(id); if (!gongxu) throw '工序不存在'; const conn = await this.db.beginTransaction(); try { await conn.delete(this.tableName, { id }); 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 } }); await conn.commit(); } catch (err) { this.ctx.log(err); await conn.rollback(); throw '删除工序失败'; } } } return QualityGongxu; };