package com.dcs.hnyz.controller;

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

import com.dcs.hnyz.domain.vo.EquipmentParamFormVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.dcs.common.annotation.Log;
import com.dcs.common.core.controller.BaseController;
import com.dcs.common.core.domain.AjaxResult;
import com.dcs.common.enums.BusinessType;
import com.dcs.hnyz.domain.EquipmentParam;
import com.dcs.hnyz.service.IEquipmentParamService;
import com.dcs.common.utils.poi.ExcelUtil;
import com.dcs.common.core.page.TableDataInfo;

/**
 * 设备参数管理Controller
 * 
 * @author hmy
 * @date 2025-04-23
 */
@Api(tags = "寄存器管理")
@RestController
@RequestMapping("/hnyz/param")
public class EquipmentParamController extends BaseController
{
    @Autowired
    private IEquipmentParamService equipmentParamService;

    /**
     * 查询设备参数管理列表
     */
    @ApiOperation("查询寄存器列表")
    @PreAuthorize("@ss.hasPermi('hnyz:param:list')")
    @GetMapping("/list")
    public TableDataInfo list(@ApiParam("寄存器对象") EquipmentParam equipmentParam)
    {
        startPage();
        List<EquipmentParamFormVO> list = equipmentParamService.selectEquipmentParamForm(equipmentParam);
        return getDataTable(list);
    }

    /**
     * 导出设备参数管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:param:export')")
    @Log(title = "设备参数管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentParam equipmentParam)
    {
        List<EquipmentParam> list = equipmentParamService.selectEquipmentParamList(equipmentParam);
        ExcelUtil<EquipmentParam> util = new ExcelUtil<EquipmentParam>(EquipmentParam.class);
        util.exportExcel(response, list, "设备参数管理数据");
    }

    /**
     * 获取设备参数管理详细信息
     */
    @ApiOperation("获取寄存器详细信息")
    @PreAuthorize("@ss.hasPermi('hnyz:param:query')")
    @GetMapping(value = "/{registerId}")
    public AjaxResult getInfo(@ApiParam("寄存器id") @PathVariable("registerId") Long registerId)
    {
        return success(equipmentParamService.selectEquipmentParamByRegisterId(registerId));
    }

    /**
     * 新增设备参数管理
     */
    @ApiOperation("新增寄存器")
    @PreAuthorize("@ss.hasPermi('hnyz:param:add')")
    @Log(title = "设备参数管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentParam equipmentParam)
    {
        return toAjax(equipmentParamService.insertEquipmentParam(equipmentParam));
    }

    /**
     * 修改设备参数管理
     */
    @ApiOperation("修改寄存器")
    @PreAuthorize("@ss.hasPermi('hnyz:param:edit')")
    @Log(title = "设备参数管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentParam equipmentParam)
    {
        return toAjax(equipmentParamService.updateEquipmentParam(equipmentParam));
    }

    /**
     * 删除设备参数管理
     */
    @ApiOperation("删除寄存器")
    @PreAuthorize("@ss.hasPermi('hnyz:param:remove')")
    @Log(title = "设备参数管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{registerIds}")
    public AjaxResult remove(@ApiParam("寄存器id数组") @PathVariable Long[] registerIds)
    {
        return toAjax(equipmentParamService.deleteEquipmentParamByRegisterIds(registerIds));
    }

    /**
     * 修改启用状态
     */
    @PreAuthorize("@ss.hasPermi('hnyz:param:edit')")
    @Log(title = "设备参数管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult editStatus(@RequestBody EquipmentParam equipmentParam){
        return toAjax(equipmentParamService.updateEquipmentParam(equipmentParam));
    }

    /**
     * 获取寄存器id对应索引值列表，用于初始化
     */
    @GetMapping("/getIndexList")
    @ApiOperation(value = "获取设备id对应索引值列表，用于初始化")
    public AjaxResult getEquipmentIndex() {
        return success(equipmentParamService.getEquipmentIndexList());
    }

}
