package com.goomood.phm.controller;

import java.util.List;
import java.util.Map;
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.goomood.common.annotation.Log;
import com.goomood.common.core.controller.BaseController;
import com.goomood.common.core.domain.AjaxResult;
import com.goomood.common.enums.BusinessType;
import com.goomood.phm.domain.FaultMonitor;
import com.goomood.phm.service.IFaultMonitorService;
import com.goomood.common.utils.poi.ExcelUtil;
import com.goomood.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 故障监控Controller
 * 
 * @author goomood
 * @date 2024-11-17
 */
@RestController
@RequestMapping("/fault/faultMonitor")
public class FaultMonitorController extends BaseController
{
    @Autowired
    private IFaultMonitorService faultMonitorService;

    /**
     * 查询故障监控列表
     */
    @PreAuthorize("@ss.hasPermi('fault:faultMonitor:list')")
    @GetMapping("/list")
    public TableDataInfo list(FaultMonitor faultMonitor)
    {
        startPage();
        List<FaultMonitor> list = faultMonitorService.selectFaultMonitorList(faultMonitor);
        return getDataTable(list);
    }

    /**
     * 导出故障监控列表
     */
    @PreAuthorize("@ss.hasPermi('fault:faultMonitor:export')")
    @Log(title = "故障监控", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FaultMonitor faultMonitor)
    {
        List<FaultMonitor> list = faultMonitorService.selectFaultMonitorList(faultMonitor);
        ExcelUtil<FaultMonitor> util = new ExcelUtil<FaultMonitor>(FaultMonitor.class);
        util.exportExcel(response, list, "故障监控数据");
    }

    /**
     * 获取故障监控详细信息
     */
    @PreAuthorize("@ss.hasPermi('fault:faultMonitor:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(faultMonitorService.selectFaultMonitorById(id));
    }

    /**
     * 新增故障监控
     */
    @PreAuthorize("@ss.hasPermi('fault:faultMonitor:add')")
    @Log(title = "故障监控", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FaultMonitor faultMonitor)
    {
        return toAjax(faultMonitorService.insertFaultMonitor(faultMonitor));
    }

    /**
     * 修改故障监控
     */
    @PreAuthorize("@ss.hasPermi('fault:faultMonitor:edit')")
    @Log(title = "故障监控", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FaultMonitor faultMonitor)
    {
        return toAjax(faultMonitorService.updateFaultMonitor(faultMonitor));
    }

    /**
     * 删除故障监控
     */
    @PreAuthorize("@ss.hasPermi('fault:faultMonitor:remove')")
    @Log(title = "故障监控", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(faultMonitorService.deleteFaultMonitorByIds(ids));
    }


    /**
     * 获取近三个月未处理故障条数
     * @return
     */
    @GetMapping("/unprocessedCount")
    public AjaxResult getUnprocessedFaultCount() {
        return success(faultMonitorService.getUnprocessedFaultCount());
    }


    /**
     * 导入数据
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<FaultMonitor> util = new ExcelUtil<>(FaultMonitor.class);
        List<FaultMonitor> faultMonitors = util.importExcel(file.getInputStream());
        String message = faultMonitorService.importFaultMonitor(faultMonitors);
        return AjaxResult.success(message);
    }


}
