package com.ruoyi.record.controller;

import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
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.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.record.domain.RecordBusbarAlarm;
import com.ruoyi.record.service.IRecordBusbarAlarmService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检报警记录Controller
 *
 * @author zangch
 * @date 2024-12-03
 */
@RestController
@RequestMapping("/record/recordBusbarAlarm")
public class RecordBusbarAlarmController extends BaseController
{
    @Autowired
    private IRecordBusbarAlarmService recordBusbarAlarmService;

    /**
     * 查询巡检报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarAlarm:list')")
    @GetMapping("/list")
    public TableDataInfo list(RecordBusbarAlarm recordBusbarAlarm)
    {
        startPage();
        List<RecordBusbarAlarm> list = recordBusbarAlarmService.selectRecordBusbarAlarmList(recordBusbarAlarm);
        return getDataTable(list);
    }

    /**
     * 导出巡检报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarAlarm:export')")
    @Log(title = "巡检报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RecordBusbarAlarm recordBusbarAlarm)
    {
        List<RecordBusbarAlarm> list = recordBusbarAlarmService.selectRecordBusbarAlarmList(recordBusbarAlarm);
        ExcelUtil<RecordBusbarAlarm> util = new ExcelUtil<RecordBusbarAlarm>(RecordBusbarAlarm.class);
        util.exportExcel(response, list, "巡检报警记录数据");
    }

    /**
     * 获取巡检报警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarAlarm:query')")
    @GetMapping(value = "/{objId}")
    public AjaxResult getInfo(@PathVariable("objId") Long objId)
    {
        return success(recordBusbarAlarmService.selectRecordBusbarAlarmByObjId(objId));
    }

    /**
     * 新增巡检报警记录
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarAlarm:add')")
    @Log(title = "巡检报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RecordBusbarAlarm recordBusbarAlarm)
    {
        return toAjax(recordBusbarAlarmService.insertRecordBusbarAlarm(recordBusbarAlarm));
    }

    /**
     * 修改巡检报警记录
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarAlarm:edit')")
    @Log(title = "巡检报警记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RecordBusbarAlarm recordBusbarAlarm)
    {
        return toAjax(recordBusbarAlarmService.updateRecordBusbarAlarm(recordBusbarAlarm));
    }

    /**
     * 删除巡检报警记录
     */
    @PreAuthorize("@ss.hasPermi('record:recordBusbarAlarm:remove')")
    @Log(title = "巡检报警记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{objIds}")
    public AjaxResult remove(@PathVariable Long[] objIds)
    {
        return toAjax(recordBusbarAlarmService.deleteRecordBusbarAlarmByObjIds(objIds));
    }


    /**
     * 获取巡检报警记录列表。
     * @param recordBusbarAlarm 需要查询的故巡检报警记录信息。
     * @return 返回包含所有符合条件的巡检报警记录的列表，如果没有找到任何记录，则返回空列表。
     */
    @PostMapping("/recordBusbarAlarmList")
    public AjaxResult recordBusbarAlarmList(RecordBusbarAlarm recordBusbarAlarm)
    {
        List<RecordBusbarAlarm> list = recordBusbarAlarmService.selectRecordBusbarAlarmList(recordBusbarAlarm);
        // 反转列表顺序
         Collections.reverse(list);
        return success(list);
    }


   //记录母排测温近七天每天一天的巡检记录次数。
    @PostMapping("/recordBusbarAlarmCount")
    public AjaxResult recordBusbarAlarmCount(RecordBusbarAlarm recordBusbarAlarm) {
        return AjaxResult.success(recordBusbarAlarmService.recordBusbarAlarmCount(recordBusbarAlarm));
        }
}
