package com.ruoyi.system.controller;

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

import com.ruoyi.system.domain.dto.DeviceRunningDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusDeviceRunning;
import com.ruoyi.system.service.IBusDeviceRunningService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 运行状态Controller
 * 
 * @author zsl
 * @date 2022-06-17
 */
@Api("运行管理")
@RestController
@RequestMapping("/system/running")
public class BusDeviceRunningController extends BaseController
{
    @Autowired
    private IBusDeviceRunningService busDeviceRunningService;

    /**
     * 查询运行状态列表
     */
   // @PreAuthorize("@ss.hasPermi('system:running:list')")
    @GetMapping("/list")
    @ApiOperation("查询设备运行状态")
    public TableDataInfo list(BusDeviceRunning busDeviceRunning)
    {
        startPage();
        System.out.println(busDeviceRunning.getId());
        List<BusDeviceRunning> list = busDeviceRunningService.selectBusDeviceRunningList(busDeviceRunning);
        return getDataTable(list);
    }

    /**
     * 导出运行状态列表
     */
 //   @PreAuthorize("@ss.hasPermi('system:running:export')")
    @Log(title = "运行状态", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出运行状态列表")
    public void export(HttpServletResponse response, BusDeviceRunning busDeviceRunning)
    {
        List<BusDeviceRunning> list = busDeviceRunningService.selectBusDeviceRunningList(busDeviceRunning);
        ExcelUtil<BusDeviceRunning> util = new ExcelUtil<BusDeviceRunning>(BusDeviceRunning.class);
        util.exportExcel(response, list, "运行状态数据");
    }

    /**
     * 获取运行状态详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:running:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取运行状态详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(busDeviceRunningService.selectBusDeviceRunningById(id));
    }

    /**
     * 新增运行状态
     */
 //   @PreAuthorize("@ss.hasPermi('system:running:add')")
    @Log(title = "运行状态")
    @PostMapping("/add")
    @ApiOperation("新增运行状态")
    public AjaxResult add(@RequestBody DeviceRunningDto deviceRunningDto)
    {

        System.out.println(deviceRunningDto);
        return toAjax(1==1);
    }
    /**
     * 修改运行状态
     */
   // @PreAuthorize("@ss.hasPermi('system:running:edit')")
    @Log(title = "运行状态", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改运行状态")
    public AjaxResult edit(@RequestBody BusDeviceRunning busDeviceRunning)
    {
        return toAjax(busDeviceRunningService.updateBusDeviceRunning(busDeviceRunning));
    }

    /**
     * 删除运行状态
     */
 //   @PreAuthorize("@ss.hasPermi('system:running:remove')")
    @Log(title = "运行状态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    @ApiOperation("删除运行状态")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(busDeviceRunningService.deleteBusDeviceRunningByIds(ids));
    }
}
