85 lines
2.6 KiB
JavaScript
85 lines
2.6 KiB
JavaScript
'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;
|