package cn.ezhizao.project.business.channelCategory.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import cn.ezhizao.project.business.channelCategory.domain.BizChannelCategory;
import cn.ezhizao.project.business.channelCategory.service.IBizChannelCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
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 cn.ezhizao.framework.aspectj.lang.annotation.Log;
import cn.ezhizao.framework.aspectj.lang.enums.BusinessType;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.domain.AjaxResult;
import cn.ezhizao.common.utils.poi.ExcelUtil;
import cn.ezhizao.framework.web.page.TableDataInfo;

/**
 * 渠道类型Controller
 *
 * @author ruoyi
 * @date 2023-10-26
 */
@RestController
@RequestMapping("/business/category")
public class BizChannelCategoryController extends BaseController
{
    @Resource
    private IBizChannelCategoryService bizChannelCategoryService;

    /**
     * 查询渠道类型列表
     */
    @PreAuthorize("@ss.hasPermi('business:channel:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizChannelCategory bizChannelCategory) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizChannelCategory);
        startPage();
        startOrderBy();
        List<BizChannelCategory> list = bizChannelCategoryService.getList(bizChannelCategory);
        return getDataTable(list);
    }

    /**
     * 导出渠道类型列表
     */
    @PreAuthorize("@ss.hasPermi('business:category:export')")
    @Log(title = "渠道类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizChannelCategory bizChannelCategory) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizChannelCategory);
        List<BizChannelCategory> list = bizChannelCategoryService.getList(bizChannelCategory);
        ExcelUtil<BizChannelCategory> util = new ExcelUtil<BizChannelCategory>(BizChannelCategory.class);
        util.exportExcel(response, list, "渠道类型数据");
    }

    /**
     * 获取渠道类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizChannelCategoryService.getById(id));
    }

    /**
     * 新增渠道类型
     */
    @PreAuthorize("@ss.hasPermi('business:category:add')")
    @Log(title = "渠道类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizChannelCategory bizChannelCategory) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizChannelCategory);
        return toAjax(bizChannelCategoryService.save(bizChannelCategory));
    }

    /**
     * 修改渠道类型
     */
    @PreAuthorize("@ss.hasPermi('business:category:edit')")
    @Log(title = "渠道类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizChannelCategory bizChannelCategory) throws NoSuchFieldException, IllegalAccessException
    {
        setTenantId(bizChannelCategory);
        return toAjax(bizChannelCategoryService.updateById(bizChannelCategory));
    }

    /**
     * 删除渠道类型
     */
    @PreAuthorize("@ss.hasPermi('business:category:remove')")
    @Log(title = "渠道类型", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids)
    {
        return toAjax(bizChannelCategoryService.removeBatchByIds(ids));
    }
}
