liufumingren 9c2b254206 1
Co-authored-by: Copilot <copilot@github.com>
2026-05-11 08:44:27 +08:00

85 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const MainService = require('../../main');
class SettingWarehouseMethodsService extends MainService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
const _noNeedRight = 'getSettings,getFieldMeta,saveSettings';
const _noNeedLog = '*';
const _noNeedAuth = 'getSettings,getFieldMeta,saveSettings';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 获取仓库设置(subject_config)。
*
* @return {Promise<Object>} 统一响应结果。
*/
async getSettings() {
const targetService = this.service && this.service.systems && this.service.systems.setting && this.service.systems.setting.warehouse;
if (!targetService || typeof targetService.getSettings !== 'function') {
return this.fail('获取仓库设置失败', { code: 500 });
}
try {
const result = await targetService.getSettings();
return this.success('ok', result);
} catch (error) {
return this.fail(error.message || '获取仓库设置失败', {
code: Number(error.code) || 500,
});
}
}
/**
* 获取仓库设置字段元信息列表。
*
* @return {Promise<Object>} 统一响应结果。
*/
async getFieldMeta() {
const targetService = this.service && this.service.systems && this.service.systems.setting && this.service.systems.setting.warehouse;
if (!targetService || typeof targetService.getFieldMeta !== 'function') {
return this.fail('获取仓库设置字段信息失败', { code: 500 });
}
try {
const list = await targetService.getFieldMeta();
return this.success('ok', { list });
} catch (error) {
return this.fail(error.message || '获取仓库设置字段信息失败', {
code: Number(error.code) || 500,
});
}
}
/**
* 修改仓库设置并清理当前仓库缓存。
*
* @param {Object} data 请求参数。
* @return {Promise<Object>} 统一响应结果。
*/
async saveSettings(data = {}) {
const targetService = this.service && this.service.systems && this.service.systems.setting && this.service.systems.setting.warehouse;
if (!targetService || typeof targetService.saveSettings !== 'function') {
return this.fail('保存仓库设置失败', { code: 500 });
}
try {
const { subject_config } = data || {};
const result = await targetService.saveSettings({ subject_config });
return this.success('ok', result);
} catch (error) {
return this.fail(error.message || '保存仓库设置失败', {
code: Number(error.code) || 500,
});
}
}
}
module.exports = SettingWarehouseMethodsService;