[Build 1.2.0] feat: 更新职位规则和晋升逻辑以支持新数据结构
- 修改职位规则读取逻辑,调整列索引以适应新的数据格式 - 增加晋升级别和档次的计算逻辑,确保正确处理职务晋升 - 优化异常处理,确保在职务不存在时记录警告信息 - 更新文档以反映晋升级别档次变化的记录方式
This commit is contained in:
parent
cdb2716064
commit
018981f42f
34
main.py
34
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:
|
||||
History_pd.at[index, "级别档次"] = f"{jb-1}-{dc-1}"
|
||||
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:
|
||||
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["时间"])
|
||||
|
Loading…
x
Reference in New Issue
Block a user