From 018981f42f1e262e92a713368b6197e8f720318a Mon Sep 17 00:00:00 2001 From: mxr612 Date: Tue, 3 Jun 2025 12:23:25 +0800 Subject: [PATCH] =?UTF-8?q?[Build=201.2.0]=20feat:=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=81=8C=E4=BD=8D=E8=A7=84=E5=88=99=E5=92=8C=E6=99=8B=E5=8D=87?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BB=A5=E6=94=AF=E6=8C=81=E6=96=B0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改职位规则读取逻辑,调整列索引以适应新的数据格式 - 增加晋升级别和档次的计算逻辑,确保正确处理职务晋升 - 优化异常处理,确保在职务不存在时记录警告信息 - 更新文档以反映晋升级别档次变化的记录方式 --- main.py | 34 +++++++++++++++++++++++++--------- 使用说明.md | 2 ++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 2f0b86d..cdf10ad 100644 --- a/main.py +++ b/main.py @@ -35,7 +35,7 @@ for index, row in Promote.iterrows(): logging.info("人员信息加载完成") Rule_Role = [] -col = 2 +col = 4 while True: # 职位规则 try: rule = pd.read_excel("原数据.xlsx", sheet_name="职位规则",usecols=f"{get_column_letter(col)}:{get_column_letter(col+1)}", header=None) @@ -76,11 +76,13 @@ while True: # 名称变化 # 读取职位对应的级别限制 Level_Limit_tmp = pd.read_excel("原数据.xlsx", sheet_name="职位规则", usecols="A:A", skiprows=2, names=["limit"]) +Promote_Level_tmp = pd.read_excel("原数据.xlsx", sheet_name="职位规则", usecols="A:B", skiprows=2, names=["级别","档次"]) Level_Limit = {} +Promote_Level = {} for rule in Rule_Role: for index, row in rule["rule"].iterrows(): Level_Limit[row["role"]] = Level_Limit_tmp.iloc[index]["limit"] - + Promote_Level[row["role"]] = (Promote_Level_tmp.iloc[index]["级别"], Promote_Level_tmp.iloc[index]["档次"]) logging.info("规则加载完成") @@ -95,7 +97,7 @@ def split_level(level:str): parts = level.split('-') return (int(parts[0]), int(parts[1])) except: - logging.warning(f"职级[{level}]格式错误") + raise Exception(f"职级[{level}]格式错误") return (0, 0) def role_salary(role:str, time): @@ -253,7 +255,7 @@ for index, row in BaseData.iterrows(): History_pd = History_pd.sort_values(by="时间").reset_index(drop=True) if History_pd.at[0,"时间"] != row["入职时间"]: - raise Exception(f"入职时间晚于其他计算的时间:{row['入职时间']} < {History_pd.at[0,'时间']} ({History_pd.at[0,'变动原因']})") + raise Exception(f"入职时间晚于其他时间:{row['入职时间']} < {History_pd.at[0,'时间']} ({History_pd.at[0,'变动原因']})") for index, hrow in History_pd.iterrows(): # 数据计算 # 调整职务职级 if index > 0 and hrow["职务"] == "": @@ -271,12 +273,26 @@ for index, row in BaseData.iterrows(): elif hrow["变动原因"] == "工资调标": History_pd.at[index, "级别档次"] = f"{jb}-{dc}" elif hrow["变动原因"] == "晋升": - if role_limit(History_pd.iloc[index]["职务"]) == 99: # 99tag - History_pd.at[index, "级别档次"] = f"{jb}-{dc}" - elif jb == role_limit(History_pd.iloc[index]["职务"]): - History_pd.at[index, "级别档次"] = f"{jb}-{dc+1}" + role = History_pd.iloc[index]["职务"] + if role in Promote_Level.keys(): + new_jb = jb + Promote_Level[role][0] + new_dc = dc + Promote_Level[role][1] + if pd.isna(new_jb) or pd.isna(new_dc): + print(Promote_Level[role][1]) + raise Exception(f"级别档次计算出现NaN值:[{new_jb}]-[{new_dc}]({role})") + else: + new_jb = int(new_jb) + new_dc = int(new_dc) + if role_limit(role) == 99: # 99tag + History_pd.at[index, "级别档次"] = f"{jb}-{dc}" + elif new_jb < role_limit(role): + History_pd.at[index, "级别档次"] = f"{jb}-{dc+1}" + elif new_jb < 1 or new_dc < 1: + raise Exception(f"级别档次小于0:[{new_jb}]-[{new_dc}]") + else: + History_pd.at[index, "级别档次"] = f"{new_jb}-{new_dc}" else: - History_pd.at[index, "级别档次"] = f"{jb-1}-{dc-1}" + logging.warning(f"职位[{role}]不存在职级上限规则") # 计算工资 History_pd.at[index, "职务工资"] = role_salary(History_pd.iloc[index]["职务"], hrow["时间"]) History_pd.at[index, "级别工资"] = level_salary(History_pd.iloc[index]["级别档次"], hrow["时间"]) diff --git a/使用说明.md b/使用说明.md index 599ea83..36b8581 100644 --- a/使用说明.md +++ b/使用说明.md @@ -35,6 +35,8 @@ 晋级晋档起始时间不会进行添加级别档次变化记录。 +晋升的级别档次变化记录:正数增加,负数减小。 + ## 3. 打包成 .exe 文件 本程序使用Win7兼容的**Python 3.8.10**,需要在电脑上使用此版本,并确保打包的环境是此版本。