80 lines
2.8 KiB
TypeScript
80 lines
2.8 KiB
TypeScript
const SHANGHAI_TIME_ZONE = 'Asia/Shanghai'
|
||
|
||
type ShanghaiDateTimeParts = {
|
||
year: string
|
||
month: string
|
||
day: string
|
||
hour: string
|
||
minute: string
|
||
second: string
|
||
}
|
||
|
||
const getShanghaiDateTimeParts = (date: Date): ShanghaiDateTimeParts => {
|
||
if (Number.isNaN(date.getTime())) {
|
||
throw new Error('导出时间无效')
|
||
}
|
||
|
||
const parts = new Intl.DateTimeFormat('en-CA', {
|
||
timeZone: SHANGHAI_TIME_ZONE,
|
||
year: 'numeric',
|
||
month: '2-digit',
|
||
day: '2-digit',
|
||
hour: '2-digit',
|
||
minute: '2-digit',
|
||
second: '2-digit',
|
||
hourCycle: 'h23'
|
||
}).formatToParts(date)
|
||
const partMap = new Map(parts.map((part) => [part.type, part.value]))
|
||
|
||
return {
|
||
year: partMap.get('year') || '',
|
||
month: partMap.get('month') || '',
|
||
day: partMap.get('day') || '',
|
||
hour: partMap.get('hour') || '',
|
||
minute: partMap.get('minute') || '',
|
||
second: partMap.get('second') || ''
|
||
}
|
||
}
|
||
|
||
export const formatShanghaiExportDateTime = (date: Date) => {
|
||
const parts = getShanghaiDateTimeParts(date)
|
||
return `${parts.year}-${parts.month}-${parts.day} ${parts.hour}:${parts.minute}:${parts.second}`
|
||
}
|
||
|
||
export const formatShanghaiExportFilenameTimestamp = (date: Date) => {
|
||
const parts = getShanghaiDateTimeParts(date)
|
||
return `${parts.year}${parts.month}${parts.day}_${parts.hour}${parts.minute}${parts.second}`
|
||
}
|
||
|
||
export const buildEquipmentExportDescriptionRows = (exportedAt: Date) => [
|
||
{ item: '文件性质', description: '导出时点快照' },
|
||
{
|
||
item: '导出时间',
|
||
description: `${formatShanghaiExportDateTime(exportedAt)}(Asia/Shanghai)`
|
||
},
|
||
{
|
||
item: '关系口径',
|
||
description:
|
||
'按导出时同一次只读事务快照中的当前 parent_id / children 父子关系生成,不包含历史挂载记录。'
|
||
},
|
||
{
|
||
item: '时效提醒',
|
||
description: '父子关系会随挂载、卸载而变化,请以系统最新导出为准。'
|
||
},
|
||
{
|
||
item: '台账阅读',
|
||
description:
|
||
'“行政资产台账”每个根资产只占一行;当前子资产按 CPU、主板、内存、固态硬盘、机械硬盘、显卡六类拆列,无法识别的类型完整保留在“其他子资产”。同一分类有多项时按资产编码稳定排序并换行显示。'
|
||
},
|
||
{
|
||
item: '关系核对',
|
||
description:
|
||
'“关系核对”只提示非电脑类根资产包含硬件子资产、存在未识别子资产或存在多个当前借用记录,不会自动改写当前资产关系;完整父子关系请查看“资产关系明细”。'
|
||
},
|
||
{
|
||
item: '金额口径',
|
||
description:
|
||
'“当前价值(元)”沿用现有金额口径:根资产组合金额在导出快照内汇总组内全部本体价值,每个根资产只占一行,可安全求和;子资产自身价值请查看“资产关系明细”。'
|
||
}
|
||
]
|