From 3e76d3d2349b07a2dfe6ce40f2949bc49bedb0cb Mon Sep 17 00:00:00 2001 From: spudding <1115683088@qq.com> Date: Wed, 12 Aug 2026 17:47:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8A=A0=E7=8F=AD?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=E4=B8=8EOA=E5=8D=95?= =?UTF-8?q?=E6=8D=AE=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9EExcel=E9=87=8D=E7=AE=97=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 加班校验不通过时直接返回驳回结果,不再执行后续校验 2. 为OA待办查询接口添加去重逻辑,避免重复审批单据 3. 新增WPS COM调用的Excel公式重算测试工具 --- app/service/hrbp/oa/common/oa_api.py | 16 +++++- .../hrbp/oa/work_overtime/validator.py | 9 ++- tests/wps.py | 57 +++++++++++++++++++ yingdao/leave_approval_yingdao.py | 16 +++++- yingdao/overtime_approval_yingdao.py | 26 ++++++++- 5 files changed, 117 insertions(+), 7 deletions(-) create mode 100644 tests/wps.py diff --git a/app/service/hrbp/oa/common/oa_api.py b/app/service/hrbp/oa/common/oa_api.py index 018a9ef..15c30aa 100644 --- a/app/service/hrbp/oa/common/oa_api.py +++ b/app/service/hrbp/oa/common/oa_api.py @@ -229,7 +229,21 @@ def get_documents( all_docs.extend(docs) logger.info("第 %d 页获取 %d 条,累计 %d 条", p, len(docs), len(all_docs)) - return all_docs + # 去重:OA 待办接口分页可能返回重复单据(同一条在多次/多页重复出现), + # 以详情链接 detail_url(含唯一 taskId)为键去重,避免同一单重复审批、重复推送 + seen = set() + unique_docs = [] + for doc in all_docs: + key = doc.get("detail_url") or doc.get("title") + if key in seen: + continue + seen.add(key) + unique_docs.append(doc) + + if len(unique_docs) != len(all_docs): + logger.warning("去重前 %d 条,去重后 %d 条(已过滤 %d 条重复单据)", + len(all_docs), len(unique_docs), len(all_docs) - len(unique_docs)) + return unique_docs # ---------- WfActivity 接口:通过 taskId 获取 formId ---------- diff --git a/app/service/hrbp/oa/work_overtime/validator.py b/app/service/hrbp/oa/work_overtime/validator.py index 9f49fd2..b87617e 100644 --- a/app/service/hrbp/oa/work_overtime/validator.py +++ b/app/service/hrbp/oa/work_overtime/validator.py @@ -230,11 +230,16 @@ def _validate_delayed( actual_checkout = _parse_dt(punch.get("当日最晚打卡")) reasons = [] - # 1. 日期校验 + # 1. 日期校验:加班开始日期与申请加班日期不一致时直接驳回, + # 无需再校验后续的时长、区间合规等内容 if start is None: reasons.append("加班开始时间缺失") elif start.strftime("%Y-%m-%d") != ot_date: - reasons.append(f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致") + info["计算加班时长(小时)"] = None + info["弹性扣减(小时)"] = 0 + info["有效加班时长(小时)"] = 0 + info["弹性额度D(小时)"] = 0 + return "驳回", f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致" # 2. 时长校验 hours = None diff --git a/tests/wps.py b/tests/wps.py new file mode 100644 index 0000000..331346f --- /dev/null +++ b/tests/wps.py @@ -0,0 +1,57 @@ +import win32com.client +from openpyxl import load_workbook +import os + + +def recalc_excel_by_wps_com(file_path: str): + """ + 使用WPS COM重算表格,保存计算缓存到文件 + 仅支持 WPS专业版 / MS‑Excel + """ + abs_path = os.path.abspath(file_path) + app = None + try: + # 尝试WPS表格 COM + app = win32com.client.gencache.EnsureDispatch("Ket.Application") + app.Visible = False # 后台不显示窗口 + app.DisplayAlerts = False # 关闭弹窗警告 + + # UpdateLinks=2 更新外部链接;你是本文件公式也带上无妨 + wb = app.Workbooks.Open(abs_path, UpdateLinks=2) + + # 强制完整重算全部公式 + wb.Application.CalculateFullRebuild() + + # 关键:保存,把计算结果缓存写入xlsx磁盘 + wb.Save() + wb.Close() + + except Exception as e: + print(f"COM执行异常: {e}") + raise + finally: + if app is not None: + app.Quit() + del app + + +if __name__ == "__main__": + file = r"C:\Users\admin\Desktop\test.xlsx" + + # ==========1. openpyxl写入测试数据(模拟粘贴数值到目标表)========== + wb = load_workbook(file) + ws = wb.active + ws["A2"] = 10 + ws["B2"] = 20 + # C2单元格预先在文件内写好公式 =A2+B2 + wb.save(file) + wb.close() + + # ==========2.调用WPS COM后台重算并保存缓存========== + recalc_excel_by_wps_com(file) + + # ==========3. openpyxl读取计算后的值========== + wb_final = load_workbook(file, data_only=True) + val = wb_final.active["C2"].value + print(f"C2计算结果 = {val}") + wb_final.close() \ No newline at end of file diff --git a/yingdao/leave_approval_yingdao.py b/yingdao/leave_approval_yingdao.py index 3c3604f..d393bd5 100644 --- a/yingdao/leave_approval_yingdao.py +++ b/yingdao/leave_approval_yingdao.py @@ -228,7 +228,21 @@ def get_documents(session, subject, page_size=DEFAULT_PAGE_SIZE): all_docs.extend(docs) logger.info("第 %d 页获取 %d 条,累计 %d 条", p, len(docs), len(all_docs)) - return all_docs + # 去重:OA 待办接口分页可能返回重复单据(同一条在多次/多页重复出现), + # 以详情链接 detail_url(含唯一 taskId)为键去重,避免同一单重复审批、重复推送 + seen = set() + unique_docs = [] + for doc in all_docs: + key = doc.get("detail_url") or doc.get("title") + if key in seen: + continue + seen.add(key) + unique_docs.append(doc) + + if len(unique_docs) != len(all_docs): + logger.warning("去重前 %d 条,去重后 %d 条(已过滤 %d 条重复单据)", + len(all_docs), len(unique_docs), len(all_docs) - len(unique_docs)) + return unique_docs def get_wf_activity_by_task_id(session, task_id): diff --git a/yingdao/overtime_approval_yingdao.py b/yingdao/overtime_approval_yingdao.py index 8dbb6bf..d07f43d 100644 --- a/yingdao/overtime_approval_yingdao.py +++ b/yingdao/overtime_approval_yingdao.py @@ -233,7 +233,21 @@ def get_documents(session, subject, page_size=DEFAULT_PAGE_SIZE): all_docs.extend(docs) logger.info("第 %d 页获取 %d 条,累计 %d 条", p, len(docs), len(all_docs)) - return all_docs + # 去重:OA 待办接口分页可能返回重复单据(同一条在多次/多页重复出现), + # 以详情链接 detail_url(含唯一 taskId)为键去重,避免同一单重复审批、重复推送 + seen = set() + unique_docs = [] + for doc in all_docs: + key = doc.get("detail_url") or doc.get("title") + if key in seen: + continue + seen.add(key) + unique_docs.append(doc) + + if len(unique_docs) != len(all_docs): + logger.warning("去重前 %d 条,去重后 %d 条(已过滤 %d 条重复单据)", + len(all_docs), len(unique_docs), len(all_docs) - len(unique_docs)) + return unique_docs def get_wf_activity_by_task_id(session, task_id): @@ -1198,11 +1212,17 @@ def _validate_delayed(info, punch, session, staff_id): actual_checkout = _parse_dt(punch.get("当日最晚打卡")) reasons = [] - # 1. 日期校验 + # 1. 日期校验:加班开始日期与申请加班日期不一致时直接驳回, + # 无需再校验后续的时长、区间合规等内容 if start is None: reasons.append("加班开始时间缺失") elif start.strftime("%Y-%m-%d") != ot_date: - reasons.append(f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致") + reason = f"加班开始日期({start:%Y-%m-%d})与申请加班日期({ot_date})不一致" + info["计算加班时长(小时)"] = None + info["弹性扣减(小时)"] = 0 + info["有效加班时长(小时)"] = 0 + info["弹性额度D(小时)"] = 0 + return "驳回", reason # 2. 时长校验 hours = None