该调研未开放或已关闭
@@ -1703,6 +1718,114 @@ function SurveySubmit({ surveyId, session }: { surveyId: string; session: any })
)
}
+function SubmittedResponseDetail({
+ questions,
+ response,
+ submittedAt,
+}: {
+ questions: Template['questions']
+ response?: any
+ submittedAt?: string | Date | null
+}) {
+ const responseScores = response?.scores && typeof response.scores === 'object'
+ ? response.scores as Record
+ : {}
+ const scoreOf = (questionId: string) => {
+ const value = Number(responseScores[questionId])
+ return Number.isFinite(value) ? value : 0
+ }
+ const formatScore = (value: unknown) => {
+ const numberValue = Number(value)
+ if (!Number.isFinite(numberValue)) return '-'
+ return Number.isInteger(numberValue) ? String(numberValue) : numberValue.toFixed(1)
+ }
+ const submittedLabel = submittedAt || response?.createdAt
+ ? formatDate(submittedAt || response?.createdAt)
+ : '已提交'
+
+ return (
+
+
+
+
+
已提交
+
{submittedLabel}
+
+
+ 返回已处理
+
+
+
+
+
总分
+
{formatScore(response?.totalScore)}
+
+
+
达成分
+
{formatScore(response?.achievementScore)}
+
+
+
加权分
+
{formatScore(response?.weightedScore)}
+
+
+
+
+ {questions.map((question, index) => {
+ const value = scoreOf(question.id)
+ const scorePercent = Math.max(0, Math.min(100, (value / 20) * 100))
+ const accentColor = getQuestionAccentColor(index)
+ return (
+
+
+
+ {index + 1}
+
+
+
问题 {index + 1}
+
{question.title}
+ {question.description && (
+
{question.description}
+ )}
+
+
+ {formatScore(value)}
+ /20
+
+
+
+
+ 0
+ 5
+ 10
+ 15
+ 20
+
+
+ )
+ })}
+
+ {response?.comment && (
+
+ 补充评价
+ {response.comment}
+
+ )}
+
+ )
+}
+
function getSurveyInitials(name: string) {
const text = String(name || '').trim()
if (!text) return '用'
diff --git a/lib/performance-survey-service.ts b/lib/performance-survey-service.ts
index bbc9e342..9ec1c8ac 100644
--- a/lib/performance-survey-service.ts
+++ b/lib/performance-survey-service.ts
@@ -359,6 +359,7 @@ export async function getPerformanceSurveyMe(session: Session | null) {
isDepartmentAdmin: ctx.isDepartmentAdmin,
isLeadership: ctx.isLeadership,
scopeDepartment: ctx.scopeDepartment,
+ canCreate: true,
},
}
}
@@ -370,11 +371,6 @@ export async function getPerformanceSurveyTemplates(session: Session | null) {
export async function searchPerformanceSurveyEmployees(session: Session | null, params: URLSearchParams) {
const ctx = await getPerformanceSurveyContext(session)
- if (!ctx.isDepartmentAdmin) {
- if (!ctx.employee) return []
- return [serializeEmployee(ctx.employee)]
- }
-
const search = clean(params.get('search')) || ''
const department = clean(params.get('department'))
const limit = Math.max(1, Math.min(Number(params.get('limit') || 50), 200))
@@ -537,7 +533,6 @@ export async function searchPerformanceSurveyEmployees(session: Session | null,
export async function listPerformanceSurveyDepartments(session: Session | null, params?: URLSearchParams) {
const ctx = await getPerformanceSurveyContext(session)
- ensureManager(ctx)
const isEvaluatorPicker = clean(params?.get('purpose')) === 'evaluator'
const accountWhere = await getPerformanceSurveyAccountProfileWhere()
@@ -785,13 +780,13 @@ export async function listPerformanceSurveys(session: Session | null) {
isSystemAdmin: ctx.isSystemAdmin,
isDepartmentAdmin: ctx.isDepartmentAdmin,
scopeDepartment: ctx.scopeDepartment,
+ canCreate: true,
},
}
}
export async function createPerformanceSurvey(session: Session | null, body: any) {
const ctx = await getPerformanceSurveyContext(session)
- ensureManager(ctx)
const title = clean(body?.title)
if (!title) throw new PerformanceSurveyApiError('调研标题不能为空')
@@ -801,10 +796,11 @@ export async function createPerformanceSurvey(session: Session | null, body: any
const surveyKind = clean(body?.surveyKind) || template.surveyType
const dueAt = toDate(body?.dueAt)
const openNow = Boolean(body?.openNow || body?.status === 'open')
- const departmentName = clean(body?.departmentName) || ctx.scopeDepartment
+ const requestedDepartmentName = clean(body?.departmentName)
+ const departmentName = requestedDepartmentName || ctx.scopeDepartment
- if (!ctx.isSystemAdmin && ctx.scopeDepartment && departmentName !== ctx.scopeDepartment) {
- throw new PerformanceSurveyApiError('部门管理员只能创建本部门考核调研', 403)
+ if (!ctx.isSystemAdmin && requestedDepartmentName && requestedDepartmentName !== ctx.scopeDepartment) {
+ throw new PerformanceSurveyApiError('只能创建本人部门范围内的考核调研', 403)
}
const targets = await resolveSurveyTargets(body, surveyKind)
@@ -910,6 +906,7 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey
},
assignments: {
where: { evaluatorKey: ctx.evaluatorKey },
+ include: { response: true },
},
_count: {
select: { assignments: true, responses: true, targets: true },
@@ -952,6 +949,7 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey
canViewResults: canManage || survey.creatorUserId === ctx.user.id || (survey.status === 'closed' && isTarget),
targets: survey.targets.map((target) => {
const currentAssignment = currentAssignments.get(target.id)
+ const response = currentAssignment?.response
return {
id: target.id,
targetType: target.targetType,
@@ -964,6 +962,18 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey
id: currentAssignment.id,
status: currentAssignment.status,
submittedAt: currentAssignment.submittedAt,
+ response: response
+ ? {
+ id: response.id,
+ scores: response.scores,
+ comment: response.comment,
+ totalScore: response.totalScore,
+ achievementScore: response.achievementScore,
+ kpiScore: response.kpiScore,
+ weightedScore: response.weightedScore,
+ createdAt: response.createdAt,
+ }
+ : null,
}
: null,
assignments: canManage
@@ -981,7 +991,6 @@ export async function getPerformanceSurveyDetail(session: Session | null, survey
export async function updatePerformanceSurvey(session: Session | null, surveyId: string, body: any) {
const ctx = await getPerformanceSurveyContext(session)
- ensureManager(ctx)
const survey = await prisma.performanceSurvey.findUnique({ where: { id: surveyId } })
if (!survey) throw new PerformanceSurveyApiError('调研不存在', 404)