package com.ningdatech.kqapi.scheduler.controller;


import com.ningdatech.kqapi.scheduler.manage.SynManage;
import com.ningdatech.kqapi.scheduler.task.CheckMattersUrlTask;
import com.ningdatech.kqapi.scheduler.task.RemoveMattersTask;
import com.ningdatech.kqapi.scheduler.task.SynTask;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.MalformedURLException;
import java.net.UnknownHostException;
import java.util.Arrays;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ZPF
 * @since 2023-10-27
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/api/v1/task/")
@Api(value = "TaskController", tags = "柯桥-定时控制器")
@RequiredArgsConstructor
public class TaskController {
    private final RemoveMattersTask removeMattersTask;

    private final CheckMattersUrlTask checkMattersUrlTask;

    private final SynTask synTask;

    private final SynManage synManage;

    @ApiOperation(value = "主动调删除数据", notes = "主动调删除数据")
    @GetMapping("/remove-matters")
    public void removeMatters() throws UnknownHostException {
        removeMattersTask.doTask();
    }

    @ApiOperation(value = "主动同步三表", notes = "主动同步三表")
    @GetMapping("/syn-data")
    public void synData() throws UnknownHostException {
        synManage.synData();
    }

    @ApiOperation(value = "同步菜单链接数据", notes = "同步菜单链接数据")
    @GetMapping("/syn")
    public String synMenu() throws UnknownHostException {
        synTask.synData();
        return "同步成功";
    }

    @ApiOperation(value = "剔除某个菜单组件名称数据", notes = "英文逗号','分割")
    @GetMapping("/synEliminate")
    public String synEliminate(String keys){
        return synTask.synEliminate(Arrays.asList(keys.split(",")));
    }

    @ApiOperation(value = "同步单个菜单组件名称", notes = "同步菜单链接数据")
    @GetMapping("/synSingle")
    public String synSingle(String key){
        synTask.synSingle(key);
        return "同步成功";
    }

    @ApiOperation(value = "同步菜单链接数据", notes = "同步菜单链接数据")
    @GetMapping("/syn-menu")
    public String synMenuData() {
        synTask.synMenu();
        return "同步成功";
    }

    @ApiOperation(value = "check链接", notes = "check链接")
    @GetMapping("/check-url")
    public String checkUrl() throws UnknownHostException, MalformedURLException {
        checkMattersUrlTask.doTask();
        return "操作成功";
    }
}
