diff --git a/.gitignore b/.gitignore index 8e7b0c8..22e87c5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ main.spec *.zip .venv/* build/ -zip/ \ No newline at end of file +zip/ +log.txt \ No newline at end of file diff --git a/main.py b/main.py index 284a40d..42b7a26 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,10 @@ from openpyxl.utils import get_column_letter from openpyxl import load_workbook from datetime import datetime from dateutil.relativedelta import relativedelta +import logging +# 配置日志记录 +logging.basicConfig(filename='log.txt', level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') P_LIMIT = 6 # 最大晋升次数 @@ -56,7 +59,7 @@ def role_salary(role:str, time): tmp = rule["rule"][rule["rule"]["role"] == role].iloc[0] return tmp["salary"] except: - print(f"[Error] 职位{role}在{time}时不存在工资规则") + logging.error(f"职位{role}在{time}时不存在工资规则") return 0 def level_salary(level:str, time): @@ -66,7 +69,7 @@ def level_salary(level:str, time): tmp = rule["rule"][rule["rule"]["level"] == level].iloc[0] return tmp["salary"] except: - print(f"[Error] 职级{level}在{time}时不存在工资规则") + logging.error(f"职级{level}在{time}时不存在工资规则") return 0 def role_limit(role:str): @@ -106,7 +109,7 @@ def fill_basic_info(ws, row):# 填充基本信息 def fill_prompt_info(ws, promote):# 填充晋升信息 for index, prow in promote.iterrows(): if index > P_LIMIT-1: - print(f"[Error] 超过{P_LIMIT}条晋升信息,共{promote.shape[0]}条。") + 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")) @@ -131,7 +134,7 @@ BaseData["Latest_Prom"] = None for index, row in BaseData.iterrows(): try: - print("[Debug] 台账:第",index+1,"共",BaseData.shape[0],"现在是",row["身份证号码"]) + logging.info(f"台账:第{index+1}共{BaseData.shape[0]}现在是{row['身份证号码']}") BaseData.at[index, "Latest_Role"] = row["初始职务"] BaseData.at[index, "Latest_Prom"] = row["入职时间"].strftime("%Y.%m") wb = load_workbook("个人台账.xlsx") @@ -199,13 +202,13 @@ for index, row in BaseData.iterrows(): fill_history_info(ws, History_pd)# 填充历史记录 wb.save(f"./output/{row['姓名']}_{row['身份证号码']}.xlsx") except Exception as e: - print("[Error]",e) + logging.error(e) wb = load_workbook("./汇总.xlsx") ws = wb.active for index, row in BaseData.iterrows(): # 汇总 try: - print("[Debug] 汇总:第",index+1,"共",BaseData.shape[0],"现在是",row["身份证号码"]) + logging.info(f"汇总:第{index+1}共{BaseData.shape[0]}现在是{row['身份证号码']}") for col in range(1,16): ws.cell(row=3+index, column=col)._style = ws.cell(row=3, column=col)._style ws.cell(row=6+index, column=1, value=index+1) @@ -223,10 +226,10 @@ for index, row in BaseData.iterrows(): # 汇总 ws.cell(row=6+index, column=13, value=row["职务2"]) ws.cell(row=6+index, column=14, value=row["日期2"]) except Exception as e: - print("[Error]",e) + logging.error(e) wb.save("./名册.xlsx") # 保存汇总 if max_promote > 0: - print(f"[Error]最多有{max_promote}条晋升信息,需要调整模板。记得同时调整薪资历史的起始行和个人评价结果。") + logging.error(f"最多有{max_promote}条晋升信息,需要调整模板。记得同时调整薪资历史的起始行和个人评价结果。") if max_history > 0: - print(f"[Error]最多有{max_history}条薪资历史,需要调整模板。") \ No newline at end of file + logging.error(f"最多有{max_history}条薪资历史,需要调整模板。") \ No newline at end of file diff --git a/规则需求.md b/规则需求.md index d67cd19..f7c2acb 100644 --- a/规则需求.md +++ b/规则需求.md @@ -15,4 +15,4 @@ - [ ] 有一行数据样例,展示数据格式,实际不生成 - [ ] 带输入格式检测(修正、提示) - [ ] doc: 打包成exe教程 -- [ ] feat: 【赠送】输出log到文件 \ No newline at end of file +- [x] feat: 【赠送】输出log到文件 [completion:: 2025-05-27] \ No newline at end of file