考核岗位
-
{onAdminNavigate && positionGroupsState.data && (
- availablePositionGroups.every((group: any) => group.status !== 'ready')
+ membershipStatus !== 'matched'
+ || selectedPositionGroup?.status !== 'ready'
|| (selectedPositionGroupCode && !templatesState.loading && templates.length === 0)
) && (
- {availablePositionGroups.every((group: any) => group.status !== 'ready')
- ? `${assessmentMonth} 暂无可发起的岗位`
- : '所选岗位还没有可用考核模板'}
+ {membershipStatus !== 'matched'
+ ? '当前人员还不能自动关联岗位'
+ : selectedPositionGroup?.status !== 'ready'
+ ? '当前岗位尚未完成配置'
+ : '当前岗位还没有可用考核模板'}
-
请先补齐岗位设置、人员归属和可用模板,再回来发起调研。
+
请先补齐人员归属、岗位设置和可用模板,再回来发起调研。
{([
['positions', '检查岗位设置'],
diff --git a/lib/__tests__/performance-survey-service-policy.test.ts b/lib/__tests__/performance-survey-service-policy.test.ts
index 726e2451..efac1ce4 100644
--- a/lib/__tests__/performance-survey-service-policy.test.ts
+++ b/lib/__tests__/performance-survey-service-policy.test.ts
@@ -872,7 +872,6 @@ describe('performance survey service policies', () => {
await createPerformanceSurvey(session, {
templateCode: 'course_share',
- positionGroupCode: 'brand_designer',
assessmentMonth: '2026-07',
targetEmployeeIds: ['employee-1'],
evaluatorEmployeeIds: ['employee-2'],
@@ -891,6 +890,29 @@ describe('performance survey service policies', () => {
expect(transactionClient.performanceSurveyTarget.findMany.mock.invocationCallOrder[0]).toBeLessThan(
transactionClient.performanceSurvey.create.mock.invocationCallOrder[0],
)
+ expect(getPerformanceSurveyPositionGroupByCode).not.toHaveBeenCalled()
+ expect(transactionClient.performanceSurvey.create).toHaveBeenCalledWith({
+ data: expect.objectContaining({
+ positionGroupCode: 'brand_designer',
+ positionGroupId: 'position-group-brand',
+ }),
+ })
+ })
+
+ test('客户端不能用旧岗位参数覆盖被考核人的自动岗位', async () => {
+ await expect(createPerformanceSurvey(session, {
+ templateCode: 'course_share',
+ positionGroupCode: 'ai_designer',
+ assessmentMonth: '2026-07',
+ targetEmployeeIds: ['employee-1'],
+ evaluatorEmployeeIds: ['employee-2'],
+ openNow: false,
+ })).rejects.toEqual(
+ new PerformanceSurveyApiError('考核岗位已根据被考核人的人员分配自动关联,请刷新页面后重试', 409),
+ )
+
+ expect(getPerformanceSurveyPositionGroupByCode).not.toHaveBeenCalled()
+ expect(prisma.$transaction).not.toHaveBeenCalled()
})
test('发起人不能手动选择自己作为评分人员', async () => {
diff --git a/lib/performance-survey-service.ts b/lib/performance-survey-service.ts
index fbab05c8..17546dd8 100644
--- a/lib/performance-survey-service.ts
+++ b/lib/performance-survey-service.ts
@@ -2821,28 +2821,26 @@ export async function createPerformanceSurvey(session: Session | null, body: any
const assessmentMonthInput = normalizePerformanceSurveyAssessmentMonth(body?.assessmentMonth)
if (!assessmentMonthInput) throw new PerformanceSurveyApiError('请选择有效的考核月份')
- const positionGroupCode = clean(body?.positionGroupCode)
- if (!positionGroupCode) throw new PerformanceSurveyApiError('请选择考核岗位组')
- let positionGroup
+ if (!ctx.employee) throw new PerformanceSurveyApiError('当前账户尚未匹配人员档案', 409)
+ let creatorMembership
try {
- positionGroup = await getPerformanceSurveyPositionGroupByCode(positionGroupCode, assessmentMonthInput)
+ creatorMembership = await getPerformanceSurveyPositionGroupForEmployee(ctx.employee, assessmentMonthInput)
} catch (error) {
return rethrowPositionConfigError(error)
}
+ if (creatorMembership.status !== 'matched' || !creatorMembership.group) {
+ throw new PerformanceSurveyApiError(
+ creatorMembership.status === 'conflict'
+ ? '当前被考核人命中多个考核岗位组,请联系管理员处理'
+ : '当前被考核人尚未配置考核岗位组',
+ 409,
+ )
+ }
+ const positionGroup = creatorMembership.group
if (positionGroup.status !== 'ready') throw new PerformanceSurveyApiError('该岗位组尚未完成配置,不能发起调研', 409)
-
- if (!ctx.isSystemAdmin && !ctx.isLeadership && !ctx.isDepartmentAdmin) {
- if (!ctx.employee) throw new PerformanceSurveyApiError('当前账户尚未匹配人员档案', 409)
- const creatorMembership = await getPerformanceSurveyPositionGroupForEmployee(ctx.employee, assessmentMonthInput)
- if (creatorMembership.status !== 'matched') {
- throw new PerformanceSurveyApiError(
- creatorMembership.status === 'conflict' ? '当前账户命中多个考核岗位组,请联系管理员处理' : '当前账户尚未配置考核岗位组',
- 409,
- )
- }
- if (creatorMembership.group?.code !== positionGroup.code) {
- throw new PerformanceSurveyApiError('普通员工只能发起本人岗位组的考核调研', 403)
- }
+ const legacyRequestedPositionGroupCode = clean(body?.positionGroupCode)
+ if (legacyRequestedPositionGroupCode && legacyRequestedPositionGroupCode !== positionGroup.code) {
+ throw new PerformanceSurveyApiError('考核岗位已根据被考核人的人员分配自动关联,请刷新页面后重试', 409)
}
const templateVersionId = clean(body?.templateVersionId)