advance_file.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. 'use strict';
  2. const auditConst = require('../const/audit');
  3. /**
  4. * 附件表 数据模型
  5. * @author LanJianRong
  6. * @date 2020/8/17
  7. * @version
  8. */
  9. module.exports = app => {
  10. class AdvanceFile extends app.BaseService {
  11. /**
  12. * 构造函数
  13. * @param {Object} ctx - egg全局变量
  14. * @return {void}
  15. */
  16. constructor(ctx) {
  17. super(ctx);
  18. this.tableName = 'advance_file';
  19. }
  20. /**
  21. * 获取文件
  22. * @param {*} payload 载荷|查询条件
  23. */
  24. async getAdvanceFiles(payload) {
  25. const { ctx } = this;
  26. const result = await this.db.select(this.tableName, { where: payload });
  27. const list = result.map(item => {
  28. if (!ctx.helper.canPreview(item.fileext)) {
  29. item.filepath = `tender/${ctx.tender.id}/advance/${item.vid}/file/${item.id}/download`;
  30. }
  31. return item;
  32. });
  33. return list;
  34. }
  35. /**
  36. * 存储上传的文件信息至数据库
  37. * @param {Array} payload 载荷
  38. * @return {Promise<void>} 数据库插入执行实例
  39. */
  40. async saveFileMsgToDb(payload) {
  41. return await this.db.insert(this.tableName, payload);
  42. }
  43. /**
  44. * 删除附件
  45. * @param {Number} id - 附件id
  46. * @return {void}
  47. */
  48. async delete(id) {
  49. return await this.deleteById(id);
  50. }
  51. }
  52. return AdvanceFile;
  53. };