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.QyPerson;
import com.ruoyi.system.service.IQyPersonService;
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;

/**
 * 人员表Controller
 * 
 * @author ruoyi
 * @date 2019-09-10
 */
@Controller
@RequestMapping("/Ytj/person")
public class QyPersonController extends BaseController
{
    private String prefix = "Ytj/person";

    @Autowired
    private IQyPersonService qyPersonService;

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

    /**
     * 查询人员表列表
     */
    @RequiresPermissions("system:person:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(QyPerson qyPerson)
    {
        startPage();
        List<QyPerson> list = qyPersonService.selectQyPersonList(qyPerson);
        return getDataTable(list);
    }

    /**
     * 导出人员表列表
     */
    @RequiresPermissions("system:person:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(QyPerson qyPerson)
    {
        List<QyPerson> list = qyPersonService.selectQyPersonList(qyPerson);
        ExcelUtil<QyPerson> util = new ExcelUtil<QyPerson>(QyPerson.class);
        return util.exportExcel(list, "person");
    }

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

    /**
     * 新增保存人员表
     */
    @RequiresPermissions("system:person:add")
    @Log(title = "人员表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(QyPerson qyPerson)
    {
        return toAjax(qyPersonService.insertQyPerson(qyPerson));
    }

    /**
     * 修改人员表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        QyPerson qyPerson = qyPersonService.selectQyPersonById(id);
        mmap.put("qyPerson", qyPerson);
        return prefix + "/edit";
    }

    /**
     * 修改保存人员表
     */
    @RequiresPermissions("system:person:edit")
    @Log(title = "人员表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(QyPerson qyPerson)
    {
        return toAjax(qyPersonService.updateQyPerson(qyPerson));
    }

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