思路
1. 实现在页面上的动态配置规则组(2张数据表+枚举类+service+impl+action)
2. 从数据库中表staffmoverules(规则明细表)或者staffmovetyperule(规则组表) ,根据传入类型,取出规则编号
3. 根据规则编号反射找到对应的方法名
4. 执行对应方法
1. 页面上实现手工配置
CREATE TABLE `staffmoverules` (
`rulenumber` int DEFAULT NULL COMMENT '规则组编号',
`movetype` varchar(50) DEFAULT NULL COMMENT '使用类型',
`message` varchar(500) DEFAULT NULL COMMENT '规则说明',
`operationtype` varchar(50) DEFAULT NULL COMMENT '操作类型',
`createtime` datetime DEFAULT NULL COMMENT '创建时间',
`creator` varchar(100) DEFAULT NULL COMMENT '创建者',
`lastermodifier` varchar(100) DEFAULT NULL COMMENT '最近修改人',
`lastertime` datetime DEFAULT NULL COMMENT '最近修改时间',
`id` varchar(100) DEFAULT NULL,
UNIQUE KEY `staffmoverules_rulenumber_IDX` (`rulenumber`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='人员调度规则明细'
CREATE TABLE `staffmovetyperule` (
`movetype` varchar(50) DEFAULT NULL COMMENT '规则组类型',
`message` varchar(500) DEFAULT NULL COMMENT '规则说明',
`createtime` datetime DEFAULT NULL COMMENT '创建时间',
`creator` varchar(100) DEFAULT NULL COMMENT '创建者',
`lastermodifier` varchar(100) DEFAULT NULL COMMENT '最近修改人',
`lastertime` datetime DEFAULT NULL COMMENT '最近修改时间',
`id` varchar(100) DEFAULT NULL,
UNIQUE KEY `staffmovetyperule_movetype_IDX` (`movetype`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='人员调度规则组校验'
2. 枚举类
package com.hrs.controller.rules;
public enum StaffMoveRulesEnum {
//规则组配置数据库里:2张表 //1.配置规则组 、2 具体的规则
//ehr页面上可以配置 规则组跟 具体规则,设置权限
//internal recruitmen-- IR 内部招聘,Staff regularization-- SR 转正
//1XXX--OA,2xxx-IR,3xxx-SR,4xxx-public
//OA规则
PROMOTIONA(1001,"OA","晋升提拔","check","promotiona"),
INTERPERSONALCONNECTIONS(1002,"OA","人脉关系","check","interpersonalConnections"),
//内招规则
EDUCATION(2001,"IR","学历","check","education"),
//人员转正规则
ALTERNATEDAYS(3001,"SR","调休天数","check","alternatedays"),
//共有规则
KINSHIP(4001,"PUBLIC","上下级亲属关系","check","kinship"),
STAFFINFOUPDATE(4002,"PUBLIC","人员信息更新","update","staffinfoUpdate"),
DELETESCHEDULINGRECORD(4003,"PUBLIC","删除调度关系","C","deleteSchedulingRecord"),
REVOCATIONSIGN(4004,"PUBLIC","撤销电子签","revocation","revocationSign"),
RESOURCEALLOCATIONNOTIFICATION(4005,"PUBLIC","资源配置通知","inform","resourceAllocationNotification");
public int ruleNumber;//规则编码
String moveType;//使用类型
String message;//说明
String operationType;//操作类型
String methodName;//方法名
public int getRuleNumber() {
return ruleNumber;
}
public void setRuleNumber(int ruleNumber) {
this.ruleNumber = ruleNumber;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public String getMoveType() {
return moveType;
}
public void setMoveType(String moveType) {
this.moveType = moveType;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getOperationType() {
return operationType;
}
public void setOperationType(String operationType) {
this.operationType = operationType;
}
StaffMoveRulesEnum(int ruleNumber, String moveType, String message, String operationType, String methodName) {
this.ruleNumber = ruleNumber;
this.moveType = moveType;
this.message = message;
this.operationType = operationType;
this.methodName = methodName;
}
}
3. service 、impl类
package com.hrs.service;
import org.springframework.stereotype.Service;
@Service
public interface StaffMoveService {
Object promotiona(Object o);
Object interpersonalConnections(Object o);
Object education(Object o);
Object alternatedays(Object o);
Object kinship(Object o);
Object staffinfoUpdate(Object o);
Object deleteSchedulingRecord(Object o);
Object revocationSign(Object o);
Object resourceAllocationNotification(Object o);
}
package com.hrs.service;
import com.hrs.service.StaffMoveService;
import org.springframework.stereotype.Service;
@Service
public class StaffMoveImpl implements StaffMoveService {
@Override
public Object promotiona(Object o) {
return "promotiona:" + o;
}
@Override
public Object interpersonalConnections(Object o) {
return "interpersonalConnections:" + o;
}
@Override
public Object education(Object o) {
return "education";
}
@Override
public Object alternatedays(Object o) {
return "alternatedays:" + o;
}
@Override
public Object kinship(Object o) {
return "kinship:" + o;
}
@Override
public Object staffinfoUpdate(Object o) {
return "staffinfoUpdate";
}
@Override
public Object deleteSchedulingRecord(Object o) {
return "deleteSchedulingRecord";
}
@Override
public Object revocationSign(Object o) {
return "revocationSign";
}
@Override
public Object resourceAllocationNotification(Object o) {
return "resourceAllocationNotification";
}
}
4 action类
package com.hrs.controller.rules;
import com.hrs.entity.ResultVo;
import com.hrs.service.StaffMoveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
public class StaffMoveAction {
StaffMoveService staffMoveService;
public ResultVo adjust(Object o){
String type;//从入参中取出
//1.从数据库中表staffmoverules或者staffmovetyperule 取出规则编号
//List<Integer> rulesNumber = ucc.adjutst();
List<Integer> rulesNumber = new ArrayList<>();
rulesNumber.add(1001);
rulesNumber.add(1002);
//2.
// 根据规则编号找到对应的枚举值
for (StaffMoveRulesEnum rule : StaffMoveRulesEnum.values()){
if (rulesNumber.contains(rule.ruleNumber)){
// 获取对应的方法名
String methodName = rule.getMethodName();
// 通过反射执行对应的方法
try {
Class<?> clazz = staffMoveService.getClass();
Method method = clazz.getDeclaredMethod(methodName);
Object result = method.invoke(staffMoveService);
System.out.println(result);
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
return ResultVo.failure();
}
}
}
return ResultVo.ok("success");
}
}