package com.ruixuan.launch.controller;

import com.alibaba.fastjson.JSONArray;
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.entity.KuaishouLaunchTargetTemplate;
import com.ruixuan.launch.service.IKuaishouLaunchTargetTemplateService;
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/template")
public class KuaishouLaunchTargetTemplateController extends BaseController {
    @Autowired
    private IKuaishouLaunchTargetTemplateService kuaishouLaunchTargetTemplateService;

    /**
     * 查询账户下所属定向信息列表
     */
    @ApiOperation(value = "查询账户下所属定向信息列表")
    @GetMapping("/list")
    public TableDataInfo list(KuaishouLaunchTargetTemplate kuaishouLaunchTargetTemplate) {
        startPage();
        List<KuaishouLaunchTargetTemplate> list = kuaishouLaunchTargetTemplateService.selectKuaishouLaunchTargetTemplateList(kuaishouLaunchTargetTemplate);
        return getDataTable(list);
    }

    /**
     * 获取账户下所属定向信息详细信息
     */
    @ApiOperation(value = "获取账户下所属定向信息详细信息")
    @GetMapping("/getById")
    public AjaxResult getInfo(@ApiParam("id") @RequestParam(value = "id", required = true) Long id) {
        return AjaxResult.success(kuaishouLaunchTargetTemplateService.selectKuaishouLaunchTargetTemplateById(id));
    }

    /**
     * 获取账户下所属定向信息详细信息
     */
    @ApiOperation(value = "批量获取账户下所属定向信息详细信息")
    @GetMapping("/getByIds")
    public ResultResponse getInfo(@ApiParam("ids") @RequestParam(value = "ids", required = true) String ids) {
        return kuaishouLaunchTargetTemplateService.selectKuaishouLaunchTargetTemplateByIds(ids);
    }

    /**
     * 新增广告组定向信息
     */
    @PostMapping(value = "/add")
    @ApiOperation(value = "新增广告组定向信息")
    public ResultResponse add(@RequestBody JSONObject request) {
        return kuaishouLaunchTargetTemplateService.insertKuaishouLaunchTargetTemplate(request);
    }

    /**
     * 批量新增广告组定向信息
     */
    @PostMapping(value = "/adds")
    @ApiOperation(value = "批量新增广告组定向信息")
    public ResultResponse adds(@RequestBody JSONObject request) {
        return kuaishouLaunchTargetTemplateService.insertMore(request);
    }

    /**
     * 修改账户下所属定向信息
     */
    @PostMapping(value = "/edit")
    @ApiOperation(value = "修改账户下所属定向信息")
    public AjaxResult edit(@RequestBody KuaishouLaunchTargetTemplate kuaishouLaunchTargetTemplate) {
        return toAjax(kuaishouLaunchTargetTemplateService.updateKuaishouLaunchTargetTemplate(kuaishouLaunchTargetTemplate));
    }
}