| | |
| | | package cn.gistack.sm.alarmRule.controller; |
| | | |
| | | import cn.gistack.sm.alarmRule.entity.AlarmRule; |
| | | import cn.gistack.sm.alarmRule.entity.AlarmRuleDetail; |
| | | import cn.gistack.sm.alarmRule.service.AlarmRuleDetailService; |
| | | import cn.gistack.sm.alarmRule.service.AlarmRuleService; |
| | | import cn.gistack.sm.alarmRule.vo.AlarmRuleVO; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 告警规则控制层 |
| | |
| | | public class AlarmRuleController extends BladeController { |
| | | |
| | | private final AlarmRuleService alarmRuleService; |
| | | |
| | | private final AlarmRuleDetailService alarmRuleDetailService; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | |
| | | */ |
| | | @ApiOperation(value="告警规则-添加", notes="告警规则-添加") |
| | | @PostMapping(value = "/add") |
| | | public R add(@RequestBody AlarmRule alarmRule) { |
| | | return R.data(alarmRuleService.save(alarmRule)); |
| | | public R add(@RequestBody AlarmRuleVO alarmRule) { |
| | | boolean flag = false; |
| | | boolean save = alarmRuleService.save(alarmRule); |
| | | // 新增成功 |
| | | if (save){ |
| | | if (alarmRule.getAlarmRuleDetailList().size() > 0){ |
| | | for (AlarmRuleDetail alarmRuleDetail : alarmRule.getAlarmRuleDetailList()) { |
| | | alarmRuleDetail.setAlarmRuleId(alarmRule.getId()); |
| | | // 新增明细 |
| | | flag = alarmRuleDetailService.save(alarmRuleDetail); |
| | | } |
| | | } |
| | | } |
| | | // 返回结果 |
| | | return R.status(flag); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @ApiOperation(value="告警规则-编辑", notes="告警规则-编辑") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
| | | public R edit(@RequestBody AlarmRule alarmRule) { |
| | | return R.data(alarmRuleService.updateById(alarmRule)); |
| | | public R edit(@RequestBody AlarmRuleVO alarmRule) { |
| | | boolean flag = false; |
| | | // 更新 |
| | | boolean update = alarmRuleService.updateById(alarmRule); |
| | | if (update){ |
| | | if (alarmRule.getAlarmRuleDetailList().size() > 0){ |
| | | for (AlarmRuleDetail alarmRuleDetail : alarmRule.getAlarmRuleDetailList()) { |
| | | alarmRuleDetail.setAlarmRuleId(alarmRule.getId()); |
| | | if (null == alarmRuleDetail.getId()){ |
| | | // 新增明细 |
| | | flag = alarmRuleDetailService.save(alarmRuleDetail); |
| | | }else { |
| | | // 修改 |
| | | flag = alarmRuleDetailService.updateById(alarmRuleDetail); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return R.status(flag); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @ApiOperation(value="告警规则-通过id删除", notes="告警规则-通过id删除") |
| | | @DeleteMapping(value = "/delete") |
| | | @PostMapping(value = "/delete") |
| | | public R delete(@RequestParam(name="id",required=true) String id) { |
| | | return R.data(alarmRuleService.removeById(id)); |
| | | return R.status(alarmRuleService.removeById(id)); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @return |
| | | */ |
| | | @ApiOperation(value="告警规则-批量删除", notes="告警规则-批量删除") |
| | | @DeleteMapping(value = "/deleteBatch") |
| | | @PostMapping(value = "/deleteBatch") |
| | | public R deleteBatch(@RequestParam(name="ids",required=true) String ids) { |
| | | return R.data(this.alarmRuleService.removeByIds(Arrays.asList(ids.split(",")))); |
| | | boolean flag = false; |
| | | // |
| | | boolean remove = alarmRuleService.removeByIds(Arrays.asList(ids.split(","))); |
| | | if (remove){ |
| | | // 查询明细 |
| | | List<String> idList = Arrays.asList(ids.split(",")); |
| | | for (String id : idList) { |
| | | QueryWrapper<AlarmRuleDetail> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("alarm_rule_id",id); |
| | | // 删除明细 |
| | | flag = alarmRuleDetailService.remove(wrapper); |
| | | } |
| | | } |
| | | return R.status(flag); |
| | | } |
| | | |
| | | /** |
| | |
| | | return R.data(alarmRule); |
| | | } |
| | | |
| | | /** |
| | | * 通过id查询 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @ApiOperation(value="告警规则-通过id查询", notes="告警规则-通过id查询") |
| | | @GetMapping(value = "/detail") |
| | | public R getDetail(@RequestParam(name="id",required=true) String id) { |
| | | return R.data(alarmRuleService.getDetail(id)); |
| | | } |
| | | |
| | | } |