chenpei 4dba93c4e5 feat: 完成任务-详情素材迁移到新逻辑
- 迁移57个老素材到新逻辑(本地zip + S3预览图)
- 优化文件命名:SPU_作者_店铺_类型.zip
- PSD文件单独存储,不打包进all.zip
- 修复下载接口,优先使用本地zip文件
- 修复预览图重复问题
- 添加迁移脚本和验证脚本
- 更新文档和迁移计划

迁移统计:
- 总素材数:77个
- 成功迁移:57个
- 新逻辑上传:18个
- 空记录:2个
2026-01-21 10:16:28 +08:00

90 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextRequest, NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
export async function POST(request: NextRequest) {
try {
const { userId, department } = await request.json()
if (!userId || !department) {
return NextResponse.json(
{ success: false, message: '缺少必要参数' },
{ status: 400 }
)
}
console.log('完善用户信息(选择部门):', { userId, department })
// 获取当前钉钉用户信息
const currentUser = await prisma.user.findUnique({
where: { id: userId }
})
if (!currentUser) {
return NextResponse.json(
{ success: false, message: '用户不存在' },
{ status: 404 }
)
}
// 双写:同时更新 department(旧字段)和 departmentId(新字段)
let updateData: any = {
department: department // 旧字段(向后兼容)
};
// 查找对应的部门ID
if (department && department.trim() !== '') {
const dept = await prisma.department.findUnique({
where: { name: department.trim() }
});
if (dept) {
updateData.departmentId = dept.id; // 新字段(阶段二新增)
} else {
// 部门不存在,清除 departmentId
updateData.departmentId = null;
}
} else {
// 部门为空,清除 departmentId
updateData.departmentId = null;
}
// 更新用户部门信息
const user = await prisma.user.update({
where: { id: userId },
data: updateData,
include: {
departmentRef: true // 包含部门关联信息
}
})
console.log('用户信息更新成功:', user.username)
// 返回用户信息(不包含敏感信息)
return NextResponse.json({
success: true,
message: '信息完善成功',
user: {
id: user.id,
username: user.username,
email: user.email,
realName: user.realName,
avatar: user.avatar,
role: user.role,
department: user.department,
isActive: user.isActive,
status: (user as any).status || (user.isActive ? 'active' : 'pending') // 阶段一新增
}
})
} catch (error: any) {
console.error('完善用户信息失败:', error)
return NextResponse.json(
{
success: false,
message: error.message || '信息提交失败,请稍后再试'
},
{ status: 500 }
)
}
}