package com.ruoyi.web.controller.news;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BomanNews;
import com.ruoyi.system.service.IBomanNewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * boman_newsController
 * 
 * @author boman
 * @date 2023-11-02
 */
@RestController
@RequestMapping("/system/news")
public class BomanNewsController extends BaseController
{
    @Autowired
    private IBomanNewsService bomanNewsService;

    /**
     * 查询boman_news列表
     */
    //@PreAuthorize("@ss.hasPermi('system:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(BomanNews bomanNews)
    {
        startPage();
        List<BomanNews> list = bomanNewsService.selectBomanNewsList(bomanNews);
        return getDataTable(list);
    }

    /**
     * 导出boman_news列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "boman_news", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BomanNews bomanNews)
    {
        List<BomanNews> list = bomanNewsService.selectBomanNewsList(bomanNews);
        ExcelUtil<BomanNews> util = new ExcelUtil<BomanNews>(BomanNews.class);
        util.exportExcel(response, list, "boman_news数据");
    }

    /**
     * 获取boman_news详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:news:query')")
    @GetMapping(value = "/{newsId}")
    public AjaxResult getInfo(@PathVariable("newsId") Long newsId)
    {
        return success(bomanNewsService.selectBomanNewsByNewsId(newsId));
    }

    /**
     * 新增boman_news
     */
    @PreAuthorize("@ss.hasPermi('system:news:add')")
    @Log(title = "boman_news", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody BomanNews bomanNews)
    {
        return toAjax(bomanNewsService.insertBomanNews(bomanNews));
    }

    /**
     * 修改boman_news
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "boman_news", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@Validated @RequestBody BomanNews bomanNews)
    {
        return toAjax(bomanNewsService.updateBomanNews(bomanNews));
    }

    /**
     * 删除boman_news
     */
    @PreAuthorize("@ss.hasPermi('system:news:remove')")
    @Log(title = "boman_news", businessType = BusinessType.DELETE)
	@GetMapping("/delete/{newsIds}")
    public AjaxResult remove(@PathVariable Long[] newsIds)
    {
        return toAjax(bomanNewsService.deleteBomanNewsByNewsIds(newsIds));
    }
}
