编程语言
首页 > 编程语言> > java 方法作为参数封装在map

java 方法作为参数封装在map

作者:互联网

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;
    }

}

 

标签:map,java,funcMap,RuleParam,封装,Inject,getUserList,put,import
来源: https://www.cnblogs.com/deepalley/p/15678384.html