'use strict'; /** * 决策大屏标段管理-数据模型 * * @author ellisran * @date 2021/09/23 * @version */ // const accountGroup = require('../const/account_group').group; module.exports = app => { class datacollectTender extends app.BaseService { constructor(ctx) { super(ctx); this.tableName = 'datacollect_tender'; } // async getGroupInfo(pid, groupid) { // const sql = 'SELECT * FROM ?? WHERE pid = ? AND groupid = ? AND uid is NULL'; // const sqlParam = [this.tableName, pid, groupid]; // return await this.db.queryOne(sql, sqlParam); // } // // async saveAudit(pid, groupid, uid) { // const data = { // pid, // groupid, // uid, // create_time: new Date(), // }; // return await this.db.insert(this.tableName, data); // } // // async saveGroup(pid, groupid) { // const transaction = await this.db.beginTransaction(); // try { // // 删除所在组的用户 // await transaction.delete(this.tableName, { pid, groupid }); // const data = { // pid, // groupid, // create_time: new Date(), // }; // await transaction.insert(this.tableName, data); // await transaction.commit(); // return true; // } catch (err) { // await transaction.rollback(); // throw err; // } // } // // async delAudit(id) { // return await this.db.delete(this.tableName, { id }); // } async getList(pid, spid = this.ctx.subProject.id || '') { const sql = 'SELECT dt.* FROM ?? AS dt LEFT JOIN ?? AS t ON dt.tid = t.id WHERE dt.pid = ? AND t.spid = ?'; const sqlParam = [this.tableName, this.ctx.service.tender.tableName, pid, spid]; return await this.db.query(sql, sqlParam); } async updateList(pid, tids) { // 初始化事务 const transaction = await this.db.beginTransaction(); try { const oldList = await this.getList(pid, this.ctx.subProject.id); const oldIds = this._.map(oldList, 'tid'); const insertTids = this._.difference(tids, oldIds); const delTids = this._.difference(oldIds, tids); if (insertTids.length > 0) { const insertDatas = []; for (const i of insertTids) { insertDatas.push({ pid, tid: i, }); } await transaction.insert(this.tableName, insertDatas); } if (delTids.length > 0) { for (const d of delTids) { await transaction.delete(this.tableName, { pid, tid: d }); } } transaction.commit(); } catch (e) { console.log(e); transaction.rollback(); } } async add(pid, tid) { const data = { pid, tid, }; return await this.db.insert(this.tableName, data); } } return datacollectTender; };