package com.cmvr.web.controller.device;

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

import com.cmvr.edge.client.service.EdgeSystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
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.cmvr.common.annotation.Log;
import com.cmvr.common.core.controller.BaseController;
import com.cmvr.common.core.domain.AjaxResult;
import com.cmvr.common.enums.BusinessType;
import com.cmvr.device.domain.DeDeviceRegistration;
import com.cmvr.device.service.IDeDeviceRegistrationService;
import com.cmvr.common.utils.poi.ExcelUtil;
import com.cmvr.common.core.page.TableDataInfo;

/**
 * 设备注册Controller
 * 
 * @author cmvr-iot
 * @date 2025-05-08
 */
@RestController
@RequestMapping("/device/register")
@RequiredArgsConstructor
@Api(tags = "设备--注册")
public class DeDeviceRegistrationController extends BaseController
{
    @Autowired
    private IDeDeviceRegistrationService deDeviceRegistrationService;

    private final EdgeSystemService systemService;

    /**
     * 查询设备注册列表
     */
    @ApiOperation("查询设备注册列表")
    @PreAuthorize("@ss.hasPermi('device:register:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeDeviceRegistration deDeviceRegistration)
    {
        startPage();
        List<DeDeviceRegistration> list = deDeviceRegistrationService.selectDeDeviceRegistrationList(deDeviceRegistration);
        return getDataTable(list);
    }

    /**
     * 导出设备注册列表
     */
    @ApiOperation("导出设备注册列表")
    @PreAuthorize("@ss.hasPermi('device:register:export')")
    @Log(title = "设备注册", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeDeviceRegistration deDeviceRegistration)
    {
        List<DeDeviceRegistration> list = deDeviceRegistrationService.selectDeDeviceRegistrationList(deDeviceRegistration);
        ExcelUtil<DeDeviceRegistration> util = new ExcelUtil<DeDeviceRegistration>(DeDeviceRegistration.class);
        util.exportExcel(response, list, "设备注册数据");
    }

    /**
     * 获取设备注册详细信息
     */
    @ApiOperation("获取设备注册详细信息")
    @PreAuthorize("@ss.hasPermi('device:register:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(deDeviceRegistrationService.selectDeDeviceRegistrationById(id));
    }

    /**
     * 新增设备注册
     */
    @ApiOperation("新增设备注册")
    @PreAuthorize("@ss.hasPermi('device:register:add')")
    @Log(title = "设备注册", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeDeviceRegistration deDeviceRegistration)
    {
        return toAjax(deDeviceRegistrationService.insertDeDeviceRegistration(deDeviceRegistration));
    }

    /**
     * 修改设备注册
     */
    @ApiOperation("修改设备注册")
    @PreAuthorize("@ss.hasPermi('device:register:edit')")
    @Log(title = "设备注册", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeDeviceRegistration deDeviceRegistration)
    {
        return toAjax(deDeviceRegistrationService.updateDeDeviceRegistration(deDeviceRegistration));
    }




    /**
     * 删除设备注册
     */
    @ApiOperation("删除设备注册")
    @PreAuthorize("@ss.hasPermi('device:register:remove')")
    @Log(title = "设备注册", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(deDeviceRegistrationService.deleteDeDeviceRegistrationByIds(ids));
    }
}
