1、创建函数接口类

    //函数接口类
    public interface IFunction {
        Map<String, Object> queryYearData(Map<String, Object> map);
    };

2、方法调用时,使用lambda表达式传入函数参数

    public CommonResult<List<Map<String, Object>>> queryGeneralFollowUpYear(String loginType) {
        return queryYearData(loginType, (map) -> mapper.queryGeneralFollowUpYear(map));
    }

3、具体方法实现

    private CommonResult<List<Map<String, Object>>> queryYearData(String loginType, IFunction myFunction) {
        SysUser sysUser = SystemUtil.getLoginUser(loginType);
        if (null == sysUser){
            return  new CommonResult<>(CommonResultEmnu.INVALID_USER);
        }
        Map<String, Object> map = new HashMap<>();
        Long createSysId = sysUser.getId();
        map.put("createId", createSysId);

        Map<String, Object> recordYear = myFunction.queryYearData(map);
        return new CommonResult<>(ChartUtil.getLastTwelfthMonthData(recordYear));
    }

新时代农民工

更多推荐

JAVA如何将函数作为方法参数传入