package com.tzld.piaoquan.api.controller;

import com.tzld.piaoquan.api.job.ExternalChannelProcessJob;
import com.tzld.piaoquan.api.model.vo.ExternalChannelVO;
import com.tzld.piaoquan.api.service.ExternalService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
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;

@Slf4j
@RestController
@RequestMapping("/external")
public class ExternalController {

    @Autowired
    private ExternalService service;
    @Autowired
    private ExternalChannelProcessJob job;

    @ApiOperation(value = "获取外部渠道信息")
    @GetMapping("/getChannelByRootSourceId")
    public CommonResponse<ExternalChannelVO> getChannelByRootSourceId(@RequestParam String rootSourceId) {
        return CommonResponse.success(service.getChannelByRootSourceId(rootSourceId));
    }

    @ApiOperation(value = "处理外部渠道数据")
    @GetMapping("/job/processExternalChannel")
    public CommonResponse<Null> processExternalChannel() {
        job.processExternalChannel(null);
        return CommonResponse.success();
    }

    @ApiOperation(value = "历史数据导入")
    @GetMapping("/job/initExternalChannelHistory")
    public CommonResponse<Null> initExternalChannelHistory(@RequestParam String days) {
        job.initExternalChannelHistory(days);
        return CommonResponse.success();
    }

    @ApiOperation(value = "历史数据导入")
    @GetMapping("/job/fillExternalChannelVideoId")
    public CommonResponse<Void> fillExternalChannelVideoId() {
        job.fillExternalChannelVideoId(null);
        return CommonResponse.success();
    }

}
