package com.pm.web.controller.subsystem;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.pm.common.annotation.Log;
import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.enums.BusinessType;
import com.pm.common.config.PageData;
import com.pm.subsystem.service.IElevatorService;
import com.pm.common.core.page.TableDataInfo;

/**
 * 电梯系统Controller
 * 
 * @author pm
 * @date 2025-01-01
 */
@RestController
@RequestMapping("/subsystem/elevator")
public class ElevatorController extends BaseController
{
    @Autowired
    private IElevatorService elevatorService;

    /**
     * 查询电梯设备列表
     */
    @PreAuthorize("@ss.hasPermi('subsystem:elevator:list')")
    @GetMapping("/device/list")
    public TableDataInfo deviceList()
    {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = elevatorService.selectElevatorDeviceList(pd);
        return getDataTable(list);
    }

    /**
     * 查询电梯运行记录列表
     */
    @PreAuthorize("@ss.hasPermi('subsystem:elevator:record')")
    @GetMapping("/record/list")
    public TableDataInfo recordList()
    {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = elevatorService.selectElevatorRecordList(pd);
        return getDataTable(list);
    }

    /**
     * 查询电梯报警列表
     */
    @PreAuthorize("@ss.hasPermi('subsystem:elevator:alarm')")
    @GetMapping("/alarm/list")
    public TableDataInfo alarmList()
    {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = elevatorService.selectElevatorAlarmList(pd);
        return getDataTable(list);
    }

    /**
     * 处理电梯报警
     */
    @PreAuthorize("@ss.hasPermi('subsystem:elevator:alarm')")
    @Log(title = "处理电梯报警", businessType = BusinessType.UPDATE)
    @PostMapping("/alarm/handle")
    public AjaxResult handleAlarm(@RequestBody PageData pd)
    {
        return toAjax(elevatorService.handleElevatorAlarm(pd));
    }

    /**
     * 获取电梯统计数据
     */
    @PreAuthorize("@ss.hasPermi('subsystem:elevator:statistics')")
    @GetMapping("/statistics")
    public AjaxResult statistics()
    {
        return success(elevatorService.getElevatorStatistics());
    }
}