/**
* 提供业务逻辑单元
*/@ServicepublicclassBizUnitService{publicStringbizOne(String order){return order +"各种花式操作1";}publicStringbizTwo(String order){return order +"各种花式操作2";}publicStringbizThree(String order){return order +"各种花式操作3";}}
/**
* 某个业务服务类
*/@ServicepublicclassBizService{@AutowiredprivateBizUnitService bizUnitService;privateMap<String,Function<String,String>> checkResultDispatcherComX =newHashMap<>();/**
* 初始化 业务逻辑分派Map 其中value 存放的是 lambda表达式
*/@PostConstructpublicvoidcheckResultDispatcherComXInit(){
checkResultDispatcherComX.put("key_订单1", order -> bizUnitService.bizOne(order));
checkResultDispatcherComX.put("key_订单1_订单2", order -> bizUnitService.bizTwo(order));
checkResultDispatcherComX.put("key_订单1_订单2_订单3", order -> bizUnitService.bizThree(order));}publicStringgetCheckResultComX(String order,int level){//写一段生成key的逻辑:String key =getDispatcherComXKey(order, level);Function<String,String> result = checkResultDispatcherComX.get(key);if(result !=null){//执行这段表达式获得String类型的结果return result.apply(order);}return"不在处理的逻辑中返回业务错误";}/**
* 判断条件方法
*/privateStringgetDispatcherComXKey(String order,int level){StringBuilder key =newStringBuilder("key");for(int i =1; i <= level; i++){
key.append("_"+ order + i);}return key.toString();}}