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.QyDjxx;
import com.ruoyi.system.service.IQyDjxxService;
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;

/**
 * djxx表Controller
 * 
 * @author xxx
 * @date 2019-09-10
 */
@Controller
@RequestMapping("/Ytj/djxx")
public class QyDjxxController extends BaseController
{
    private String prefix = "Ytj/djxx";

    @Autowired
    private IQyDjxxService qyDjxxService;

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

    /**
     * 查询djxx表列表
     */
    @RequiresPermissions("system:djxx:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QyDjxx qyDjxx)
    {
        startPage();
        List<QyDjxx> list = qyDjxxService.selectQyDjxxList(qyDjxx);
        return getDataTable(list);
    }

    /**
     * 导出djxx表列表
     */
    @RequiresPermissions("system:djxx:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QyDjxx qyDjxx)
    {
        List<QyDjxx> list = qyDjxxService.selectQyDjxxList(qyDjxx);
        ExcelUtil<QyDjxx> util = new ExcelUtil<QyDjxx>(QyDjxx.class);
        return util.exportExcel(list, "djxx");
    }

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

    /**
     * 新增保存djxx表
     */
    @RequiresPermissions("system:djxx:add")
    @Log(title = "djxx表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QyDjxx qyDjxx)
    {
        return toAjax(qyDjxxService.insertQyDjxx(qyDjxx));
    }

    /**
     * 修改djxx表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QyDjxx qyDjxx = qyDjxxService.selectQyDjxxById(id);
        mmap.put("qyDjxx", qyDjxx);
        return prefix + "/edit";
    }

    /**
     * 修改保存djxx表
     */
    @RequiresPermissions("system:djxx:edit")
    @Log(title = "djxx表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QyDjxx qyDjxx)
    {
        return toAjax(qyDjxxService.updateQyDjxx(qyDjxx));
    }

    /**
     * 删除djxx表
     */
    @RequiresPermissions("system:djxx:remove")
    @Log(title = "djxx表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(qyDjxxService.deleteQyDjxxByIds(ids));
    }
}
