123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- '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;
- };
|