package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.abnormal.domain.AbnormalQuery;
import com.ruoyi.ss.abnormal.domain.AbnormalVO;
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.PathVariable;
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.ss.abnormal.service.AbnormalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备故障Controller
 *
 * @author ruoyi
 * @date 2024-04-30
 */
@RestController
@RequestMapping("/ss/abnormal")
public class AbnormalController extends BaseController
{
    @Autowired
    private AbnormalService abnormalService;

    /**
     * 查询设备故障列表
     */
    @PreAuthorize("@ss.hasPermi('ss:abnormal:list')")
    @GetMapping("/list")
    public TableDataInfo list(AbnormalQuery abnormal)
    {
        startPage();
        List<AbnormalVO> list = abnormalService.selectAbnormalList(abnormal);
        return getDataTable(list);
    }

    /**
     * 导出设备故障列表
     */
    @PreAuthorize("@ss.hasPermi('ss:abnormal:export')")
    @Log(title = "设备故障", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AbnormalQuery abnormal)
    {
        List<AbnormalVO> list = abnormalService.selectAbnormalList(abnormal);
        ExcelUtil<AbnormalVO> util = new ExcelUtil<AbnormalVO>(AbnormalVO.class);
        util.exportExcel(response, list, "设备故障数据");
    }

    /**
     * 获取设备故障详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:abnormal:query')")
    @GetMapping(value = "/{abnormalId}")
    public AjaxResult getInfo(@PathVariable("abnormalId") Long abnormalId)
    {
        return success(abnormalService.selectAbnormalByAbnormalId(abnormalId));
    }

    @ApiOperation("查询故障数量")
    @GetMapping("/count")
    public AjaxResult getCount(AbnormalQuery query) {
        return success(abnormalService.selectCount(query));
    }

}
