package com.jjt.rz.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jjt.common.annotation.Log;
import com.jjt.common.core.controller.BaseController;
import com.jjt.common.core.domain.AjaxResult;
import com.jjt.common.enums.BusinessType;
import com.jjt.rz.domain.TwinDeviceType;
import com.jjt.rz.service.ITwinDeviceTypeService;
import com.jjt.common.utils.poi.ExcelUtil;
import com.jjt.common.core.page.TableDataInfo;

/**
 * 设备类型管理Controller
 *
 * @author wukai
 * @date 2025-05-21
 */
@Api(tags="设备类型管理")
@RestController
@RequestMapping("/rz/dtype")
public class TwinDeviceTypeController extends BaseController{
    @Resource
    private ITwinDeviceTypeService twinDeviceTypeService;

    /**
     * 查询设备类型管理列表
     */
    @ApiOperation("查询设备类型管理列表")
    @PreAuthorize("@ss.hasPermi('rz:dtype:list')")
    @GetMapping("/list")
    public TableDataInfo list(TwinDeviceType twinDeviceType)
    {
        startPage();
        List<TwinDeviceType> list = twinDeviceTypeService.selectTwinDeviceTypeList(twinDeviceType);
        return getDataTable(list);
    }

    /**
     * 导出设备类型管理列表
     */
    @ApiOperation("导出设备类型管理列表")
    @PreAuthorize("@ss.hasPermi('rz:dtype:export')")
    @Log(title = "设备类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TwinDeviceType twinDeviceType)
    {
        List<TwinDeviceType> list = twinDeviceTypeService.selectTwinDeviceTypeList(twinDeviceType);
        ExcelUtil<TwinDeviceType> util = new ExcelUtil<TwinDeviceType>(TwinDeviceType.class);
        util.exportExcel(response, list, "设备类型管理数据");
    }

    /**
     * 获取设备类型管理详细信息
     */
    @ApiOperation("获取设备类型管理详细信息")
    @PreAuthorize("@ss.hasPermi('rz:dtype:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return success(twinDeviceTypeService.selectTwinDeviceTypeByTypeId(typeId));
    }

    /**
     * 新增设备类型管理
     */
    @ApiOperation("新增设备类型管理")
    @PreAuthorize("@ss.hasPermi('rz:dtype:add')")
    @Log(title = "设备类型管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TwinDeviceType twinDeviceType)
    {
        return toAjax(twinDeviceTypeService.insertTwinDeviceType(twinDeviceType));
    }

    /**
     * 修改设备类型管理
     */
    @ApiOperation("修改设备类型管理")
    @PreAuthorize("@ss.hasPermi('rz:dtype:edit')")
    @Log(title = "设备类型管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TwinDeviceType twinDeviceType)
    {
        return toAjax(twinDeviceTypeService.updateTwinDeviceType(twinDeviceType));
    }

    /**
     * 删除设备类型管理
     */
    @ApiOperation("删除设备类型管理")
    @PreAuthorize("@ss.hasPermi('rz:dtype:remove')")
    @Log(title = "设备类型管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(twinDeviceTypeService.deleteTwinDeviceTypeByTypeIds(typeIds));
    }
}
