Files
37duAutomation/plugins/xq0038/report/__init__.py
T
puddy 843ff244a6 feat: 新增多插件 UI 支持及运行日志集中回传功能
本次提交包含多项功能更新:
1. 为多个插件(xq0002/0003/0004/0008/0010/0011/0020/0031_xq0032/0033/0035/0037/0045_xq0046/0047/0048)新增 UI 界面及配置支持
2. 新增运行日志集中回传功能,客户端自动上传运行日志到中心机集中存储
3. 新增插件分类字段支持,用于场景库分组管理
4. 优化 xq0034/0037/0048 等插件的功能及描述
5. 修复控制面响应兼容问题,支持新旧版本数据格式
6. 新增 xq0033 插件的状态存储模块,用于历史记录管理
7. 优化 CRM 登录窗口模式,支持全屏置顶
2026-10-26 15:42:50 +08:00

121 lines
5.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""XQ0038 定性评价推送 插件 - 报告层:导出当天定性评价单并核对当前处理人。
导出按门户查询方案(管理/专业序列,searchId 固化),以 创建时间=EXPORT_DATE(空=当天)
为条件,走 search.do 结构化导出接口;导出后按「当前处理人」含登录账号姓名的行判为
「异常」,生成 *_核对.xlsx(末列「异常标记」)。
"""
import os
import re
import time
import traceback
from .. import config
from ..data import export_plan_once, get_login_user
def audit_xls(path, user_name):
"""核对导出 xls:「当前处理人」含登录账号姓名 -> 异常,生成 *_核对.xlsx。
返回异常行数(user_name 为空时跳过核对返回 -1)。
导出表只有姓名文本、无处理人工号列(字段字典无此字段),故按姓名匹配。
"""
import openpyxl
import xlrd
wb = xlrd.open_workbook(path)
sh = wb.sheet_by_index(0)
head = [str(sh.cell_value(0, c)) for c in range(sh.ncols)]
if '当前处理人' not in head:
config.log(' 核对跳过:导出表无「当前处理人」列')
return -1
proc_idx = head.index('当前处理人')
key_idx = {n: (head.index(n) if n in head else -1)
for n in ('员工工号', '被评价人', '当前环节')}
rows_out, bad = [], []
for r in range(sh.nrows):
vals = []
for c in range(sh.ncols):
v = sh.cell_value(r, c)
if isinstance(v, float) and '时间' in head[c]:
try:
v = xlrd.xldate.xldate_as_datetime(v, wb.datemode).strftime(
'%Y-%m-%d %H:%M')
except Exception:
pass
vals.append('' if v is None else str(v))
if r == 0:
vals.append('异常标记')
else:
handlers = [x.strip() for x in re.split(r'[;;,,]', vals[proc_idx])
if x.strip()]
mark = '异常:当前处理人含登录账号' if user_name and user_name in handlers else ''
if mark:
bad.append(vals)
vals.append(mark)
rows_out.append(vals)
out_path = re.sub(r'\.xls$', '_核对.xlsx', path)
owb = openpyxl.Workbook()
osh = owb.active
osh.title = '核对结果'
for vals in rows_out:
osh.append(vals)
owb.save(out_path)
config.log(' sheet=%s 行=%d(含表头) 列=%d -> %s'
% (sh.name, sh.nrows, sh.ncols, os.path.basename(out_path)))
config.log(' 异常 %d 行(当前处理人=%s)' % (len(bad), user_name or '未知,未核对'))
for vals in bad[:20]:
config.log(' %s | %s | %s | 处理人=%s' % (
vals[key_idx['员工工号']], vals[key_idx['被评价人']],
vals[key_idx['当前环节']], vals[proc_idx]))
return len(bad)
def run_export():
"""导出编排:逐方案导出 + 核对。返回 {summary, detail, path}。"""
day = config.get_export_date() or time.strftime('%Y-%m-%d')
out_dir = config.export_output_dir()
s = config.get_oa_session()
config.log('导出模式:创建时间=%s,方案 %d 个' % (day, len(config.SEARCH_PLANS)))
user_name, login_no = get_login_user(s)
if user_name:
config.log('登录账号:%s(%s),将核对当前处理人' % (user_name, login_no))
else:
config.log('警告:未取得门户登录账号,跳过当前处理人核对')
fail = []
detail = {}
for idx, (name, sid) in enumerate(config.SEARCH_PLANS.items()):
config.progress(int(100 * idx / len(config.SEARCH_PLANS)))
label = name.split('(')[0]
out_path = os.path.join(out_dir, '定性评价结果_%s_%s.xls'
% (label, day.replace('-', '')))
last_err = ''
for attempt in range(1, config.MAX_RETRY + 1):
try:
total, err = export_plan_once(s, sid, day, out_path)
except Exception:
total, err = None, '异常: ' + traceback.format_exc(limit=1).replace('\n', ' ')
if not err:
config.log('%s -> %d 条 -> %s' % (name, total, out_path))
bad = 0
if total:
bad = audit_xls(out_path, user_name)
detail[label] = {'total': total, 'path': out_path,
'audit': bad if total else 0}
break
last_err = err
config.log('%s -> 第%d次失败:%s' % (name, attempt, err))
time.sleep(1)
else:
fail.append((name, last_err))
detail[label] = {'success': False, 'error': last_err}
config.progress(int(100 * (idx + 1) / len(config.SEARCH_PLANS)))
config.progress(100)
config.log('==== 导出完成:成功 %d / 失败 %d ====' % (len(config.SEARCH_PLANS) - len(fail),
len(fail)))
for name, err in fail:
config.log('失败 %s:%s' % (name, err))
summary = '定性评价导出核对完成:成功 %d 个方案 / 失败 %d 个%s' % (
len(config.SEARCH_PLANS) - len(fail), len(fail),
'(%s)' % '、'.join(f[0] for f in fail) if fail else '')
return {'summary': summary, 'detail': detail, 'path': out_dir}