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.TrsNamenmgWords;
import com.ruoyi.project.service.ITrsNamenmgWordsService;
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-04-20
 */
@Controller
@RequestMapping("/project/trsnamenmgwords")
public class TrsNamenmgWordsController extends BaseController
{
    private String prefix = "project/trsnamenmgwords";

    @Autowired
    private ITrsNamenmgWordsService trsNamenmgWordsService;

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

    /**
     * 查询内蒙古自治区领导人词库列表
     */
    @RequiresPermissions("project:trsnamenmgwords:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TrsNamenmgWords trsNamenmgWords)
    {
        startPage();
        List<TrsNamenmgWords> list = trsNamenmgWordsService.selectTrsNamenmgWordsList(trsNamenmgWords);
        return getDataTable(list);
    }

    /**
     * 导出内蒙古自治区领导人词库列表
     */
    @RequiresPermissions("project:trsnamenmgwords:export")
    @Log(title = "内蒙古自治区领导人词库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TrsNamenmgWords trsNamenmgWords)
    {
        List<TrsNamenmgWords> list = trsNamenmgWordsService.selectTrsNamenmgWordsList(trsNamenmgWords);
        ExcelUtil<TrsNamenmgWords> util = new ExcelUtil<TrsNamenmgWords>(TrsNamenmgWords.class);
        return util.exportExcel(list, "内蒙古自治区领导人词库数据");
    }

    /**
     * 新增内蒙古自治区领导人词库
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存内蒙古自治区领导人词库
     */
    @RequiresPermissions("project:trsnamenmgwords:add")
    @Log(title = "内蒙古自治区领导人词库", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TrsNamenmgWords trsNamenmgWords)
    {
        Long deptId = getSysUser().getDeptId();
        if(deptId == 1){
            deptId = 100L;
        }
        trsNamenmgWords.setDeptId(deptId);
        return toAjax(trsNamenmgWordsService.insertTrsNamenmgWords(trsNamenmgWords));
    }

    /**
     * 修改内蒙古自治区领导人词库
     */
    @RequiresPermissions("project:trsnamenmgwords:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TrsNamenmgWords trsNamenmgWords = trsNamenmgWordsService.selectTrsNamenmgWordsById(id);
        mmap.put("trsNamenmgWords", trsNamenmgWords);
        return prefix + "/edit";
    }

    /**
     * 修改保存内蒙古自治区领导人词库
     */
    @RequiresPermissions("project:trsnamenmgwords:edit")
    @Log(title = "内蒙古自治区领导人词库", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TrsNamenmgWords trsNamenmgWords)
    {
        return toAjax(trsNamenmgWordsService.updateTrsNamenmgWords(trsNamenmgWords));
    }

    /**
     * 删除内蒙古自治区领导人词库
     */
    @RequiresPermissions("project:trsnamenmgwords:remove")
    @Log(title = "内蒙古自治区领导人词库", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(trsNamenmgWordsService.deleteTrsNamenmgWordsByIds(ids));
    }
}
