package com.ruoyi.system.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.system.domain.LoginUserDept;
import com.ruoyi.system.service.ILoginUserDeptService;
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 2022-05-11
 */
@Controller
@RequestMapping("/system/plat")
public class LoginUserDeptController extends BaseController
{
    private String prefix = "system/plat";

    @Autowired
    private ILoginUserDeptService loginUserDeptService;

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

    /**
     * 查询平台公司权限列表
     */
    @RequiresPermissions("system:plat:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LoginUserDept loginUserDept)
    {
        startPage();
        List<LoginUserDept> list = loginUserDeptService.selectLoginUserDeptList(loginUserDept);
        return getDataTable(list);
    }

    /**
     * 导出平台公司权限列表
     */
    @RequiresPermissions("system:plat:export")
    @Log(title = "平台公司权限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LoginUserDept loginUserDept)
    {
        List<LoginUserDept> list = loginUserDeptService.selectLoginUserDeptList(loginUserDept);
        ExcelUtil<LoginUserDept> util = new ExcelUtil<LoginUserDept>(LoginUserDept.class);
        return util.exportExcel(list, "平台公司权限数据");
    }

    /**
     * 新增平台公司权限
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存平台公司权限
     */
    @RequiresPermissions("system:plat:add")
    @Log(title = "平台公司权限", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LoginUserDept loginUserDept)
    {
        return toAjax(loginUserDeptService.insertLoginUserDept(loginUserDept));
    }

    /**
     * 修改平台公司权限
     */
    @RequiresPermissions("system:plat:edit")
    @GetMapping("/edit/{loginName}")
    public String edit(@PathVariable("loginName") String loginName, ModelMap mmap)
    {
        LoginUserDept loginUserDept = loginUserDeptService.selectLoginUserDeptByLoginName(loginName);
        mmap.put("loginUserDept", loginUserDept);
        return prefix + "/edit";
    }

    /**
     * 修改保存平台公司权限
     */
    @RequiresPermissions("system:plat:edit")
    @Log(title = "平台公司权限", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LoginUserDept loginUserDept)
    {
        return toAjax(loginUserDeptService.updateLoginUserDept(loginUserDept));
    }

    /**
     * 删除平台公司权限
     */
    @RequiresPermissions("system:plat:remove")
    @Log(title = "平台公司权限", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(loginUserDeptService.deleteLoginUserDeptByLoginNames(ids));
    }
}
