package com.flossom.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.flossom.common.core.domain.R;
import com.flossom.common.core.domain.entity.ActivityChannelInfo;
import com.flossom.common.core.utils.poi.ExcelUtil;
import com.flossom.common.core.web.controller.BaseController;
import com.flossom.common.core.web.domain.AjaxResult;
import com.flossom.common.core.web.page.TableDataInfo;
import com.flossom.common.log.annotation.Log;
import com.flossom.common.log.enums.BusinessType;
import com.flossom.common.security.annotation.RequiresPermissions;
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.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.flossom.system.service.IActivityChannelInfoService;

/**
 * 活动渠道信息Controller
 *
 * @author flossom
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/channelInfo")
public class ActivityChannelInfoController extends BaseController
{
    @Autowired
    private IActivityChannelInfoService activityChannelInfoService;

    /**
     * 查询活动渠道信息列表
     */
    @RequiresPermissions("system:channelInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(ActivityChannelInfo activityChannelInfo)
    {
        startPage();
        List<ActivityChannelInfo> list = activityChannelInfoService.selectActivityChannelInfoList(activityChannelInfo);
        return getDataTable(list);
    }

    /**
     * 导出活动渠道信息列表
     */
    @RequiresPermissions("system:channelInfo:export")
    @Log(title = "活动渠道信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityChannelInfo activityChannelInfo)
    {
        List<ActivityChannelInfo> list = activityChannelInfoService.selectActivityChannelInfoList(activityChannelInfo);
        ExcelUtil<ActivityChannelInfo> util = new ExcelUtil<ActivityChannelInfo>(ActivityChannelInfo.class);
        util.exportExcel(response, list, "活动渠道信息数据");
    }

    /**
     * 获取活动渠道信息详细信息
     */
    @RequiresPermissions("system:channelInfo:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(activityChannelInfoService.selectActivityChannelInfoById(id));
    }

    /**
     * 新增活动渠道信息
     */
    @RequiresPermissions("system:channelInfo:add")
    @Log(title = "活动渠道信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityChannelInfo activityChannelInfo)
    {
        return toAjax(activityChannelInfoService.insertActivityChannelInfo(activityChannelInfo));
    }

    /**
     * 修改活动渠道信息
     */
    @RequiresPermissions("system:channelInfo:edit")
    @Log(title = "活动渠道信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ActivityChannelInfo activityChannelInfo)
    {
        return toAjax(activityChannelInfoService.updateActivityChannelInfo(activityChannelInfo));
    }

    /**
     * 删除活动渠道信息
     */
    @RequiresPermissions("system:channelInfo:remove")
    @Log(title = "活动渠道信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(activityChannelInfoService.deleteActivityChannelInfoByIds(ids));
    }

    /**
     * 获取购买渠道
     * @return
     */
    @GetMapping("/getPurchaseChannel")
    public R getPurchaseChannel() {
        return R.ok(activityChannelInfoService.getPurchaseChannel());
    }
}
