[Build 1.2.0] feat: 更新职位规则和晋升逻辑以支持新数据结构

- 修改职位规则读取逻辑,调整列索引以适应新的数据格式
- 增加晋升级别和档次的计算逻辑,确保正确处理职务晋升
- 优化异常处理,确保在职务不存在时记录警告信息
- 更新文档以反映晋升级别档次变化的记录方式
This commit is contained in:
Miu Li 2025-06-03 12:23:25 +08:00
parent cdb2716064
commit 018981f42f
2 changed files with 27 additions and 9 deletions

34
main.py
View File

@ -35,7 +35,7 @@ for index, row in Promote.iterrows():
logging.info("人员信息加载完成") logging.info("人员信息加载完成")
Rule_Role = [] Rule_Role = []
col = 2 col = 4
while True: # 职位规则 while True: # 职位规则
try: try:
rule = pd.read_excel("原数据.xlsx", sheet_name="职位规则",usecols=f"{get_column_letter(col)}:{get_column_letter(col+1)}", header=None) 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"]) 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 = {} Level_Limit = {}
Promote_Level = {}
for rule in Rule_Role: for rule in Rule_Role:
for index, row in rule["rule"].iterrows(): for index, row in rule["rule"].iterrows():
Level_Limit[row["role"]] = Level_Limit_tmp.iloc[index]["limit"] 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("规则加载完成") logging.info("规则加载完成")
@ -95,7 +97,7 @@ def split_level(level:str):
parts = level.split('-') parts = level.split('-')
return (int(parts[0]), int(parts[1])) return (int(parts[0]), int(parts[1]))
except: except:
logging.warning(f"职级[{level}]格式错误") raise Exception(f"职级[{level}]格式错误")
return (0, 0) return (0, 0)
def role_salary(role:str, time): 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) History_pd = History_pd.sort_values(by="时间").reset_index(drop=True)
if History_pd.at[0,"时间"] != row["入职时间"]: 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(): # 数据计算 for index, hrow in History_pd.iterrows(): # 数据计算
# 调整职务职级 # 调整职务职级
if index > 0 and hrow["职务"] == "": if index > 0 and hrow["职务"] == "":
@ -271,12 +273,26 @@ for index, row in BaseData.iterrows():
elif hrow["变动原因"] == "工资调标": elif hrow["变动原因"] == "工资调标":
History_pd.at[index, "级别档次"] = f"{jb}-{dc}" History_pd.at[index, "级别档次"] = f"{jb}-{dc}"
elif hrow["变动原因"] == "晋升": elif hrow["变动原因"] == "晋升":
if role_limit(History_pd.iloc[index]["职务"]) == 99: # 99tag role = History_pd.iloc[index]["职务"]
History_pd.at[index, "级别档次"] = f"{jb}-{dc}" if role in Promote_Level.keys():
elif jb == role_limit(History_pd.iloc[index]["职务"]): new_jb = jb + Promote_Level[role][0]
History_pd.at[index, "级别档次"] = f"{jb}-{dc+1}" 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: 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, "职务工资"] = role_salary(History_pd.iloc[index]["职务"], hrow["时间"])
History_pd.at[index, "级别工资"] = level_salary(History_pd.iloc[index]["级别档次"], hrow["时间"]) History_pd.at[index, "级别工资"] = level_salary(History_pd.iloc[index]["级别档次"], hrow["时间"])

View File

@ -35,6 +35,8 @@
晋级晋档起始时间不会进行添加级别档次变化记录。 晋级晋档起始时间不会进行添加级别档次变化记录。
晋升的级别档次变化记录:正数增加,负数减小。
## 3. 打包成 .exe 文件 ## 3. 打包成 .exe 文件
本程序使用Win7兼容的**Python 3.8.10**,需要在电脑上使用此版本,并确保打包的环境是此版本。 本程序使用Win7兼容的**Python 3.8.10**,需要在电脑上使用此版本,并确保打包的环境是此版本。