v4.0.17企业微信API插件优化
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { maskContactPhone } from './phone';
|
||||
import { shanghaiYmd, startOfShanghaiDay } from './shanghai-date';
|
||||
import { wecomReportPeriod, type WecomReportKind, type WecomReportPeriod } from './wecom-report';
|
||||
import { addShanghaiDays, shanghaiYmd, startOfShanghaiDay } from './shanghai-date';
|
||||
import {
|
||||
wecomReportPeriod,
|
||||
type WecomReportKind,
|
||||
type WecomReportPeriod,
|
||||
type WecomReportStats,
|
||||
} from './wecom-report';
|
||||
|
||||
export const WECOM_PLUGIN_PAGE_SIZE_DEFAULT = 5;
|
||||
export const WECOM_PLUGIN_PAGE_SIZE_MAX = 10;
|
||||
@@ -53,6 +58,20 @@ export function isWecomPluginEnabled(env: {
|
||||
return env.WECOM_PLUGIN_ENABLED === 'true' && Boolean(String(env.WECOM_PLUGIN_API_KEY ?? '').trim());
|
||||
}
|
||||
|
||||
/** 在少量启用实例中做常量时间匹配(长度不等仍会先失败) */
|
||||
export function matchWecomPluginByApiKey<T extends { apiKey: string }>(
|
||||
provided: string,
|
||||
candidates: T[],
|
||||
): T | null {
|
||||
const got = String(provided ?? '').trim();
|
||||
if (!got) return null;
|
||||
let hit: T | null = null;
|
||||
for (const row of candidates) {
|
||||
if (verifyWecomPluginApiKey(got, row.apiKey)) hit = row;
|
||||
}
|
||||
return hit;
|
||||
}
|
||||
|
||||
export function wecomPluginMetricsPeriod(
|
||||
kind: WecomPluginMetricsKind,
|
||||
now = new Date(),
|
||||
@@ -74,6 +93,45 @@ export function wecomPluginMetricsPeriod(
|
||||
return { ...period, kind };
|
||||
}
|
||||
|
||||
export type WecomPluginDateRange = { gte?: Date; lt?: Date };
|
||||
|
||||
/** 插件时间筛选:from/to 支持 YYYY-MM-DD 或 ISO;日期含当天全天 */
|
||||
export function parseWecomPluginDateRange(
|
||||
fromRaw?: string | null,
|
||||
toRaw?: string | null,
|
||||
): WecomPluginDateRange | undefined {
|
||||
const from = parseWecomPluginDate(fromRaw);
|
||||
const to = parseWecomPluginDate(toRaw);
|
||||
if (!from && !to) return undefined;
|
||||
const range: WecomPluginDateRange = {};
|
||||
if (from) range.gte = from;
|
||||
if (to) {
|
||||
range.lt = isWecomPluginDateOnly(toRaw) ? addShanghaiDays(startOfShanghaiDay(to), 1) : to;
|
||||
}
|
||||
return range;
|
||||
}
|
||||
|
||||
function isWecomPluginDateOnly(raw?: string | null): boolean {
|
||||
return /^\d{4}-\d{2}-\d{2}$/.test(String(raw ?? '').trim());
|
||||
}
|
||||
|
||||
function parseWecomPluginDate(raw?: string | null): Date | null {
|
||||
const v = String(raw ?? '').trim();
|
||||
if (!v) return null;
|
||||
if (/^\d{4}-\d{2}-\d{2}$/.test(v)) {
|
||||
return startOfShanghaiDay(new Date(`${v}T00:00:00+08:00`));
|
||||
}
|
||||
const d = new Date(v);
|
||||
return Number.isFinite(d.getTime()) ? d : null;
|
||||
}
|
||||
|
||||
export function toWecomPluginMetricsView(stats: WecomReportStats) {
|
||||
return {
|
||||
...stats,
|
||||
newStores: stats.storesIncrement,
|
||||
};
|
||||
}
|
||||
|
||||
export function toWecomPluginUserView(user: {
|
||||
userNo: string;
|
||||
nickname?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user