feat: 媒体存储改为模板ID/档案编号层级并按人类可读命名归位(出库图独立追溯码子目录)
This commit is contained in:
@@ -32,7 +32,10 @@ export class OutboundService {
|
||||
) {}
|
||||
|
||||
async updateSingle(traceCodeId: bigint, dto: OutboundDto) {
|
||||
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
|
||||
const code = await this.prisma.traceCode.findUnique({
|
||||
where: { id: traceCodeId },
|
||||
include: { artwork: { select: { templateId: true, archiveNo: true } } },
|
||||
});
|
||||
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
|
||||
// 一物一码只能出库一次:已登记出库时间或出库图任一即视为已出库
|
||||
if (isOutbound(code)) {
|
||||
@@ -46,10 +49,17 @@ export class OutboundService {
|
||||
const data: Prisma.TraceCodeUpdateInput = {};
|
||||
if ('outTime' in dto) data.outTime = dto.outTime ? new Date(dto.outTime) : null;
|
||||
if ('outImageKeys' in dto || 'outImageKey' in dto) {
|
||||
let imageItems = imageKeys.map((key) => ({ key, type: 'image', name: key.split('/').pop() || '出库实况图' }));
|
||||
// 出库实况图归位到 {模板ID}/{档案编号}/{追溯码}/出库实况_{时间戳}_{序号}
|
||||
if (imageItems.length && code.artwork?.archiveNo) {
|
||||
const dir = `${code.artwork.templateId}/${code.artwork.archiveNo}/${code.shortCode}`;
|
||||
imageItems = (await this.storage.relocateMedia(imageItems, dir, '出库实况')).items.map((item) => ({
|
||||
...item,
|
||||
name: item.key.split('/').pop() || item.name,
|
||||
}));
|
||||
}
|
||||
// 无图时写 DB NULL(而非 JSON null),保证出库状态筛选一致
|
||||
data.outImages = imageKeys.length
|
||||
? imageKeys.map((key) => ({ key, type: 'image', name: key.split('/').pop() || '出库实况图' }))
|
||||
: Prisma.DbNull;
|
||||
data.outImages = imageItems.length ? imageItems : Prisma.DbNull;
|
||||
}
|
||||
if ('remark' in dto) data.remark = dto.remark || null;
|
||||
return this.prisma.traceCode.update({
|
||||
|
||||
Reference in New Issue
Block a user