package com.dcs.hnyz.controller;

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

import com.dcs.hnyz.domain.vo.EquipmentExtensionFormVO;
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.*;
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.EquipmentExtension;
import com.dcs.hnyz.service.IEquipmentExtensionService;
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/extension")
public class EquipmentExtensionController extends BaseController
{
    @Autowired
    private IEquipmentExtensionService equipmentExtensionService;

    /**
     * 查询设备拓展管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:extension:list')")
    @GetMapping("/list")
    @ApiOperation("查询设备拓展管理列表")
    public TableDataInfo list(@ApiParam("设备拓展对象") EquipmentExtension equipmentExtension)
    {
        startPage();
        List<EquipmentExtension> list = equipmentExtensionService.selectEquipmentExtensionList(equipmentExtension);
        return getDataTable(list);
    }

    /**
     * 导出设备拓展管理列表
     */
    @PreAuthorize("@ss.hasPermi('hnyz:extension:export')")
    @Log(title = "设备拓展管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentExtension equipmentExtension)
    {
        List<EquipmentExtension> list = equipmentExtensionService.selectEquipmentExtensionList(equipmentExtension);
        ExcelUtil<EquipmentExtension> util = new ExcelUtil<EquipmentExtension>(EquipmentExtension.class);
        util.exportExcel(response, list, "设备拓展管理数据");
    }

    /**
     * 获取设备拓展管理详细信息
     */
    @ApiOperation("获取设备拓展管理详细信息")
    @PreAuthorize("@ss.hasPermi('hnyz:extension:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam("设备拓展") @PathVariable("id") Long id)
    {
        return success(equipmentExtensionService.selectEquipmentExtensionById(id));
    }

    /**
     * 新增设备拓展管理
     */
    @ApiOperation("新增设备拓展管理")
    @PreAuthorize("@ss.hasPermi('hnyz:extension:add')")
    @Log(title = "设备拓展管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentExtension equipmentExtension)
    {
        return toAjax(equipmentExtensionService.insertEquipmentExtension(equipmentExtension));
    }

    /**
     * 修改设备拓展管理
     */
    @ApiOperation("修改设备拓展管理")
    @PreAuthorize("@ss.hasPermi('hnyz:extension:edit')")
    @Log(title = "设备拓展管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentExtension equipmentExtension)
    {
        return toAjax(equipmentExtensionService.updateEquipmentExtension(equipmentExtension));
    }

    /**
     * 删除设备拓展管理
     */
    @ApiOperation("删除设备拓展管理")
    @PreAuthorize("@ss.hasPermi('hnyz:extension:remove')")
    @Log(title = "设备拓展管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam("设备拓展id数组") @PathVariable Long[] ids)
    {
        return toAjax(equipmentExtensionService.deleteEquipmentExtensionByIds(ids));
    }

    /**
     * 查询设备拓展表单列表
     */
    @ApiOperation("查询设备拓展表单列表")
    @GetMapping("/getEquipmentExtensionFormList")
    public TableDataInfo getEquipmentExtensionFormList(@ApiParam("设备拓展表单参数") EquipmentExtensionFormVO equipmentExtensionFormVo)
    {
        startPage();
        List<EquipmentExtensionFormVO> list = equipmentExtensionService.getEquipmentExtensionFormList(equipmentExtensionFormVo);
        return getDataTable(list);
    }

    /**
     * 修改启用状态
     */
    @PreAuthorize("@ss.hasPermi('hnyz:extension:edit')")
    @Log(title = "设备拓展管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody EquipmentExtension equipmentExtension){
        return toAjax(equipmentExtensionService.changeStatus(equipmentExtension));
    }

    /**
     * 获取设备拓展布局相关参数
     * @param flowId
     * @return
     */
    @ApiOperation("获取设备拓展布局相关参数")
    @GetMapping("/layout")
    public AjaxResult getLayout(@ApiParam("流程id") @RequestParam Integer flowId) {
        return success(equipmentExtensionService.getLayout(flowId));
    }
}
