[Build 1.1.5] fix: 改进时间格式处理并添加错误日志
- 修改format_time函数,增加info参数用于标识不同时间字段 - 在所有调用format_time的地方添加对应的字段标识 - 简化晋升时间处理逻辑,统一使用format_time函数 - 修正工龄计算方式,使用年份直接相减 - 为所有时间格式转换添加错误日志记录
This commit is contained in:
parent
2fb98db060
commit
4cc8451c80
30
main.py
30
main.py
@ -127,10 +127,11 @@ def role_limit(role:str):
|
|||||||
logging.warning(f"职位[{role}]不存在职级上限规则")
|
logging.warning(f"职位[{role}]不存在职级上限规则")
|
||||||
return -1
|
return -1
|
||||||
|
|
||||||
def format_time(dt):
|
def format_time(dt,info):
|
||||||
try:
|
try:
|
||||||
return dt.strftime("%Y.%m")
|
return dt.strftime("%Y.%m")
|
||||||
except:
|
except:
|
||||||
|
logging.warning(f"[{info}]时间格式错误:{dt}")
|
||||||
return dt
|
return dt
|
||||||
|
|
||||||
def to_int(x):
|
def to_int(x):
|
||||||
@ -161,10 +162,10 @@ def fill_basic_info(ws, row):# 填充基本信息
|
|||||||
ws.cell(row=7, column=9, value=row["级别工资"])
|
ws.cell(row=7, column=9, value=row["级别工资"])
|
||||||
ws.cell(row=7, column=10, value=row["职务工资金额"])
|
ws.cell(row=7, column=10, value=row["职务工资金额"])
|
||||||
ws.cell(row=17, column=1, value=row["个人评价结果"])
|
ws.cell(row=17, column=1, value=row["个人评价结果"])
|
||||||
ws.cell(row=3, column=8, value=format_time(row["出生年月"]))
|
ws.cell(row=3, column=8, value=format_time(row["出生年月"],"出生年月"))
|
||||||
ws.cell(row=3, column=10, value=format_time(row["参加工作时间"]))
|
ws.cell(row=3, column=10, value=format_time(row["参加工作时间"],"参加工作时间"))
|
||||||
ws.cell(row=5, column=4, value=format_time(row["任职年月"]))
|
ws.cell(row=5, column=4, value=format_time(row["任职年月"],"任职年月"))
|
||||||
ws.cell(row=6, column=4, value=format_time(row["原职时间"]))
|
ws.cell(row=6, column=4, value=format_time(row["原职时间"],"原职时间"))
|
||||||
|
|
||||||
def fill_prompt_info(ws, promote):# 填充晋升信息
|
def fill_prompt_info(ws, promote):# 填充晋升信息
|
||||||
for index, prow in promote.iterrows():
|
for index, prow in promote.iterrows():
|
||||||
@ -172,10 +173,7 @@ def fill_prompt_info(ws, promote):# 填充晋升信息
|
|||||||
logging.warning(f"超过[{P_LIMIT}]条晋升信息,共[{promote.shape[0]}]条。")
|
logging.warning(f"超过[{P_LIMIT}]条晋升信息,共[{promote.shape[0]}]条。")
|
||||||
max_promote = max(max_promote, promote.shape[0])
|
max_promote = max(max_promote, promote.shape[0])
|
||||||
break
|
break
|
||||||
try:
|
ws.cell(row=P_START+index, column=1, value=format_time(prow["任职时间"],"晋升时间"))
|
||||||
ws.cell(row=P_START+index, column=1, value=format_time(prow["任职时间"]))
|
|
||||||
except:
|
|
||||||
logging.warning(f"晋升时间格式错误:{prow['任职时间']}")
|
|
||||||
ws.cell(row=P_START+index, column=2, value=prow["变动批注"])
|
ws.cell(row=P_START+index, column=2, value=prow["变动批注"])
|
||||||
ws.cell(row=P_START+index, column=3, value="任"+prow["新职务"])
|
ws.cell(row=P_START+index, column=3, value="任"+prow["新职务"])
|
||||||
|
|
||||||
@ -184,7 +182,7 @@ def fill_history_info(ws, History_pd):# 填充历史记录
|
|||||||
for col in range(1, 11): # 复制样式
|
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=col)._style = ws.cell(row=H_START, column=col)._style
|
||||||
try:
|
try:
|
||||||
ws.cell(row=H_START+index, column=1, value=hrow["时间"].strftime("%Y.%m"))
|
ws.cell(row=H_START+index, column=1, value=format_time(hrow["时间"],"历史时间"))
|
||||||
except:
|
except:
|
||||||
logging.warning(f"历史时间格式错误:{hrow['时间']}")
|
logging.warning(f"历史时间格式错误:{hrow['时间']}")
|
||||||
ws.cell(row=H_START+index, column=2, value=hrow["职务"])
|
ws.cell(row=H_START+index, column=2, value=hrow["职务"])
|
||||||
@ -291,17 +289,17 @@ for index, row in BaseData.iterrows(): # 汇总
|
|||||||
ws.cell(row=6+index, column=1, value=index+1)
|
ws.cell(row=6+index, column=1, value=index+1)
|
||||||
ws.cell(row=6+index, column=2, value=row["姓名"])
|
ws.cell(row=6+index, column=2, value=row["姓名"])
|
||||||
ws.cell(row=6+index, column=3, value=row["性别"])
|
ws.cell(row=6+index, column=3, value=row["性别"])
|
||||||
ws.cell(row=6+index, column=4, value=format_time(row["出生年月"]))
|
ws.cell(row=6+index, column=4, value=format_time(row["出生年月"], "出生年月"))
|
||||||
ws.cell(row=6+index, column=5, value=format_time(row["参加工作时间"]))
|
ws.cell(row=6+index, column=5, value=format_time(row["参加工作时间"], "参加工作时间"))
|
||||||
ws.cell(row=6+index, column=6, value=row["学历"])
|
ws.cell(row=6+index, column=6, value=row["学历"])
|
||||||
ws.cell(row=6+index, column=7, value=relativedelta(nowtime, row["入职时间"]).years+row["工龄调增"]-row["工龄调减"]+1)
|
ws.cell(row=6+index, column=7, value=nowtime.year-row["入职时间"].year+row["工龄调增"]-row["工龄调减"]+1)
|
||||||
ws.cell(row=6+index, column=8, value=relativedelta(nowtime, row["入职时间"]).years)
|
ws.cell(row=6+index, column=8, value=nowtime.year-row["入职时间"].year)
|
||||||
ws.cell(row=6+index, column=9, value=row["工龄调增"])
|
ws.cell(row=6+index, column=9, value=row["工龄调增"])
|
||||||
ws.cell(row=6+index, column=10, value=row["工龄调减"])
|
ws.cell(row=6+index, column=10, value=row["工龄调减"])
|
||||||
ws.cell(row=6+index, column=11, value=row["Latest_Role"])
|
ws.cell(row=6+index, column=11, value=row["Latest_Role"])
|
||||||
ws.cell(row=6+index, column=12, value=format_time(row["Latest_Prom"]))
|
ws.cell(row=6+index, column=12, value=format_time(row["Latest_Prom"], "Latest_Prom"))
|
||||||
ws.cell(row=6+index, column=13, value=row["职务2"])
|
ws.cell(row=6+index, column=13, value=row["职务2"])
|
||||||
ws.cell(row=6+index, column=14, value=format_time(row["日期2"]))
|
ws.cell(row=6+index, column=14, value=format_time(row["日期2"], "日期2"))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"{row['身份证号码']}:{e}")
|
logging.error(f"{row['身份证号码']}:{e}")
|
||||||
wb.save("汇总名册.xlsx") # 保存汇总
|
wb.save("汇总名册.xlsx") # 保存汇总
|
||||||
|
Loading…
x
Reference in New Issue
Block a user