Compare commits

...

2 Commits

Author SHA1 Message Date
aaf849013a Merge branch 'master' into zjw 2024-09-05 14:58:12 +08:00
2ed6bcc144 模拟数据产生与报警诊断功能更新 2024-09-05 14:57:12 +08:00
30 changed files with 869 additions and 3 deletions

View File

@ -29,6 +29,11 @@
<artifactId>imt-module-system-api</artifactId> <artifactId>imt-module-system-api</artifactId>
<version>${revision}</version> <version>${revision}</version>
</dependency> </dependency>
<dependency>
<groupId>com.inspur</groupId>
<artifactId>imt-module-system-biz</artifactId>
<version>${revision}</version>
</dependency>
<dependency> <dependency>
<groupId>com.inspur</groupId> <groupId>com.inspur</groupId>
<artifactId>imt-module-infra-api</artifactId> <artifactId>imt-module-infra-api</artifactId>

View File

@ -0,0 +1,45 @@
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);
}
}

View File

@ -0,0 +1,48 @@
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);
}
}

View File

@ -0,0 +1,46 @@
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);
}
}

View File

@ -0,0 +1,49 @@
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);
}
}

View File

@ -0,0 +1,47 @@
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);
}
}

View File

@ -0,0 +1,67 @@
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);
}
}

View File

@ -0,0 +1,10 @@
package com.inspur.module.system.api.alarm;
/**
* @Author zhangjunwen
* @create 2024/9/4
*/
public interface AlarmDataApi {
}

View File

@ -0,0 +1,24 @@
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);
}

View File

@ -0,0 +1,15 @@
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 {
}

View File

@ -0,0 +1,79 @@
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;
}

View File

@ -0,0 +1,78 @@
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;
}

View File

@ -0,0 +1,52 @@
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;
/**
* 报警等级11级22级33级
*/
private Integer alarmLevel;
/**
* 首次报警时间
*/
private LocalDateTime firstAlarmTime;
/**
* 最新报警时间
*/
private LocalDateTime latestAlarmTime;
/**
* 状态0:待处理1已处理
*/
private Integer status;
/**
* 机床分析状态0正常1磨损中2磨损严重
*/
private Integer equipAnalyseStatus;
}

View File

@ -0,0 +1,158 @@
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();
}
}

View File

@ -0,0 +1,8 @@
package com.inspur.module.system.api.alarm;
/**
* @Author zhangjunwen
* @create 2024/9/4
*/
public class EquipAlarmDataApiImpl {
}

View File

@ -0,0 +1,44 @@
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 = "区间外";
}

View File

