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

/**
 * 页面管理Controller
 * 
 * @author hmy
 * @date 2025-07-25
 */
@Api
@RestController
@RequestMapping("/hnyz/pageControl")
public class PageController extends BaseController
{
    @Autowired
    private IPageControlService pageControlService;

    /**
     * 查询页面管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:pageControl:list')")
    @GetMapping("/list")
    public TableDataInfo list(PageControl pageControl)
    {
        startPage();
        List<PageControl> list = pageControlService.selectPageControlList(pageControl);
        return getDataTable(list);
    }

    /**
     * 导出页面管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:pageControl:export')")
    @Log(title = "页面管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageControl pageControl)
    {
        List<PageControl> list = pageControlService.selectPageControlList(pageControl);
        ExcelUtil<PageControl> util = new ExcelUtil<PageControl>(PageControl.class);
        util.exportExcel(response, list, "页面管理数据");
    }

    /**
     * 获取页面管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('hnyz:pageControl:query')")
    @GetMapping(value = "/{pageId}")
    public AjaxResult getInfo(@PathVariable("pageId") Long pageId)
    {
        return success(pageControlService.selectPageControlByPageId(pageId));
    }

    /**
     * 新增页面管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:pageControl:add')")
    @Log(title = "页面管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageControl pageControl)
    {
        return toAjax(pageControlService.insertPageControl(pageControl));
    }

    /**
     * 修改页面管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:pageControl:edit')")
    @Log(title = "页面管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageControl pageControl)
    {
        return toAjax(pageControlService.updatePageControl(pageControl));
    }

    /**
     * 删除页面管理
     */
    @PreAuthorize("@ss.hasPermi('hnyz:pageControl:remove')")
    @Log(title = "页面管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pageIds}")
    public AjaxResult remove(@PathVariable Long[] pageIds)
    {
        return toAjax(pageControlService.deletePageControlByPageIds(pageIds));
    }

    /**
     * 获取页面下拉框列表
     */
    @GetMapping("/getPageList")
    @ApiOperation(value = "获取设备对应页面列表（用于下拉框）")
    public AjaxResult getPageList(@ApiParam(name = "equipmentId" ,value="设备id") Long equipmentId){
        return success(pageControlService.getPageList(equipmentId));
    }
}
