package com.zyc.web.controller.api;

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

/**
 * 机房Controller
 * 
 * @author zyc
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/system/ComputerRoomsController")
public class ComputerRoomsController extends BaseController
{
    @Autowired
    private IComputerRoomsService computerRoomsService;

    /**
     * 查询机房列表
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComputerRooms computerRooms)
    {
        startPage();
        List<ComputerRooms> list = computerRoomsService.selectComputerRoomsList(computerRooms);
        return getDataTable(list);
    }

    /**
     * 导出机房列表
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:export')")
    @Log(title = "机房", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ComputerRooms computerRooms)
    {
        List<ComputerRooms> list = computerRoomsService.selectComputerRoomsList(computerRooms);
        ExcelUtil<ComputerRooms> util = new ExcelUtil<ComputerRooms>(ComputerRooms.class);
        util.exportExcel(response, list, "机房数据");
    }

    /**
     * 获取机房详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(computerRoomsService.selectComputerRoomsById(id));
    }

    /**
     * 新增机房
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:add')")
    @Log(title = "机房", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComputerRooms computerRooms)
    {
        return toAjax(computerRoomsService.insertComputerRooms(computerRooms));
    }

    /**
     * 修改机房
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:edit')")
    @Log(title = "机房", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComputerRooms computerRooms)
    {
        return toAjax(computerRoomsService.updateComputerRooms(computerRooms));
    }

    /**
     * 删除机房
     */
    @PreAuthorize("@ss.hasPermi('system:rooms:remove')")
    @Log(title = "机房", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(computerRoomsService.deleteComputerRoomsByIds(ids));
    }
}
