1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- 'use strict';
- /**
- *
- * 附件
- * @author Ellisran
- * @date 2019/1/11
- * @version
- */
- module.exports = app => {
- class StageAtt extends app.BaseService {
- /**
- * 构造函数
- *
- * @param {Object} ctx - egg全局变量
- * @return {void}
- */
- constructor(ctx) {
- super(ctx);
- this.tableName = 'stage_attachment';
- }
- /**
- * 添加附件
- * @param {Object} postData - 表单信息
- * @param {Object} fileData - 文件信息
- * @param {int} uid - 上传者id
- * @return {void}
- */
- async save(postData, fileData, uid) {
- const data = {
- lid: postData.lid,
- uid,
- remark: '',
- };
- Object.assign(data, fileData);
- const result = await this.db.insert(this.tableName, data);
- return result;
- }
- /**
- * 添加附件
- * @param {Object} postData - 表单信息
- * @param {Object} fileData - 文件信息
- * @param {int} uid - 上传者id
- * @return {void}
- */
- async updateByID(postData, fileData) {
- delete postData.size;
- const data = {};
- Object.assign(data, fileData);
- Object.assign(data, postData);
- const result = await this.db.update(this.tableName, data);
- return result.affectedRows === 1;
- }
- /**
- * 获取所有附件
- * @param {int} tid - 标段id
- * @param {int} sid - 当前期数
- * @return {void}
- */
- async getDataByTenderIdAndStageId(tid, sid) {
- const { ctx } = this;
- const sql = 'SELECT att.id, att.lid, att.uid, att.filename, att.fileext, att.filesize, att.re_upload, att.remark, att.in_time,' +
- ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`, leg.b_code as `b_code`' +
- ' FROM ?? AS att,?? AS pa,?? AS leg' +
- ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.tid = ? AND att.sid = ? ORDER BY att.id DESC';
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, tid, sid];
- return await this.db.query(sql, sqlParam);
- }
- /**
- * 获取单个附件
- * @param {int} tid - 标段id
- * @param {int} sid - 当前期数
- * @return {void}
- */
- async getDataByFid(id) {
- const { ctx } = this;
- const sql = 'SELECT att.id, att.lid, att.uid, att.filepath, att.filename, att.re_upload, att.fileext, att.filesize, att.remark, att.in_time,' +
- ' pa.name as `username`, leg.name as `lname`, leg.code as `code`, leg.ledger_id as `ledger_id`,leg.b_code as `b_code`' +
- ' FROM ?? AS att,?? AS pa,?? AS leg' +
- ' WHERE leg.id = att.lid AND pa.id = att.uid AND att.id = ? ORDER BY att.in_time DESC';
- const sqlParam = [this.tableName, this.ctx.service.projectAccount.tableName, this.ctx.service.ledger.tableName, id];
- const result = await this.db.queryOne(sql, sqlParam);
- if (!ctx.helper.canPreview(result.fileext)) result.filepath = `/tender/${ctx.tender.id}/measure/stage/${ctx.params.order}/download/file/${result.id}`;
- else result.filepath = result.filepath.replace(/^app|\/app/, '');
- return result;
- }
- }
- return StageAtt;
- };
|