package com.ruixuan.launch.controller;

import com.alibaba.fastjson.JSONObject;
import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.AjaxResult;
import com.ruixuan.common.core.domain.ResultResponse;
import com.ruixuan.common.core.page.TableDataInfo;
import com.ruixuan.launch.service.IKuaishouLaunchCampaignAutoStrategyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 投流策略Controller
 *
 * @author ruoyi
 * @date 2022-07-05
 */
@Api(tags = "投流策略")
@RestController
@RequestMapping("/launch/strategy")
public class KuaishouLaunchCampaignAutoStrategyController extends BaseController {
    @Autowired
    private IKuaishouLaunchCampaignAutoStrategyService kuaishouLaunchCampaignAutoStrategyService;

    /**
     * 查询投流策略列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询投流策略列表")
    public TableDataInfo list(@ApiParam("计划名称") @RequestParam(value = "campaignName", required = false) String campaignName,
                              @ApiParam("账户名称") @RequestParam(value = "accountName", required = false) String accountName) {
        startPage();
        List<JSONObject> list = kuaishouLaunchCampaignAutoStrategyService.selectKuaishouLaunchCampaignAutoStrategyList(campaignName, accountName);
        return getDataTable(list);
    }

    /**
     * 获取投流策略详细信息
     */
    @ApiOperation(value = "获取投流策略详细信息")
    @GetMapping("/getById")
    public AjaxResult getInfo(@ApiParam("id") @RequestParam(value = "id", required = true) Long id) {
        return AjaxResult.success(kuaishouLaunchCampaignAutoStrategyService.selectKuaishouLaunchCampaignAutoStrategyById(id));
    }

    /**
     * 新增投流策略
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增投流策略")
    public ResultResponse add(@RequestBody JSONObject requestJson) {
        return kuaishouLaunchCampaignAutoStrategyService.insertKuaishouLaunchCampaignAutoStrategy(requestJson);
    }

    /**
     * 修改投流策略
     */
    @PostMapping(value = "/edit")
    @ApiOperation(value = "修改投流策略")
    public AjaxResult edit(@RequestBody JSONObject requestJson) {
        return toAjax(kuaishouLaunchCampaignAutoStrategyService.updateKuaishouLaunchCampaignAutoStrategy(requestJson));
    }

    @PostMapping(value = "/createByStrategy")
    @ApiOperation(value = "执行策略")
    public ResultResponse createByStrategy(@ApiParam("id") @RequestParam(value = "id", required = true) Long id) {
        return kuaishouLaunchCampaignAutoStrategyService.createByStrategy(id);
    }

}