|
|
@@ -2,7 +2,7 @@ import { FastifyRequest, FastifyReply, FastifyInstance } from 'fastify'
|
|
|
import { FishService } from '../services/fish.service'
|
|
|
import { ResultEnum } from '../entities/fish.entity'
|
|
|
import { UserRole } from '../entities/user.entity'
|
|
|
-import { ListFishQuery, CreateFishBody, UpdateFishBody, DeleteFishBody, StatisticsQuery } from '../dto/fish.dto'
|
|
|
+import { ListFishQuery, CreateFishBody, UpdateFishBody, DeleteFishBody, StatisticsQuery, BatchUpdateFishBody } from '../dto/fish.dto'
|
|
|
import { getClientIP } from '../utils/ip.util'
|
|
|
|
|
|
export class FishController {
|
|
|
@@ -242,4 +242,34 @@ export class FishController {
|
|
|
return reply.code(500).send({ message: '导出失败' })
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ async batchUpdateOwner(request: FastifyRequest<{ Body: BatchUpdateFishBody }>, reply: FastifyReply) {
|
|
|
+ try {
|
|
|
+ const { ids, ownerId, ownerName } = request.body
|
|
|
+
|
|
|
+ if (!ids || ids.length === 0) {
|
|
|
+ return reply.code(400).send({ message: '请提供要更新的记录ID' })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!ownerId) {
|
|
|
+ return reply.code(400).send({ message: '请提供新的所有者ID' })
|
|
|
+ }
|
|
|
+
|
|
|
+ const updateData: any = { ownerId }
|
|
|
+ if (ownerName) {
|
|
|
+ updateData.ownerName = ownerName
|
|
|
+ }
|
|
|
+
|
|
|
+ const result = await this.fishService.batchUpdateOwner(ids, updateData)
|
|
|
+
|
|
|
+ return reply.send({
|
|
|
+ message: `成功更新 ${result.updatedCount} 条记录的所有者`,
|
|
|
+ updatedCount: result.updatedCount,
|
|
|
+ failedIds: result.failedIds
|
|
|
+ })
|
|
|
+ } catch (error) {
|
|
|
+ console.error('批量更新所有者失败:', error)
|
|
|
+ return reply.code(500).send({ message: '批量更新失败' })
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|