绩效管理中强制分布经常会用到,如:
如图,部门人数在五人以上适用此表,举例:
张三的部门业绩为A,
属于A等部门, 部门有20人, 张三个人考评在部门排名第8名;按此表,张三属于B等员工,可以转换为95分;
但部门少于 6人,那么排名规则为:
引入rulebook规则引擎,代码结构:
pom.xml
4.0.0 com.youway kpi-rulebook 1.0-SNAPSHOT UTF-8 UTF-8 1.8 3.1.0 1.7.25 0.9.1 com.deliveredtechnologies rulebook-core ${rulebook.version} org.slf4j slf4j-simple ${slf4j.version} org.projectlombok lombok 1.16.8 provided
规则执行测试代码 Launcher.java
package com.youway;import com.deliveredtechnologies.rulebook.NameValueReferableMap;import com.deliveredtechnologies.rulebook.FactMap;import com.deliveredtechnologies.rulebook.model.runner.RuleBookRunner;/** * 规则执行测试代码 * @author youway * */public class Launcher { public static void main(String args[]) { RuleBookRunner ruleBook = new RuleBookRunner("com.youway.rules"); //加载制定package中所有规则 NameValueReferableMap facts = new FactMap(); facts.setValue("num", 5); //部门人数:5 facts.setValue("deptLevel", "B"); //部门业绩评级:B facts.setValue("rank", 3); //该员工在部门考评中排名:3 ruleBook.run(facts); ruleBook.getResult().ifPresent(System.out::println); //打印规则执行的输出结果 }}
规则执行输出的结果类型 Response.java
package com.youway.pojos;import lombok.Data;/** * 强制分布结果,根据规则所输出的结果 * @author youway * */@Datapublic class Response { public Response() { } public Response(String level, double score) { this.level = level; this.score = score; } //评级 private String level; //转换分数 private double score;}
强制分布规则RuleParams.java
package com.youway.rules;/** * 强制分布规则 * * @author youway * */public interface RuleParams { //转换分数 double SCORE_A = 100.00; double SCORE_B = 95.00; double SCORE_C = 95.00; double SCORE_D = 90.00; double SCORE_E = 85.00; }
1人强制分布规则LessRule1
package com.youway.rules;import com.deliveredtechnologies.rulebook.RuleState;import com.deliveredtechnologies.rulebook.annotation.Given;import com.deliveredtechnologies.rulebook.annotation.Result;import com.deliveredtechnologies.rulebook.annotation.Rule;import com.deliveredtechnologies.rulebook.annotation.Then;import com.deliveredtechnologies.rulebook.annotation.When;import com.youway.pojos.Response;/** * 1人强制分布规则 * @author youway * */@Rulepublic class LessRule1 implements RuleParams { // 所在部门的员工数 @Given("num") private int num; // 所属部门等级 @Given("deptLevel") private String deptLevel; // 所在部门排名 @Given("rank") private int rank; @Result private Response response; @When public boolean when() { return num==1; } @Then public RuleState then() { System.out.println("LessRule1被执行......"); if (deptLevel == "A") { this.response = new Response("A", SCORE_A); } if (deptLevel == "B") { this.response = new Response("B", SCORE_B); } if (deptLevel == "C") { this.response = new Response("C", SCORE_C); } if (deptLevel == "D") { this.response = new Response("D", SCORE_D); } if (deptLevel == "E") { this.response = new Response("E", SCORE_E); } return RuleState.BREAK; }}
...... 其他强制分布规则结构依此类同
运行结果:
LessRule5被执行......Response(level=C, score=95.0)
附图: