1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- 'use strict';
- /**
- * Created by EllisRan on 2020/3/3.
- */
- const BaseService = require('../base/base_service');
- module.exports = app => {
- class ConstructionAtt extends BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'construction_attachment';
- }
- /**
- * 添加附件
- * @param {Object} postData - 表单信息
- * @param {Object} fileData - 文件信息
- * @param {int} uid - 上传者id
- * @return {void}
- */
- async save(postData, fileData, uid) {
- const data = {
- tid: postData.tid,
- log_id: postData.log_id,
- uid,
- };
- Object.assign(data, fileData);
- const result = await this.db.insert(this.tableName, data);
- return result;
- }
- /**
- * 获取 详情 所有附件
- * @param {uuid} td_id - 详情id
- * @return {Promise<void>}
- */
- async getConstructionAttachment(log_id, sort = 'asc') {
- const sql = 'SELECT ca.*, pa.name As u_name, pa.role As u_role ' +
- ' FROM ?? As ca ' +
- ' Left Join ?? As pa ' +
- ' On ca.uid = pa.id ' +
- ' Where ca.log_id = ? order by id ' + sort;
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, log_id];
- const result = await this.db.query(sql, sqlParam);
- return result.map(item => {
- item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
- if (!this.ctx.helper.canPreview(item.fileext)) {
- item.filepath = `/construction/${item.tid}/log/${item.log_id}/file/${item.id}/download`;
- } else {
- item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
- item.viewpath = item.filepath;
- }
- return item;
- });
- }
- }
- return ConstructionAtt;
- };
|