feat: 完善档案删除与追溯码筛选
This commit is contained in:
@@ -60,6 +60,11 @@ export class QueryTraceCodeDto extends PaginationDto {
|
||||
@IsEnum(TraceCodeStatus)
|
||||
status?: TraceCodeStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: '出库状态', enum: ['OUTBOUND', 'NOT_OUTBOUND'] })
|
||||
@IsOptional()
|
||||
@IsIn(['OUTBOUND', 'NOT_OUTBOUND'])
|
||||
outboundStatus?: 'OUTBOUND' | 'NOT_OUTBOUND';
|
||||
|
||||
@ApiPropertyOptional({ description: '分组 ID' })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@@ -203,6 +208,11 @@ export class ExportTraceCodeDto {
|
||||
@IsEnum(TraceCodeStatus)
|
||||
status?: TraceCodeStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: '出库状态', enum: ['OUTBOUND', 'NOT_OUTBOUND'] })
|
||||
@IsOptional()
|
||||
@IsIn(['OUTBOUND', 'NOT_OUTBOUND'])
|
||||
outboundStatus?: 'OUTBOUND' | 'NOT_OUTBOUND';
|
||||
|
||||
@ApiPropertyOptional({ description: '关键词' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -344,20 +344,36 @@ export class TraceCodeService {
|
||||
return buildPage(list, total, query.page, query.pageSize);
|
||||
}
|
||||
|
||||
async list(query: QueryTraceCodeDto) {
|
||||
private buildTraceCodeWhere(
|
||||
query: Pick<QueryTraceCodeDto | ExportTraceCodeDto, 'artworkId' | 'batchId' | 'groupId' | 'status' | 'outboundStatus' | 'keyword'>,
|
||||
): Prisma.TraceCodeWhereInput {
|
||||
const where: Prisma.TraceCodeWhereInput = {};
|
||||
const and: Prisma.TraceCodeWhereInput[] = [];
|
||||
if (query.artworkId) where.artworkId = query.artworkId;
|
||||
if (query.batchId) where.batchId = query.batchId;
|
||||
if (query.groupId) where.groupId = query.groupId;
|
||||
if (query.status) where.status = query.status;
|
||||
if (query.keyword) {
|
||||
where.OR = [
|
||||
{ shortCode: { contains: query.keyword } },
|
||||
{ code: { contains: query.keyword } },
|
||||
{ artwork: { archiveNo: { contains: query.keyword } } },
|
||||
{ artwork: { title: { contains: query.keyword } } },
|
||||
];
|
||||
if (query.outboundStatus === 'OUTBOUND') {
|
||||
and.push({ OR: [{ outTime: { not: null } }, { outImage: { not: null } }] });
|
||||
} else if (query.outboundStatus === 'NOT_OUTBOUND') {
|
||||
and.push({ outTime: null, outImage: null });
|
||||
}
|
||||
if (query.keyword) {
|
||||
and.push({
|
||||
OR: [
|
||||
{ shortCode: { contains: query.keyword } },
|
||||
{ code: { contains: query.keyword } },
|
||||
{ artwork: { archiveNo: { contains: query.keyword } } },
|
||||
{ artwork: { title: { contains: query.keyword } } },
|
||||
],
|
||||
});
|
||||
}
|
||||
if (and.length) where.AND = and;
|
||||
return where;
|
||||
}
|
||||
|
||||
async list(query: QueryTraceCodeDto) {
|
||||
const where = this.buildTraceCodeWhere(query);
|
||||
const [list, total] = await this.prisma.$transaction([
|
||||
this.prisma.traceCode.findMany({
|
||||
where,
|
||||
@@ -413,18 +429,7 @@ export class TraceCodeService {
|
||||
.map((s) => BigInt(s));
|
||||
where.id = { in: idList };
|
||||
} else {
|
||||
if (dto.artworkId) where.artworkId = dto.artworkId;
|
||||
if (dto.batchId) where.batchId = dto.batchId;
|
||||
if (dto.groupId) where.groupId = dto.groupId;
|
||||
if (dto.status) where.status = dto.status;
|
||||
if (dto.keyword) {
|
||||
where.OR = [
|
||||
{ shortCode: { contains: dto.keyword } },
|
||||
{ code: { contains: dto.keyword } },
|
||||
{ artwork: { archiveNo: { contains: dto.keyword } } },
|
||||
{ artwork: { title: { contains: dto.keyword } } },
|
||||
];
|
||||
}
|
||||
Object.assign(where, this.buildTraceCodeWhere(dto));
|
||||
}
|
||||
|
||||
const codes = await this.prisma.traceCode.findMany({
|
||||
|
||||
Reference in New Issue
Block a user