来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
71 lines
2.2 KiB
TypeScript
71 lines
2.2 KiB
TypeScript
export function formatCycleCode(code?: string | null): string {
|
||
const raw = String(code || '').trim();
|
||
if (!raw) return '-';
|
||
|
||
const rangeMatch = /^(\d{4})(\d{2})(\d{2})_(\d{4})(\d{2})(\d{2})$/.exec(raw);
|
||
if (rangeMatch) {
|
||
return `${rangeMatch[1]}-${rangeMatch[2]}-${rangeMatch[3]} ~ ${rangeMatch[4]}-${rangeMatch[5]}-${rangeMatch[6]}`;
|
||
}
|
||
|
||
const dayMatch = /^(\d{4})(\d{2})(\d{2})$/.exec(raw);
|
||
if (dayMatch) {
|
||
return `${dayMatch[1]}-${dayMatch[2]}-${dayMatch[3]}`;
|
||
}
|
||
|
||
const monthMatch = /^(\d{4})-?(\d{2})$/.exec(raw);
|
||
if (monthMatch) {
|
||
return `${monthMatch[1]}年${monthMatch[2]}月`;
|
||
}
|
||
|
||
const weekMatch = /^(\d{4})-?W(\d{1,2})$/i.exec(raw);
|
||
if (weekMatch) {
|
||
return `${weekMatch[1]}年第${weekMatch[2].padStart(2, '0')}周`;
|
||
}
|
||
|
||
if (/^CYC/i.test(raw)) {
|
||
return `旧履约周期(尾号${raw.slice(-6)})`;
|
||
}
|
||
|
||
if (/^REF/i.test(raw)) {
|
||
return `售后退款周期(尾号${raw.slice(-6)})`;
|
||
}
|
||
|
||
return raw;
|
||
}
|
||
|
||
/** 从 cycle_code 解析账期起止(YYYYMMDD / YYYYMM / YYYYMMDD_YYYYMMDD) */
|
||
export function parseCycleCodePeriod(cycleCode?: string | null): { start: string; end: string } | null {
|
||
const raw = String(cycleCode || '').trim();
|
||
const rangeMatch = /^(\d{4})(\d{2})(\d{2})_(\d{4})(\d{2})(\d{2})$/.exec(raw);
|
||
if (rangeMatch) {
|
||
return {
|
||
start: `${rangeMatch[1]}-${rangeMatch[2]}-${rangeMatch[3]}`,
|
||
end: `${rangeMatch[4]}-${rangeMatch[5]}-${rangeMatch[6]}`,
|
||
};
|
||
}
|
||
const dayMatch = /^(\d{4})(\d{2})(\d{2})$/.exec(raw);
|
||
if (dayMatch) {
|
||
const d = `${dayMatch[1]}-${dayMatch[2]}-${dayMatch[3]}`;
|
||
return { start: d, end: d };
|
||
}
|
||
const monthMatch = /^(\d{4})(\d{2})$/.exec(raw.replace('-', ''));
|
||
if (!monthMatch) return null;
|
||
const y = Number(monthMatch[1]);
|
||
const m = Number(monthMatch[2]);
|
||
const start = `${y}-${String(m).padStart(2, '0')}-01`;
|
||
const next = new Date(y, m, 1);
|
||
next.setDate(0);
|
||
const end = `${next.getFullYear()}-${String(next.getMonth() + 1).padStart(2, '0')}-${String(next.getDate()).padStart(2, '0')}`;
|
||
return { start, end };
|
||
}
|
||
|
||
/** 账期与筛选区间是否重叠(闭区间) */
|
||
export function periodsOverlap(
|
||
aStart: string,
|
||
aEnd: string,
|
||
bStart: string,
|
||
bEnd: string
|
||
): boolean {
|
||
return aStart <= bEnd && aEnd >= bStart;
|
||
}
|