change_att.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. /**
  3. *
  4. * 附件
  5. * @author Ellisran
  6. * @date 2019/1/11
  7. * @version
  8. */
  9. module.exports = app => {
  10. class ChangeAtt extends app.BaseService {
  11. /**
  12. * 构造函数
  13. *
  14. * @param {Object} ctx - egg全局变量
  15. * @return {void}
  16. */
  17. constructor(ctx) {
  18. super(ctx);
  19. this.tableName = 'change_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. tid: postData.tid,
  31. cid: postData.cid,
  32. uid,
  33. };
  34. Object.assign(data, fileData);
  35. const result = await this.db.insert(this.tableName, data);
  36. return result;
  37. }
  38. /**
  39. * 获取 变更令 所有附件
  40. * @param {uuid} cid - 变更令id
  41. * @returns {Promise<void>}
  42. */
  43. async getChangeAttachment(cid) {
  44. const sql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
  45. ' FROM ?? As ca ' +
  46. ' Left Join ?? As pa ' +
  47. ' On ca.uid = pa.id ' +
  48. ' Where ca.cid = ?';
  49. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid];
  50. return await this.db.query(sql, sqlParam);
  51. }
  52. }
  53. return ChangeAtt;
  54. };