package com.ruoyi.web.controller.system;

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.common.core.domain.entity.ColumnNews;
import com.ruoyi.system.service.IColumnNewsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章信息Controller
 * 
 * @author boman
 * @date 2021-12-24
 */
@RestController
@RequestMapping("/system/news")
public class ColumnNewsController extends BaseController
{
    @Autowired
    private IColumnNewsService columnNewsService;

    /**
     * 查询文章信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:list')")
    @GetMapping("/list")
    public TableDataInfo list(ColumnNews columnNews)
    {
        startPage();
        List<ColumnNews> list = columnNewsService.selectColumnNewsList(columnNews);
        return getDataTable(list);
    }

    /**
     * 导出文章信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "文章信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ColumnNews columnNews)
    {
        List<ColumnNews> list = columnNewsService.selectColumnNewsList(columnNews);
        ExcelUtil<ColumnNews> util = new ExcelUtil<ColumnNews>(ColumnNews.class);
        util.exportExcel(response, list, "文章信息数据");
    }

    /**
     * 获取文章信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:query')")
    @GetMapping(value = "/{newsId}")
    public AjaxResult getInfo(@PathVariable("newsId") Integer newsId)
    {
        return AjaxResult.success(columnNewsService.selectColumnNewsByNewsId(newsId));
    }

    /**
     * 新增文章信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:add')")
    @Log(title = "文章信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody ColumnNews columnNews)
    {
        columnNews.setCreateBy(getUsername());
        return toAjax(columnNewsService.insertColumnNews(columnNews));
    }

    /**
     * 修改文章信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:edit')")
    @Log(title = "文章信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody ColumnNews columnNews)
    {
        columnNews.setUpdateBy(getUsername());
        return toAjax(columnNewsService.updateColumnNews(columnNews));
    }

    /**
     * 删除文章信息
     */
    @PreAuthorize("@ss.hasPermi('system:news:remove')")
    @Log(title = "文章信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{newsIds}")
    public AjaxResult remove(@PathVariable Integer[] newsIds)
    {
        return toAjax(columnNewsService.deleteColumnNewsByNewsIds(newsIds));
    }
/*    *//**
     * 文章审核通过
     *//*
    @PreAuthorize("@ss.hasPermi('system:news:examine')")
    @Log(title = "文章信息", businessType = BusinessType.EXAMINE)
    @GetMapping(value = "/examine/{newsId}")
    public AjaxResult examine(@PathVariable("newsId") Integer newsId)
    {
        return toAjax(columnNewsService.examineColumnNews(newsId));
    }
    *//**
     * 驳回文章信息
     *//*
    @PreAuthorize("@ss.hasPermi('system:news:reject')")
    @Log(title = "驳回文章信息", businessType = BusinessType.REJECT)
    @PostMapping("/reject")
    public AjaxResult reject(@RequestBody ColumnNews columnNews)
    {
        //驳回
        columnNews.setStatus("2");
        return toAjax(columnNewsService.updateColumnNews(columnNews));
    }*/
}
