package com.ruoyi.web.controller.system;

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.BaseDatadictionarydetail;
import com.ruoyi.system.service.IBaseDatadictionarydetailService;
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.utils.StringUtils;
import com.ruoyi.common.core.domain.Ztree;

/**
 * 行业树表Controller
 *
 * @author ruoyi
 * @date 2020-07-07
 */
@Controller
@RequestMapping("/system/datadictionarydetail")
public class BaseDatadictionarydetailController extends BaseController
{
    private String prefix = "system/datadictionarydetail";

    @Autowired
    private IBaseDatadictionarydetailService baseDatadictionarydetailService;

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

    /**
     * 查询行业树表树列表
     */
    @RequiresPermissions("system:datadictionarydetail:list")
    @PostMapping("/list")
    @ResponseBody
    public List<BaseDatadictionarydetail> list(BaseDatadictionarydetail baseDatadictionarydetail)
    {
        List<BaseDatadictionarydetail> list = baseDatadictionarydetailService.selectBaseDatadictionarydetailList(baseDatadictionarydetail);
        return list;
    }

    /**
     * 导出行业树表列表
     */
    @RequiresPermissions("system:datadictionarydetail:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseDatadictionarydetail baseDatadictionarydetail)
    {
        List<BaseDatadictionarydetail> list = baseDatadictionarydetailService.selectBaseDatadictionarydetailList(baseDatadictionarydetail);
        ExcelUtil<BaseDatadictionarydetail> util = new ExcelUtil<BaseDatadictionarydetail>(BaseDatadictionarydetail.class);
        return util.exportExcel(list, "datadictionarydetail");
    }

    /**
     * 新增行业树表
     */
    @GetMapping(value = { "/add/{datadictionarydetailid}", "/add/" })
    public String add(@PathVariable(value = "datadictionarydetailid", required = false) String datadictionarydetailid, ModelMap mmap)
    {
        if (StringUtils.isNotNull(datadictionarydetailid))
        {
            mmap.put("baseDatadictionarydetail", baseDatadictionarydetailService.selectBaseDatadictionarydetailById(datadictionarydetailid));
        }
        return prefix + "/add";
    }

    /**
     * 新增保存行业树表
     */
    @RequiresPermissions("system:datadictionarydetail:add")
    @Log(title = "行业树表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseDatadictionarydetail baseDatadictionarydetail)
    {
        return toAjax(baseDatadictionarydetailService.insertBaseDatadictionarydetail(baseDatadictionarydetail));
    }

    /**
     * 修改行业树表
     */
    @GetMapping("/edit/{datadictionarydetailid}")
    public String edit(@PathVariable("datadictionarydetailid") String datadictionarydetailid, ModelMap mmap)
    {
        BaseDatadictionarydetail baseDatadictionarydetail = baseDatadictionarydetailService.selectBaseDatadictionarydetailById(datadictionarydetailid);
        mmap.put("baseDatadictionarydetail", baseDatadictionarydetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存行业树表
     */
    @RequiresPermissions("system:datadictionarydetail:edit")
    @Log(title = "行业树表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseDatadictionarydetail baseDatadictionarydetail)
    {
        return toAjax(baseDatadictionarydetailService.updateBaseDatadictionarydetail(baseDatadictionarydetail));
    }

    /**
     * 删除
     */
    @RequiresPermissions("system:datadictionarydetail:remove")
    @Log(title = "行业树表", businessType = BusinessType.DELETE)
    @GetMapping("/remove/{datadictionarydetailid}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("datadictionarydetailid") String datadictionarydetailid)
    {
        return toAjax(baseDatadictionarydetailService.deleteBaseDatadictionarydetailById(datadictionarydetailid));
    }

    /**
     * 选择行业树表树
     */
    @GetMapping(value = { "/selectDatadictionarydetailTree/{datadictionarydetailid}", "/selectDatadictionarydetailTree/" })
    public String selectDatadictionarydetailTree(@PathVariable(value = "datadictionarydetailid", required = false) String datadictionarydetailid, ModelMap mmap)
    {
        if (StringUtils.isNotNull(datadictionarydetailid))
        {
            mmap.put("baseDatadictionarydetail", baseDatadictionarydetailService.selectBaseDatadictionarydetailById(datadictionarydetailid));
        }
        return prefix + "/tree";
    }

    /**
     * 加载行业树表树列表
     */
    @GetMapping("/treeData")
    @ResponseBody
    public List<Ztree> treeData()
    {
        List<Ztree> ztrees = baseDatadictionarydetailService.selectBaseDatadictionarydetailTree();
        return ztrees;
    }
}
