Compare commits
No commits in common. "aaf849013a7aeb9bdd9f89c9af16608ba1b62ce5" and "161e94603d4e1279c7ac26c209d37093820a8e4a" have entirely different histories.
aaf849013a
...
161e94603d
@ -29,11 +29,6 @@
|
||||
<artifactId>imt-module-system-api</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inspur</groupId>
|
||||
<artifactId>imt-module-system-biz</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.inspur</groupId>
|
||||
<artifactId>imt-module-infra-api</artifactId>
|
||||
|
@ -1,45 +0,0 @@
|
||||
package com.inspur.module.data.service.task;
|
||||
|
||||
import com.inspur.framework.common.util.spring.SpringUtils;
|
||||
import com.inspur.module.data.service.InfluxDBService;
|
||||
import com.inspur.module.system.api.alarm.AlarmRulesApi;
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
public class Channel1DataProcess implements Runnable{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Channel1DataProcess.class);
|
||||
@Override
|
||||
public void run() {
|
||||
process();
|
||||
}
|
||||
|
||||
private void process() {
|
||||
String measurement = "gateway_channel_current_data";
|
||||
String equid = "2e3d0190e63eda526da89d6c751f08f3";
|
||||
|
||||
InfluxDBService influxDBService = SpringUtils.getBean(InfluxDBService.class);
|
||||
AlarmRulesApi alarmRulesApi = SpringUtils.getBean(AlarmRulesApi.class);
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
fields.put("x_push_temp", Math.random());
|
||||
fields.put("y_push_temp",Math.random());
|
||||
|
||||
//报警过滤
|
||||
List<AlarmRulesRespDTO> rules = alarmRulesApi.selectAlarmRulesListByCatch(equid);
|
||||
if(rules != null && rules.size() > 0){//报警规则过滤
|
||||
int alarmNum = alarmRulesApi.alarmRulesFilter(fields, rules);
|
||||
logger.info("本次产生报警{}条",alarmNum);
|
||||
}
|
||||
influxDBService.insert(measurement,tags, fields);
|
||||
logger.info("数据已插入{}表中!",measurement);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.inspur.module.data.service.task;
|
||||
|
||||
import com.inspur.framework.common.util.spring.SpringUtils;
|
||||
import com.inspur.module.data.service.InfluxDBService;
|
||||
import com.inspur.module.system.api.alarm.AlarmRulesApi;
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/5
|
||||
*/
|
||||
public class Channel2DataProcess implements Runnable{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Channel2DataProcess.class);
|
||||
@Override
|
||||
public void run() {
|
||||
process();
|
||||
}
|
||||
|
||||
private void process() {
|
||||
String measurement = "gateway_channel_hydra_data";
|
||||
String equid = "2e3d0190e63eda526da89d6c751f08f3";
|
||||
|
||||
InfluxDBService influxDBService = SpringUtils.getBean(InfluxDBService.class);
|
||||
AlarmRulesApi alarmRulesApi = SpringUtils.getBean(AlarmRulesApi.class);
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
fields.put("x_lube_press", Math.random());
|
||||
fields.put("y_lube_press",Math.random());
|
||||
fields.put("z_lube_press",Math.random());
|
||||
|
||||
//报警过滤
|
||||
List<AlarmRulesRespDTO> rules = alarmRulesApi.selectAlarmRulesListByCatch(equid);
|
||||
if(rules != null && rules.size() > 0){//报警规则过滤
|
||||
int alarmNum = alarmRulesApi.alarmRulesFilter(fields, rules);
|
||||
logger.info("本次产生报警{}条",alarmNum);
|
||||
}
|
||||
influxDBService.insert(measurement,tags, fields);
|
||||
logger.info("数据已插入{}表中!",measurement);
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package com.inspur.module.data.service.task;
|
||||
|
||||
import com.inspur.framework.common.util.spring.SpringUtils;
|
||||
import com.inspur.module.data.service.InfluxDBService;
|
||||
import com.inspur.module.system.api.alarm.AlarmRulesApi;
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/5
|
||||
*/
|
||||
public class Channel3DataProcess implements Runnable{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Channel3DataProcess.class);
|
||||
@Override
|
||||
public void run() {
|
||||
process();
|
||||
}
|
||||
|
||||
private void process() {
|
||||
String measurement = "gateway_channel_vibr_data";
|
||||
String equid = "2e3d0190e63eda526da89d6c751f08f3";
|
||||
|
||||
InfluxDBService influxDBService = SpringUtils.getBean(InfluxDBService.class);
|
||||
AlarmRulesApi alarmRulesApi = SpringUtils.getBean(AlarmRulesApi.class);
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
fields.put("x_entropy", Math.random());
|
||||
|
||||
//报警过滤
|
||||
List<AlarmRulesRespDTO> rules = alarmRulesApi.selectAlarmRulesListByCatch(equid);
|
||||
if(rules != null && rules.size() > 0){//报警规则过滤
|
||||
int alarmNum = alarmRulesApi.alarmRulesFilter(fields, rules);
|
||||
logger.info("本次产生报警{}条",alarmNum);
|
||||
}
|
||||
influxDBService.insert(measurement,tags, fields);
|
||||
logger.info("数据已插入{}表中!",measurement);
|
||||
}
|
||||
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
package com.inspur.module.data.service.task;
|
||||
|
||||
import com.inspur.framework.common.util.spring.SpringUtils;
|
||||
import com.inspur.module.data.service.InfluxDBService;
|
||||
import com.inspur.module.system.api.alarm.AlarmRulesApi;
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/5
|
||||
*/
|
||||
public class Channel4DataProcess implements Runnable{
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(Channel4DataProcess.class);
|
||||
@Override
|
||||
public void run() {
|
||||
process();
|
||||
}
|
||||
|
||||
private void process() {
|
||||
String measurement = "gateway_channel_temp_data";
|
||||
String equid = "2e3d0190e63eda526da89d6c751f08f3";
|
||||
|
||||
InfluxDBService influxDBService = SpringUtils.getBean(InfluxDBService.class);
|
||||
AlarmRulesApi alarmRulesApi = SpringUtils.getBean(AlarmRulesApi.class);
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
fields.put("x_bear_temp", Math.random());
|
||||
fields.put("y_bear_temp", Math.random());
|
||||
fields.put("x_debris_temp", Math.random());
|
||||
fields.put("z_debris_temp", Math.random());
|
||||
fields.put("at_temp", Math.random());
|
||||
|
||||
//报警过滤
|
||||
List<AlarmRulesRespDTO> rules = alarmRulesApi.selectAlarmRulesListByCatch(equid);
|
||||
if(rules != null && rules.size() > 0){//报警规则过滤
|
||||
int alarmNum = alarmRulesApi.alarmRulesFilter(fields, rules);
|
||||
logger.info("本次产生报警{}条",alarmNum);
|
||||
}
|
||||
influxDBService.insert(measurement,tags, fields);
|
||||
logger.info("数据已插入{}表中!",measurement);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.inspur.module.data.service.task;
|
||||
|
||||
import com.inspur.framework.common.util.spring.SpringUtils;
|
||||
import com.inspur.module.data.service.InfluxDBService;
|
||||
import com.inspur.module.system.api.alarm.AlarmRulesApi;
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/5
|
||||
*/
|
||||
public class Channel5DataProcess implements Runnable{
|
||||
private static final Logger logger = LoggerFactory.getLogger(Channel5DataProcess.class);
|
||||
@Override
|
||||
public void run() {
|
||||
process();
|
||||
}
|
||||
|
||||
private void process() {
|
||||
String measurement = "gateway_channel_work_data";
|
||||
String equid = "2e3d0190e63eda526da89d6c751f08f3";
|
||||
|
||||
InfluxDBService influxDBService = SpringUtils.getBean(InfluxDBService.class);
|
||||
// AlarmRulesApi alarmRulesApi = SpringUtils.getBean(AlarmRulesApi.class);
|
||||
Map<String, Object> fields = new HashMap<>();
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
fields.put("work_total", Math.round(Math.random()*100));
|
||||
fields.put("work_time", Math.round(Math.random() * 100.0) / 100.0);
|
||||
fields.put("on_time", Math.round(Math.random() * 100.0) / 100.0);
|
||||
fields.put("work_items", Math.round(Math.random()*100));
|
||||
|
||||
// //报警过滤
|
||||
// List<AlarmRulesRespDTO> rules = alarmRulesApi.selectAlarmRulesListByCatch(equid);
|
||||
// if(rules != null && rules.size() > 0){//报警规则过滤
|
||||
// int alarmNum = alarmRulesApi.alarmRulesFilter(fields, rules);
|
||||
// logger.info("本次产生报警{}条",alarmNum);
|
||||
// }
|
||||
influxDBService.insert(measurement,tags, fields);
|
||||
logger.info("数据已插入{}表中!",measurement);
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package com.inspur.module.data.service.task;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
@Component()
|
||||
@Order(value = 1)
|
||||
public class DataProducerTask implements ApplicationRunner {
|
||||
|
||||
@Autowired
|
||||
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
Timer timer1 = new Timer();
|
||||
timer1.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
threadPoolTaskExecutor.execute(new Channel1DataProcess());
|
||||
}
|
||||
},1000,10000);
|
||||
|
||||
Timer timer2 = new Timer();
|
||||
timer2.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
threadPoolTaskExecutor.execute(new Channel2DataProcess());
|
||||
}
|
||||
},5000,10000);
|
||||
|
||||
Timer timer3 = new Timer();
|
||||
timer3.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
threadPoolTaskExecutor.execute(new Channel3DataProcess());
|
||||
}
|
||||
},10000,10000);
|
||||
|
||||
Timer timer4 = new Timer();
|
||||
timer4.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
threadPoolTaskExecutor.execute(new Channel4DataProcess());
|
||||
}
|
||||
},14000,10000);
|
||||
|
||||
Timer timer5 = new Timer();
|
||||
timer5.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
threadPoolTaskExecutor.execute(new Channel5DataProcess());
|
||||
}
|
||||
},19000,10000);
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
public interface AlarmDataApi {
|
||||
|
||||
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm;
|
||||
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
public interface AlarmRulesApi {
|
||||
|
||||
/**
|
||||
* 查询告警规则缓存
|
||||
*/
|
||||
public List<AlarmRulesRespDTO> selectAlarmRulesListByCatch(String equipId);
|
||||
|
||||
/**
|
||||
* 报警规则过滤
|
||||
*/
|
||||
public Integer alarmRulesFilter(Map<String, Object> fields,List<AlarmRulesRespDTO> rules);
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm;
|
||||
|
||||
import com.inspur.framework.common.pojo.PageResult;
|
||||
import com.inspur.module.system.api.alarm.dto.EquipAlarmDataRespDTO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
public interface EquipAlarmDataApi {
|
||||
|
||||
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
@Data
|
||||
public class AlarmDataRespDTO {
|
||||
/**
|
||||
* 机床设备报警记录id
|
||||
*/
|
||||
private Long alarmDataId;
|
||||
/**
|
||||
* 报警规则id
|
||||
*/
|
||||
private String alarmRulesId;
|
||||
/**
|
||||
* 机床设备id
|
||||
*/
|
||||
private String equipId;
|
||||
/**
|
||||
* 机床组件id
|
||||
*/
|
||||
private String componentId;
|
||||
/**
|
||||
* 规则参数key
|
||||
*/
|
||||
private String nameKey;
|
||||
/**
|
||||
* 报警内容
|
||||
*/
|
||||
private String content;
|
||||
/**
|
||||
* 报警值
|
||||
*/
|
||||
private BigDecimal alarmValue;
|
||||
/**
|
||||
* 首次报警时间
|
||||
*/
|
||||
private LocalDateTime firstAlarmTime;
|
||||
/**
|
||||
* 处理结果
|
||||
*/
|
||||
private String result;
|
||||
/**
|
||||
* 报警记录的状态(0:未处理,1:已处理)
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 处理人
|
||||
*/
|
||||
private Long operatorId;
|
||||
/**
|
||||
* 等级
|
||||
*/
|
||||
private Integer alarmLevel;
|
||||
/**
|
||||
* 最新报警时间
|
||||
*/
|
||||
private LocalDateTime lastAlarmTime;
|
||||
/**
|
||||
* 可能故障原因
|
||||
*/
|
||||
private String reasonDescription;
|
||||
/**
|
||||
* 设备预警信息主键
|
||||
*/
|
||||
private String equipAlarmId;
|
||||
|
||||
/**
|
||||
* 报警类型
|
||||
*/
|
||||
private Integer alarmType;
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
@Data
|
||||
public class AlarmRulesRespDTO {
|
||||
/**
|
||||
* 报警规则信息id
|
||||
*/
|
||||
private String alarmId;
|
||||
/**
|
||||
* 报警信息的key
|
||||
*/
|
||||
private String alarmNameKey;
|
||||
/**
|
||||
* 报警规则信息名称
|
||||
*/
|
||||
private String alarmName;
|
||||
/**
|
||||
* 报警规则信息单位
|
||||
*/
|
||||
private String alarmInfoUnit;
|
||||
/**
|
||||
* 机床设备id
|
||||
*/
|
||||
private String equipId;
|
||||
/**
|
||||
* 机床组件id
|
||||
*/
|
||||
private String componentId;
|
||||
/**
|
||||
* 报警规则上限值
|
||||
*/
|
||||
private BigDecimal alertUpperBound;
|
||||
/**
|
||||
* 报警规则下限值
|
||||
*/
|
||||
private BigDecimal alertLowerBound;
|
||||
/**
|
||||
* 报警规则信息的类型(0:阈值报警,1:趋势报警)
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
* 状态(0:启用,1:停用)
|
||||
*/
|
||||
private Integer status;
|
||||
/**
|
||||
* 报警可能原因描述
|
||||
*/
|
||||
private String reasonDescription;
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String remark;
|
||||
/**
|
||||
* 规则描述
|
||||
*/
|
||||
private String referenceName;
|
||||
/**
|
||||
* 判断规则
|
||||
*/
|
||||
private String referenceCon;
|
||||
/**
|
||||
* 等级
|
||||
*/
|
||||
private Integer alarmLevel;
|
||||
/**
|
||||
* 排序
|
||||
*/
|
||||
private Integer sort;
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
@Data
|
||||
public class EquipAlarmDataRespDTO {
|
||||
/**
|
||||
* 设备报警id
|
||||
*/
|
||||
private String equipAlarmId;
|
||||
|
||||
/**
|
||||
* 机床id
|
||||
*/
|
||||
private String equipId;
|
||||
|
||||
/**
|
||||
* 机床组件id
|
||||
*/
|
||||
private String componentId;
|
||||
|
||||
/**
|
||||
* 报警等级(1:1级,2:2级,3:3级)
|
||||
*/
|
||||
private Integer alarmLevel;
|
||||
|
||||
/**
|
||||
* 首次报警时间
|
||||
*/
|
||||
private LocalDateTime firstAlarmTime;
|
||||
|
||||
/**
|
||||
* 最新报警时间
|
||||
*/
|
||||
private LocalDateTime latestAlarmTime;
|
||||
|
||||
/**
|
||||
* 状态(0:待处理,1:已处理)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 机床分析状态(0:正常,1:磨损中,2:磨损严重)
|
||||
*/
|
||||
private Integer equipAnalyseStatus;
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm;
|
||||
|
||||
import com.inspur.framework.common.util.json.JsonUtils;
|
||||
import com.inspur.framework.common.util.object.BeanUtils;
|
||||
import com.inspur.module.system.api.alarm.dto.AlarmRulesRespDTO;
|
||||
import com.inspur.module.system.constant.JudgeConstant;
|
||||
import com.inspur.module.system.controller.admin.alarm.vo.AlarmDataSaveReqVO;
|
||||
import com.inspur.module.system.controller.admin.alarm.vo.EquipAlarmDataSaveReqVO;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.AlarmDataDO;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.EquipAlarmDataDO;
|
||||
import com.inspur.module.system.service.alarm.AlarmDataService;
|
||||
import com.inspur.module.system.service.alarm.AlarmRulesService;
|
||||
import com.inspur.module.system.service.alarm.EquipAlarmDataService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
@Service
|
||||
public class AlarmRulesApiImpl implements AlarmRulesApi{
|
||||
@Resource
|
||||
private AlarmRulesService alarmRulesService;
|
||||
|
||||
@Resource
|
||||
private AlarmDataService alarmDataService;
|
||||
|
||||
@Resource
|
||||
private EquipAlarmDataService equipAlarmDataService;
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public List<AlarmRulesRespDTO> selectAlarmRulesListByCatch(String equipId) {
|
||||
List<AlarmRulesRespDTO> alarmRules = JsonUtils.parseArray(stringRedisTemplate.opsForValue().get(equipId),AlarmRulesRespDTO.class);
|
||||
if(alarmRules == null || alarmRules.size() == 0){
|
||||
alarmRules = BeanUtils.toBean(alarmRulesService.getAlarmRulesListByEquipId(equipId), AlarmRulesRespDTO.class);
|
||||
stringRedisTemplate.opsForValue().set(equipId, JsonUtils.toJsonString(alarmRules));
|
||||
}
|
||||
return alarmRules ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 报警规则过滤
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public Integer alarmRulesFilter(Map<String, Object> fields, List<AlarmRulesRespDTO> rules){
|
||||
int count = 0;
|
||||
for (AlarmRulesRespDTO rule : rules) {
|
||||
if(fields.get(rule.getAlarmNameKey())!=null && judgeAlarm(fields.get(rule.getAlarmNameKey()),rule.getAlertUpperBound(), rule.getAlertLowerBound(), rule.getReferenceCon())){
|
||||
String equipAlarmId = refreshEquipAlarmData(rule);
|
||||
BigDecimal val = BigDecimal.valueOf((Double) fields.get(rule.getAlarmNameKey()));
|
||||
BigDecimal realValue =val.setScale(2, BigDecimal.ROUND_HALF_UP);//去两位小数并四舍五入
|
||||
refreshAlarmData(rule,realValue,equipAlarmId);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据报警规则判断是否正常
|
||||
*
|
||||
* @param realValueObj 实际值
|
||||
* @param referenceValue1 上限值
|
||||
* @param referenceValue2 下限值
|
||||
* @param referenceCon 比较标准
|
||||
* @return 是否报警
|
||||
*/
|
||||
public static Boolean judgeAlarm(Object realValueObj, BigDecimal referenceValue1, BigDecimal referenceValue2, String referenceCon) {
|
||||
// 是否报警
|
||||
Boolean flag = false;
|
||||
BigDecimal realValue;
|
||||
// 无法转为数字即异常数据
|
||||
if (realValueObj instanceof String || realValueObj instanceof Number) {
|
||||
try {
|
||||
realValue = new BigDecimal(String.valueOf(realValueObj));
|
||||
} catch (Exception e) {
|
||||
flag = true;
|
||||
return flag;
|
||||
}
|
||||
} else {
|
||||
flag = true;
|
||||
return flag;
|
||||
}
|
||||
if (JudgeConstant.GREATER.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) > 0;
|
||||
} else if (JudgeConstant.GREATER_EQUAL.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) >= 0;
|
||||
} else if (JudgeConstant.LESS.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) < 0;
|
||||
} else if (JudgeConstant.LESS_EQUAL.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) <= 0;
|
||||
} else if (JudgeConstant.EQUAL.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) == 0;
|
||||
} else if (JudgeConstant.WIDTHIN_INTERVAL.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) >= 0 && realValue.compareTo(referenceValue2) <= 0;
|
||||
} else if (JudgeConstant.OUTSIDE_INTERVAL.equals(referenceCon)) {
|
||||
flag = realValue.compareTo(referenceValue1) <= 0 || realValue.compareTo(referenceValue2) >= 0;
|
||||
} else {
|
||||
flag = true;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数报警数据更新
|
||||
* (参数报警数据针对每条规则只有一条,没有则新增,有则更新时间)
|
||||
*/
|
||||
public void refreshAlarmData(AlarmRulesRespDTO rule,BigDecimal value,String equipAlarmId ){
|
||||
|
||||
AlarmDataDO alarmData = alarmDataService.getAlarmDataByRulesId(rule.getAlarmId());
|
||||
if(alarmData == null){
|
||||
alarmDataService.createAlarmData(new AlarmDataSaveReqVO(null,rule.getAlarmId(),rule.getEquipId(),
|
||||
rule.getComponentId(),rule.getAlarmNameKey(),rule.getReferenceName(),value, LocalDateTime.now(),
|
||||
null,0,rule.getAlarmLevel(),LocalDateTime.now(),rule.getReasonDescription(),equipAlarmId,
|
||||
"0"));
|
||||
return;
|
||||
}
|
||||
AlarmDataSaveReqVO updateData = new AlarmDataSaveReqVO();
|
||||
updateData.setAlarmDataId(alarmData.getAlarmDataId());
|
||||
updateData.setAlarmValue(value);
|
||||
updateData.setLastAlarmTime(LocalDateTime.now());
|
||||
updateData.setAlarmLevel(rule.getAlarmLevel());
|
||||
updateData.setEquipId(rule.getEquipId());
|
||||
alarmDataService.updateAlarmData(updateData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备报警数据更新
|
||||
*/
|
||||
public String refreshEquipAlarmData(AlarmRulesRespDTO rule){
|
||||
List<EquipAlarmDataDO> equipAlarmData = equipAlarmDataService.getEquipAlarmDataByEquipId(rule.getEquipId());
|
||||
if(equipAlarmData == null || equipAlarmData.size() == 0){
|
||||
return equipAlarmDataService.createEquipAlarmData(new EquipAlarmDataSaveReqVO(null,rule.getEquipId(),
|
||||
rule.getComponentId(),rule.getAlarmLevel(),0,LocalDateTime.now(),LocalDateTime.now(),0,null));
|
||||
}
|
||||
//如果没有则新增
|
||||
EquipAlarmDataSaveReqVO updateData = new EquipAlarmDataSaveReqVO();
|
||||
updateData.setEquipAlarmId(equipAlarmData.get(0).getEquipAlarmId());
|
||||
updateData.setAlarmLevel(rule.getAlarmLevel());
|
||||
updateData.setLatestAlarmTime(LocalDateTime.now());
|
||||
equipAlarmDataService.updateEquipAlarmData(updateData);
|
||||
return equipAlarmData.get(0).getEquipAlarmId();
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
package com.inspur.module.system.api.alarm;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
public class EquipAlarmDataApiImpl {
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package com.inspur.module.system.constant;
|
||||
|
||||
/**
|
||||
* @Author zhangjunwen
|
||||
* @create 2024/9/4
|
||||
*/
|
||||
public class JudgeConstant {
|
||||
|
||||
/**
|
||||
* 大于
|
||||
*/
|
||||
public static final String GREATER = "大于";
|
||||
|
||||
/**
|
||||
* 小于
|
||||
*/
|
||||
public static final String LESS = "小于";
|
||||
|
||||
/**
|
||||
* 大于等于
|
||||
*/
|
||||
public static final String GREATER_EQUAL = "大于等于";
|
||||
|
||||
/**
|
||||
* 小于等于
|
||||
*/
|
||||
public static final String LESS_EQUAL = "小于等于";
|
||||
|
||||
/**
|
||||
* 等于
|
||||
*/
|
||||
public static final String EQUAL = "等于";
|
||||
|
||||
/**
|
||||
* 区间内
|
||||
*/
|
||||
public static final String WIDTHIN_INTERVAL = "区间内";
|
||||
|
||||
/**
|
||||
* 区间外
|
||||
*/
|
||||
public static final String OUTSIDE_INTERVAL = "区间外";
|
||||
|
||||
}
|
@ -13,8 +13,6 @@ import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 机床参数报警记录新增/修改 Request VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AlarmDataSaveReqVO {
|
||||
|
||||
@Schema(description = "机床设备报警记录id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
|
@ -9,14 +9,13 @@ import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 机床设备报警数据新增/修改 Request VO")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class EquipAlarmDataSaveReqVO {
|
||||
|
||||
@Schema(description = "设备预警信息主键", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
private String equipAlarmId;
|
||||
|
||||
@Schema(description = "机床设备id", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotEmpty(message = "机床设备id不能为空")
|
||||
private String equipId;
|
||||
|
||||
@Schema(description = "机床组件id", example = "10773")
|
||||
|
@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.inspur.framework.common.pojo.PageResult;
|
||||
import com.inspur.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import com.inspur.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import com.inspur.framework.tenant.core.aop.TenantIgnore;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.AlarmDataDO;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.EquipAlarmDataDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
@ -43,11 +42,5 @@ public interface AlarmDataMapper extends BaseMapperX<AlarmDataDO> {
|
||||
/**
|
||||
* 根据id查询参数报警
|
||||
*/
|
||||
@TenantIgnore
|
||||
public AlarmDataDO selectAlarmDataById(@Param("id") Long id);
|
||||
|
||||
/**
|
||||
* 根据规则id查询参数报警
|
||||
*/
|
||||
public AlarmDataDO selectAlarmDataByRulesId(@Param("alarmRulesId") String alarmRulesId);
|
||||
}
|
||||
|
@ -49,9 +49,4 @@ public interface AlarmRulesMapper extends BaseMapperX<AlarmRulesDO> {
|
||||
* 根据id查询报警规则
|
||||
*/
|
||||
public AlarmRulesDO selectAlarmRulesById(@Param("id") String id);
|
||||
|
||||
/**
|
||||
* 根据设备id查询报警规则
|
||||
*/
|
||||
List<AlarmRulesDO> getAlarmRulesListByEquipId(String equipId);
|
||||
}
|
@ -10,8 +10,6 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import com.inspur.module.system.controller.admin.alarm.vo.*;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 机床设备报警数据 Mapper
|
||||
*
|
||||
@ -42,9 +40,4 @@ public interface EquipAlarmDataMapper extends BaseMapperX<EquipAlarmDataDO> {
|
||||
* 根据id查询设备报警
|
||||
*/
|
||||
public EquipAlarmDataDO selectEquipAlarmById(@Param("id") String id);
|
||||
|
||||
/**
|
||||
* 通过设备id查询设备报警数据
|
||||
*/
|
||||
List<EquipAlarmDataDO> getEquipAlarmDataByEquipId(String equipId);
|
||||
}
|
||||
|
@ -53,10 +53,4 @@ public interface AlarmDataService {
|
||||
*/
|
||||
PageResult<AlarmDataDO> getAlarmDataPage(AlarmDataPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 根据规则id获取参数报警记录
|
||||
* @param ruleId 规则id
|
||||
* @return 参数报警记录
|
||||
*/
|
||||
AlarmDataDO getAlarmDataByRulesId(String ruleId);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.inspur.module.system.service.alarm;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.inspur.framework.tenant.core.aop.TenantIgnore;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.EquipAlarmDataDO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -35,7 +34,6 @@ public class AlarmDataServiceImpl implements AlarmDataService {
|
||||
private AlarmDataMapper alarmDataMapper;
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public Long createAlarmData(AlarmDataSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
AlarmDataDO alarmData = BeanUtils.toBean(createReqVO, AlarmDataDO.class);
|
||||
@ -45,7 +43,6 @@ public class AlarmDataServiceImpl implements AlarmDataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public void updateAlarmData(AlarmDataSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateAlarmDataExists(updateReqVO.getAlarmDataId());
|
||||
@ -62,7 +59,6 @@ public class AlarmDataServiceImpl implements AlarmDataService {
|
||||
alarmDataMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@TenantIgnore
|
||||
private void validateAlarmDataExists(Long id) {
|
||||
if (alarmDataMapper.selectAlarmDataById(id) == null) {
|
||||
throw exception(ALARM_DATA_NOT_EXISTS);
|
||||
@ -81,9 +77,4 @@ public class AlarmDataServiceImpl implements AlarmDataService {
|
||||
return new PageResult<>(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public AlarmDataDO getAlarmDataByRulesId(String ruleId){
|
||||
return alarmDataMapper.selectAlarmDataByRulesId(ruleId);
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import com.inspur.module.system.controller.admin.alarm.vo.*;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.AlarmRulesDO;
|
||||
import com.inspur.framework.common.pojo.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 机床报警规则 Service 接口
|
||||
*
|
||||
@ -52,8 +50,4 @@ public interface AlarmRulesService {
|
||||
*/
|
||||
PageResult<AlarmRulesDO> getAlarmRulesPage(AlarmRulesPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 根据设备id查询报警规则
|
||||
*/
|
||||
List<AlarmRulesDO> getAlarmRulesListByEquipId(String equipId);
|
||||
}
|
@ -2,8 +2,6 @@ package com.inspur.module.system.service.alarm;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.inspur.framework.tenant.core.aop.TenantIgnore;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
@ -15,8 +13,6 @@ import com.inspur.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.inspur.module.system.dal.mysql.alarm.AlarmRulesMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.inspur.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.inspur.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
@ -32,16 +28,12 @@ public class AlarmRulesServiceImpl implements AlarmRulesService {
|
||||
@Resource
|
||||
private AlarmRulesMapper alarmRulesMapper;
|
||||
|
||||
@Resource
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public String createAlarmRules(AlarmRulesSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
AlarmRulesDO alarmRules = BeanUtils.toBean(createReqVO, AlarmRulesDO.class);
|
||||
alarmRules.setStatus(0);//默认开启
|
||||
alarmRulesMapper.insert(alarmRules);
|
||||
stringRedisTemplate.delete(createReqVO.getEquipId());
|
||||
// 返回
|
||||
return alarmRules.getAlarmId();
|
||||
}
|
||||
@ -64,11 +56,8 @@ public class AlarmRulesServiceImpl implements AlarmRulesService {
|
||||
}
|
||||
|
||||
private void validateAlarmRulesExists(String id) {
|
||||
AlarmRulesDO alarmRule = alarmRulesMapper.selectAlarmRulesById(id);
|
||||
if (alarmRule == null) {
|
||||
if (alarmRulesMapper.selectAlarmRulesById(id) == null) {
|
||||
throw exception(ALARM_RULES_NOT_EXISTS);
|
||||
}else{
|
||||
alarmRulesMapper.selectAlarmRulesById(alarmRule.getEquipId());//更新或者删除时,直接删除redis缓存
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,10 +73,4 @@ public class AlarmRulesServiceImpl implements AlarmRulesService {
|
||||
return new PageResult<>(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public List<AlarmRulesDO> getAlarmRulesListByEquipId(String equipId){
|
||||
return alarmRulesMapper.getAlarmRulesListByEquipId(equipId);
|
||||
}
|
||||
}
|
@ -53,8 +53,4 @@ public interface EquipAlarmDataService {
|
||||
*/
|
||||
PageResult<EquipAlarmDataDO> getEquipAlarmDataPage(EquipAlarmDataPageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 通过设备id查询设备报警数据
|
||||
*/
|
||||
List<EquipAlarmDataDO> getEquipAlarmDataByEquipId(String equipId);
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.inspur.module.system.service.alarm;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.inspur.framework.tenant.core.aop.TenantIgnore;
|
||||
import com.inspur.module.system.dal.dataobject.alarm.AlarmRulesDO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@ -46,7 +45,6 @@ public class EquipAlarmDataServiceImpl implements EquipAlarmDataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public void updateEquipAlarmData(EquipAlarmDataSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateEquipAlarmDataExists(updateReqVO.getEquipAlarmId());
|
||||
@ -63,7 +61,6 @@ public class EquipAlarmDataServiceImpl implements EquipAlarmDataService {
|
||||
equipAlarmDataMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@TenantIgnore
|
||||
private void validateEquipAlarmDataExists(String id) {
|
||||
if (equipAlarmDataMapper.selectEquipAlarmById(id) == null) {
|
||||
throw exception(EQUIP_ALARM_DATA_NOT_EXISTS);
|
||||
@ -82,9 +79,4 @@ public class EquipAlarmDataServiceImpl implements EquipAlarmDataService {
|
||||
return new PageResult<>(page.getRecords(), page.getTotal());
|
||||
}
|
||||
|
||||
@Override
|
||||
@TenantIgnore
|
||||
public List<EquipAlarmDataDO> getEquipAlarmDataByEquipId(String equipId) {
|
||||
return equipAlarmDataMapper.getEquipAlarmDataByEquipId(equipId);
|
||||
}
|
||||
}
|
||||
|
@ -41,15 +41,8 @@
|
||||
order by ad.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectAlarmDataById" parameterType="Long" resultMap="AlarmDataResult">
|
||||
<select id="selectAlarmDataById" parameterType="String" resultMap="AlarmDataResult">
|
||||
<include refid="selectAlarmDataVo"/>
|
||||
where ad.alarm_data_id = #{id} and ad.deleted = '0'
|
||||
</select>
|
||||
|
||||
<select id="selectAlarmDataByRulesId" parameterType="String" resultMap="AlarmDataResult">
|
||||
<include refid="selectAlarmDataVo"/>
|
||||
where ad.alarm_rules_id = #{alarmRulesId}
|
||||
and ad.status = 0
|
||||
and ad.deleted = '0'
|
||||
</select>
|
||||
</mapper>
|
@ -51,9 +51,4 @@
|
||||
where iar.alarm_id = #{id} and iar.deleted = '0'
|
||||
</select>
|
||||
|
||||
<select id="getAlarmRulesListByEquipId" parameterType="String" resultMap="AlarmRulesResult">
|
||||
<include refid="selectAlarmRulesVo"/>
|
||||
where iar.status = 0 and iar.deleted = '0'
|
||||
<if test="equipId != null and equipId != ''">and iar.equip_id = #{equipId}</if>
|
||||
</select>
|
||||
</mapper>
|
@ -40,11 +40,4 @@
|
||||
<include refid="selectEquipAlarmVo"/>
|
||||
where iead.equip_alarm_id = #{id} and iead.deleted = '0'
|
||||
</select>
|
||||
|
||||
<select id="getEquipAlarmDataByEquipId" parameterType="String" resultMap="EquipAlarmResult">
|
||||
<include refid="selectEquipAlarmVo"/>
|
||||
where iead.equip_id = #{equipId}
|
||||
and iead.status = 0
|
||||
and iead.deleted = '0'
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user