feat: 增加告警信息查询接口
parent
faa3721fc5
commit
6e928dd5a1
@ -0,0 +1,33 @@
|
|||||||
|
package com.xydl.cac.controller;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Warning;
|
||||||
|
import com.xydl.cac.model.ConditionModel;
|
||||||
|
import com.xydl.cac.model.Response;
|
||||||
|
import com.xydl.cac.service.WarningService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@Api(tags = {"告警信息相关接口"})
|
||||||
|
@RequestMapping("warning")
|
||||||
|
@Slf4j
|
||||||
|
public class WarningController extends BasicController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
WarningService service;
|
||||||
|
|
||||||
|
@GetMapping("list")
|
||||||
|
@ApiOperation("查询列表")
|
||||||
|
public Response<Page<Warning>> list(@Validated ConditionModel condition) throws Exception {
|
||||||
|
condition.setPageNum(this.initPageNum(condition.getPageNum()));
|
||||||
|
condition.setPageSize(this.initPageSize(condition.getPageSize()));
|
||||||
|
Page<Warning> result = service.list(condition);
|
||||||
|
return Response.success(result);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,69 @@
|
|||||||
|
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.*;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Entity
|
||||||
|
@Table(name = "warning")
|
||||||
|
@ApiModel("告警信息表")
|
||||||
|
public class Warning {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
@Column(name = "id")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@ApiModelProperty("装置ID")
|
||||||
|
@Column(name = "eqmid")
|
||||||
|
private String eqmid;
|
||||||
|
|
||||||
|
@ApiModelProperty("告警时间")
|
||||||
|
@Column(name = "warn_time")
|
||||||
|
private Date warnTime;
|
||||||
|
|
||||||
|
@ApiModelProperty("告警值")
|
||||||
|
@Column(name = "warning_value")
|
||||||
|
private String warningValue;
|
||||||
|
|
||||||
|
@ApiModelProperty("阈值")
|
||||||
|
@Column(name = "threadval")
|
||||||
|
private String threadval;
|
||||||
|
|
||||||
|
@ApiModelProperty("告警信息")
|
||||||
|
@Column(name = "warn_desc")
|
||||||
|
private String warnDesc;
|
||||||
|
|
||||||
|
@ApiModelProperty("告警级别 0:高 1:中 2:低")
|
||||||
|
@Column(name = "warn_level")
|
||||||
|
private String warnLevel;
|
||||||
|
|
||||||
|
@ApiModelProperty("处理状态")
|
||||||
|
@Column(name = "state")
|
||||||
|
private String state;
|
||||||
|
|
||||||
|
@ApiModelProperty("处理结果描述")
|
||||||
|
@Column(name = "process")
|
||||||
|
private String process;
|
||||||
|
|
||||||
|
@ApiModelProperty("处理人id")
|
||||||
|
@Column(name = "process_user")
|
||||||
|
private String processUser;
|
||||||
|
|
||||||
|
@ApiModelProperty("处理时间")
|
||||||
|
@Column(name = "process_time")
|
||||||
|
private Date processTime;
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
package com.xydl.cac.repository;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Warning;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface WarningRepository extends JpaRepository<Warning, Integer>, JpaSpecificationExecutor<Warning> {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package com.xydl.cac.service;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Warning;
|
||||||
|
import com.xydl.cac.model.ConditionModel;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
|
||||||
|
|
||||||
|
public interface WarningService {
|
||||||
|
|
||||||
|
Page<Warning> list(ConditionModel condition) throws Exception;
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.xydl.cac.service.impl;
|
||||||
|
|
||||||
|
import com.xydl.cac.entity.Warning;
|
||||||
|
import com.xydl.cac.model.ConditionModel;
|
||||||
|
import com.xydl.cac.repository.WarningRepository;
|
||||||
|
import com.xydl.cac.service.WarningService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.persistence.criteria.Predicate;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
@Slf4j
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public class WarningServiceImpl implements WarningService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
WarningRepository repository;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<Warning> list(ConditionModel condition) throws Exception {
|
||||||
|
PageRequest request = PageRequest.of(condition.getPageNum(), condition.getPageSize());
|
||||||
|
Specification<Warning> specification = (root, query, builder) -> {
|
||||||
|
Predicate predicate = builder.conjunction();
|
||||||
|
if (condition.getDevId() != null) {
|
||||||
|
predicate.getExpressions().add(builder.equal(root.get("eqmid"), condition.getDevId().toString()));
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(condition.getState())) {
|
||||||
|
predicate.getExpressions().add(builder.equal(root.get("state"), condition.getState()));
|
||||||
|
}
|
||||||
|
if (condition.getStartTime() != null) {
|
||||||
|
predicate.getExpressions().add(builder.greaterThan(root.get("warnTime"), condition.getStartTime()));
|
||||||
|
}
|
||||||
|
if (condition.getEndTime() != null) {
|
||||||
|
predicate.getExpressions().add(builder.lessThanOrEqualTo(root.get("warnTime"), condition.getEndTime()));
|
||||||
|
}
|
||||||
|
query.orderBy(builder.desc(root.get("warnTime")));
|
||||||
|
return predicate;
|
||||||
|
};
|
||||||
|
Page<Warning> result = repository.findAll(specification, request);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue