package com.exe.competency.service.impl; import com.exe.competency.domain.RuleParam; import com.exe.competency.domain.RuleResult; import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.inject.Inject; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Function; @Service public class RuleContext { @Inject LegalPersonServer legalPersonServer; @Inject AssignPostServer assignPostServer; @Inject AssignTagServer assignTagServer; @Inject AssignPositionServer assignPositionServer; @Inject ParentLegalPersonServer parentLegalPersonServer; @Inject AssignDeptAndPostServer assignDeptAndPostServer; @Inject LeaderServer leaderServer; Map<Integer, Function<RuleParam, RuleResult>> funcMap = new HashMap<>(); @PostConstruct public void init() { funcMap.put(1, RuleParam -> legalPersonServer.getUserList(RuleParam)); funcMap.put(2, RuleParam -> assignPostServer.getUserList(RuleParam)); funcMap.put(3, RuleParam -> assignTagServer.getUserList(RuleParam)); funcMap.put(4, RuleParam -> assignPositionServer.getUserList(RuleParam)); funcMap.put(5, RuleParam -> parentLegalPersonServer.getUserList(RuleParam)); funcMap.put(6, RuleParam -> assignDeptAndPostServer.getUserList(RuleParam)); funcMap.put(7, RuleParam -> leaderServer.getUserList(RuleParam)); } public RuleResult getUserList(int kind, String userId, List<String> fromIds, int type) { Function<RuleParam, RuleResult> stringListFunction = funcMap.get(kind); if (stringListFunction != null) { RuleParam rule = new RuleParam(); rule.setUserId(userId); rule.setFromId(fromIds); rule.setType(type); return stringListFunction.apply(rule); } return null; } }