package com.ruoyi.project.controller;

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.project.domain.TrsArticleInfo;
import com.ruoyi.project.service.ITrsArticleInfoService;
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 2025-03-20
 */
@Controller
@RequestMapping("/project/trsArticleInfo")
public class TrsArticleInfoController extends BaseController
{
    private String prefix = "project/trsArticleInfo";

    @Autowired
    private ITrsArticleInfoService trsArticleInfoService;

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

    /**
     * 查询稿件列表
     */
    @RequiresPermissions("project:trsArticleInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrsArticleInfo trsArticleInfo)
    {
        startPage();
        List<TrsArticleInfo> list = trsArticleInfoService.selectTrsArticleInfoList(trsArticleInfo);
        return getDataTable(list);
    }

    /**
     * 导出稿件列表
     */
    @RequiresPermissions("project:trsArticleInfo:export")
    @Log(title = "稿件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrsArticleInfo trsArticleInfo)
    {
        List<TrsArticleInfo> list = trsArticleInfoService.selectTrsArticleInfoList(trsArticleInfo);
        ExcelUtil<TrsArticleInfo> util = new ExcelUtil<TrsArticleInfo>(TrsArticleInfo.class);
        return util.exportExcel(list, "稿件数据");
    }

    /**
     * 新增稿件
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存稿件
     */
    @RequiresPermissions("project:trsArticleInfo:add")
    @Log(title = "稿件", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrsArticleInfo trsArticleInfo)
    {
        return toAjax(trsArticleInfoService.insertTrsArticleInfo(trsArticleInfo));
    }

    /**
     * 修改稿件
     */
    @RequiresPermissions("project:trsArticleInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TrsArticleInfo trsArticleInfo = trsArticleInfoService.selectTrsArticleInfoById(id);
        mmap.put("trsArticleInfo", trsArticleInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存稿件
     */
    @RequiresPermissions("project:trsArticleInfo:edit")
    @Log(title = "稿件", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrsArticleInfo trsArticleInfo)
    {
        return toAjax(trsArticleInfoService.updateTrsArticleInfo(trsArticleInfo));
    }

    /**
     * 删除稿件
     */
    @RequiresPermissions("project:trsArticleInfo:remove")
    @Log(title = "稿件", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trsArticleInfoService.deleteTrsArticleInfoByIds(ids));
    }
}
