package com.inspur.web.controller.work;

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

import com.inspur.domain.ElevatorPbxInfo;
import com.inspur.service.IElevatorPbxInfoService;
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.inspur.common.annotation.Log;
import com.inspur.common.core.controller.BaseController;
import com.inspur.common.core.domain.AjaxResult;
import com.inspur.common.enums.BusinessType;
import com.inspur.common.utils.poi.ExcelUtil;
import com.inspur.common.core.page.TableDataInfo;

/**
 * PBXController
 *
 * @author inspur
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/pbx/info")
public class ElevatorPbxInfoController extends BaseController
{
    @Autowired
    private IElevatorPbxInfoService elevatorPbxInfoService;

    /**
     * 查询PBX列表
     */
    @PreAuthorize("@ss.hasPermi('pbx:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(ElevatorPbxInfo elevatorPbxInfo)
    {
        startPage();
        List<ElevatorPbxInfo> list = elevatorPbxInfoService.selectElevatorPbxInfoList(elevatorPbxInfo);
        return getDataTable(list);
    }

    /**
     * 导出PBX列表
     */
    @PreAuthorize("@ss.hasPermi('pbx:info:export')")
    @Log(title = "PBX", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ElevatorPbxInfo elevatorPbxInfo)
    {
        List<ElevatorPbxInfo> list = elevatorPbxInfoService.selectElevatorPbxInfoList(elevatorPbxInfo);
        ExcelUtil<ElevatorPbxInfo> util = new ExcelUtil<ElevatorPbxInfo>(ElevatorPbxInfo.class);
        util.exportExcel(response, list, "PBX数据");
    }

    /**
     * 获取PBX详细信息
     */
    @PreAuthorize("@ss.hasPermi('pbx:info:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(elevatorPbxInfoService.selectElevatorPbxInfoById(id));
    }

    /**
     * 新增PBX
     */
    @PreAuthorize("@ss.hasPermi('pbx:info:add')")
    @Log(title = "PBX", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ElevatorPbxInfo elevatorPbxInfo)
    {
        return toAjax(elevatorPbxInfoService.insertElevatorPbxInfo(elevatorPbxInfo));
    }

    /**
     * 修改PBX
     */
    @PreAuthorize("@ss.hasPermi('pbx:info:edit')")
    @Log(title = "PBX", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ElevatorPbxInfo elevatorPbxInfo)
    {
        return toAjax(elevatorPbxInfoService.updateElevatorPbxInfo(elevatorPbxInfo));
    }

    /**
     * 删除PBX
     */
    @PreAuthorize("@ss.hasPermi('pbx:info:remove')")
    @Log(title = "PBX", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(elevatorPbxInfoService.deleteElevatorPbxInfoByIds(ids));
    }
}
