package com.zksy.data.controller;

import com.zksy.common.domain.Result;
import com.zksy.data.schedule.CollectDataSchedule;
import com.zksy.data.service.IBaseSaveDataInterface;
import com.zksy.data.utils.PublisherMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Optional;

@RestController
@RequestMapping("/invoker")
@Api(tags = "调用接口",description = "调用接口")
public class InvokerController {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    private PublisherMessage publisherMessage;
    @GetMapping
    @ApiOperation("调用指定的表同步")
    public Result invokerTargetTable(@RequestParam String targetTableString) {
        Object bean = null;
        try {
            bean = applicationContext.getBean(targetTableString);
        } catch (BeansException e) {
            return Result.error("调用失败,请检查参数");
        }
        if (bean instanceof IBaseSaveDataInterface){
            publisherMessage.emitToInvoker(targetTableString);
        }
        return Result.ok("成功发起调用");
    }
}
