131 lines
4.7 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');
/**
* 系统方法层:report.deliveryPlan(货主报表投递计划接口包装层)。
* 仅做出口包装与参数解构,业务逻辑下沉 systems/reportDelivery。
*/
class ReportDeliveryPlanMethodService extends MainService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
// 计划管理属于管理类操作:不声明免权限,仅通配符角色(超级管理员/仓库管理员)可用,
// 后续由 wms_permission 同步流程按需授权,不扩大任何角色授权范围
const _noNeedRight = '';
const _noNeedLog = '';
const _noNeedAuth = '';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 新增/更新投递计划(货主+报表定义ID唯一,存在则更新)。
* @param {Object} data 请求体
* @param {number} data.store_id 货主ID(必填)
* @param {number} data.report_id 报表定义ID(必填,兼容 reportId)
* @param {Array<string>} data.schedule_times 每日投递时间点数组(HH:mm,自动去重排序)
* @param {string} [data.channel='inbox'] 投递渠道(仅支持 inbox)
* @param {number} [data.late_grace_minutes=60] 补投宽限分钟(0-1440)
* @param {string|null} [data.name] 计划名称(可空;未传不覆盖,null/空串清空,非空 trim ≤100)
* @param {string} [data.remark] 备注
* @param {string} [data.notify_template] 文本通知模板(≤500,白名单标签 {time}/{url}/{report_name}/{biz_date})
* @param {Array<number>} [data.notify_group_ids] 通知群ID数组(wms_inbox_group.id,≤20)
* @param {Array<string>} [data.notify_member_ids] 通知成员ID数组(外部IM用户ID,≤100)
* @return {Promise<Object>} 统一 success 包装
*/
async save(data = {}) {
const { service } = this;
const {
store_id: storeId,
report_id: reportIdSnake,
reportId: reportIdCamel,
schedule_times: scheduleTimes,
channel,
late_grace_minutes: lateGraceMinutes,
name,
remark,
notify_template: notifyTemplate,
notify_group_ids: notifyGroupIds,
notify_member_ids: notifyMemberIds,
} = data;
// 基础参数解构透传;通知类参数仅在入参存在时附加,
// 保持旧调用形状与既有回归断言一致(undefined 不进入参数对象)
const saveArgs = {
storeId,
reportId: reportIdCamel !== undefined ? reportIdCamel : reportIdSnake,
scheduleTimes,
channel,
lateGraceMinutes,
remark,
};
if (name !== undefined) {
saveArgs.name = name;
}
if (notifyTemplate !== undefined) {
saveArgs.notifyTemplate = notifyTemplate;
}
if (notifyGroupIds !== undefined) {
saveArgs.notifyGroupIds = notifyGroupIds;
}
if (notifyMemberIds !== undefined) {
saveArgs.notifyMemberIds = notifyMemberIds;
}
const result = await service.systems.reportDelivery.savePlan(saveArgs);
return this.success('ok', result);
}
/**
* 快速复制投递计划到其他货主(目标已存在相同报表定义计划时跳过,不覆盖不报错)。
* @param {Object} data 请求体
* @param {number} data.id 源计划ID(必填,正整数)
* @param {Array<number>} data.store_ids 目标货主ID数组(必填,兼容 storeIds 驼峰)
* @return {Promise<Object>} 统一 success 包装,data={ created, skipped }
*/
async copy(data = {}) {
const { service } = this;
const {
id,
store_ids: storeIdsSnake,
storeIds: storeIdsCamel,
} = data;
// 兼容 storeIds 驼峰入参,优先取驼峰形式,保持与 save 的 reportId 兼容口径一致
const storeIds = storeIdsCamel !== undefined ? storeIdsCamel : storeIdsSnake;
const result = await service.systems.reportDelivery.copyPlan({ id, storeIds });
return this.success('ok', result);
}
/**
* 分页查询投递计划列表。
* @param {Object} data 请求体
* @param {Object} [data.where] 查询条件(store_id/report_id/enabled)
* @param {Object} [data.pagination] 分页 { page, pageSize }
* @param {Object} [data.sort] 排序 { sortField, sortOrder }
* @return {Promise<Object>} 统一 success 包装
*/
async list(data = {}) {
const { service } = this;
const { whereValue = {} } = this.prepareWhereContext(data);
const {
store_id: storeId,
report_id: reportId,
enabled,
} = whereValue;
const { pagination = {}, sort = {} } = data;
const result = await service.systems.reportDelivery.listPlans({
storeId,
reportId,
enabled,
pagination,
sort,
});
return this.success('ok', result);
}
}
module.exports = ReportDeliveryPlanMethodService;