12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- 'use strict';
- const archiver = require('archiver');
- const path = require('path');
- const fs = require('fs');
- /**
- * 附件表 数据模型
- * @author LanJianRong
- * @date 2020/6/30
- * @version
- */
- module.exports = app => {
- class QualityInspectionAtt extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'quality_inspection_attachment';
- }
- /**
- * 获取当前标段(期)所有上传的附件
- * @param {Number} tid 标段id
- * @param {Number?} mid 期id
- * @return {Promise<void>} 数据库查询实例
- */
- async getAllAtt(tid, qiid) {
- const { ctx } = this;
- // qiid 如果qiid只有一个就转成数组
- if (!tid || !qiid) {
- return [];
- }
- qiid = qiid instanceof Array ? qiid : [qiid];
- const sql = 'SELECT a.*,b.name as username FROM ?? as a LEFT JOIN ?? as b ON a.uid = b.id WHERE a.tid = ? AND a.qiid in (' + ctx.helper.getInArrStrSqlFilter(qiid) + ') ORDER BY upload_time DESC';
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, tid];
- const result = await this.db.query(sql, sqlParam);
- return result.map(item => {
- item.orginpath = this.ctx.app.config.fujianOssPath + item.filepath;
- if (!ctx.helper.canPreview(item.fileext)) {
- item.filepath = `/tender/${ctx.tender.id}/change/plan/${item.cpid}/information/file/${item.id}/download`;
- } else {
- item.filepath = this.ctx.app.config.fujianOssPath + item.filepath;
- }
- return item;
- });
- }
- /**
- * 存储上传的文件信息至数据库
- * @param {Array} payload 载荷
- * @return {Promise<void>} 数据库插入执行实例
- */
- async saveFileMsgToDb(payload) {
- return await this.db.insert(this.tableName, payload);
- }
- /**
- * 获取单个文件信息
- * @param {Number} id 文件id
- * @return {Promise<void>} 数据库查询实例
- */
- async getMaterialFileById(id) {
- return await this.getDataByCondition({ id });
- }
- /**
- * 删除附件
- * @param {Number} id - 附件id
- * @return {void}
- */
- async delete(id) {
- return await this.deleteById(id);
- }
- }
- return QualityInspectionAtt;
- };
|