package com.casic.missiles.service.Impl.business;

import com.casic.missiles.mapper.business.BusinessBoardMapper;
import lombok.Data;
import lombok.SneakyThrows;

import java.lang.reflect.Method;
import java.util.Objects;
import java.util.concurrent.RecursiveTask;

/**
 * @Description:
 * @Author: wangpeng
 * @Date: 2023/4/15 12:19
 */
@Data
public class BoardRecursiveTask extends RecursiveTask<Object> {
    private BusinessBoardMapper boardMapper;
    //执行的方法
    private String methodName;
    //方法的参数
    private Object param;

    public BoardRecursiveTask(BusinessBoardMapper boardMapper, String methodName, Object param) {
        this.boardMapper = boardMapper;
        this.methodName = methodName;
        this.param = param;
    }

    @SneakyThrows
    @Override
    protected Object compute() {
        Class c = BusinessBoardMapper.class;
        Method declaredMethod = c.getDeclaredMethod(methodName);
        if (Objects.nonNull(param)) {
            return declaredMethod.invoke(boardMapper, param);
        }
        return declaredMethod.invoke(boardMapper);
    }
}