@ -13,6 +13,8 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - 机床参数报警记录新增/修改 Request VO") @Schema(description = "管理后台 - 机床参数报警记录新增/修改 Request VO")
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
public class AlarmDataSaveReqVO { public class AlarmDataSaveReqVO {
@Schema(description = "机床设备报警记录id", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "机床设备报警记录id", requiredMode = Schema.RequiredMode.REQUIRED)

View File

@ -9,13 +9,14 @@ import java.time.LocalDateTime;
@Schema(description = "管理后台 - 机床设备报警数据新增/修改 Request VO") @Schema(description = "管理后台 - 机床设备报警数据新增/修改 Request VO")
@Data @Data
@NoArgsConstructor
@AllArgsConstructor
public class EquipAlarmDataSaveReqVO { public class EquipAlarmDataSaveReqVO {
@Schema(description = "设备预警信息主键", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "设备预警信息主键", requiredMode = Schema.RequiredMode.REQUIRED)
private String equipAlarmId; private String equipAlarmId;
@Schema(description = "机床设备id", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "机床设备id", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "机床设备id不能为空")
private String equipId; private String equipId;
@Schema(description = "机床组件id", example = "10773") @Schema(description = "机床组件id", example = "10773")

View File

@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.inspur.framework.common.pojo.PageResult; import com.inspur.framework.common.pojo.PageResult;
import com.inspur.framework.mybatis.core.query.LambdaQueryWrapperX; import com.inspur.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.inspur.framework.mybatis.core.mapper.BaseMapperX; 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.AlarmDataDO;
import com.inspur.module.system.dal.dataobject.alarm.EquipAlarmDataDO; import com.inspur.module.system.dal.dataobject.alarm.EquipAlarmDataDO;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@ -42,5 +43,11 @@ public interface AlarmDataMapper extends BaseMapperX<AlarmDataDO> {
/** /**
* 根据id查询参数报警 * 根据id查询参数报警
*/ */
@TenantIgnore
public AlarmDataDO selectAlarmDataById(@Param("id") Long id); public AlarmDataDO selectAlarmDataById(@Param("id") Long id);
/**
* 根据规则id查询参数报警
*/
public AlarmDataDO selectAlarmDataByRulesId(@Param("alarmRulesId") String alarmRulesId);
} }

View File

@ -49,4 +49,9 @@ public interface AlarmRulesMapper extends BaseMapperX<AlarmRulesDO> {
* 根据id查询报警规则 * 根据id查询报警规则
*/ */
public AlarmRulesDO selectAlarmRulesById(@Param("id") String id); public AlarmRulesDO selectAlarmRulesById(@Param("id") String id);
/**
* 根据设备id查询报警规则
*/
List<AlarmRulesDO> getAlarmRulesListByEquipId(String equipId);
} }

View File

@ -10,6 +10,8 @@ import org.apache.ibatis.annotations.Mapper;
import com.inspur.module.system.controller.admin.alarm.vo.*; import com.inspur.module.system.controller.admin.alarm.vo.*;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 机床设备报警数据 Mapper * 机床设备报警数据 Mapper
* *
@ -40,4 +42,9 @@ public interface EquipAlarmDataMapper extends BaseMapperX<EquipAlarmDataDO> {
* 根据id查询设备报警 * 根据id查询设备报警
*/ */
public EquipAlarmDataDO selectEquipAlarmById(@Param("id") String id); public EquipAlarmDataDO selectEquipAlarmById(@Param("id") String id);
/**
* 通过设备id查询设备报警数据
*/
List<EquipAlarmDataDO> getEquipAlarmDataByEquipId(String equipId);
} }

View File

@ -53,4 +53,10 @@ public interface AlarmDataService {
*/ */
PageResult<AlarmDataDO> getAlarmDataPage(AlarmDataPageReqVO pageReqVO); PageResult<AlarmDataDO> getAlarmDataPage(AlarmDataPageReqVO pageReqVO);
/**
* 根据规则id获取参数报警记录
* @param ruleId 规则id
* @return 参数报警记录
*/
AlarmDataDO getAlarmDataByRulesId(String ruleId);
} }

View File

