package com.muyu.warn.controller; import java.util.Arrays; import java.util.List; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import jakarta.servlet.http.HttpServletResponse; import javax.annotation.Resource; import org.springframework.web.bind.annotation.*; import com.muyu.common.security.annotation.RequiresPermissions; import com.muyu.warn.domain.WarnRule; import com.muyu.warn.service.IWarnRuleService; import com.muyu.common.core.web.controller.BaseController; import com.muyu.common.core.domain.Result; import com.muyu.common.core.utils.poi.ExcelUtil; import com.muyu.common.security.utils.SecurityUtils; import org.springframework.validation.annotation.Validated; import com.muyu.common.core.web.page.TableDataInfo; /** * 预警规则Controller * * @author muyu * @date 2024-09-20 */ @RestController @RequestMapping("/rule") public class WarnRuleController extends BaseController { @Resource private IWarnRuleService warnRuleService; /** * 查询预警规则列表 */ @RequiresPermissions("warn:rule:list") @GetMapping("/list") public Result> list(WarnRule warnRule) { startPage(); List list = warnRuleService.selectWarnRuleList(warnRule); return getDataTable(list); } /** * 导出预警规则列表 */ @RequiresPermissions("warn:rule:export") @PostMapping("/export") public void export(HttpServletResponse response, WarnRule warnRule) { List list = warnRuleService.selectWarnRuleList(warnRule); ExcelUtil util = new ExcelUtil(WarnRule.class); util.exportExcel(response, list, "预警规则数据"); } /** * 获取预警规则详细信息 */ @RequiresPermissions("warn:rule:query") @GetMapping(value = "/{id}") public Result> getInfo(@PathVariable("id") Long id) { return success(warnRuleService.selectWarnRuleById(id)); } /** * 新增预警规则 */ @RequiresPermissions("warn:rule:add") @PostMapping public Result add( @Validated @RequestBody WarnRule warnRule) { if (warnRuleService.checkIdUnique(warnRule)) { return error("新增 预警规则 '" + warnRule + "'失败,预警规则已存在"); } return toAjax(warnRuleService.save(warnRule)); } /** * 修改预警规则 */ @RequiresPermissions("warn:rule:edit") @PutMapping public Result edit( @Validated @RequestBody WarnRule warnRule) { if (!warnRuleService.checkIdUnique(warnRule)) { return error("修改 预警规则 '" + warnRule + "'失败,预警规则不存在"); } return toAjax(warnRuleService.updateById(warnRule)); } /** * 删除预警规则 */ @RequiresPermissions("warn:rule:remove") @DeleteMapping("/{ids}") public Result remove(@PathVariable("ids") Long[] ids) { warnRuleService.removeBatchByIds(Arrays.asList(ids)); return success(); } /** * 根据策略id查询规则 * @param strategyId * @return */ @GetMapping("/selectByStrategyId") public Result> selectByStrategyId (@RequestParam("strategyId") Long strategyId){ List list = warnRuleService.list (new LambdaQueryWrapper().eq(WarnRule::getStrategyId, strategyId)); return success(list); } }