package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CompanySale;
import com.ruoyi.system.service.ICompanySaleService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告主销售Controller
 *
 * @author ruoyi
 * @date 2023-05-15
 */
@Controller
@RequestMapping("/system/sale")
public class CompanySaleController extends BaseController
{
    private String prefix = "system/sale";

    @Autowired
    private ICompanySaleService companySaleService;

    @RequiresPermissions("system:sale:view")
    @GetMapping()
    public String sale()
    {
        return prefix + "/sale";
    }

    /**
     * 查询广告主销售列表
     */
    @RequiresPermissions("system:sale:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CompanySale companySale)
    {
        startPage();
        List<CompanySale> list = companySaleService.selectCompanySaleList(companySale);
        return getDataTable(list);
    }

    /**
     * 导出广告主销售列表
     */
    @RequiresPermissions("system:sale:export")
    @Log(title = "广告主销售", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CompanySale companySale)
    {
        List<CompanySale> list = companySaleService.selectCompanySaleList(companySale);
        ExcelUtil<CompanySale> util = new ExcelUtil<CompanySale>(CompanySale.class);
        return util.exportExcel(list, "广告主销售数据");
    }

    /**
     * 新增广告主销售
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广告主销售
     */
    @RequiresPermissions("system:sale:add")
    @Log(title = "广告主销售", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CompanySale companySale)
    {
        return toAjax(companySaleService.insertCompanySale(companySale));
    }

    /**
     * 修改广告主销售
     */
    @RequiresPermissions("system:sale:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CompanySale companySale = companySaleService.selectCompanySaleById(id);
        mmap.put("companySale", companySale);
        return prefix + "/edit";
    }

    /**
     * 修改保存广告主销售
     */
    @RequiresPermissions("system:sale:edit")
    @Log(title = "广告主销售", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CompanySale companySale)
    {
        return toAjax(companySaleService.updateCompanySale(companySale));
    }

    /**
     * 删除广告主销售
     */
    @RequiresPermissions("system:sale:remove")
    @Log(title = "广告主销售", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(companySaleService.deleteCompanySaleByIds(ids));
    }
}
