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