package com.dcs.hnyz.controller;

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

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.CommunicationProtocol;
import com.dcs.hnyz.service.ICommunicationProtocolService;
import com.dcs.common.utils.poi.ExcelUtil;
import com.dcs.common.core.page.TableDataInfo;

/**
 * 通讯协议管理Controller
 * 
 * @author hmy
 * @date 2025-04-27
 */
@Api(tags = "通讯协议管理")
@RestController
@RequestMapping("/hnyz/commProtocol")
public class CommunicationProtocolController extends BaseController
{
    @Autowired
    private ICommunicationProtocolService communicationProtocolService;

    /**
     * 查询通讯协议管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:list')")
    @GetMapping("/list")
    @ApiOperation("通讯协议管理列表")
    public TableDataInfo list(@ApiParam("通讯协议对象") CommunicationProtocol communicationProtocol)
    {
        startPage();
        List<CommunicationProtocol> list = communicationProtocolService.selectCommunicationProtocolList(communicationProtocol);
        return getDataTable(list);
    }

    /**
     * 导出通讯协议管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:export')")
    @Log(title = "通讯协议管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunicationProtocol communicationProtocol)
    {
        List<CommunicationProtocol> list = communicationProtocolService.selectCommunicationProtocolList(communicationProtocol);
        ExcelUtil<CommunicationProtocol> util = new ExcelUtil<CommunicationProtocol>(CommunicationProtocol.class);
        util.exportExcel(response, list, "通讯协议管理数据");
    }

    /**
     * 获取通讯协议管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:query')")
    @GetMapping(value = "/{protocolId}")
    @ApiOperation("获取通讯协议管理详细信息")
    public AjaxResult getInfo(@ApiParam("通讯协议id") @PathVariable("protocolId") Long protocolId)
    {
        return success(communicationProtocolService.selectCommunicationProtocolByProtocolId(protocolId));
    }

    /**
     * 新增通讯协议管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:add')")
    @Log(title = "通讯协议管理", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增通讯协议管理")
    public AjaxResult add(@ApiParam("通讯协议对象") @RequestBody CommunicationProtocol communicationProtocol)
    {
        return toAjax(communicationProtocolService.insertCommunicationProtocol(communicationProtocol));
    }

    /**
     * 修改通讯协议管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:edit')")
    @Log(title = "通讯协议管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改通讯协议管理")
    public AjaxResult edit(@ApiParam("通讯协议对象") @RequestBody CommunicationProtocol communicationProtocol)
    {
        return toAjax(communicationProtocolService.updateCommunicationProtocol(communicationProtocol));
    }

    /**
     * 删除通讯协议管理
     */
    @ApiOperation(value = "删除通讯协议管理")
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:remove')")
    @Log(title = "通讯协议管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{protocolIds}")
    public AjaxResult remove(@ApiParam("通讯协议id数组") @PathVariable Long[] protocolIds)
    {
        return toAjax(communicationProtocolService.deleteCommunicationProtocolByProtocolIds(protocolIds));
    }

    /**
     * 获取通讯协议列表
     */
    @ApiOperation("获取所有通讯协议的列表")
    @GetMapping("/getCommProtocolList")
    public AjaxResult getCommProtocolList(){
        return success(communicationProtocolService.getCommProtocolList());
    }

    /**
     * 修改通讯协议启用状态
     */
    @PreAuthorize("@ss.hasPermi('hnyz:commProtocol:edit')")
    @Log(title = "通讯协议管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeProtocolStatus(@RequestBody CommunicationProtocol cp)
    {
        return toAjax(communicationProtocolService.changeProtocolStatus(cp));
    }
}
