feat: 增强追溯码单码管理
This commit is contained in:
@@ -96,6 +96,7 @@
|
|||||||
- 后台列表布局与分页统一(2026-07-03):后台主列表统一接入 `useTablePage`,默认每页 20,分页容量支持 20/50/100/200/不限制/自定义;“不限制”前端用 `Number.MAX_SAFE_INTEGER` 保持分页器稳定,请求时转换为 `pageSize=0`。后端 `PaginationDto` 约定 `pageSize=0` 表示不分页,`take` 返回 `undefined`,`buildPage` 返回 page=1/pageSize=0。所有主数据表页面(艺术品档案、模板、内容审核、查询日志、用户、追溯码面板)使用 `table-page` + `table-fill`,页面布局固定为“工具栏 / 表格滚动区 / 底部分页栏”;`n-data-table` 禁用内置分页,外置 `n-pagination` 固定在底部,避免空数据/少数据时分页贴在表头下方,也避免多数据时分页被表格内容挤出视口。追溯码嵌套页需让 `n-card-content -> trace-table-wrap -> TraceCodePanel` 全链路传递 `min-height:0` 与 flex 高度,防止表体高度塌为 0。自定义分页条数只在选择“自定义条数”后展开输入框和应用按钮,应用后自动收起,并把输入值动态加入分页容量下拉显示为 `{n} / 页`。已用浏览器实测艺术品档案、查询日志、批次与追溯码管理行数据显示正常。
|
- 后台列表布局与分页统一(2026-07-03):后台主列表统一接入 `useTablePage`,默认每页 20,分页容量支持 20/50/100/200/不限制/自定义;“不限制”前端用 `Number.MAX_SAFE_INTEGER` 保持分页器稳定,请求时转换为 `pageSize=0`。后端 `PaginationDto` 约定 `pageSize=0` 表示不分页,`take` 返回 `undefined`,`buildPage` 返回 page=1/pageSize=0。所有主数据表页面(艺术品档案、模板、内容审核、查询日志、用户、追溯码面板)使用 `table-page` + `table-fill`,页面布局固定为“工具栏 / 表格滚动区 / 底部分页栏”;`n-data-table` 禁用内置分页,外置 `n-pagination` 固定在底部,避免空数据/少数据时分页贴在表头下方,也避免多数据时分页被表格内容挤出视口。追溯码嵌套页需让 `n-card-content -> trace-table-wrap -> TraceCodePanel` 全链路传递 `min-height:0` 与 flex 高度,防止表体高度塌为 0。自定义分页条数只在选择“自定义条数”后展开输入框和应用按钮,应用后自动收起,并把输入值动态加入分页容量下拉显示为 `{n} / 页`。已用浏览器实测艺术品档案、查询日志、批次与追溯码管理行数据显示正常。
|
||||||
- 后台全局页脚(2026-07-03):`MainLayout.vue` 在登录后的管理后台底部统一增加页脚,先放置版权年份和“备案信息待补充”占位,后续版权/ICP备案/公安备案只改全局布局即可;全局 CSS 新增 `--admin-header-height` / `--admin-footer-height`,内容区和 `table-page` 高度统一扣除页脚高度,避免列表分页被页脚遮挡或挤出。
|
- 后台全局页脚(2026-07-03):`MainLayout.vue` 在登录后的管理后台底部统一增加页脚,先放置版权年份和“备案信息待补充”占位,后续版权/ICP备案/公安备案只改全局布局即可;全局 CSS 新增 `--admin-header-height` / `--admin-footer-height`,内容区和 `table-page` 高度统一扣除页脚高度,避免列表分页被页脚遮挡或挤出。
|
||||||
- 查询日志列表单行展示(2026-07-04):`QueryLogs.vue` 中短码、档案编号、批次编号、IP、设备信息列使用 Naive UI `ellipsis: { tooltip: true }`,列表内保持单行省略,鼠标悬浮查看完整内容;已浏览器测量设备信息列为 `white-space: nowrap` / `text-overflow: ellipsis`,避免设备信息换行拉高行高。
|
- 查询日志列表单行展示(2026-07-04):`QueryLogs.vue` 中短码、档案编号、批次编号、IP、设备信息列使用 Naive UI `ellipsis: { tooltip: true }`,列表内保持单行省略,鼠标悬浮查看完整内容;已浏览器测量设备信息列为 `white-space: nowrap` / `text-overflow: ellipsis`,避免设备信息换行拉高行高。
|
||||||
|
- 批次与追溯码管理增强(2026-07-04):艺术品批次管理页上方摘要新增批次数量统计(`ArtworkService.get` 的 `codeStats.batchTotal`);`TraceCodePanel` 操作列固定为二维码按钮 + 悬停操作菜单,单码支持修改分组、移动到同作品其他批次、启用/禁用、删除。后端新增 `PUT /trace-codes/:id` 与 `DELETE /trace-codes/:id`;移动批次会维护源/目标批次 `generatedCount`,删除单码会先把查询日志的 `traceCodeId` 置空保留日志快照,再删除码并扣减批次生成数。
|
||||||
|
|
||||||
## 当前代码基准与注意事项
|
## 当前代码基准与注意事项
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ export const traceCodeApi = {
|
|||||||
post('/trace-codes/batch', data),
|
post('/trace-codes/batch', data),
|
||||||
batches: (params: object) => get<PageResult<any>>('/batches', params),
|
batches: (params: object) => get<PageResult<any>>('/batches', params),
|
||||||
list: (params: object) => get<PageResult<any>>('/trace-codes', params),
|
list: (params: object) => get<PageResult<any>>('/trace-codes', params),
|
||||||
|
update: (id: string, data: { groupId?: number | null; batchId?: number; disabled?: boolean }) =>
|
||||||
|
put(`/trace-codes/${id}`, data),
|
||||||
|
remove: (id: string) => del(`/trace-codes/${id}`),
|
||||||
qrUrl: (id: string) => `/api/trace-codes/${id}/qrcode`,
|
qrUrl: (id: string) => `/api/trace-codes/${id}/qrcode`,
|
||||||
onchain: (id: string) => post(`/trace-codes/${id}/onchain`, {}),
|
onchain: (id: string) => post(`/trace-codes/${id}/onchain`, {}),
|
||||||
// 分组
|
// 分组
|
||||||
|
|||||||
@@ -149,8 +149,8 @@
|
|||||||
import { computed, h, onMounted, reactive, ref, watch } from 'vue';
|
import { computed, h, onMounted, reactive, ref, watch } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { NButton, NIcon, NTag, NText, type DataTableColumns } from 'naive-ui';
|
import { NButton, NDropdown, NIcon, NTag, NText, type DataTableColumns, type DropdownOption } from 'naive-ui';
|
||||||
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline } from '@vicons/ionicons5';
|
import { SearchOutline, AddOutline, DownloadOutline, QrCodeOutline, FolderOutline, OpenOutline, EllipsisHorizontalOutline } from '@vicons/ionicons5';
|
||||||
import { TraceCodeStatus } from '@artveris/shared';
|
import { TraceCodeStatus } from '@artveris/shared';
|
||||||
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
import { traceCodeApi, jobApi, artworkApi } from '@/api';
|
||||||
import { useAuthStore } from '@/stores/auth';
|
import { useAuthStore } from '@/stores/auth';
|
||||||
@@ -163,6 +163,9 @@ const props = defineProps<{
|
|||||||
artworkId?: number;
|
artworkId?: number;
|
||||||
embedded?: boolean;
|
embedded?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
const emit = defineEmits<{
|
||||||
|
(e: 'changed'): void;
|
||||||
|
}>();
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
@@ -198,6 +201,13 @@ const groupAssignOptions = computed(() => [
|
|||||||
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
{ label: t('pages.traceCode.noGroup'), key: '__none__' },
|
||||||
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
...groups.value.map((g) => ({ label: g.name, key: String(g.id) })),
|
||||||
]);
|
]);
|
||||||
|
const rowGroupOptions = computed<DropdownOption[]>(() => [
|
||||||
|
{ label: t('pages.traceCode.noGroup'), key: 'group:__none__' },
|
||||||
|
...groups.value.map((g) => ({ label: g.name, key: `group:${g.id}` })),
|
||||||
|
]);
|
||||||
|
const rowBatchOptions = computed<DropdownOption[]>(() =>
|
||||||
|
batchOptions.value.map((b) => ({ label: b.label, key: `batch:${b.value}` })),
|
||||||
|
);
|
||||||
|
|
||||||
const genModal = ref(false);
|
const genModal = ref(false);
|
||||||
const generating = ref(false);
|
const generating = ref(false);
|
||||||
@@ -248,9 +258,25 @@ const columns = computed<DataTableColumns<any>>(() => {
|
|||||||
{
|
{
|
||||||
title: () => t('common.label.operation'),
|
title: () => t('common.label.operation'),
|
||||||
key: 'ops',
|
key: 'ops',
|
||||||
width: 70,
|
width: auth.canWrite ? 104 : 70,
|
||||||
render: (r) =>
|
render: (r) =>
|
||||||
|
h('div', { class: 'row-actions' }, [
|
||||||
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
h(NButton, { quaternary: true, circle: true, size: 'small', onClick: () => showQr(r) }, { icon: () => h(NIcon, null, { default: () => h(QrCodeOutline) }) }),
|
||||||
|
auth.canWrite
|
||||||
|
? h(
|
||||||
|
NDropdown,
|
||||||
|
{ trigger: 'hover', options: rowActionOptions(r), onSelect: (key) => onRowAction(r, String(key)) },
|
||||||
|
{
|
||||||
|
default: () =>
|
||||||
|
h(
|
||||||
|
NButton,
|
||||||
|
{ quaternary: true, circle: true, size: 'small' },
|
||||||
|
{ icon: () => h(NIcon, null, { default: () => h(EllipsisHorizontalOutline) }) },
|
||||||
|
),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -270,7 +296,7 @@ function currentArtworkId() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadBatches() {
|
async function loadBatches() {
|
||||||
const params: Record<string, unknown> = { pageSize: 100 };
|
const params: Record<string, unknown> = { pageSize: 0 };
|
||||||
const aid = currentArtworkId();
|
const aid = currentArtworkId();
|
||||||
if (aid) params.artworkId = aid;
|
if (aid) params.artworkId = aid;
|
||||||
const res: any = await traceCodeApi.batches(params);
|
const res: any = await traceCodeApi.batches(params);
|
||||||
@@ -351,6 +377,7 @@ async function generate() {
|
|||||||
genForm.batchNo = '';
|
genForm.batchNo = '';
|
||||||
await loadBatches();
|
await loadBatches();
|
||||||
await load();
|
await load();
|
||||||
|
emit('changed');
|
||||||
} finally {
|
} finally {
|
||||||
generating.value = false;
|
generating.value = false;
|
||||||
}
|
}
|
||||||
@@ -397,12 +424,71 @@ async function batchAssignGroup(key: string) {
|
|||||||
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
await traceCodeApi.batchGroup(checkedKeys.value.map(String), groupId);
|
||||||
message.success(t('common.msg.operationSuccess'));
|
message.success(t('common.msg.operationSuccess'));
|
||||||
await load();
|
await load();
|
||||||
|
emit('changed');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function batchStatus(disabled: boolean) {
|
async function batchStatus(disabled: boolean) {
|
||||||
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
await traceCodeApi.batchStatus(checkedKeys.value.map(String), disabled);
|
||||||
message.success(t('common.msg.operationSuccess'));
|
message.success(t('common.msg.operationSuccess'));
|
||||||
await load();
|
await load();
|
||||||
|
emit('changed');
|
||||||
|
}
|
||||||
|
|
||||||
|
function rowActionOptions(row: any): DropdownOption[] {
|
||||||
|
return [
|
||||||
|
{ label: t('pages.traceCode.changeGroup'), key: 'changeGroup', children: rowGroupOptions.value },
|
||||||
|
{ label: t('pages.traceCode.changeBatch'), key: 'changeBatch', children: rowBatchOptions.value },
|
||||||
|
{ type: 'divider', key: 'divider-1' },
|
||||||
|
{
|
||||||
|
label: row.status === TraceCodeStatus.DISABLED ? t('pages.traceCode.enableOne') : t('pages.traceCode.disableOne'),
|
||||||
|
key: row.status === TraceCodeStatus.DISABLED ? 'status:enable' : 'status:disable',
|
||||||
|
},
|
||||||
|
{ label: t('common.action.delete'), key: 'delete' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
async function onRowAction(row: any, key: string) {
|
||||||
|
if (key.startsWith('group:')) {
|
||||||
|
const groupKey = key.slice('group:'.length);
|
||||||
|
await traceCodeApi.update(String(row.id), { groupId: groupKey === '__none__' ? null : Number(groupKey) });
|
||||||
|
message.success(t('common.msg.saved'));
|
||||||
|
await load();
|
||||||
|
emit('changed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key.startsWith('batch:')) {
|
||||||
|
await traceCodeApi.update(String(row.id), { batchId: Number(key.slice('batch:'.length)) });
|
||||||
|
message.success(t('common.msg.saved'));
|
||||||
|
await loadBatches();
|
||||||
|
await load();
|
||||||
|
emit('changed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key === 'status:disable' || key === 'status:enable') {
|
||||||
|
await traceCodeApi.update(String(row.id), { disabled: key === 'status:disable' });
|
||||||
|
message.success(t('common.msg.operationSuccess'));
|
||||||
|
await load();
|
||||||
|
emit('changed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (key === 'delete') {
|
||||||
|
dialog.warning({
|
||||||
|
title: t('common.action.delete'),
|
||||||
|
content: t('common.msg.confirmDelete'),
|
||||||
|
positiveText: t('common.action.confirm'),
|
||||||
|
negativeText: t('common.action.cancel'),
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
await traceCodeApi.remove(String(row.id));
|
||||||
|
message.success(t('common.msg.deleted'));
|
||||||
|
await loadBatches();
|
||||||
|
await load();
|
||||||
|
emit('changed');
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetGroupForm() {
|
function resetGroupForm() {
|
||||||
@@ -437,6 +523,7 @@ function removeGroup(g: any) {
|
|||||||
message.success(t('common.msg.deleted'));
|
message.success(t('common.msg.deleted'));
|
||||||
await loadGroups();
|
await loadGroups();
|
||||||
await load();
|
await load();
|
||||||
|
emit('changed');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -505,6 +592,11 @@ onMounted(async () => {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
.row-actions {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
}
|
||||||
.mr8 {
|
.mr8 {
|
||||||
margin-right: 8px;
|
margin-right: 8px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -190,6 +190,7 @@
|
|||||||
"artist": "Artist",
|
"artist": "Artist",
|
||||||
"template": "Template",
|
"template": "Template",
|
||||||
"archiveNo": "Archive No.",
|
"archiveNo": "Archive No.",
|
||||||
|
"batchCount": "Batches",
|
||||||
"codeCount": "Codes",
|
"codeCount": "Codes",
|
||||||
"activeCount": "Activated",
|
"activeCount": "Activated",
|
||||||
"queryTotal": "Total Queries",
|
"queryTotal": "Total Queries",
|
||||||
@@ -261,6 +262,10 @@
|
|||||||
"batchGroup": "Set Group",
|
"batchGroup": "Set Group",
|
||||||
"batchEnable": "Enable",
|
"batchEnable": "Enable",
|
||||||
"batchDisable": "Disable",
|
"batchDisable": "Disable",
|
||||||
|
"changeGroup": "Change Group",
|
||||||
|
"changeBatch": "Change Batch",
|
||||||
|
"enableOne": "Enable",
|
||||||
|
"disableOne": "Disable",
|
||||||
"selected": "{n} selected",
|
"selected": "{n} selected",
|
||||||
"assignGroup": "Assign group"
|
"assignGroup": "Assign group"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -190,6 +190,7 @@
|
|||||||
"artist": "艺术家",
|
"artist": "艺术家",
|
||||||
"template": "所属模板",
|
"template": "所属模板",
|
||||||
"archiveNo": "档案编号",
|
"archiveNo": "档案编号",
|
||||||
|
"batchCount": "批次数量",
|
||||||
"codeCount": "追溯码数",
|
"codeCount": "追溯码数",
|
||||||
"activeCount": "已激活",
|
"activeCount": "已激活",
|
||||||
"queryTotal": "查询总数",
|
"queryTotal": "查询总数",
|
||||||
@@ -261,6 +262,10 @@
|
|||||||
"batchGroup": "批量分组",
|
"batchGroup": "批量分组",
|
||||||
"batchEnable": "批量启用",
|
"batchEnable": "批量启用",
|
||||||
"batchDisable": "批量停用",
|
"batchDisable": "批量停用",
|
||||||
|
"changeGroup": "修改分组",
|
||||||
|
"changeBatch": "修改批次",
|
||||||
|
"enableOne": "启用",
|
||||||
|
"disableOne": "禁用",
|
||||||
"selected": "已选 {n} 项",
|
"selected": "已选 {n} 项",
|
||||||
"assignGroup": "设为分组"
|
"assignGroup": "设为分组"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
</n-tag>
|
</n-tag>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<n-descriptions :column="4" label-placement="top" bordered size="small">
|
<n-descriptions :column="5" label-placement="top" bordered size="small">
|
||||||
<n-descriptions-item :label="t('pages.artwork.archiveNo')">{{ artwork?.archiveNo || '-' }}</n-descriptions-item>
|
<n-descriptions-item :label="t('pages.artwork.archiveNo')">{{ artwork?.archiveNo || '-' }}</n-descriptions-item>
|
||||||
|
<n-descriptions-item :label="t('pages.artwork.batchCount')">{{ artwork?.codeStats?.batchTotal ?? artwork?.batches?.length ?? 0 }}</n-descriptions-item>
|
||||||
<n-descriptions-item :label="t('pages.artwork.codeCount')">{{ artwork?.codeStats?.total ?? 0 }}</n-descriptions-item>
|
<n-descriptions-item :label="t('pages.artwork.codeCount')">{{ artwork?.codeStats?.total ?? 0 }}</n-descriptions-item>
|
||||||
<n-descriptions-item :label="t('pages.artwork.activeCount')">{{ artwork?.codeStats?.active ?? 0 }}</n-descriptions-item>
|
<n-descriptions-item :label="t('pages.artwork.activeCount')">{{ artwork?.codeStats?.active ?? 0 }}</n-descriptions-item>
|
||||||
<n-descriptions-item :label="t('pages.artwork.queryTotal')">{{ artwork?.codeStats?.queryTotal ?? 0 }}</n-descriptions-item>
|
<n-descriptions-item :label="t('pages.artwork.queryTotal')">{{ artwork?.codeStats?.queryTotal ?? 0 }}</n-descriptions-item>
|
||||||
@@ -27,7 +28,7 @@
|
|||||||
|
|
||||||
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false" class="table-card">
|
<n-card :title="t('pages.artwork.traceCodes')" :bordered="false" class="table-card">
|
||||||
<div class="trace-table-wrap">
|
<div class="trace-table-wrap">
|
||||||
<trace-code-panel :artwork-id="artworkId" />
|
<trace-code-panel :artwork-id="artworkId" @changed="loadArtwork" />
|
||||||
</div>
|
</div>
|
||||||
</n-card>
|
</n-card>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -112,9 +112,10 @@ export class ArtworkService {
|
|||||||
});
|
});
|
||||||
if (!a) throw new BusinessException(ErrorCode.ARTWORK_NOT_FOUND, '艺术品不存在', 404);
|
if (!a) throw new BusinessException(ErrorCode.ARTWORK_NOT_FOUND, '艺术品不存在', 404);
|
||||||
// 码统计:总数、已激活数、查询总次数(按款聚合)
|
// 码统计:总数、已激活数、查询总次数(按款聚合)
|
||||||
const [total, active, agg] = await this.prisma.$transaction([
|
const [total, active, batchTotal, agg] = await this.prisma.$transaction([
|
||||||
this.prisma.traceCode.count({ where: { artworkId: id } }),
|
this.prisma.traceCode.count({ where: { artworkId: id } }),
|
||||||
this.prisma.traceCode.count({ where: { artworkId: id, status: 'ACTIVE' } }),
|
this.prisma.traceCode.count({ where: { artworkId: id, status: 'ACTIVE' } }),
|
||||||
|
this.prisma.batch.count({ where: { artworkId: id } }),
|
||||||
this.prisma.traceCode.aggregate({ where: { artworkId: id }, _sum: { queryCount: true } }),
|
this.prisma.traceCode.aggregate({ where: { artworkId: id }, _sum: { queryCount: true } }),
|
||||||
]);
|
]);
|
||||||
return {
|
return {
|
||||||
@@ -126,7 +127,7 @@ export class ArtworkService {
|
|||||||
originUrl: c.originFileUrl ? this.storage.getUrl(c.originFileUrl) : null,
|
originUrl: c.originFileUrl ? this.storage.getUrl(c.originFileUrl) : null,
|
||||||
watermarkUrl: c.watermarkFileUrl ? this.storage.getUrl(c.watermarkFileUrl) : null,
|
watermarkUrl: c.watermarkFileUrl ? this.storage.getUrl(c.watermarkFileUrl) : null,
|
||||||
})),
|
})),
|
||||||
codeStats: { total, active, queryTotal: agg._sum.queryCount ?? 0 },
|
codeStats: { total, active, batchTotal, queryTotal: agg._sum.queryCount ?? 0 },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,25 @@ export class BatchStatusDto {
|
|||||||
abnormal?: boolean;
|
abnormal?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class UpdateTraceCodeDto {
|
||||||
|
@ApiPropertyOptional({ description: '目标分组 ID,null 表示移出分组' })
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsInt()
|
||||||
|
groupId?: number | null;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: '目标批次 ID' })
|
||||||
|
@IsOptional()
|
||||||
|
@Type(() => Number)
|
||||||
|
@IsInt()
|
||||||
|
batchId?: number;
|
||||||
|
|
||||||
|
@ApiPropertyOptional({ description: 'true 停用,false 启用' })
|
||||||
|
@IsOptional()
|
||||||
|
@IsBoolean()
|
||||||
|
disabled?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export class QueryBatchDto extends PaginationDto {
|
export class QueryBatchDto extends PaginationDto {
|
||||||
@ApiPropertyOptional({ description: '作品/款式 ID' })
|
@ApiPropertyOptional({ description: '作品/款式 ID' })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import {
|
|||||||
GroupDto,
|
GroupDto,
|
||||||
QueryBatchDto,
|
QueryBatchDto,
|
||||||
QueryTraceCodeDto,
|
QueryTraceCodeDto,
|
||||||
|
UpdateTraceCodeDto,
|
||||||
} from './dto/trace-code.dto';
|
} from './dto/trace-code.dto';
|
||||||
import { Roles } from '../common/decorators/roles.decorator';
|
import { Roles } from '../common/decorators/roles.decorator';
|
||||||
import { Public } from '../common/decorators/public.decorator';
|
import { Public } from '../common/decorators/public.decorator';
|
||||||
@@ -87,6 +88,20 @@ export class TraceCodeController {
|
|||||||
return this.service.batchSetStatus(dto);
|
return this.service.batchSetStatus(dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Put('trace-codes/:id')
|
||||||
|
@Roles(RoleType.OPERATOR)
|
||||||
|
@ApiOperation({ summary: '更新单个追溯码' })
|
||||||
|
updateOne(@Param('id') id: string, @Body() dto: UpdateTraceCodeDto) {
|
||||||
|
return this.service.updateOne(id, dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete('trace-codes/:id')
|
||||||
|
@Roles(RoleType.OPERATOR)
|
||||||
|
@ApiOperation({ summary: '删除单个追溯码' })
|
||||||
|
removeOne(@Param('id') id: string) {
|
||||||
|
return this.service.removeOne(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('trace-codes')
|
@Get('trace-codes')
|
||||||
@ApiOperation({ summary: '追溯码列表' })
|
@ApiOperation({ summary: '追溯码列表' })
|
||||||
list(@Query() query: QueryTraceCodeDto) {
|
list(@Query() query: QueryTraceCodeDto) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import {
|
|||||||
GroupDto,
|
GroupDto,
|
||||||
QueryBatchDto,
|
QueryBatchDto,
|
||||||
QueryTraceCodeDto,
|
QueryTraceCodeDto,
|
||||||
|
UpdateTraceCodeDto,
|
||||||
} from './dto/trace-code.dto';
|
} from './dto/trace-code.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@@ -138,6 +139,76 @@ export class TraceCodeService {
|
|||||||
return { success: true, count: ids.length };
|
return { success: true, count: ids.length };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateOne(id: string, dto: UpdateTraceCodeDto) {
|
||||||
|
const traceCodeId = BigInt(id);
|
||||||
|
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
|
||||||
|
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
|
||||||
|
|
||||||
|
const data: Prisma.TraceCodeUncheckedUpdateInput = {};
|
||||||
|
|
||||||
|
if (Object.prototype.hasOwnProperty.call(dto, 'groupId')) {
|
||||||
|
if (dto.groupId !== null && dto.groupId !== undefined) await this.ensureGroup(dto.groupId);
|
||||||
|
data.groupId = dto.groupId ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dto.batchId !== undefined) {
|
||||||
|
const targetBatch = await this.prisma.batch.findUnique({ where: { id: dto.batchId } });
|
||||||
|
if (!targetBatch || targetBatch.artworkId !== code.artworkId) {
|
||||||
|
throw new BusinessException(ErrorCode.BAD_REQUEST, '目标批次不存在或不属于当前艺术品档案');
|
||||||
|
}
|
||||||
|
data.batchId = dto.batchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dto.disabled !== undefined) {
|
||||||
|
data.status = dto.disabled
|
||||||
|
? TraceCodeStatus.DISABLED
|
||||||
|
: code.firstActivatedAt
|
||||||
|
? TraceCodeStatus.ACTIVE
|
||||||
|
: TraceCodeStatus.INACTIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(data).length === 0) return code;
|
||||||
|
|
||||||
|
if (data.batchId !== undefined && data.batchId !== code.batchId) {
|
||||||
|
await this.prisma.$transaction([
|
||||||
|
this.prisma.traceCode.update({ where: { id: traceCodeId }, data }),
|
||||||
|
this.prisma.batch.update({ where: { id: code.batchId }, data: { generatedCount: { decrement: 1 } } }),
|
||||||
|
this.prisma.batch.update({ where: { id: data.batchId as number }, data: { generatedCount: { increment: 1 } } }),
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
await this.prisma.traceCode.update({ where: { id: traceCodeId }, data });
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.prisma.traceCode.findUnique({
|
||||||
|
where: { id: traceCodeId },
|
||||||
|
include: {
|
||||||
|
artwork: { select: { id: true, title: true, archiveNo: true } },
|
||||||
|
batch: { select: { id: true, batchNo: true } },
|
||||||
|
group: { select: { id: true, name: true } },
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async removeOne(id: string) {
|
||||||
|
const traceCodeId = BigInt(id);
|
||||||
|
const code = await this.prisma.traceCode.findUnique({ where: { id: traceCodeId } });
|
||||||
|
if (!code) throw new BusinessException(ErrorCode.TRACE_CODE_NOT_FOUND, '追溯码不存在', 404);
|
||||||
|
|
||||||
|
await this.prisma.$transaction([
|
||||||
|
this.prisma.queryLog.updateMany({
|
||||||
|
where: { traceCodeId },
|
||||||
|
data: { traceCodeId: null },
|
||||||
|
}),
|
||||||
|
this.prisma.traceCode.delete({ where: { id: traceCodeId } }),
|
||||||
|
this.prisma.batch.update({
|
||||||
|
where: { id: code.batchId },
|
||||||
|
data: { generatedCount: { decrement: 1 } },
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
}
|
||||||
|
|
||||||
async listBatches(query: QueryBatchDto) {
|
async listBatches(query: QueryBatchDto) {
|
||||||
const where: Prisma.BatchWhereInput = {};
|
const where: Prisma.BatchWhereInput = {};
|
||||||
if (query.artworkId) where.artworkId = query.artworkId;
|
if (query.artworkId) where.artworkId = query.artworkId;
|
||||||
|
|||||||
Reference in New Issue
Block a user