stage_att.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. 'use strict';
  2. /**
  3. *
  4. * 附件
  5. * @author Ellisran
  6. * @date 2019/1/11
  7. * @version
  8. */
  9. module.exports = app => {
  10. class StageAtt extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'stage_attachment';
  20. }
  21. /**
  22. * 添加附件
  23. * @param {Object} postData - 表单信息
  24. * @param {Object} fileData - 文件信息
  25. * @param {int} uid - 上传者id
  26. * @return {void}
  27. */
  28. async save(postData, fileData, uid) {
  29. const data = {
  30. lid: postData.lid,
  31. uid,
  32. remark: '',
  33. };
  34. Object.assign(data, fileData);
  35. const result = await this.db.insert(this.tableName, data);
  36. return result;
  37. }
  38. /**
  39. * 添加附件
  40. * @param {Object} postData - 表单信息
  41. * @param {Object} fileData - 文件信息
  42. * @param {int} uid - 上传者id
  43. * @return {void}
  44. */
  45. async updateByID(postData, fileData) {
  46. delete postData.size;
  47. const data = {};
  48. Object.assign(data, fileData);
  49. Object.assign(data, postData);
  50. const result = await this.db.update(this.tableName, data);
  51. return result.affectedRows === 1;
  52. }
  53. /**
  54. * 获取所有附件
  55. * @param {int} tid - 标段id
  56. * @param {int} sid - 当前期数
  57. * @return {void}
  58. */
  59. async getDataByTenderIdAndStageId(tid, sid) {
  60. const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.remark, att.in_time,' +
  61. ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.b_code as `b_code`' +
  62. ' FROM ?? AS att,?? AS pa,?? AS leg' +
  63. ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.tid = ? AND att.sid = ? ORDER BY att.in_time DESC';
  64. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, tid, sid];
  65. return await this.db.query(sql, sqlParam);
  66. }
  67. /**
  68. * 获取单个附件
  69. * @param {int} tid - 标段id
  70. * @param {int} sid - 当前期数
  71. * @return {void}
  72. */
  73. async getDataByFid(id) {
  74. const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.remark, att.in_time,' +
  75. ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.b_code as `b_code`' +
  76. ' FROM ?? AS att,?? AS pa,?? AS leg' +
  77. ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.id = ? ORDER BY att.in_time DESC';
  78. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, id];
  79. return await this.db.queryOne(sql, sqlParam);
  80. }
  81. }
  82. return StageAtt;
  83. };