feat:告警增加是否已读状态,更新接口

dev
郭承 8 months ago
parent eb04d0ce89
commit 07cec04b6c

@ -2,6 +2,7 @@ package com.xydl.cac.controller;
import com.alibaba.excel.EasyExcel;
import com.xydl.cac.entity.Warning;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.ConditionModel;
import com.xydl.cac.model.Response;
import com.xydl.cac.service.ReportService;
@ -52,4 +53,15 @@ public class WarningController extends BasicController {
.sheet("告警数据")
.doWrite(result);
}
@PostMapping("updateRead")
@ApiOperation("修改是否已读状态")
public Response<String> updateRead(@Validated @RequestBody Warning warning) throws Exception {
if (warning.getId() == null) {
throw new BusinessException("id不能为空!");
}
service.updateRead(warning);
return Response.success("OK");
}
}

@ -118,4 +118,9 @@ public class Warning {
@ExcelIgnore
private Date processTime;
@ApiModelProperty("是否已读 0:未读 1:已读")
@Column(name = "isread")
@ExcelIgnore
private Integer isread;
}

@ -12,4 +12,6 @@ public interface WarningService {
Page<Warning> list(ConditionModel condition) throws Exception;
List<Warning> listAll(ConditionModel condition) throws Exception;
void updateRead(Warning warning) throws Exception;
}

@ -1,6 +1,8 @@
package com.xydl.cac.service.impl;
import com.xydl.cac.entity.NSensor;
import com.xydl.cac.entity.Warning;
import com.xydl.cac.exception.BusinessException;
import com.xydl.cac.model.ConditionModel;
import com.xydl.cac.repository.WarningRepository;
import com.xydl.cac.service.WarningService;
@ -15,6 +17,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import javax.persistence.criteria.Predicate;
import java.util.List;
import java.util.Optional;
@Service
@Slf4j
@ -69,4 +72,15 @@ public class WarningServiceImpl implements WarningService {
};
return repository.findAll(specification);
}
@Override
public void updateRead(Warning warning) throws Exception {
Optional<Warning> byId = repository.findById(warning.getId());
if (!byId.isPresent()) {
throw new BusinessException("未找到该告警" + warning.getId());
}
Warning war = byId.get();
war.setIsread(warning.getIsread());
repository.save(war);
}
}

@ -85,6 +85,7 @@ public class RuleCheckTask {
.triggerDesc(rule.getOperatorDesc() + " 阈值(" + rule.getThreshold() + ")")
.warnTime(new Date())
.processTime(new Date())
.isread(0)
.build();
warningRepository.save(warning);
String str = warning.getZsbName() + "--" + warning.getWarnDesc() + " "

Loading…
Cancel
Save