fix: 1.1.2修复日期解析错误并增强日志记录
- 添加自定义日期解析函数以兼容不同日期格式 - 在读取Excel文件时应用日期解析器 - 增加日期格式错误的异常处理和日志记录 - 更新需求文档中的日期格式兼容性说明
This commit is contained in:
parent
5a1d4a0aa8
commit
016142821c
22
main.py
22
main.py
@ -4,6 +4,7 @@ from openpyxl import load_workbook
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
import logging
|
||||
from datetime import datetime
|
||||
|
||||
# 配置日志记录
|
||||
logging.basicConfig(filename='log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
@ -13,8 +14,15 @@ P_LIMIT = 6 # 最大晋升次数
|
||||
P_START = 10 # 晋升记录开始行
|
||||
H_START = 15 + P_LIMIT # 历史记录开始行
|
||||
|
||||
BaseData = pd.read_excel("原数据.xlsx", sheet_name="入职信息")
|
||||
Promote = pd.read_excel("原数据.xlsx", sheet_name="职务变动")
|
||||
# 自定义日期解析函数
|
||||
def custom_date_parser(x):
|
||||
try:
|
||||
return datetime.strptime(x, '%Y-%m-%d')
|
||||
except:
|
||||
return x
|
||||
|
||||
BaseData = pd.read_excel("原数据.xlsx", sheet_name="入职信息", parse_dates=["出生年月","任职年月","入职时间", "二档起始", "五档起始", "日期2"],date_parser=custom_date_parser)
|
||||
Promote = pd.read_excel("原数据.xlsx", sheet_name="职务变动", parse_dates=["任职时间","工资执行时间"],date_parser=custom_date_parser)
|
||||
Level_Limit = pd.read_excel("原数据.xlsx", sheet_name="职位规则",usecols="A:B", skiprows=2, names=["limit","role"])
|
||||
Rule_Role = []
|
||||
col = 2
|
||||
@ -112,7 +120,10 @@ def fill_prompt_info(ws, promote):# 填充晋升信息
|
||||
logging.error(f"超过{P_LIMIT}条晋升信息,共{promote.shape[0]}条。")
|
||||
max_promote = max(max_promote, promote.shape[0])
|
||||
break
|
||||
ws.cell(row=P_START+index, column=1, value=prow["任职时间"].strftime("%Y.%m"))
|
||||
try:
|
||||
ws.cell(row=P_START+index, column=1, value=prow["任职时间"].strftime("%Y.%m"))
|
||||
except:
|
||||
logging.error(f"晋升时间格式错误:{prow['任职时间']}")
|
||||
ws.cell(row=P_START+index, column=2, value=prow["变动批注"])
|
||||
ws.cell(row=P_START+index, column=3, value="任"+prow["新职务"])
|
||||
|
||||
@ -120,7 +131,10 @@ def fill_history_info(ws, History_pd):# 填充历史记录
|
||||
for index, hrow in History_pd.iterrows(): # 打印
|
||||
for col in range(1, 11): # 复制样式
|
||||
ws.cell(row=H_START+index, column=col)._style = ws.cell(row=H_START, column=col)._style
|
||||
ws.cell(row=H_START+index, column=1, value=hrow["时间"].strftime("%Y.%m"))
|
||||
try:
|
||||
ws.cell(row=H_START+index, column=1, value=hrow["时间"].strftime("%Y.%m"))
|
||||
except:
|
||||
logging.error(f"历史时间格式错误:{hrow['时间']}")
|
||||
ws.cell(row=H_START+index, column=2, value=hrow["职务"])
|
||||
ws.cell(row=H_START+index, column=3, value=hrow["工资额1"])
|
||||
ws.cell(row=H_START+index, column=4, value=hrow["级别档次"])
|
||||
|
13
规则需求.md
13
规则需求.md
@ -12,7 +12,16 @@
|
||||
- [ ] feat: 职位名称变化
|
||||
新增名称变化规则,起始、终止时间内自动替换
|
||||
- [ ] feat: 原数据模版(带校验数据值填写规范提示)
|
||||
- [ ] 有一行数据样例,展示数据格式,实际不生成
|
||||
- [x] 兼容 2003-11-20格式 [completion:: 2025-05-27]
|
||||
- [ ] 有一行数据样例,展示数据格式,实际不生成。
|
||||
需要特定格式的:
|
||||
- [ ] 任职年月
|
||||
- [ ] 入职时间
|
||||
- [ ] 二档起始
|
||||
- [ ] 五档起始
|
||||
- [ ] 带输入格式检测(修正、提示)
|
||||
- [ ] doc: 打包成exe教程
|
||||
- [x] feat: 【赠送】输出log到文件 [completion:: 2025-05-27]
|
||||
- [x] feat: 【赠送】输出log到文件 [completion:: 2025-05-27]
|
||||
- [ ] feat:【赠送】新增fall-back逻辑
|
||||
- [ ] 工龄=入职时间到现在时间
|
||||
- [ ] 职务2 优先计算结果
|
Loading…
x
Reference in New Issue
Block a user