package com.cmvr.web.controller.device;

import com.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.core.page.TableDataInfo;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.device.domain.DeDeviceTerminalConfig;
import com.cmvr.device.service.IDeDeviceTerminalConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 设备终端配置Controller
 *
 * @author cmvr-iot
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/device/terminal")
@RequiredArgsConstructor
@Api(tags = "设备--终端配置")
public class DeDeviceTerminalConfigController extends BaseController {
    @Autowired
    private IDeDeviceTerminalConfigService deDeviceTerminalConfigService;

    /**
     * 查询设备终端配置列表
     */
    @ApiOperation("查询设备终端配置列表")
    @PreAuthorize("@ss.hasPermi('device:terminal:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeDeviceTerminalConfig deDeviceTerminalConfig) {
        startPage();
        List<DeDeviceTerminalConfig> list = deDeviceTerminalConfigService.selectDeDeviceTerminalConfigList(deDeviceTerminalConfig);
        return getDataTable(list);
    }

    /**
     * 导出设备终端配置列表
     */
    @ApiOperation("导出设备终端配置列表")
    @PreAuthorize("@ss.hasPermi('device:terminal:export')")
    @Log(title = "设备终端配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeDeviceTerminalConfig deDeviceTerminalConfig) {
        List<DeDeviceTerminalConfig> list = deDeviceTerminalConfigService.selectDeDeviceTerminalConfigList(deDeviceTerminalConfig);
        ExcelUtil<DeDeviceTerminalConfig> util = new ExcelUtil<DeDeviceTerminalConfig>(DeDeviceTerminalConfig.class);
        util.exportExcel(response, list, "设备终端配置数据");
    }

    /**
     * 获取设备终端配置详细信息
     */
    @ApiOperation("获取设备终端配置详细信息")
    @PreAuthorize("@ss.hasPermi('device:terminal:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(deDeviceTerminalConfigService.selectDeDeviceTerminalConfigById(id));
    }

    /**
     * 新增设备终端配置
     */
    @ApiOperation("新增设备终端配置")
    @PreAuthorize("@ss.hasPermi('device:terminal:add')")
    @Log(title = "设备终端配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeDeviceTerminalConfig deDeviceTerminalConfig) {
        return toAjax(deDeviceTerminalConfigService.insertDeDeviceTerminalConfig(deDeviceTerminalConfig));
    }

    /**
     * 修改设备终端配置
     */
    @ApiOperation("修改设备终端数据")
    @PreAuthorize("@ss.hasPermi('device:terminal:edit')")
    @Log(title = "设备终端配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeDeviceTerminalConfig deDeviceTerminalConfig) {
        return toAjax(deDeviceTerminalConfigService.updateDeDeviceTerminalConfig(deDeviceTerminalConfig));
    }

    /**
     * 删除设备终端配置
     */
    @ApiOperation("删除设备终端配置")
    @PreAuthorize("@ss.hasPermi('device:terminal:remove')")
    @Log(title = "设备终端配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(deDeviceTerminalConfigService.deleteDeDeviceTerminalConfigByIds(ids));
    }
}
