Selaa lähdekoodia

更新扫描记录接口以支持维护码,修改相关DTO和服务方法,优化二维码信息查询逻辑。

wuyi 1 kuukausi sitten
vanhempi
commit
f52791163c

+ 2 - 2
src/controllers/scan-record.controller.ts

@@ -52,9 +52,9 @@ export class ScanRecordController {
    */
   async getRecent(request: FastifyRequest<{ Querystring: QueryScanRecordDto }>, reply: FastifyReply) {
     try {
-      const { qrCode } = request.query
+      const { qrCode, maintenanceCode } = request.query
 
-      const records = await this.scanRecordService.getRecentRecords(qrCode, 10)
+      const records = await this.scanRecordService.getRecentRecords(qrCode, 10, maintenanceCode)
 
       return reply.send({
         qrCode,

+ 4 - 0
src/dto/scan-record.dto.ts

@@ -33,6 +33,10 @@ export class QueryScanRecordDto {
   @IsString()
   qrCode: string
 
+  @IsOptional()
+  @IsString()
+  maintenanceCode?: string
+
   @IsOptional()
   @IsNumber()
   limit?: number = 10

+ 2 - 3
src/entities/goods-info.entity.ts

@@ -32,10 +32,10 @@ export class GoodsInfo {
   @Column({ length: 100, nullable: true })
   contactEmail: string
 
-  @Column({ length: 500, nullable: true })
+  @Column({ type: 'text', nullable: true })
   remark: string
 
-  @Column({ length: 500, nullable: true })
+  @Column({ type: 'text', nullable: true })
   location: string
 
   @Column({ default: true })
@@ -51,4 +51,3 @@ export class GoodsInfo {
   @JoinColumn({ name: 'qrCodeId' })
   qrCode: QrCode
 }
-

+ 2 - 2
src/entities/person-info.entity.ts

@@ -50,10 +50,10 @@ export class PersonInfo {
   @Column({ length: 100, nullable: true })
   emergencyContactEmail: string
 
-  @Column({ length: 500, nullable: true })
+  @Column({ type: 'text', nullable: true })
   remark: string
 
-  @Column({ length: 500, nullable: true })
+  @Column({ type: 'text', nullable: true })
   location: string
 
   @Column({ default: true })

+ 2 - 2
src/entities/pet-info.entity.ts

@@ -32,10 +32,10 @@ export class PetInfo {
   @Column({ length: 100, nullable: true })
   contactEmail: string
 
-  @Column({ length: 500, nullable: true })
+  @Column({ type: 'text', nullable: true })
   remark: string
 
-  @Column({ length: 500, nullable: true })
+  @Column({ type: 'text', nullable: true })
   location: string
 
   @Column({ default: true })

+ 8 - 1
src/services/scan-record.service.ts

@@ -57,12 +57,19 @@ export class ScanRecordService {
   /**
    * 获取最近N次扫描记录
    */
-  async getRecentRecords(qrCode: string, limit: number = 10): Promise<ScanRecord[]> {
+  async getRecentRecords(qrCode: string, limit: number = 10, maintenanceCode?: string): Promise<ScanRecord[]> {
     const qrCodeEntity = await this.qrCodeService.findByQrCode(qrCode)
     if (!qrCodeEntity) {
       throw new Error('二维码不存在')
     }
 
+    if (maintenanceCode) {
+      const isValid = await this.qrCodeService.verifyMaintenanceCode(qrCode, maintenanceCode)
+      if (!isValid) {
+        throw new Error('维护码错误')
+      }
+    }
+
     return this.scanRecordRepository.find({
       where: { qrCodeId: qrCodeEntity.id },
       order: { scanTime: 'DESC' },