package com.dkl.large.controller;

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

import com.dkl.common.annotation.DataScope;
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.dkl.common.annotation.Log;
import com.dkl.common.core.controller.BaseController;
import com.dkl.common.core.domain.AjaxResult;
import com.dkl.common.enums.BusinessType;
import com.dkl.large.domain.DklWarningRules;
import com.dkl.large.service.IDklWarningRulesService;
import com.dkl.common.utils.poi.ExcelUtil;
import com.dkl.common.core.page.TableDataInfo;

/**
 * 预警规则Controller
 *
 * @author Dkl
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/large/rules")
public class DklWarningRulesController extends BaseController
{
    @Autowired
    private IDklWarningRulesService dklWarningRulesService;

    /**
     * 查询预警规则列表
     */
//    @PreAuthorize("@ss.hasPermi('large:rules:list')")
    @GetMapping("/list")
    public TableDataInfo list(DklWarningRules dklWarningRules)
    {
        startPage();
        List<DklWarningRules> list = dklWarningRulesService.selectDklWarningRulesList(dklWarningRules);
        return getDataTable(list);
    }
//    @PreAuthorize("@ss.hasPermi('large:rules:list')")
    @GetMapping("/listAll")
//    @DataScope(deptAlias = "d")
    public TableDataInfo listAll(DklWarningRules dklWarningRules)
    {
        dklWarningRules.setDelFlag("0");
        List<DklWarningRules> list = dklWarningRulesService.selectDklWarningRulesList(dklWarningRules);
        return getDataTable(list);
    }


    /**
     * 导出预警规则列表
     */
    @Log(title = "预警规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DklWarningRules dklWarningRules)
    {
        List<DklWarningRules> list = dklWarningRulesService.selectDklWarningRulesList(dklWarningRules);
        ExcelUtil<DklWarningRules> util = new ExcelUtil<DklWarningRules>(DklWarningRules.class);
        util.exportExcel(response, list, "预警规则数据");
    }

    /**
     * 获取预警规则详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dklWarningRulesService.selectDklWarningRulesById(id));
    }

    /**
     * 新增预警规则
     */
    @Log(title = "预警规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DklWarningRules dklWarningRules)
    {
        //添加系统信息
        dklWarningRules.setDelFlag("0");
        dklWarningRules.setCreateTime(new Date());
        dklWarningRules.setCreateBy(getUsername());
        dklWarningRules.setUpdateTime(new Date());
        dklWarningRules.setUpdateBy(getUsername());
        return toAjax(dklWarningRulesService.insertDklWarningRules(dklWarningRules));
    }

    /**
     * 修改预警规则
     */
    @Log(title = "预警规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DklWarningRules dklWarningRules)
    {
        //添加系统信息
        dklWarningRules.setUpdateTime(new Date());
        dklWarningRules.setUpdateBy(getUsername());
        return toAjax(dklWarningRulesService.updateDklWarningRules(dklWarningRules));
    }

    /**
     * 删除预警规则
     */
    @Log(title = "预警规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable int[] ids)
    {
        return toAjax(dklWarningRulesService.deleteDklWarningRulesByIds(ids));
    }
}
