fix: 过滤考核调研离职人员
This commit is contained in:
parent
fed5058080
commit
17182a90a5
@ -534,13 +534,28 @@ function PerformanceDashboardBoard({ view }: { view: 'personal' | 'public' }) {
|
||||
return (
|
||||
<section className="mb-5 space-y-4">
|
||||
{view === 'public' && (
|
||||
<div className="rounded-[14px] bg-white px-4 py-4 shadow-[0_10px_24px_rgba(45,43,80,0.07)] dark:border dark:border-gray-700 dark:bg-gray-900">
|
||||
<div className="grid gap-2 sm:grid-cols-[150px_minmax(180px,1fr)_minmax(180px,0.8fr)]">
|
||||
<div className="rounded-[18px] border border-[#e6ebf2] bg-white px-4 py-4 shadow-[0_12px_28px_rgba(15,23,42,0.05)] dark:border-gray-700 dark:bg-gray-900">
|
||||
<div className="mb-3 flex items-center justify-between gap-3">
|
||||
<h2 className="text-[17px] font-semibold text-[#101828] dark:text-white">公共看板</h2>
|
||||
{(department || employee) && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setDepartment('')
|
||||
setEmployee(null)
|
||||
}}
|
||||
className="rounded-full bg-[#f3f6fb] px-3 py-1.5 text-xs font-semibold text-[#475467] hover:bg-[#e8eef7] dark:bg-gray-800 dark:text-gray-200"
|
||||
>
|
||||
清除
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="grid gap-2 lg:grid-cols-[150px_minmax(210px,0.9fr)_minmax(220px,1fr)]">
|
||||
<input
|
||||
type="month"
|
||||
value={month}
|
||||
onChange={(event) => setMonth(event.target.value)}
|
||||
className="rounded-lg border border-[#dbe5f2] bg-white px-3 py-2 text-sm font-semibold text-[#101828] dark:border-gray-700 dark:bg-gray-900 dark:text-white"
|
||||
className="h-11 rounded-[12px] border border-[#dbe5f2] bg-white px-3 text-sm font-semibold text-[#101828] outline-none transition-colors focus:border-[#1677ff] focus:ring-4 focus:ring-[#1677ff]/10 dark:border-gray-700 dark:bg-gray-950 dark:text-white"
|
||||
/>
|
||||
<DepartmentFilterTree
|
||||
departments={departments.data || []}
|
||||
@ -636,63 +651,24 @@ function MonthlyPublicLedger({
|
||||
if (rows.length === 0) return <EmptyLedger title="暂无人员数据" />
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="hidden overflow-hidden rounded-[14px] border border-[#e5eaf2] bg-white shadow-[0_10px_24px_rgba(45,43,80,0.06)] dark:border-gray-700 dark:bg-gray-900 sm:block">
|
||||
<table className="w-full table-fixed border-collapse">
|
||||
<thead>
|
||||
<tr className="border-b border-[#eef1f6] text-left text-xs font-semibold text-[#667085] dark:border-gray-800 dark:text-gray-400">
|
||||
<th className="w-[28%] px-4 py-3">人员</th>
|
||||
{templates.map((template) => (
|
||||
<th key={template.code} className="px-3 py-3">{template.name}</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody className="divide-y divide-[#eef1f6] dark:divide-gray-800">
|
||||
{rows.map((row) => (
|
||||
<tr key={row.employee.id}>
|
||||
<td className="px-4 py-4">
|
||||
<div className="truncate text-sm font-semibold text-[#101828] dark:text-white">{row.employee.displayName}</div>
|
||||
<div className="mt-1 truncate text-xs text-[#667085] dark:text-gray-400">
|
||||
{[row.employee.departmentName, row.employee.positionLevel || row.employee.levelType].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
</td>
|
||||
{templates.map((template) => (
|
||||
<td key={template.code} className="px-3 py-4">
|
||||
<MonthlyScoreCell
|
||||
compact
|
||||
template={template}
|
||||
cell={row.cells?.[template.code]}
|
||||
canOpenOverride={canOpenPublicDetail}
|
||||
onClick={() => onOpenDetail({
|
||||
month: row.month,
|
||||
employeeId: row.employee.id,
|
||||
templateCode: template.code,
|
||||
})}
|
||||
/>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3 sm:hidden">
|
||||
{rows.map((row) => (
|
||||
<article
|
||||
key={row.employee.id}
|
||||
className="rounded-[16px] border border-[#e5eaf2] bg-white px-4 py-4 shadow-[0_10px_24px_rgba(45,43,80,0.06)] dark:border-gray-700 dark:bg-gray-900"
|
||||
>
|
||||
<div className="mb-3">
|
||||
<div className="text-[18px] font-semibold text-[#101828] dark:text-white">{row.employee.displayName}</div>
|
||||
<div className="mt-1 text-xs font-semibold text-[#667085] dark:text-gray-400">
|
||||
<div className="space-y-2.5">
|
||||
{rows.map((row) => (
|
||||
<article
|
||||
key={row.employee.id}
|
||||
className="rounded-[18px] border border-[#e6ebf2] bg-white px-4 py-4 shadow-[0_10px_26px_rgba(15,23,42,0.045)] dark:border-gray-700 dark:bg-gray-900"
|
||||
>
|
||||
<div className="grid gap-3 xl:grid-cols-[minmax(180px,0.75fr)_minmax(0,2.25fr)] xl:items-center">
|
||||
<div className="min-w-0">
|
||||
<div className="truncate text-[18px] font-semibold text-[#101828] dark:text-white">{row.employee.displayName}</div>
|
||||
<div className="mt-1 truncate text-[12px] font-semibold text-[#667085] dark:text-gray-400">
|
||||
{[row.employee.departmentName, row.employee.positionLevel || row.employee.levelType].filter(Boolean).join(' · ')}
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-2">
|
||||
<div className="grid grid-cols-2 gap-2 md:grid-cols-4">
|
||||
{templates.map((template) => (
|
||||
<MonthlyScoreCell
|
||||
key={template.code}
|
||||
compact
|
||||
template={template}
|
||||
cell={row.cells?.[template.code]}
|
||||
canOpenOverride={canOpenPublicDetail}
|
||||
@ -704,10 +680,10 @@ function MonthlyPublicLedger({
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
</div>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@ -726,7 +702,7 @@ function MonthlyScoreCell({
|
||||
}) {
|
||||
const hasScore = cell && cell.score !== null && cell.score !== undefined
|
||||
const canOpen = Boolean(hasScore && (canOpenOverride ?? cell?.detailAllowed))
|
||||
const className = `${compact ? 'min-h-[74px] px-3 py-3' : 'min-h-[88px] px-3.5 py-3.5'} rounded-[12px] border text-left transition-colors ${
|
||||
const className = `${compact ? 'min-h-[72px] px-3 py-3' : 'min-h-[88px] px-3.5 py-3.5'} rounded-[14px] border text-left transition-colors ${
|
||||
canOpen
|
||||
? 'border-[#cfe0ff] bg-[#f7fbff] hover:border-[#1677ff] hover:bg-[#eef6ff] dark:border-blue-500/30 dark:bg-blue-500/10'
|
||||
: 'border-[#e7edf5] bg-[#f8fafc] dark:border-gray-700 dark:bg-gray-800'
|
||||
@ -734,11 +710,11 @@ function MonthlyScoreCell({
|
||||
const content = (
|
||||
<>
|
||||
<div className="text-xs font-semibold text-[#667085] dark:text-gray-400">{template.name}</div>
|
||||
<div className="mt-2 flex items-end gap-1">
|
||||
<span className={`text-[24px] font-semibold leading-none ${hasScore ? 'text-[#101828] dark:text-white' : 'text-[#98a2b3] dark:text-gray-500'}`}>
|
||||
<div className="mt-2 flex items-baseline gap-1">
|
||||
<span className={`${compact ? 'text-[23px]' : 'text-[24px]'} font-semibold leading-none ${hasScore ? 'text-[#101828] dark:text-white' : 'text-[#98a2b3] dark:text-gray-500'}`}>
|
||||
{hasScore ? formatNullableScore(cell.score) : '-'}
|
||||
</span>
|
||||
{hasScore && <span className="pb-0.5 text-xs font-semibold text-[#98a2b3]">/120</span>}
|
||||
{hasScore && <span className="text-[11px] font-semibold text-[#98a2b3]">/120</span>}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
@ -1442,18 +1418,18 @@ function DepartmentFilterTree({
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setOpen((current) => !current)}
|
||||
className="flex h-10 w-full items-center justify-between gap-2 rounded-lg border border-gray-300 bg-white px-3 text-left text-sm text-gray-900 dark:border-gray-600 dark:bg-gray-900 dark:text-white"
|
||||
className="flex h-11 w-full items-center justify-between gap-2 rounded-[12px] border border-[#dbe5f2] bg-white px-3 text-left text-sm font-semibold text-[#101828] outline-none transition-colors hover:border-[#b9c7dc] dark:border-gray-700 dark:bg-gray-950 dark:text-white"
|
||||
>
|
||||
<span className="truncate">{selectedLabel}</span>
|
||||
<span className="text-gray-400">{open ? '收起' : '选择'}</span>
|
||||
<span className="text-xs text-[#98a2b3]">{open ? '收起' : '选择'}</span>
|
||||
</button>
|
||||
{open && (
|
||||
<div className="absolute left-0 right-0 z-30 mt-2 rounded-[12px] border border-gray-200 bg-white p-2 shadow-[0_18px_42px_rgba(15,23,42,0.16)] dark:border-gray-700 dark:bg-gray-900">
|
||||
<div className="absolute left-0 right-0 z-30 mt-2 rounded-[16px] border border-[#e6ebf2] bg-white p-2 shadow-[0_18px_42px_rgba(15,23,42,0.12)] dark:border-gray-700 dark:bg-gray-900">
|
||||
<input
|
||||
value={keyword}
|
||||
onChange={(event) => setKeyword(event.target.value)}
|
||||
placeholder="搜索组织"
|
||||
className="mb-2 w-full rounded-lg border border-gray-300 px-3 py-2 text-sm text-gray-900 dark:border-gray-600 dark:bg-gray-950 dark:text-white"
|
||||
className="mb-2 h-10 w-full rounded-[12px] border border-[#dbe5f2] px-3 text-sm text-[#101828] outline-none focus:border-[#1677ff] focus:ring-4 focus:ring-[#1677ff]/10 dark:border-gray-700 dark:bg-gray-950 dark:text-white"
|
||||
/>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@ -73,6 +73,21 @@ const GROUP_TABLE = {
|
||||
table: process.env.REPORT_DB_GROUP_TABLE || 'hr_groups',
|
||||
}
|
||||
|
||||
const INACTIVE_EMPLOYEE_STATUS_KEYWORDS = ['离职', '停用', '退休']
|
||||
|
||||
export function getActivePerformanceSurveyEmployeeProfileWhere() {
|
||||
return {
|
||||
OR: [
|
||||
{ employmentStatus: null },
|
||||
{
|
||||
AND: INACTIVE_EMPLOYEE_STATUS_KEYWORDS.map((keyword) => ({
|
||||
employmentStatus: { not: { contains: keyword } },
|
||||
})),
|
||||
},
|
||||
],
|
||||
} as any
|
||||
}
|
||||
|
||||
const FIELD_CANDIDATES = {
|
||||
dingtalkUserId: ['userid', 'user_id', 'ding_userid', 'dingtalk_userid', 'dingtalk_user_id', 'userId'],
|
||||
email: ['email', 'org_email', 'work_email', 'mail', '邮箱'],
|
||||
@ -109,6 +124,8 @@ const FIELD_CANDIDATES = {
|
||||
flowerBookDirector: ['director', 'directorName', '主管'],
|
||||
flowerBookManager: ['manager', 'managerName', '经理'],
|
||||
flowerBookEmployeeStatus: ['empStatus', 'employee_status', '在职状态'],
|
||||
flowerBookStatus: ['status'],
|
||||
flowerBookLeaveDate: ['leaveDate', 'leave_date', '离职日期'],
|
||||
}
|
||||
|
||||
let dailyWorkerStarted = false
|
||||
@ -367,6 +384,31 @@ function eqCondition(alias: string, column: string | null, paramName: string) {
|
||||
return column ? `${alias}.${quoteIdentifier(column)} = @${paramName}` : null
|
||||
}
|
||||
|
||||
function notInactiveStatusCondition(alias: string, column: string | null) {
|
||||
if (!column) return null
|
||||
const expr = `${alias}.${quoteIdentifier(column)}`
|
||||
return `(${expr} IS NULL OR ${expr} NOT LIKE N'%离职%')`
|
||||
}
|
||||
|
||||
function emptyDateCondition(alias: string, column: string | null) {
|
||||
return column ? `${alias}.${quoteIdentifier(column)} IS NULL` : null
|
||||
}
|
||||
|
||||
function getFlowerBookActiveConditions(
|
||||
alias: string,
|
||||
flowerColumns: {
|
||||
status?: string | null
|
||||
employeeStatus?: string | null
|
||||
leaveDate?: string | null
|
||||
},
|
||||
) {
|
||||
return [
|
||||
notInactiveStatusCondition(alias, flowerColumns.status || null),
|
||||
notInactiveStatusCondition(alias, flowerColumns.employeeStatus || null),
|
||||
emptyDateCondition(alias, flowerColumns.leaveDate || null),
|
||||
].filter((item): item is string => Boolean(item))
|
||||
}
|
||||
|
||||
async function getTableColumns(pool: any, schema: string, table: string): Promise<TableColumns> {
|
||||
const result = await pool
|
||||
.request()
|
||||
@ -467,6 +509,8 @@ function buildSelectSql(
|
||||
director: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookDirector),
|
||||
manager: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookManager),
|
||||
employeeStatus: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookEmployeeStatus),
|
||||
status: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookStatus),
|
||||
leaveDate: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookLeaveDate),
|
||||
}
|
||||
const activeFilter = e.active ? `AND (e.${quoteIdentifier(e.active)} = 1 OR e.${quoteIdentifier(e.active)} = '1')` : ''
|
||||
const joinSql = registerColumns.size > 0
|
||||
@ -478,7 +522,7 @@ function buildSelectSql(
|
||||
f.flowerName && r.flowerName ? `f.${quoteIdentifier(f.flowerName)} = r.${quoteIdentifier(r.flowerName)}` : null,
|
||||
].filter(Boolean)
|
||||
const flowerJoinSql = flowerColumns.size > 0 && flowerJoinConditions.length > 0
|
||||
? `LEFT JOIN ${quoteIdentifier(FLOWER_TABLE.schema)}.${quoteIdentifier(FLOWER_TABLE.table)} f ON ${flowerJoinConditions.join(' OR ')}`
|
||||
? `LEFT JOIN ${quoteIdentifier(FLOWER_TABLE.schema)}.${quoteIdentifier(FLOWER_TABLE.table)} f ON (${flowerJoinConditions.join(' OR ')})${getFlowerBookActiveConditions('f', f).map((condition) => ` AND ${condition}`).join('')}`
|
||||
: ''
|
||||
|
||||
return `
|
||||
@ -623,7 +667,14 @@ function buildFlowerListSql(flowerColumns: TableColumns, whereSql?: string) {
|
||||
director: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookDirector),
|
||||
manager: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookManager),
|
||||
employeeStatus: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookEmployeeStatus),
|
||||
status: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookStatus),
|
||||
leaveDate: pickColumn(flowerColumns, FIELD_CANDIDATES.flowerBookLeaveDate),
|
||||
}
|
||||
const whereParts = [
|
||||
...getFlowerBookActiveConditions('f', f),
|
||||
whereSql ? `(${whereSql})` : null,
|
||||
].filter(Boolean)
|
||||
const whereClause = whereParts.length > 0 ? `WHERE ${whereParts.join(' AND ')}` : ''
|
||||
|
||||
return `
|
||||
SELECT TOP (@limit)
|
||||
@ -640,7 +691,7 @@ function buildFlowerListSql(flowerColumns: TableColumns, whereSql?: string) {
|
||||
${columnExpr('f', f.manager)} AS "flowerBookManager",
|
||||
${columnExpr('f', f.employeeStatus)} AS "flowerBookEmployeeStatus"
|
||||
FROM ${quoteIdentifier(FLOWER_TABLE.schema)}.${quoteIdentifier(FLOWER_TABLE.table)} f
|
||||
${whereSql ? `WHERE ${whereSql}` : ''}
|
||||
${whereClause}
|
||||
ORDER BY COALESCE(${columnExpr('f', f.flowerName)}, ${columnExpr('f', f.name)}, ${columnExpr('f', f.jobNumber)}) ASC
|
||||
`
|
||||
}
|
||||
@ -723,7 +774,8 @@ export async function getPerformanceSurveyAccountProfileWhere() {
|
||||
}
|
||||
}
|
||||
|
||||
return or.length > 0 ? { OR: or } : { id: { in: [] } }
|
||||
const accountWhere = or.length > 0 ? { OR: or } : { id: { in: [] } }
|
||||
return { AND: [accountWhere, getActivePerformanceSurveyEmployeeProfileWhere()] }
|
||||
}
|
||||
|
||||
function uniqueClean(values: unknown[]) {
|
||||
|
||||
@ -166,8 +166,18 @@ function getScopeDepartmentWhere(scopeDepartment: string) {
|
||||
}
|
||||
|
||||
function parseDepartmentSelection(value: string) {
|
||||
if (value.startsWith(DEPARTMENT_PATH_VALUE_PREFIX)) {
|
||||
const payload = value.slice(DEPARTMENT_PATH_VALUE_PREFIX.length)
|
||||
const normalizedValue = clean(value)
|
||||
if (
|
||||
!normalizedValue ||
|
||||
normalizedValue === ALL_DEPARTMENTS_NODE_ID ||
|
||||
normalizedValue === ALL_DEPARTMENTS_NODE_NAME ||
|
||||
normalizedValue === '全部组织'
|
||||
) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (normalizedValue.startsWith(DEPARTMENT_PATH_VALUE_PREFIX)) {
|
||||
const payload = normalizedValue.slice(DEPARTMENT_PATH_VALUE_PREFIX.length)
|
||||
const decoded = decodeDepartmentPart(payload)
|
||||
if (decoded.includes('|')) {
|
||||
const [departmentNameRaw, departmentPathRaw] = decoded.split('|')
|
||||
@ -187,7 +197,7 @@ function parseDepartmentSelection(value: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const departmentName = clean(value)
|
||||
const departmentName = clean(normalizedValue)
|
||||
return departmentName ? { departmentName, departmentPath: null } : null
|
||||
}
|
||||
|
||||
@ -1175,6 +1185,15 @@ export async function getPerformanceSurveyDashboard(session: Session | null, par
|
||||
const publicEmployees = await getPublicDashboardEmployees(ctx, params)
|
||||
const publicTargets = await getMonthlyTargets(publicEmployees.map((employee) => employee.id), monthRange)
|
||||
const publicDetailAllowed = Boolean(ctx.isSystemAdmin || ctx.isLeadership)
|
||||
const publicRows = publicEmployees
|
||||
.map((employee) => buildMonthlyRow(
|
||||
employee,
|
||||
monthValue,
|
||||
templates,
|
||||
publicTargets.filter((target) => target.employeeProfileId === employee.id),
|
||||
publicDetailAllowed,
|
||||
))
|
||||
.filter((row) => row.hasData)
|
||||
|
||||
return {
|
||||
month: monthValue,
|
||||
@ -1206,13 +1225,7 @@ export async function getPerformanceSurveyDashboard(session: Session | null, par
|
||||
},
|
||||
public: {
|
||||
month: monthValue,
|
||||
rows: publicEmployees.map((employee) => buildMonthlyRow(
|
||||
employee,
|
||||
monthValue,
|
||||
templates,
|
||||
publicTargets.filter((target) => target.employeeProfileId === employee.id),
|
||||
publicDetailAllowed,
|
||||
)),
|
||||
rows: publicRows,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user