feat: 告警规则增删改查接口
parent
19ed689f69
commit
9e21b2bf9e
@ -0,0 +1,60 @@
|
||||
package com.xydl.cac.controller;
|
||||
|
||||
import com.xydl.cac.entity.WarnRule;
|
||||
import com.xydl.cac.exception.BusinessException;
|
||||
import com.xydl.cac.model.Response;
|
||||
import com.xydl.cac.service.WarnRuleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@Api(tags = {"告警规则相关接口"})
|
||||
@RequestMapping("rule")
|
||||
@Slf4j
|
||||
public class WarnRuleController extends BasicController {
|
||||
|
||||
@Resource
|
||||
WarnRuleService service;
|
||||
|
||||
@GetMapping("listAll")
|
||||
@ApiOperation("查询全部列表")
|
||||
public Response<List<WarnRule>> listAll() {
|
||||
List<WarnRule> result = service.listAll();
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("add")
|
||||
@ApiOperation("新增")
|
||||
public Response<WarnRule> add(@Validated @RequestBody WarnRule item) throws Exception {
|
||||
WarnRule result = service.add(item);
|
||||
return Response.success(result);
|
||||
}
|
||||
|
||||
@PostMapping("update")
|
||||
@ApiOperation("更新")
|
||||
public Response<String> update(@Validated @RequestBody WarnRule item) throws Exception {
|
||||
if (item.getId() == null) {
|
||||
throw new BusinessException("ID不能为空!");
|
||||
}
|
||||
service.update(item);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
@PostMapping("delete")
|
||||
@ApiOperation("删除")
|
||||
public Response<String> delete(@Validated @NotNull(message = "id不能为空!") Integer id) throws Exception {
|
||||
if (id == null) {
|
||||
throw new BusinessException("id不能为空!");
|
||||
}
|
||||
service.delete(id);
|
||||
return Response.success("OK");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.xydl.cac.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = "warn_rule")
|
||||
@ApiModel("告警规则表")
|
||||
public class WarnRule {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("装置ID")
|
||||
@Column(name = "eqmid")
|
||||
private String eqmid;
|
||||
|
||||
@ApiModelProperty("属性点")
|
||||
@Column(name = "modevtype_point_id")
|
||||
private Integer modevtypePointId;
|
||||
|
||||
@ApiModelProperty("阈值")
|
||||
@Column(name = "threshold")
|
||||
private String threshold;
|
||||
|
||||
@ApiModelProperty("比较器")
|
||||
@Column(name = "comparator")
|
||||
private String comparator;
|
||||
|
||||
@ApiModelProperty("告警级别 0:高 1:中 2:低")
|
||||
@Column(name = "level")
|
||||
private Integer level;
|
||||
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.xydl.cac.repository;
|
||||
|
||||
import com.xydl.cac.entity.WarnRule;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface WarnRuleRepository extends JpaRepository<WarnRule, Integer>, JpaSpecificationExecutor<WarnRule> {
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.xydl.cac.service;
|
||||
|
||||
import com.xydl.cac.entity.WarnRule;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface WarnRuleService {
|
||||
|
||||
List<WarnRule> listAll();
|
||||
|
||||
WarnRule add(WarnRule item) throws Exception;
|
||||
|
||||
void update(WarnRule item) throws Exception;
|
||||
|
||||
void delete(Integer id) throws Exception;
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package com.xydl.cac.service.impl;
|
||||
|
||||
import com.xydl.cac.entity.WarnRule;
|
||||
import com.xydl.cac.repository.WarnRuleRepository;
|
||||
import com.xydl.cac.service.WarnRuleService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class WarnRuleServiceImpl implements WarnRuleService {
|
||||
|
||||
@Resource
|
||||
WarnRuleRepository repository;
|
||||
|
||||
@Override
|
||||
public List<WarnRule> listAll() {
|
||||
return repository.findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WarnRule add(WarnRule item) throws Exception {
|
||||
item.setId(null);
|
||||
return repository.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(WarnRule item) throws Exception {
|
||||
repository.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Integer id) throws Exception {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue