package com.ruoyi.device.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.device.domain.BaseType;
import com.ruoyi.device.service.IBaseTypeService;
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 2025-05-19
 */
@Controller
@RequestMapping("/device/base_type")
public class BaseTypeController extends BaseController
{
    private String prefix = "device/base_type";

    @Autowired
    private IBaseTypeService baseTypeService;

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

    /**
     * 查询设备类型维护列表
     */
    @RequiresPermissions("device:base_type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseType baseType)
    {
        startPage();
        List<BaseType> list = baseTypeService.selectBaseTypeList(baseType);
        return getDataTable(list);
    }

    /**
     * 导出设备类型维护列表
     */
    @RequiresPermissions("device:base_type:export")
    @Log(title = "设备类型维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseType baseType)
    {
        List<BaseType> list = baseTypeService.selectBaseTypeList(baseType);
        ExcelUtil<BaseType> util = new ExcelUtil<BaseType>(BaseType.class);
        return util.exportExcel(list, "设备类型维护数据");
    }

    /**
     * 新增设备类型维护
     */
    @RequiresPermissions("device:base_type:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备类型维护
     */
    @RequiresPermissions("device:base_type:add")
    @Log(title = "设备类型维护", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseType baseType)
    {
        return toAjax(baseTypeService.insertBaseType(baseType));
    }



    /**
     * 修改设备类型维护
     */
    @RequiresPermissions("device:base_type:edit")
    @GetMapping("/edit/{objId}")
    public String edit(@PathVariable("objId") Long objId, ModelMap mmap)
    {
        BaseType baseType = baseTypeService.selectBaseTypeByObjId(objId);
        mmap.put("baseType", baseType);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备类型维护
     */
    @RequiresPermissions("device:base_type:edit")
    @Log(title = "设备类型维护", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseType baseType)
    {
        return toAjax(baseTypeService.updateBaseType(baseType));
    }

    /**
     * 删除设备类型维护
     */
    @RequiresPermissions("device:base_type:remove")
    @Log(title = "设备类型维护", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseTypeService.deleteBaseTypeByObjIds(ids));
    }


    /**
     *校验名称重复
     */
    @PostMapping("/checkDeviceTypeName")
    @ResponseBody
    public boolean checkDeviceTypeName(BaseType baseType)  {
        return baseTypeService.checkDeviceTypeName(baseType);
    }

}
