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

/**
 * PLC信息管理Controller
 * 
 * @author hmy
 * @date 2025-04-27
 */
@Api(tags = "PLC信息管理")
@RestController
@RequestMapping("/hnyz/plcInfo")
public class PlcInfoController extends BaseController
{
    @Autowired
    private IPlcInfoService plcInfoService;

    /**
     * 查询PLC信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:plcInfo:list')")
    @GetMapping("/list")
    @ApiOperation("查询PLC信息管理列表")
    public TableDataInfo list(@ApiParam("PLC信息参数") PlcInfo plcInfo)
    {
        startPage();
        List<PlcInfo> list = plcInfoService.selectPlcInfoList(plcInfo);
        return getDataTable(list);
    }

    /**
     * 导出PLC信息管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:plcInfo:export')")
    @Log(title = "PLC信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PlcInfo plcInfo)
    {
        List<PlcInfo> list = plcInfoService.selectPlcInfoList(plcInfo);
        ExcelUtil<PlcInfo> util = new ExcelUtil<PlcInfo>(PlcInfo.class);
        util.exportExcel(response, list, "PLC信息管理数据");
    }

    /**
     * 获取PLC信息管理详细信息
     */
    @ApiOperation("获取PLC信息管理详细信息")
    @PreAuthorize("@ss.hasPermi('hnyz:plcInfo:query')")
    @GetMapping(value = "/{plcId}")
    public AjaxResult getInfo(@PathVariable("plcId") Long plcId)
    {
        return success(plcInfoService.selectPlcInfoByPlcId(plcId));
    }

    /**
     * 新增PLC信息管理
     */
    @ApiOperation("新增PLC信息管理")
    @PreAuthorize("@ss.hasPermi('hnyz:plcInfo:add')")
    @Log(title = "PLC信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PlcInfo plcInfo)
    {
        return toAjax(plcInfoService.insertPlcInfo(plcInfo));
    }

    /**
     * 修改PLC信息管理
     */
    @ApiOperation("修改PLC信息管理")
    @PreAuthorize("@ss.hasPermi('hnyz:plcInfo:edit')")
    @Log(title = "PLC信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PlcInfo plcInfo)
    {
        return toAjax(plcInfoService.updatePlcInfo(plcInfo));
    }

    /**
     * 删除PLC信息管理
     */
    @ApiOperation("删除PLC信息管理")
    @PreAuthorize("@ss.hasPermi('hnyz:plcInfo:remove')")
    @Log(title = "PLC信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{plcIds}")
    public AjaxResult remove(@PathVariable Long[] plcIds)
    {
        return toAjax(plcInfoService.deletePlcInfoByPlcIds(plcIds));
    }

    /**
     * 获取plc select选择框列表
     */
    @ApiOperation("获取plc select选择框列表")
    @GetMapping("/getPlcList")
    public AjaxResult select(){
        return success(plcInfoService.getPlcList());
    }

    /**
     * 修改plc启用状态
     */
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody PlcInfo plcInfo)
    {
        return toAjax(plcInfoService.changePlcStatus(plcInfo));
    }
}
