package com.ruoyi.web.controller.Ytjback;
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.system.domain.QyWordtemplate;
import com.ruoyi.system.service.IQyWordtemplateService;
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.*;

import java.util.List;

/**
 * word文件表Controller
 * 
 * @author ruoyi
 * @date 2019-09-10
 */
@Controller
@RequestMapping("/Ytj/wordtemplate")
public class QyWordtemplateController extends BaseController
{
    private String prefix = "Ytj/wordtemplate";

    @Autowired
    private IQyWordtemplateService qyWordtemplateService;

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

    /**
     * 查询word文件表列表
     */
    @RequiresPermissions("system:wordtemplate:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QyWordtemplate qyWordtemplate)
    {
        startPage();
        List<QyWordtemplate> list = qyWordtemplateService.selectQyWordtemplateList(qyWordtemplate);
        return getDataTable(list);
    }

    /**
     * 导出word文件表列表
     */
    @RequiresPermissions("system:wordtemplate:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QyWordtemplate qyWordtemplate)
    {
        List<QyWordtemplate> list = qyWordtemplateService.selectQyWordtemplateList(qyWordtemplate);
        ExcelUtil<QyWordtemplate> util = new ExcelUtil<QyWordtemplate>(QyWordtemplate.class);
        return util.exportExcel(list, "wordtemplate");
    }

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

    /**
     * 新增保存word文件表
     */
    @RequiresPermissions("system:wordtemplate:add")
    @Log(title = "word文件表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QyWordtemplate qyWordtemplate)
    {
        return toAjax(qyWordtemplateService.insertQyWordtemplate(qyWordtemplate));
    }

    /**
     * 修改word文件表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QyWordtemplate qyWordtemplate = qyWordtemplateService.selectQyWordtemplateById(id);
        mmap.put("qyWordtemplate", qyWordtemplate);
        return prefix + "/edit";
    }

    /**
     * 修改保存word文件表
     */
    @RequiresPermissions("system:wordtemplate:edit")
    @Log(title = "word文件表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QyWordtemplate qyWordtemplate)
    {
        return toAjax(qyWordtemplateService.updateQyWordtemplate(qyWordtemplate));
    }

    /**
     * 删除word文件表
     */
    @RequiresPermissions("system:wordtemplate:remove")
    @Log(title = "word文件表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qyWordtemplateService.deleteQyWordtemplateByIds(ids));
    }
}
