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.BaseInfo;
import com.ruoyi.device.service.IBaseInfoService;
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_info")
public class BaseInfoController extends BaseController
{
    private String prefix = "device/base_info";

    @Autowired
    private IBaseInfoService baseInfoService;

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

    /**
     * 查询设备基础信息列表
     */
    @RequiresPermissions("device:base_info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BaseInfo baseInfo)
    {
        startPage();
        List<BaseInfo> list = baseInfoService.selectBaseInfoList(baseInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备基础信息列表
     */
    @RequiresPermissions("device:base_info:export")
    @Log(title = "设备基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BaseInfo baseInfo)
    {
        List<BaseInfo> list = baseInfoService.selectBaseInfoList(baseInfo);
        ExcelUtil<BaseInfo> util = new ExcelUtil<BaseInfo>(BaseInfo.class);
        return util.exportExcel(list, "设备基础信息数据");
    }

    /**
     * 新增设备基础信息
     */
    @RequiresPermissions("device:base_info:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存设备基础信息
     */
    @RequiresPermissions("device:base_info:add")
    @Log(title = "设备基础信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BaseInfo baseInfo)
    {
        return toAjax(baseInfoService.insertBaseInfo(baseInfo));
    }

    /**
     * 修改设备基础信息
     */
    @RequiresPermissions("device:base_info:edit")
    @GetMapping("/edit/{objId}")
    public String edit(@PathVariable("objId") Long objId, ModelMap mmap)
    {
        BaseInfo baseInfo = baseInfoService.selectBaseInfoByObjId(objId);
        mmap.put("baseInfo", baseInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存设备基础信息
     */
    @RequiresPermissions("device:base_info:edit")
    @Log(title = "设备基础信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BaseInfo baseInfo)
    {
        return toAjax(baseInfoService.updateBaseInfo(baseInfo));
    }

    /**
     * 删除设备基础信息
     */
    @RequiresPermissions("device:base_info:remove")
    @Log(title = "设备基础信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(baseInfoService.deleteBaseInfoByObjIds(ids));
    }

    @PostMapping("/checkDeviceCode")
    @ResponseBody
    public boolean ccheckDeviceCode(BaseInfo baseInfo){
        return baseInfoService.checkDeviceCode(baseInfo);
    }
}
