package com.ruoyi.post.frequency.posttype.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.post.frequency.posttype.entity.PostType;
import com.ruoyi.post.frequency.posttype.service.PostTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 帖子分类Controller
 * 
 * @author liwenlong
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/frequency/postype")
public class PostTypeController extends BaseController
{
    @Autowired
    private PostTypeService postTypeService;

    /**
     * 查询帖子分类列表
     */
//    @PreAuthorize("@ss.hasPermi('frequency:postype:list')")
    @PostMapping("/list")
    public TableDataInfo<PostType> list(@RequestBody PostType postType)
    {
        startPage();
        List<PostType> list = postTypeService.selectPostTypeList(postType);
        return getDataTable(list);
    }

    /**
     * 导出帖子分类列表
     */
    @PreAuthorize("@ss.hasPermi('frequency:postype:export')")
    @Log(title = "帖子分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PostType postType)
    {
        List<PostType> list = postTypeService.selectPostTypeList(postType);
        ExcelUtil<PostType> util = new ExcelUtil<PostType>(PostType.class);
        return util.exportExcel(list, "帖子分类数据");
    }

    /**
     * 获取帖子分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('frequency:postype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult<PostType> getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(postTypeService.selectPostTypeById(id));
    }

    /**
     * 新增帖子分类
     */
    @PreAuthorize("@ss.hasPermi('frequency:postype:add')")
    @Log(title = "帖子分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostType postType)
    {
        return toAjax(postTypeService.insertPostType(postType));
    }

    /**
     * 修改帖子分类
     */
    @PreAuthorize("@ss.hasPermi('frequency:postype:edit')")
    @Log(title = "帖子分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostType postType)
    {
        return toAjax(postTypeService.updatePostType(postType));
    }

    /**
     * 删除帖子分类
     */
    @PreAuthorize("@ss.hasPermi('frequency:postype:remove')")
    @Log(title = "帖子分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}/{delFlag}")
    public AjaxResult remove(@PathVariable Long[] ids,@PathVariable Integer delFlag)
    {
        return toAjax(postTypeService.deletePostTypeByIds(ids,delFlag));
    }
}
