52 lines
1.6 KiB
JavaScript
52 lines
1.6 KiB
JavaScript
'use strict';
|
||
|
||
const Service = require('egg').Service;
|
||
|
||
/**
|
||
* 站内信工具方法集合(与业务函数无关的辅助逻辑)。
|
||
* 从 inbox/functions.js 拆出,保持 functions.js 只负责业务函数注册与执行。
|
||
*/
|
||
class InboxToolsService extends Service {
|
||
|
||
/**
|
||
* 获取仓库的录制电脑 ID(带缓存)。
|
||
* @param {number} warehouseId 仓库ID
|
||
* @return {Promise<number|null>} 录制电脑ID,找不到返回 null
|
||
*/
|
||
async getRecordingComputerId(warehouseId) {
|
||
const cacheKey = `_recordingComputer_${warehouseId}`;
|
||
if (this[cacheKey] !== undefined) {
|
||
return this[cacheKey];
|
||
}
|
||
const row = await this.ctx.model.PrintComputer.findOne({
|
||
where: { warehouse_id: warehouseId, is_recording: true, deleted_at: null },
|
||
attributes: [ 'id' ],
|
||
raw: true,
|
||
});
|
||
this[cacheKey] = row ? row.id : null;
|
||
return this[cacheKey];
|
||
}
|
||
|
||
/**
|
||
* 构建视频完整 URL。
|
||
* 格式:http://w{warehouseId}-c{recordingComputerId}.o.gztbyc.com{videoPath}
|
||
* @param {number} warehouseId 仓库ID
|
||
* @param {number|null} recordingComputerId 录制电脑ID
|
||
* @param {string} videoPath 视频路径
|
||
* @return {string} 完整 URL
|
||
*/
|
||
buildVideoUrl(warehouseId, recordingComputerId, videoPath) {
|
||
const path = String(videoPath || '').trim();
|
||
if (!path || !recordingComputerId) {
|
||
return path;
|
||
}
|
||
// 已是完整 URL 时原样返回,避免重复拼接
|
||
if (/^https?:\/\//i.test(path)) {
|
||
return path;
|
||
}
|
||
return `http://w${warehouseId}-c${recordingComputerId}.o.gztbyc.com${path}`;
|
||
}
|
||
}
|
||
|
||
module.exports = InboxToolsService;
|