package com.dcs.dcs.controller;

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.common.utils.poi.ExcelUtil;
import com.dcs.dcs.domain.DcsEquipment;
import com.dcs.dcs.domain.vo.DcsEquipmentFormVo;
import com.dcs.dcs.service.IDcsEquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 设备管理Controller
 * 
 * @author hmy
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/dcs/equipment")
@Api
public class DcsEquipmentController extends BaseController
{
    @Autowired
    private IDcsEquipmentService dcsEquipmentService;

    /**
     * 查询设备管理列表
     */
    @PreAuthorize("@ss.hasPermi('dcs:equipment:list')")
    @GetMapping("/list")
    @ApiOperation(value = "设备管理列表")
    public AjaxResult list(DcsEquipment dcsEquipment)
    {
        List<DcsEquipmentFormVo> list = dcsEquipmentService.selectDcsEquipmentVoList(dcsEquipment);
        return success(list);
    }

    /**
     * 导出设备管理列表
     */
    @ApiOperation(value = "设备管理列表导出")
    @PreAuthorize("@ss.hasPermi('dcs:equipment:export')")
    @Log(title = "设备管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcsEquipment dcsEquipment)
    {
        List<DcsEquipment> list = dcsEquipmentService.selectDcsEquipmentList(dcsEquipment);
        ExcelUtil<DcsEquipment> util = new ExcelUtil<DcsEquipment>(DcsEquipment.class);
        util.exportExcel(response, list, "设备管理数据");
    }

    /**
     * 获取设备管理详细信息
     */
    @ApiOperation(value = "设备管理详细信息")
    @PreAuthorize("@ss.hasPermi('dcs:equipment:query')")
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") Long equipmentId)
    {
        return success(dcsEquipmentService.selectDcsEquipmentByEquipmentId(equipmentId));
    }

    /**
     * 新增设备管理
     */
    @ApiOperation(value = "设备管理新增")
    @PreAuthorize("@ss.hasPermi('dcs:equipment:add')")
    @Log(title = "设备管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcsEquipment dcsEquipment)
    {
        return toAjax(dcsEquipmentService.insertDcsEquipment(dcsEquipment));
    }

    /**
     * 修改设备管理
     */
    @PreAuthorize("@ss.hasPermi('dcs:equipment:edit')")
    @Log(title = "设备管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "设备管理修改")
    public AjaxResult edit(@RequestBody DcsEquipment dcsEquipment)
    {
        return toAjax(dcsEquipmentService.updateDcsEquipment(dcsEquipment));
    }

    /**
     * 删除设备管理
     */
    @PreAuthorize("@ss.hasPermi('dcs:equipment:remove')")
    @Log(title = "设备管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    @ApiOperation(value = "设备管理删除")
    public AjaxResult remove(@PathVariable Long[] equipmentIds)
    {
        return toAjax(dcsEquipmentService.deleteDcsEquipmentByEquipmentIds(equipmentIds));
    }

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

    /**
     * 获取数据图表页面所需设备名list（树状）
     * @Param dataType 数据类型 bool,data,string
     */
    @PostMapping("/getEquipmentTreeByDataType")
    @ApiOperation(value = "获取数据图表页面所需设备名list（树状）")
    public AjaxResult getEquipmentNameList(String dataType) {
        return success(dcsEquipmentService.getEquipmentNameList(dataType));
    }

    /**
     * 获取实时图表页面温度，压力等传感器的树状list
     */
    @GetMapping("/getEquipmentSensorTree")
    @ApiOperation(value = "获取实时图表页面温度，压力等传感器的树状list")
    public AjaxResult getEquipmentTree() {
        return success(dcsEquipmentService.getEquipmentSensorTree());
    }

}
