| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | 'use strict';/** * *  附件 * @author Ellisran * @date 2019/1/11 * @version */module.exports = app => {    class ChangeAtt extends app.BaseService {        /**         * 构造函数         *         * @param {Object} ctx - egg全局变量         * @return {void}         */        constructor(ctx) {            super(ctx);            this.tableName = 'change_attachment';        }        /**         * 添加附件         * @param {Object} postData - 表单信息         * @param {Object} fileData - 文件信息         * @param {int} uid - 上传者id         * @return {void}         */        async save(postData, fileData, uid) {            const data = {                tid: postData.tid,                cid: postData.cid,                uid,            };            Object.assign(data, fileData);            const result = await this.db.insert(this.tableName, data);            return result;        }        /**         * 获取 变更令 所有附件         * @param {uuid} cid - 变更令id         * @return {Promise<void>}         */        async getChangeAttachment(cid) {            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.cid = ?';            const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, cid];            return await this.db.query(sql, sqlParam);        }        /**         * 获取所有附件         * @param {String} cid 变更令id         */        async getAllChangeFiles(cid) {            const { ctx } = this;            const result = await this.db.select(this.tableName, { where: { cid } });            return result.map(item => {                if (!ctx.helper.canPreview(item.fileext)) {                    item.filepath = `/change/download/file/${item.id}`;                } else {                    item.filepath = item.filepath.replace(/^app|\/app/, '');                }                return item;            });        }    }    return ChangeAtt;};
 |