请假流程优化

This commit is contained in:
runny committed 2026-05-15 11:53:17 +08:00
1 parent d895754d70
commit 9de63c916c
2 files changed
+162 -123

No files matched your search

+61 -31
View File
@@ -178,46 +178,76 @@ WHERE c002001 = ?
def _format_number(value):
if value is None:
return "暂无数据"
if isinstance(value, float) and value.is_integer():
return str(int(value))
return str(value)
@classmethod
def _render_section(cls, title: str, record: dict | None) -> str:
def _format_quota(cls, value) -> str:
formatted = cls._format_number(value)
if formatted == "暂无数据":
return formatted
return f"{formatted}天"
@staticmethod
def _resolve_response_year(record: dict | None, requested_year: int | None) -> str:
if record and record.get("leave_year") is not None:
return str(record["leave_year"])
if requested_year is not None:
return str(requested_year)
return str(datetime.now().year)
@classmethod
def _render_section(cls, title: str, record: dict | None, requested_year: int | None) -> str:
response_year = cls._resolve_response_year(record, requested_year)
if not record:
return f"### {title}\n\n- 当前未查询到对应记录。"
return (
f"### {title}\n\n"
f"暂未查询到您 {response_year} 年度的{title}记录。"
)
remaining = cls._format_quota(record.get("remaining_hours"))
return (
f"### {title}\n\n"
f"- 员工工号:{record.get('employee_id')}\n"
f"- 员工姓名:{record.get('employee_name')}\n"
f"- 部门:{record.get('department_name') or '暂无数据'}\n"
f"- 上级部门:{record.get('parent_department_name') or '暂无数据'}\n"
f"- 年份:{cls._format_number(record.get('leave_year'))}\n"
f"- 总时数:{cls._format_number(record.get('total_hours'))}\n"
f"- 已休时数:{cls._format_number(record.get('used_hours'))}\n"
f"- 剩余时数:{cls._format_number(record.get('remaining_hours'))}"
f"您当前{title}剩余额度为 {remaining}。\n"
f"- 年度:{response_year}\n"
f"- 年度可休:{cls._format_quota(record.get('total_hours'))}\n"
f"- 已休:{cls._format_quota(record.get('used_hours'))}\n"
f"- 当前剩余:{remaining}"
)
@classmethod
def _build_result_text(cls, query: str, employee_code: str, annual_result, childcare_result):
annual_sql, annual_record = annual_result
childcare_sql, childcare_record = childcare_result
def _build_result_text(cls, leave_type: str, requested_year: int | None, annual_result, childcare_result):
_, annual_record = annual_result
_, childcare_record = childcare_result
displayed_records = []
if leave_type in ("annual", "all"):
displayed_records.append(annual_record)
if leave_type in ("childcare", "all"):
displayed_records.append(childcare_record)
intro_year = next(
(
cls._resolve_response_year(record, requested_year)
for record in displayed_records
if record
),
str(requested_year or datetime.now().year),
)
sections = [
f"- 查询对象:当前登录人工号 `{employee_code}`",
f"- 用户问题:{query}",
"",
cls._render_section("年假", annual_record),
"",
cls._render_section("育儿假", childcare_record),
"",
"<details>",
"<summary class=\"cursor-pointer text-xs font-semibold uppercase tracking-wide text-slate-600 dark:text-slate-300 mb-2\">执行的SQL</summary>",
"",
"```sql",
annual_sql,
"",
childcare_sql,
"```",
"</details>",
f"您好,已为您查询到 {intro_year} 年度假期情况:",
]
if leave_type in ("annual", "all"):
sections.extend(["", cls._render_section("年假", annual_record, requested_year)])
if leave_type in ("childcare", "all"):
sections.extend(["", cls._render_section("育儿假", childcare_record, requested_year)])
sections.extend(
[
"",
"如需继续查询其他假期明细或历史休假记录,请告诉我,我继续帮您核对。",
"",
'如需发起请假,可点击 <a href="#" class="leave-action-trigger" data-leave-action="start-leave-flow">【点我请假】</a> 或输入 <span class="leave-intent-highlight">“我要请假”</span>。',
]
)
return "\n".join(sections)
@classmethod
@@ -229,7 +259,7 @@ WHERE c002001 = ?
leave_type = cls._detect_leave_type(query)
year = cls._extract_year(query)
yield f"data: {json.dumps({'event': 'message', 'answer': '已识别为 HR 假期查询,正在按当前登录人工号检索 SQL Server 数据...\n'}, ensure_ascii=False)}\n\n"
yield f"data: {json.dumps({'event': 'message', 'answer': '已识别为假期查询,正在为您核对假期明细,请稍候...\n'}, ensure_ascii=False)}\n\n"
annual_result = ("-- 未执行年假查询", None)
childcare_result = ("-- 未执行育儿假查询", None)
@@ -256,7 +286,7 @@ WHERE c002001 = ?
year=year,
)
result_text = cls._build_result_text(query, employee_code, annual_result, childcare_result)
result_text = cls._build_result_text(leave_type, year, annual_result, childcare_result)
latency = int((time.time() - start_time) * 1000)
if current_app:
+101 -92
View File
@@ -431,61 +431,47 @@ const { messages, isThinking, conversationId, sendMessage } = useChat();
const input = ref('');
const currentAgent = ref<any>(null);
const showGeneralFeedbackDialog = ref(false);
const showOALoginModal = ref(false);
const oaLoginForm = ref({ username: '', password: '' });
const openOALoginModal = () => {
oaLoginForm.value = {
username: currentUserEmployeeId.value || currentUser.value?.username || '',
password: ''
};
showOALoginModal.value = true;
};
const OA_LOGIN_URL = 'http://192.168.100.221:8888/login/Login.jsp?logintype=1';
const OA_VERIFY_LOGIN_URL = 'http://192.168.100.221:8888/login/VerifyLogin.jsp';
const OA_LEAVE_APPLY_PATH = '/workflow/request/AddRequest.jsp?workflowid=652&isagent=0&beagenter=0&f_weaver_belongto_userid=';
const OA_AUTO_LOGIN_USERNAME = '26040006';
const OA_AUTO_LOGIN_PASSWORD = '26040006';
const OA_AUTO_LOGIN_TARGET = 'hxops-oa-leave-request';
const submitOALogin = () => {
if (!oaLoginForm.value.username || !oaLoginForm.value.password) {
showMessageDialog('error', '请输入账号和密码');
const openOALeaveRequestDirectly = () => {
const popup = window.open(OA_LOGIN_URL, OA_AUTO_LOGIN_TARGET);
if (!popup) {
showMessageDialog('warning', '浏览器拦截了 OA 页面,请允许弹出窗口后重试。');
return;
}
// 要跳转的目标 OA 页面
const targetUrl = '/workflow/request/AddRequest.jsp?workflowid=652&isagent=0&beagenter=0&f_weaver_belongto_userid=';
// 创建隐藏表单进行 POST 提交到 OA 登录接口
const form = document.createElement('form');
form.action = 'http://192.168.100.221:8888/login/VerifyLogin.jsp';
form.action = OA_VERIFY_LOGIN_URL;
form.method = 'POST';
form.target = '_blank';
const inputLoginId = document.createElement('input');
inputLoginId.type = 'hidden';
inputLoginId.name = 'loginid';
inputLoginId.value = oaLoginForm.value.username;
form.appendChild(inputLoginId);
const inputPassword = document.createElement('input');
inputPassword.type = 'hidden';
inputPassword.name = 'userpassword';
inputPassword.value = oaLoginForm.value.password;
form.appendChild(inputPassword);
const inputGoPage = document.createElement('input');
inputGoPage.type = 'hidden';
inputGoPage.name = 'gopage';
inputGoPage.value = targetUrl;
form.appendChild(inputGoPage);
const inputLogintype = document.createElement('input');
inputLogintype.type = 'hidden';
inputLogintype.name = 'logintype';
inputLogintype.value = '1';
form.appendChild(inputLogintype);
form.target = OA_AUTO_LOGIN_TARGET;
form.style.display = 'none';
const fields = {
loginid: OA_AUTO_LOGIN_USERNAME,
userpassword: OA_AUTO_LOGIN_PASSWORD,
gopage: OA_LEAVE_APPLY_PATH,
logintype: '1',
};
Object.entries(fields).forEach(([name, value]) => {
const input = document.createElement('input');
input.type = 'hidden';
input.name = name;
input.value = value;
form.appendChild(input);
});
document.body.appendChild(form);
form.submit();
document.body.removeChild(form);
showOALoginModal.value = false;
window.setTimeout(() => {
form.submit();
document.body.removeChild(form);
}, 0);
};
const activeFeedbackMessageIndex = ref<number | null>(null);
@@ -633,6 +619,7 @@ const isStrongLeaveIntent = (content: string) => {
// 弱意图(咨询流程/步骤)应走正常问答,不触发表单分流。
const weakConsultationIntent = /(请假流程|请假怎么走|请假步骤|请假如何申请|请假如何走流程|请假怎么办|请假需要什么|请假规定)/;
if (weakConsultationIntent.test(normalized)) return false;
if (/^(请假|休假)$/.test(normalized)) return true;
return /(我要请假|申请请假|发起请假|请假申请|我要休假|申请休假|我要请个假|想请假|帮我请假|代我请假|提交请假)/.test(normalized);
};
@@ -655,6 +642,16 @@ const startLocalLeaveFlow = (content: string) => {
});
};
const handleChatMarkdownClick = (event: MouseEvent) => {
const target = event.target as HTMLElement | null;
const actionElement = target?.closest?.('[data-leave-action]') as HTMLElement | null;
if (!actionElement) return;
const action = actionElement.getAttribute('data-leave-action');
if (action !== 'start-leave-flow' || isThinking.value) return;
event.preventDefault();
startLocalLeaveFlow('我要请假');
};
const getLeaveFormPayload = (msg: any): LeaveFormPayload | null => (
msg?.type === 'leave-form' && msg?.payload ? msg.payload as LeaveFormPayload : null
);
@@ -1263,8 +1260,11 @@ const showChatRating = ref(false);
<main
ref="chatScrollContainer"
class="flex-1 p-3 md:p-8"
:class="messages.length === 0 ? 'overflow-hidden md:overflow-y-auto' : 'space-y-2 overflow-y-auto scrollbar-thin md:space-y-6'"
:class="messages.length === 0 ? 'overflow-hidden md:overflow-y-auto' : 'overflow-y-auto scrollbar-thin'"
>
<div
:class="messages.length === 0 ? 'h-full' : 'flex min-h-full flex-col justify-end'"
>
<div v-if="messages.length === 0" class="flex h-full flex-col items-center justify-center py-2 md:pb-16">
<div class="mb-6 flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-2xl font-bold text-white shadow-lg shadow-brand-500/20">
AI
@@ -1275,7 +1275,7 @@ const showChatRating = ref(false);
<template v-for="(msg, index) in messages" :key="index">
<div
v-if="shouldRenderMessage(msg)"
class="group mx-auto flex max-w-4xl animate-slide-up mb-6"
class="group mx-auto mb-6 flex w-full max-w-4xl animate-slide-up"
:class="msg.role === 'user' ? 'justify-end' : 'justify-start'"
>
<div
@@ -1296,7 +1296,7 @@ const showChatRating = ref(false);
<div v-if="msg.type === 'leave-form'" class="space-y-4">
<div class="text-sm font-medium text-slate-700 dark:text-slate-200">
<template v-if="msg.content.includes('或登录OA系统直接申请')">
已为你生成请假申请表,请直接在下方填写并提交。或 <a href="#" @click.prevent="openOALoginModal" class="text-brand-600 font-bold hover:underline">登录OA系统直接申请</a>
已为你生成请假申请表,请直接在下方填写并提交。或 <a href="#" @click.prevent="openOALeaveRequestDirectly" class="text-brand-600 font-bold hover:underline">登录OA系统直接申请</a>
</template>
<template v-else>
{{ msg.content }}
@@ -1453,6 +1453,7 @@ const showChatRating = ref(false);
<div
v-else
class="chat-markdown prose prose-sm max-w-none leading-7 text-slate-800 dark:text-slate-100 prose-a:text-blue-600 dark:prose-a:text-blue-400 prose-p:my-1 prose-li:my-0.5 prose-ol:my-2 prose-ul:my-2 prose-headings:my-2 prose-hr:my-3 prose-code:rounded prose-code:bg-slate-100 prose-code:px-1 prose-code:text-blue-700 dark:prose-code:bg-slate-800 dark:prose-code:text-blue-300 prose-pre:my-3 prose-pre:border prose-pre:border-slate-700 prose-pre:bg-slate-900 prose-pre:text-slate-100"
@click="handleChatMarkdownClick"
v-html="renderMarkdown(msg.content)"
></div>
</div>
@@ -1570,7 +1571,7 @@ const showChatRating = ref(false);
</div>
</template>
<div v-if="shouldShowThinkingBubble" class="mx-auto flex max-w-5xl">
<div v-if="shouldShowThinkingBubble" class="mx-auto flex w-full max-w-4xl justify-start">
<div class="flex items-center gap-3 rounded-2xl rounded-tl-md border border-slate-200 bg-white/95 px-5 py-3 shadow-md dark:border-slate-700 dark:bg-slate-900/85">
<div class="flex gap-1">
<span class="h-2 w-2 animate-bounce rounded-full bg-brand-400"></span>
@@ -1580,7 +1581,8 @@ const showChatRating = ref(false);
<span class="text-sm font-medium text-slate-500 dark:text-slate-300">{{ $t('chat.thinking') }}</span>
</div>
</div>
<div v-if="messages.length > 0" class="h-6 md:h-8"></div>
<div v-if="messages.length > 0" class="h-2 md:h-3"></div>
</div>
</main>
<footer class="safe-bottom sticky bottom-0 z-20 bg-transparent p-3 md:p-6">
@@ -1769,45 +1771,6 @@ const showChatRating = ref(false);
}"
/>
<div
v-if="showOALoginModal"
class="fixed inset-0 z-[100] flex items-center justify-center bg-black/40 backdrop-blur-sm p-4"
>
<div class="w-full max-w-sm rounded-2xl bg-white p-6 shadow-2xl dark:bg-slate-900">
<div class="mb-5 flex items-center justify-between">
<h3 class="text-lg font-bold text-slate-800 dark:text-slate-100">登录OA系统</h3>
<button @click="showOALoginModal = false" class="text-slate-400 hover:text-slate-600 dark:hover:text-slate-200">
<X class="h-5 w-5" />
</button>
</div>
<div class="space-y-4">
<div class="space-y-1.5">
<label class="text-sm font-semibold text-slate-600 dark:text-slate-300">账号</label>
<input
v-model="oaLoginForm.username"
type="text"
placeholder="请输入账号"
class="w-full rounded-xl border border-slate-200 bg-slate-50 px-4 py-2.5 text-sm outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100"
/>
</div>
<div class="space-y-1.5">
<label class="text-sm font-semibold text-slate-600 dark:text-slate-300">密码</label>
<input
v-model="oaLoginForm.password"
type="password"
placeholder="请输入密码"
class="w-full rounded-xl border border-slate-200 bg-slate-50 px-4 py-2.5 text-sm outline-none focus:border-brand-500 focus:ring-1 focus:ring-brand-500 dark:border-slate-700 dark:bg-slate-800 dark:text-slate-100"
/>
</div>
<button
@click="submitOALogin"
class="mt-2 w-full rounded-xl bg-brand-600 py-2.5 text-sm font-semibold text-white transition-colors hover:bg-brand-500"
>
确认登录
</button>
</div>
</div>
</div>
</template>
<style scoped>
@@ -1844,4 +1807,50 @@ const showChatRating = ref(false);
:deep(.chat-markdown details pre) {
margin-bottom: 0;
}
:deep(.chat-markdown .leave-action-trigger) {
display: inline-flex;
align-items: center;
justify-content: center;
margin: 0 0.2rem;
padding: 0.1rem 0.6rem;
border-radius: 9999px;
border: 1px solid rgb(59 130 246 / 0.28);
background: rgb(239 246 255);
color: rgb(29 78 216);
font-weight: 600;
text-decoration: none;
cursor: pointer;
transition: all 0.2s ease;
}
:deep(.chat-markdown .leave-action-trigger:hover) {
background: rgb(219 234 254);
border-color: rgb(59 130 246 / 0.4);
}
:deep(.chat-markdown .leave-intent-highlight) {
display: inline-block;
margin: 0 0.2rem;
padding: 0.05rem 0.4rem;
border-radius: 0.5rem;
background: rgb(254 249 195);
color: rgb(161 98 7);
font-weight: 600;
}
:deep(.dark .chat-markdown .leave-action-trigger) {
border-color: rgb(96 165 250 / 0.35);
background: rgb(30 41 59);
color: rgb(147 197 253);
}
:deep(.dark .chat-markdown .leave-action-trigger:hover) {
background: rgb(30 64 175 / 0.25);
}
:deep(.dark .chat-markdown .leave-intent-highlight) {
background: rgb(113 63 18 / 0.45);
color: rgb(253 224 71);
}
</style>