| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- module.exports = app => {
- class Filing extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @param {String} tableName - 表名
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'file';
- }
- async getFileList(spid, filing_id) {
- const result = await this.getAllDataByCondition({
- where: { spid, filing_id },
- orders: [['create_time', 'asc']],
- limit: this.app.config.pageSize, offset: (this.ctx.page - 1) * this.app.config.pageSize
- });
- const helper = this.ctx.helper;
- result.forEach(x => {
- x.viewpath = helper.canPreview(x.fileext) ? ctx.app.config.fujianOssPath + x.filepath : '';
- x.fileext_str = helper.fileExtStr(x.fileext);
- });
- return result;
- }
- async addFile(filing_id, fileInfo, user) {
- const filing = await this.ctx.service.filing.getDataById(filing_id);
- if (!filing || filing.is_delete) throw '当前分类不存在';
- const insertData = {
- spid: filing.spid, filing_id: filing.id, filing_type: filing.filing_type,
- user_id: user.id, user_name: user.name, user_company: user.company, user_role: user.role,
- filename: fileInfo.filename, fileext: fileInfo.fileext, filesize: fileInfo.fileSize, filepath: fileInfo.filepath,
- };
- const result = await this.db.insert(this.tableName, insertData);
- }
- }
- return Filing;
- };
|