请假流程优化
This commit is contained in:
1 parent
d895754d70
commit
9de63c916c
2 files changed
+162
-123
No files matched your search
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user