From 9de63c916c00ad1f177de41c0380dc24d748c035 Mon Sep 17 00:00:00 2001 From: "DESKTOP-JKIE562\\PC" <1013397054@qq.com> Date: Fri, 15 May 2026 11:53:17 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E5=81=87=E6=B5=81=E7=A8=8B=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/services/hr_leave_sqlserver.py | 92 ++++++---- frontend/src/views/ChatView.vue | 193 +++++++++++---------- 2 files changed, 162 insertions(+), 123 deletions(-) diff --git a/backend/app/services/hr_leave_sqlserver.py b/backend/app/services/hr_leave_sqlserver.py index 1cf836a4..5c0f9145 100644 --- a/backend/app/services/hr_leave_sqlserver.py +++ b/backend/app/services/hr_leave_sqlserver.py @@ -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), - "", - "
", - "执行的SQL", - "", - "```sql", - annual_sql, - "", - childcare_sql, - "```", - "
", + 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( + [ + "", + "如需继续查询其他假期明细或历史休假记录,请告诉我,我继续帮您核对。", + "", + '如需发起请假,可点击 【点我请假】 或输入 “我要请假”。', + ] + ) 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: diff --git a/frontend/src/views/ChatView.vue b/frontend/src/views/ChatView.vue index 9901df09..6eea4140 100644 --- a/frontend/src/views/ChatView.vue +++ b/frontend/src/views/ChatView.vue @@ -431,61 +431,47 @@ const { messages, isThinking, conversationId, sendMessage } = useChat(); const input = ref(''); const currentAgent = ref(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(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);
+
AI @@ -1275,7 +1275,7 @@ const showChatRating = ref(false);