financial_transfer_att.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use strict';
  2. /**
  3. * Created by EllisRan on 2020/3/3.
  4. */
  5. const BaseService = require('../base/base_service');
  6. module.exports = app => {
  7. class FinancialTransferAtt extends BaseService {
  8. /**
  9. * 构造函数
  10. *
  11. * @param {Object} ctx - egg全局变量
  12. * @return {void}
  13. */
  14. constructor(ctx) {
  15. super(ctx);
  16. this.tableName = 'financial_transfer_attachment';
  17. this.dataId = 'id';
  18. }
  19. async getAtt(trid) {
  20. const sql = 'SELECT a.*, b.name as username FROM ?? as a LEFT JOIN ?? as b ON a.`uid` = b.`id` WHERE a.`trid` = ? ORDER BY `upload_time` DESC';
  21. const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, trid];
  22. const result = await this.db.query(sql, sqlParam);
  23. return result.map(item => {
  24. item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
  25. if (!this.ctx.helper.canPreview(item.fileext)) {
  26. item.filepath = `/financial/${item.spid}/transfer/${item.trid}/file/${item.id}/download`;
  27. } else {
  28. item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
  29. item.viewpath = item.filepath;
  30. }
  31. return item;
  32. });
  33. }
  34. /**
  35. * 存储上传的文件信息至数据库
  36. * @param {Array} payload 载荷
  37. * @return {Promise<void>} 数据库插入执行实例
  38. */
  39. async saveFileMsgToDb(payload) {
  40. return await this.db.insert(this.tableName, payload);
  41. }
  42. /**
  43. * 删除附件
  44. * @param {Number} id - 附件id
  45. * @return {void}
  46. */
  47. async delete(id) {
  48. return await this.deleteById(id);
  49. }
  50. }
  51. return FinancialTransferAtt;
  52. };