package com.ruoyi.web.controller.manage;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manage.domain.DialIndicatorLog;
import com.ruoyi.manage.service.IDialIndicatorLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

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

/**
 * 计报警记录Controller
 *
 * @author boman
 * @date 2025-06-17
 */
@RestController
@RequestMapping("/manage/dialIndicator")
public class DialIndicatorLogController extends BaseController {
    @Autowired
    private IDialIndicatorLogService dialIndicatorLogService;

    /**
     * 查询计报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:dialIndicator:list')")
    @GetMapping("/list")
    public TableDataInfo list(DialIndicatorLog dialIndicatorLog) {
        startPage();
        List<DialIndicatorLog> list = dialIndicatorLogService.selectDialIndicatorLogList(dialIndicatorLog);
        return getDataTable(list);
    }

    /**
     * 导出计报警记录列表
     */
    @PreAuthorize("@ss.hasPermi('manage:dialIndicator:export')")
    @Log(title = "计报警记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DialIndicatorLog dialIndicatorLog) {
        List<DialIndicatorLog> list = dialIndicatorLogService.selectDialIndicatorLogList(dialIndicatorLog);
        ExcelUtil<DialIndicatorLog> util = new ExcelUtil<DialIndicatorLog>(DialIndicatorLog.class);
        util.exportExcel(response, list, "计报警记录数据");
    }

    /**
     * 获取计报警记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:dialIndicator:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId) {
        return success(dialIndicatorLogService.selectDialIndicatorLogByLogId(logId));
    }

    /**
     * 新增计报警记录
     */
    @PreAuthorize("@ss.hasPermi('manage:dialIndicator:add')")
    @Log(title = "计报警记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DialIndicatorLog dialIndicatorLog) {
        return toAjax(dialIndicatorLogService.insertDialIndicatorLog(dialIndicatorLog));
    }

    /**
     * 修改计报警记录
     */
    @PreAuthorize("@ss.hasPermi('manage:dialIndicator:edit')")
    @Log(title = "计报警记录", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody DialIndicatorLog dialIndicatorLog) {
        return toAjax(dialIndicatorLogService.updateDialIndicatorLog(dialIndicatorLog));
    }

    /**
     * 删除计报警记录
     */
    @PreAuthorize("@ss.hasPermi('manage:dialIndicator:remove')")
    @Log(title = "计报警记录", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds) {
        return toAjax(dialIndicatorLogService.deleteDialIndicatorLogByLogIds(logIds));
    }
}
