package com.ruoyi.web.controller.business;

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.business.domain.TbUserConfig;
import com.ruoyi.business.service.ITbUserConfigService;
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 xiatao
 * @date 2022-01-18
 */
@Controller
@RequestMapping("/business/userConfig")
public class TbUserConfigController extends BaseController
{
    private String prefix = "business/userConfig";

    @Autowired
    private ITbUserConfigService tbUserConfigService;

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

    /**
     * 查询用户设置列表
     */
    @RequiresPermissions("business:userConfig:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TbUserConfig tbUserConfig)
    {
        startPage();
        List<TbUserConfig> list = tbUserConfigService.selectTbUserConfigList(tbUserConfig);
        return getDataTable(list);
    }

    /**
     * 导出用户设置列表
     */
    @RequiresPermissions("business:userConfig:export")
    @Log(title = "用户设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TbUserConfig tbUserConfig)
    {
        List<TbUserConfig> list = tbUserConfigService.selectTbUserConfigList(tbUserConfig);
        ExcelUtil<TbUserConfig> util = new ExcelUtil<TbUserConfig>(TbUserConfig.class);
        return util.exportExcel(list, "用户设置数据");
    }

    /**
     * 新增用户设置
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存用户设置
     */
    @RequiresPermissions("business:userConfig:add")
    @Log(title = "用户设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TbUserConfig tbUserConfig)
    {
        return toAjax(tbUserConfigService.insertTbUserConfig(tbUserConfig));
    }

    /**
     * 修改用户设置
     */
    @RequiresPermissions("business:userConfig:edit")
    @GetMapping("/edit/{userId}")
    public String edit(@PathVariable("userId") Long userId, ModelMap mmap)
    {
        TbUserConfig tbUserConfig = tbUserConfigService.selectTbUserConfigByUserId(userId);
        mmap.put("tbUserConfig", tbUserConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户设置
     */
    @RequiresPermissions("business:userConfig:edit")
    @Log(title = "用户设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TbUserConfig tbUserConfig)
    {
        return toAjax(tbUserConfigService.updateTbUserConfig(tbUserConfig));
    }

    /**
     * 删除用户设置
     */
    @RequiresPermissions("business:userConfig:remove")
    @Log(title = "用户设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tbUserConfigService.deleteTbUserConfigByUserIds(ids));
    }
}