@ -2,6 +2,7 @@ package com.inspur.module.system.service.alarm;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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 com.inspur.module.system.dal.dataobject.alarm.EquipAlarmDataDO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,6 +35,7 @@ public class AlarmDataServiceImpl implements AlarmDataService {
private AlarmDataMapper alarmDataMapper; private AlarmDataMapper alarmDataMapper;
@Override @Override
@TenantIgnore
public Long createAlarmData(AlarmDataSaveReqVO createReqVO) { public Long createAlarmData(AlarmDataSaveReqVO createReqVO) {
// 插入 // 插入
AlarmDataDO alarmData = BeanUtils.toBean(createReqVO, AlarmDataDO.class); AlarmDataDO alarmData = BeanUtils.toBean(createReqVO, AlarmDataDO.class);
@ -43,6 +45,7 @@ public class AlarmDataServiceImpl implements AlarmDataService {
} }
@Override @Override
@TenantIgnore
public void updateAlarmData(AlarmDataSaveReqVO updateReqVO) { public void updateAlarmData(AlarmDataSaveReqVO updateReqVO) {
// 校验存在 // 校验存在
validateAlarmDataExists(updateReqVO.getAlarmDataId()); validateAlarmDataExists(updateReqVO.getAlarmDataId());
@ -59,6 +62,7 @@ public class AlarmDataServiceImpl implements AlarmDataService {
alarmDataMapper.deleteById(id); alarmDataMapper.deleteById(id);
} }
@TenantIgnore
private void validateAlarmDataExists(Long id) { private void validateAlarmDataExists(Long id) {
if (alarmDataMapper.selectAlarmDataById(id) == null) { if (alarmDataMapper.selectAlarmDataById(id) == null) {
throw exception(ALARM_DATA_NOT_EXISTS); throw exception(ALARM_DATA_NOT_EXISTS);
@ -77,4 +81,9 @@ public class AlarmDataServiceImpl implements AlarmDataService {
return new PageResult<>(page.getRecords(), page.getTotal()); return new PageResult<>(page.getRecords(), page.getTotal());
} }
@Override
@TenantIgnore
public AlarmDataDO getAlarmDataByRulesId(String ruleId){
return alarmDataMapper.selectAlarmDataByRulesId(ruleId);
}
} }

View File

@ -5,6 +5,8 @@ import com.inspur.module.system.controller.admin.alarm.vo.*;
import com.inspur.module.system.dal.dataobject.alarm.AlarmRulesDO; import com.inspur.module.system.dal.dataobject.alarm.AlarmRulesDO;
import com.inspur.framework.common.pojo.PageResult; import com.inspur.framework.common.pojo.PageResult;
import java.util.List;
/** /**
* 机床报警规则 Service 接口 * 机床报警规则 Service 接口
* *
@ -50,4 +52,8 @@ public interface AlarmRulesService {
*/ */
PageResult<AlarmRulesDO> getAlarmRulesPage(AlarmRulesPageReqVO pageReqVO); PageResult<AlarmRulesDO> getAlarmRulesPage(AlarmRulesPageReqVO pageReqVO);
/**
* 根据设备id查询报警规则
*/
List<AlarmRulesDO> getAlarmRulesListByEquipId(String equipId);
} }

View File

@ -2,6 +2,8 @@ package com.inspur.module.system.service.alarm;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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 org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -13,6 +15,8 @@ import com.inspur.framework.common.util.object.BeanUtils;
import com.inspur.module.system.dal.mysql.alarm.AlarmRulesMapper; 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.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.inspur.module.system.enums.ErrorCodeConstants.*; import static com.inspur.module.system.enums.ErrorCodeConstants.*;
@ -28,12 +32,16 @@ public class AlarmRulesServiceImpl implements AlarmRulesService {
@Resource @Resource
private AlarmRulesMapper alarmRulesMapper; private AlarmRulesMapper alarmRulesMapper;
@Resource
private StringRedisTemplate stringRedisTemplate;
@Override @Override
public String createAlarmRules(AlarmRulesSaveReqVO createReqVO) { public String createAlarmRules(AlarmRulesSaveReqVO createReqVO) {
// 插入 // 插入
AlarmRulesDO alarmRules = BeanUtils.toBean(createReqVO, AlarmRulesDO.class); AlarmRulesDO alarmRules = BeanUtils.toBean(createReqVO, AlarmRulesDO.class);
alarmRules.setStatus(0);//默认开启 alarmRules.setStatus(0);//默认开启
alarmRulesMapper.insert(alarmRules); alarmRulesMapper.insert(alarmRules);
stringRedisTemplate.delete(createReqVO.getEquipId());
// 返回 // 返回
return alarmRules.getAlarmId(); return alarmRules.getAlarmId();
} }
@ -56,8 +64,11 @@ public class AlarmRulesServiceImpl implements AlarmRulesService {
} }
private void validateAlarmRulesExists(String id) { private void validateAlarmRulesExists(String id) {
if (alarmRulesMapper.selectAlarmRulesById(id) == null) { AlarmRulesDO alarmRule = alarmRulesMapper.selectAlarmRulesById(id);
if (alarmRule == null) {
throw exception(ALARM_RULES_NOT_EXISTS); throw exception(ALARM_RULES_NOT_EXISTS);
}else{
alarmRulesMapper.selectAlarmRulesById(alarmRule.getEquipId());//更新或者删除时直接删除redis缓存
} }
} }
@ -73,4 +84,10 @@ public class AlarmRulesServiceImpl implements AlarmRulesService {
return new PageResult<>(page.getRecords(), page.getTotal()); return new PageResult<>(page.getRecords(), page.getTotal());
} }
@Override
@TenantIgnore
public List<AlarmRulesDO> getAlarmRulesListByEquipId(String equipId){
return alarmRulesMapper.getAlarmRulesListByEquipId(equipId);
}
} }

