datacollect_tender.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use strict';
  2. /**
  3. * 决策大屏标段管理-数据模型
  4. *
  5. * @author ellisran
  6. * @date 2021/09/23
  7. * @version
  8. */
  9. // const accountGroup = require('../const/account_group').group;
  10. module.exports = app => {
  11. class datacollectTender extends app.BaseService {
  12. constructor(ctx) {
  13. super(ctx);
  14. this.tableName = 'datacollect_tender';
  15. }
  16. // async getGroupInfo(pid, groupid) {
  17. // const sql = 'SELECT * FROM ?? WHERE pid = ? AND groupid = ? AND uid is NULL';
  18. // const sqlParam = [this.tableName, pid, groupid];
  19. // return await this.db.queryOne(sql, sqlParam);
  20. // }
  21. //
  22. // async saveAudit(pid, groupid, uid) {
  23. // const data = {
  24. // pid,
  25. // groupid,
  26. // uid,
  27. // create_time: new Date(),
  28. // };
  29. // return await this.db.insert(this.tableName, data);
  30. // }
  31. //
  32. // async saveGroup(pid, groupid) {
  33. // const transaction = await this.db.beginTransaction();
  34. // try {
  35. // // 删除所在组的用户
  36. // await transaction.delete(this.tableName, { pid, groupid });
  37. // const data = {
  38. // pid,
  39. // groupid,
  40. // create_time: new Date(),
  41. // };
  42. // await transaction.insert(this.tableName, data);
  43. // await transaction.commit();
  44. // return true;
  45. // } catch (err) {
  46. // await transaction.rollback();
  47. // throw err;
  48. // }
  49. // }
  50. //
  51. // async delAudit(id) {
  52. // return await this.db.delete(this.tableName, { id });
  53. // }
  54. async getList(pid) {
  55. return await this.db.select(this.tableName, { where: { pid } });
  56. }
  57. async updateList(pid, tids) {
  58. // 初始化事务
  59. const transaction = await this.db.beginTransaction();
  60. try {
  61. const oldList = await this.getList(pid);
  62. const oldIds = this._.map(oldList, 'tid');
  63. const insertTids = this._.difference(tids, oldIds);
  64. const delTids = this._.difference(oldIds, tids);
  65. if (insertTids.length > 0) {
  66. const insertDatas = [];
  67. for (const i of insertTids) {
  68. insertDatas.push({
  69. pid,
  70. tid: i,
  71. });
  72. }
  73. await transaction.insert(this.tableName, insertDatas);
  74. }
  75. if (delTids.length > 0) {
  76. for (const d of delTids) {
  77. await transaction.delete(this.tableName, { pid, tid: d });
  78. }
  79. }
  80. transaction.commit();
  81. } catch (e) {
  82. console.log(e);
  83. transaction.rollback();
  84. }
  85. }
  86. async add(pid, tid) {
  87. const data = {
  88. pid,
  89. tid,
  90. };
  91. return await this.db.insert(this.tableName, data);
  92. }
  93. }
  94. return datacollectTender;
  95. };