refactor: 将花名册填充逻辑提取为独立函数
将main函数中的花名册填充逻辑提取为独立的fill_roster函数,提高代码可维护性和复用性
This commit is contained in:
parent
2302dc1ece
commit
b0827c2829
58
main.py
58
main.py
@ -9,17 +9,16 @@ from datetime import datetime
|
|||||||
# 配置日志记录
|
# 配置日志记录
|
||||||
logging.basicConfig(filename='log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
logging.basicConfig(filename='log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
# 常量
|
# 全局变量
|
||||||
|
|
||||||
|
## 常量
|
||||||
|
|
||||||
P_LIMIT = 6 # 最大晋升次数
|
P_LIMIT = 6 # 最大晋升次数
|
||||||
|
|
||||||
P_START = 10 # 晋升记录开始行
|
P_START = 10 # 晋升记录开始行
|
||||||
H_START = 15 + P_LIMIT # 历史记录开始行
|
H_START = 15 + P_LIMIT # 历史记录开始行
|
||||||
|
|
||||||
NOWTIME = datetime.now()
|
NOWTIME = datetime.now()
|
||||||
|
|
||||||
# 全局变量
|
|
||||||
|
|
||||||
## 通过函数读取
|
## 通过函数读取
|
||||||
BaseData = pd.DataFrame()
|
BaseData = pd.DataFrame()
|
||||||
Promote = pd.DataFrame()
|
Promote = pd.DataFrame()
|
||||||
@ -266,6 +265,32 @@ def fill_history_info(ws, History_pd):# 填充历史记录
|
|||||||
ws.cell(row=H_START+index, column=7, value=hrow["变动原因"])
|
ws.cell(row=H_START+index, column=7, value=hrow["变动原因"])
|
||||||
# ws.cell(row=H_START+index, column=8, value=index) # Debug
|
# ws.cell(row=H_START+index, column=8, value=index) # Debug
|
||||||
|
|
||||||
|
def fill_roster(): # 填充花名册
|
||||||
|
wb = load_workbook("模板/汇总名册.xlsx")
|
||||||
|
ws = wb.active
|
||||||
|
for index, row in BaseData.iterrows(): # 汇总
|
||||||
|
try:
|
||||||
|
logging.info(f"汇总:第[{index+1}]共[{BaseData.shape[0]}]现在是[{row['身份证号码']}]")
|
||||||
|
for col in range(1,16):
|
||||||
|
ws.cell(row=6+index, column=col)._style = ws.cell(row=6, column=col)._style
|
||||||
|
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=3, value=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=6, value=fallback([row["现学历"],row["学历"]]))
|
||||||
|
ws.cell(row=6+index, column=7, value=row['工龄']+row["学龄"])
|
||||||
|
ws.cell(row=6+index, column=8, 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=11, value=row["Latest_Role"])
|
||||||
|
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=14, value=format_time(row["日期2"], "日期2"))
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"{row['身份证号码']}:{e}")
|
||||||
|
wb.save("汇总名册.xlsx") # 保存汇总
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
load_people()
|
load_people()
|
||||||
@ -391,30 +416,7 @@ def main():
|
|||||||
all_history.to_excel("所有人员历史记录.xlsx", index=False)
|
all_history.to_excel("所有人员历史记录.xlsx", index=False)
|
||||||
logging.info("所有人员历史记录已保存到'所有人员历史记录.xlsx'")
|
logging.info("所有人员历史记录已保存到'所有人员历史记录.xlsx'")
|
||||||
|
|
||||||
wb = load_workbook("模板/汇总名册.xlsx")
|
fill_roster()
|
||||||
ws = wb.active
|
|
||||||
for index, row in BaseData.iterrows(): # 汇总
|
|
||||||
try:
|
|
||||||
logging.info(f"汇总:第[{index+1}]共[{BaseData.shape[0]}]现在是[{row['身份证号码']}]")
|
|
||||||
for col in range(1,16):
|
|
||||||
ws.cell(row=6+index, column=col)._style = ws.cell(row=6, column=col)._style
|
|
||||||
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=3, value=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=6, value=fallback([row["现学历"],row["学历"]]))
|
|
||||||
ws.cell(row=6+index, column=7, value=row['工龄']+row["学龄"])
|
|
||||||
ws.cell(row=6+index, column=8, 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=11, value=row["Latest_Role"])
|
|
||||||
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=14, value=format_time(row["日期2"], "日期2"))
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(f"{row['身份证号码']}:{e}")
|
|
||||||
wb.save("汇总名册.xlsx") # 保存汇总
|
|
||||||
|
|
||||||
if max_promote > 0:
|
if max_promote > 0:
|
||||||
logging.warning(f"最多有[{max_promote}]条晋升信息,需要调整模板。记得同时调整薪资历史的起始行和个人评价结果。")
|
logging.warning(f"最多有[{max_promote}]条晋升信息,需要调整模板。记得同时调整薪资历史的起始行和个人评价结果。")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user