View File

@ -53,4 +53,8 @@ public interface EquipAlarmDataService {
*/ */
PageResult<EquipAlarmDataDO> getEquipAlarmDataPage(EquipAlarmDataPageReqVO pageReqVO); PageResult<EquipAlarmDataDO> getEquipAlarmDataPage(EquipAlarmDataPageReqVO pageReqVO);
/**
* 通过设备id查询设备报警数据
*/
List<EquipAlarmDataDO> getEquipAlarmDataByEquipId(String equipId);
} }

View File

@ -2,6 +2,7 @@ package com.inspur.module.system.service.alarm;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; 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 com.inspur.module.system.dal.dataobject.alarm.AlarmRulesDO;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -45,6 +46,7 @@ public class EquipAlarmDataServiceImpl implements EquipAlarmDataService {
} }
@Override @Override
@TenantIgnore
public void updateEquipAlarmData(EquipAlarmDataSaveReqVO updateReqVO) { public void updateEquipAlarmData(EquipAlarmDataSaveReqVO updateReqVO) {
// 校验存在 // 校验存在
validateEquipAlarmDataExists(updateReqVO.getEquipAlarmId()); validateEquipAlarmDataExists(updateReqVO.getEquipAlarmId());
@ -61,6 +63,7 @@ public class EquipAlarmDataServiceImpl implements EquipAlarmDataService {
equipAlarmDataMapper.deleteById(id); equipAlarmDataMapper.deleteById(id);
} }
@TenantIgnore
private void validateEquipAlarmDataExists(String id) { private void validateEquipAlarmDataExists(String id) {
if (equipAlarmDataMapper.selectEquipAlarmById(id) == null) { if (equipAlarmDataMapper.selectEquipAlarmById(id) == null) {
throw exception(EQUIP_ALARM_DATA_NOT_EXISTS); throw exception(EQUIP_ALARM_DATA_NOT_EXISTS);
@ -79,4 +82,9 @@ public class EquipAlarmDataServiceImpl implements EquipAlarmDataService {
return new PageResult<>(page.getRecords(), page.getTotal()); return new PageResult<>(page.getRecords(), page.getTotal());
} }
@Override
@TenantIgnore
public List<EquipAlarmDataDO> getEquipAlarmDataByEquipId(String equipId) {
return equipAlarmDataMapper.getEquipAlarmDataByEquipId(equipId);
}
} }

View File

@ -41,8 +41,15 @@
order by ad.create_time desc order by ad.create_time desc
</select> </select>
<select id="selectAlarmDataById" parameterType="String" resultMap="AlarmDataResult"> <select id="selectAlarmDataById" parameterType="Long" resultMap="AlarmDataResult">
<include refid="selectAlarmDataVo"/> <include refid="selectAlarmDataVo"/>
where ad.alarm_data_id = #{id} and ad.deleted = '0' where ad.alarm_data_id = #{id} and ad.deleted = '0'
</select> </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> </mapper>

View File

@ -51,4 +51,9 @@
where iar.alarm_id = #{id} and iar.deleted = '0' where iar.alarm_id = #{id} and iar.deleted = '0'
</select> </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> </mapper>

View File

@ -40,4 +40,11 @@
<include refid="selectEquipAlarmVo"/> <include refid="selectEquipAlarmVo"/>
where iead.equip_alarm_id = #{id} and iead.deleted = '0' where iead.equip_alarm_id = #{id} and iead.deleted = '0'
</select> </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> </mapper>