From 2bd3f29992f2d4713ff5f035cf9474d36cb75c90 Mon Sep 17 00:00:00 2001 From: zhanghan11 Date: Mon, 18 Nov 2024 15:06:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../industrial/IpcAlarmRecordController.java | 4 +- .../src/main/resources/application-druid.yml | 2 +- .../src/main/resources/application.yml | 6 +- .../com/inspur/common/constant/Constants.java | 6 +- .../inspur/datasyn/modbus/IpcDataProcess.java | 7 +- .../com/inspur/cache/domain/IpcCacheSync.java | 72 ++++++++++++ .../cache/mapper/IpcCacheSyncMapper.java | 70 ++++++++++++ .../cache/service/IIpcCacheSyncService.java | 70 ++++++++++++ .../service/impl/IpcCacheSyncServiceImpl.java | 104 ++++++++++++++++++ .../industrial/domain/IpcAlarmRecord.java | 4 +- .../mapper/IpcAlarmRecordMapper.java | 8 ++ .../service/IIpcAlarmRecordService.java | 8 ++ .../service/IIpcAlarmRulesService.java | 1 + .../impl/IpcAlarmRecordServiceImpl.java | 10 ++ .../impl/IpcAlarmRulesServiceImpl.java | 14 +-- .../com/inspur/industrial/utils/Constant.java | 23 ++++ .../utils/IpcRedisCacheConfiguration.java | 81 ++++++++++++++ .../com/inspur/industrial/utils/IpcUtil.java | 8 +- .../mapper/cache/IpcCacheSyncMapper.xml | 67 +++++++++++ .../industrial/IpcAlarmRecordMapper.xml | 23 +++- 20 files changed, 561 insertions(+), 27 deletions(-) create mode 100644 zfipc-server/zfipc-system/src/main/java/com/inspur/cache/domain/IpcCacheSync.java create mode 100644 zfipc-server/zfipc-system/src/main/java/com/inspur/cache/mapper/IpcCacheSyncMapper.java create mode 100644 zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/IIpcCacheSyncService.java create mode 100644 zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/impl/IpcCacheSyncServiceImpl.java create mode 100644 zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcRedisCacheConfiguration.java create mode 100644 zfipc-server/zfipc-system/src/main/resources/mapper/cache/IpcCacheSyncMapper.xml diff --git a/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/industrial/IpcAlarmRecordController.java b/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/industrial/IpcAlarmRecordController.java index 4cd7a2b..3c7cca1 100644 --- a/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/industrial/IpcAlarmRecordController.java +++ b/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/industrial/IpcAlarmRecordController.java @@ -49,14 +49,14 @@ public class IpcAlarmRecordController extends BaseController } /** - * 查询所有报警记录 + * 查询所有报警记录(最多1000条) * @param ipcAlarmRecord * @return */ @GetMapping("/listAll") public AjaxResult listAll(IpcAlarmRecord ipcAlarmRecord) { - List list = ipcAlarmRecordService.selectIpcAlarmRecordList(ipcAlarmRecord); + List list = ipcAlarmRecordService.selectIpcAlarmRecordListAll(ipcAlarmRecord); return AjaxResult.success(list); } diff --git a/zfipc-server/zfipc-admin/src/main/resources/application-druid.yml b/zfipc-server/zfipc-admin/src/main/resources/application-druid.yml index 8924ebc..a9d8d9e 100644 --- a/zfipc-server/zfipc-admin/src/main/resources/application-druid.yml +++ b/zfipc-server/zfipc-admin/src/main/resources/application-druid.yml @@ -9,7 +9,7 @@ spring: # url: jdbc:mysql://117.73.8.43:3306/phm?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 # username: phm # password: Y123456a - url: jdbc:mysql://117.73.2.117:3306/zfipc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 + url: jdbc:mysql://localhost:3306/zfipc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8 username: zfipc password: Y123456a # 从库数据源 diff --git a/zfipc-server/zfipc-admin/src/main/resources/application.yml b/zfipc-server/zfipc-admin/src/main/resources/application.yml index 4d6b774..926663f 100644 --- a/zfipc-server/zfipc-admin/src/main/resources/application.yml +++ b/zfipc-server/zfipc-admin/src/main/resources/application.yml @@ -15,7 +15,9 @@ zfipc: # 验证码类型 math 数组计算 char 字符验证 captchaType: math # 自定义参数,判定是云端还是工控机端,云端-cloud,工控机端-client,其他-other - model: client1 + model: client + # 部门ID + deptId: 100 # 开发环境配置 server: @@ -147,7 +149,7 @@ datasyn: host: 10.124.7.12 port: 502 influxdb: - url: http://117.73.2.117:8086 + url: http://localhost:8086 userName: zfipc password: Y123456a database: zfipc diff --git a/zfipc-server/zfipc-common/src/main/java/com/inspur/common/constant/Constants.java b/zfipc-server/zfipc-common/src/main/java/com/inspur/common/constant/Constants.java index 829f25b..6ea7dcc 100644 --- a/zfipc-server/zfipc-common/src/main/java/com/inspur/common/constant/Constants.java +++ b/zfipc-server/zfipc-common/src/main/java/com/inspur/common/constant/Constants.java @@ -147,7 +147,7 @@ public class Constants /** * influxdb表名-超压底缸 */ - public static final String MEASUREMENT_TOP_SCOLLER="zfipc_industrial_monitor_data1"; + public static final String MEASUREMENT_TOP_SCOLLER="zfipc_industrial_monitor_data2"; /** * influxdb表名-超压底缸 */ @@ -158,11 +158,11 @@ public class Constants */ public static final String EQUIPID_BOTTOM_CY_LINDER="e2ae4710b516419c84d1d4a819429348"; /** - * 设备ID-超压底缸 + * 设备ID-可控中高辊顶辊 */ public static final String EQUIPID_TOP_SCOLLER="5d6c1a1374ea490a91e1361c1f5400aa"; /** - * 设备ID-超压底缸 + * 设备ID-可控中高辊底辊 */ public static final String EQUIPID_BOTTOM_SCOLLER="8b2d5cb04e254c15ade1e53a4f594f3f"; } diff --git a/zfipc-server/zfipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IpcDataProcess.java b/zfipc-server/zfipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IpcDataProcess.java index 0d0e3d6..95f1d4b 100644 --- a/zfipc-server/zfipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IpcDataProcess.java +++ b/zfipc-server/zfipc-datasyn/src/main/java/com/inspur/datasyn/modbus/IpcDataProcess.java @@ -193,7 +193,7 @@ public class IpcDataProcess implements Runnable { i.insert(measurement, tags, fields); if (!alarmRecordList.isEmpty()) {//运行需放开 - // alarmRecordService.batchInsertIpcAlarmRecord(alarmRecordList); + alarmRecordService.batchInsertIpcAlarmRecord(alarmRecordList); } } @@ -300,9 +300,10 @@ public class IpcDataProcess implements Runnable { fields.put("ipc_status", results.getValue(102)); //报警处理 List rulesList = alarmRulesService.selectIpcAlarmRulesConfigListByCache(Constant.RUNNING,equipId); + System.out.println("rulesList:"+fields); alarmRecordList.addAll(ipcUtil.dealRealTimeData(fields, tags, Constant.RUNNING, rulesList));//TODO 根据运行状态确定规则 if (!alarmRecordList.isEmpty()) {//运行需放开 - // alarmRecordService.batchInsertIpcAlarmRecord(alarmRecordList); + alarmRecordService.batchInsertIpcAlarmRecord(alarmRecordList); } i.insert(measurement, tags, fields); } @@ -411,7 +412,7 @@ public class IpcDataProcess implements Runnable { List rulesList = alarmRulesService.selectIpcAlarmRulesConfigListByCache(Constant.RUNNING,equipId); alarmRecordList.addAll(ipcUtil.dealRealTimeData(fields, tags, Constant.RUNNING, rulesList));//TODO 根据运行状态确定规则 if (!alarmRecordList.isEmpty()) {//运行需放开 - // alarmRecordService.batchInsertIpcAlarmRecord(alarmRecordList); + alarmRecordService.batchInsertIpcAlarmRecord(alarmRecordList); } i.insert(measurement, tags, fields); } diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/domain/IpcCacheSync.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/domain/IpcCacheSync.java new file mode 100644 index 0000000..002bf7d --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/domain/IpcCacheSync.java @@ -0,0 +1,72 @@ +package com.inspur.cache.domain; + +import com.inspur.common.annotation.Excel; +import com.inspur.common.core.domain.BaseEntity; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * 缓存同步对象 ipc_cache_sync + * + * @author zhanghan11 + * @date 2024-09-29 + */ +public class IpcCacheSync extends BaseEntity +{ + public IpcCacheSync() { + } + + public IpcCacheSync(Long deptId, String type, String model) { + this.deptId = deptId; + this.type = type; + this.model = model; + } + + private static final long serialVersionUID = 1L; + + /** 部门ID */ + @Excel(name = "部门ID") + private Long deptId; + + /** 类型 */ + @Excel(name = "类型") + private String type; + /** 自定义参数,判定是云端还是工控机端,云端-cloud,工控机端-client,其他-other */ + @Excel(name = "自定义参数,判定是云端还是工控机端,云端-cloud,工控机端-client,其他-other") + private String model; + + public void setDeptId(Long deptId) + { + this.deptId = deptId; + } + + public Long getDeptId() + { + return deptId; + } + public void setType(String type) + { + this.type = type; + } + + public String getType() + { + return type; + } + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + @Override + public String toString() { + return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE) + .append("deptId", getDeptId()) + .append("type", getType()) + .toString(); + } +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/mapper/IpcCacheSyncMapper.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/mapper/IpcCacheSyncMapper.java new file mode 100644 index 0000000..e83de82 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/mapper/IpcCacheSyncMapper.java @@ -0,0 +1,70 @@ +package com.inspur.cache.mapper; + +import com.inspur.cache.domain.IpcCacheSync; + +import java.util.List; + +/** + * 缓存同步Mapper接口 + * + * @author zhanghan11 + * @date 2024-09-29 + */ +public interface IpcCacheSyncMapper +{ + /** + * 查询缓存同步 + * + * @param deptId 缓存同步主键 + * @return 缓存同步 + */ + public IpcCacheSync selectIpcCacheSyncByDeptId(Long deptId); + + /** + * 去重查询缓存同步列表 + * + * @param ipcCacheSync 缓存同步 + * @return 缓存同步集合 + */ + public List selectIpcCacheSyncList(IpcCacheSync ipcCacheSync); + + /** + * 新增缓存同步 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + public int insertIpcCacheSync(IpcCacheSync ipcCacheSync); + + /** + * 修改缓存同步 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + public int updateIpcCacheSync(IpcCacheSync ipcCacheSync); + + /** + * 删除缓存同步 + * + * @param deptId 缓存同步主键 + * @return 结果 + */ + public int deleteIpcCacheSyncByDeptId(Long deptId); + + /** + * 批量删除缓存同步 + * + * @param deptIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteIpcCacheSyncByDeptIds(Long[] deptIds); + + /** + * 删除缓存同步信息 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + public int deleteIpcCacheSync(IpcCacheSync ipcCacheSync); +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/IIpcCacheSyncService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/IIpcCacheSyncService.java new file mode 100644 index 0000000..fa44638 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/IIpcCacheSyncService.java @@ -0,0 +1,70 @@ +package com.inspur.cache.service; + +import com.inspur.cache.domain.IpcCacheSync; + +import java.util.List; + +/** + * 缓存同步Service接口 + * + * @author zhanghan11 + * @date 2024-09-29 + */ +public interface IIpcCacheSyncService +{ + /** + * 查询缓存同步 + * + * @param deptId 缓存同步主键 + * @return 缓存同步 + */ + public IpcCacheSync selectIpcCacheSyncByDeptId(Long deptId); + + /** + * 去重查询缓存同步列表 + * + * @param ipcCacheSync 缓存同步 + * @return 缓存同步集合 + */ + public List selectIpcCacheSyncList(IpcCacheSync ipcCacheSync); + + /** + * 新增缓存同步 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + public int insertIpcCacheSync(IpcCacheSync ipcCacheSync); + + /** + * 修改缓存同步 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + public int updateIpcCacheSync(IpcCacheSync ipcCacheSync); + + /** + * 批量删除缓存同步 + * + * @param deptIds 需要删除的缓存同步主键集合 + * @return 结果 + */ + public int deleteIpcCacheSyncByDeptIds(Long[] deptIds); + + /** + * 删除缓存同步信息 + * + * @param deptId 缓存同步主键 + * @return 结果 + */ + public int deleteIpcCacheSyncByDeptId(Long deptId); + + /** + * 删除缓存同步信息 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + public int deleteIpcCacheSync(IpcCacheSync ipcCacheSync); +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/impl/IpcCacheSyncServiceImpl.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/impl/IpcCacheSyncServiceImpl.java new file mode 100644 index 0000000..9f83465 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/cache/service/impl/IpcCacheSyncServiceImpl.java @@ -0,0 +1,104 @@ +package com.inspur.cache.service.impl; + +import com.inspur.cache.domain.IpcCacheSync; +import com.inspur.cache.mapper.IpcCacheSyncMapper; +import com.inspur.cache.service.IIpcCacheSyncService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * 缓存同步Service业务层处理 + * + * @author zhanghan11 + * @date 2024-09-29 + */ +@Service +public class IpcCacheSyncServiceImpl implements IIpcCacheSyncService +{ + @Autowired + private IpcCacheSyncMapper ipcCacheSyncMapper; + + /** + * 查询缓存同步 + * + * @param deptId 缓存同步主键 + * @return 缓存同步 + */ + @Override + public IpcCacheSync selectIpcCacheSyncByDeptId(Long deptId) + { + return ipcCacheSyncMapper.selectIpcCacheSyncByDeptId(deptId); + } + + /** + * 去重查询缓存同步列表 + * + * @param ipcCacheSync 缓存同步 + * @return 缓存同步 + */ + @Override + public List selectIpcCacheSyncList(IpcCacheSync ipcCacheSync) + { + return ipcCacheSyncMapper.selectIpcCacheSyncList(ipcCacheSync); + } + + /** + * 新增缓存同步 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + @Override + public int insertIpcCacheSync(IpcCacheSync ipcCacheSync) + { + return ipcCacheSyncMapper.insertIpcCacheSync(ipcCacheSync); + } + + /** + * 修改缓存同步 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + @Override + public int updateIpcCacheSync(IpcCacheSync ipcCacheSync) + { + return ipcCacheSyncMapper.updateIpcCacheSync(ipcCacheSync); + } + + /** + * 批量删除缓存同步 + * + * @param deptIds 需要删除的缓存同步主键 + * @return 结果 + */ + @Override + public int deleteIpcCacheSyncByDeptIds(Long[] deptIds) + { + return ipcCacheSyncMapper.deleteIpcCacheSyncByDeptIds(deptIds); + } + + /** + * 删除缓存同步信息 + * + * @param deptId 缓存同步主键 + * @return 结果 + */ + @Override + public int deleteIpcCacheSyncByDeptId(Long deptId) + { + return ipcCacheSyncMapper.deleteIpcCacheSyncByDeptId(deptId); + } + /** + * 删除缓存同步信息 + * + * @param ipcCacheSync 缓存同步 + * @return 结果 + */ + @Override + public int deleteIpcCacheSync(IpcCacheSync ipcCacheSync){ + return ipcCacheSyncMapper.deleteIpcCacheSync(ipcCacheSync); + } +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/domain/IpcAlarmRecord.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/domain/IpcAlarmRecord.java index c4ab0ad..66232b1 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/domain/IpcAlarmRecord.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/domain/IpcAlarmRecord.java @@ -48,8 +48,8 @@ public class IpcAlarmRecord extends BaseEntity private BigDecimal alarmValue; /** 报警时间 */ - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:SS") - @Excel(name = "报警时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:SS") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @Excel(name = "报警时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") private Date alarmTime; /** 处理结果 */ diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/mapper/IpcAlarmRecordMapper.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/mapper/IpcAlarmRecordMapper.java index 45a351b..3c2f2c1 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/mapper/IpcAlarmRecordMapper.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/mapper/IpcAlarmRecordMapper.java @@ -28,6 +28,14 @@ public interface IpcAlarmRecordMapper */ public List selectIpcAlarmRecordList(IpcAlarmRecord ipcAlarmRecord); + /** + * 查询报警记录列表 + * + * @param ipcAlarmRecord 报警记录 + * @return 报警记录集合 + */ + public List selectIpcAlarmRecordListAll(IpcAlarmRecord ipcAlarmRecord); + /** * 新增报警记录 * diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRecordService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRecordService.java index 354f633..13bd774 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRecordService.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRecordService.java @@ -27,6 +27,14 @@ public interface IIpcAlarmRecordService */ public List selectIpcAlarmRecordList(IpcAlarmRecord ipcAlarmRecord); + /** + * 查询报警记录列表 + * + * @param ipcAlarmRecord 报警记录 + * @return 报警记录集合 + */ + public List selectIpcAlarmRecordListAll(IpcAlarmRecord ipcAlarmRecord); + /** * 新增报警记录 * diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRulesService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRulesService.java index 5f9b06a..8636483 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRulesService.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/IIpcAlarmRulesService.java @@ -11,6 +11,7 @@ import com.inspur.industrial.domain.IpcAlarmRules; */ public interface IIpcAlarmRulesService { + public void updateRedisCache(); /** * 查询设备报警规则 * diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRecordServiceImpl.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRecordServiceImpl.java index 9b1bf8a..8922d91 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRecordServiceImpl.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRecordServiceImpl.java @@ -47,6 +47,16 @@ public class IpcAlarmRecordServiceImpl implements IIpcAlarmRecordService return ipcAlarmRecordMapper.selectIpcAlarmRecordList(ipcAlarmRecord); } + /** + * 查询报警记录列表 + * + * @param ipcAlarmRecord 报警记录 + * @return 报警记录集合 + */ + @Override + public List selectIpcAlarmRecordListAll(IpcAlarmRecord ipcAlarmRecord){ + return ipcAlarmRecordMapper.selectIpcAlarmRecordListAll(ipcAlarmRecord); + } /** * 新增报警记录 * diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRulesServiceImpl.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRulesServiceImpl.java index 94927d3..4d896af 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRulesServiceImpl.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/service/impl/IpcAlarmRulesServiceImpl.java @@ -1,6 +1,7 @@ package com.inspur.industrial.service.impl; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @@ -43,16 +44,13 @@ public class IpcAlarmRulesServiceImpl implements IIpcAlarmRulesService { @Resource private IIpcEquipInfoService ipcEquipInfoService; - //加载规则到缓存 - @PostConstruct - public void init() { + @Override + public void updateRedisCache() { List equips = ipcEquipInfoService.selectIpcEquipInfoList(null); for (IpcEquipInfo equip : equips) { - if (!redisCache.hasKey((CacheConstants.IPC_RULES_KEY + equip.getId()))) { - List rulesList = selectIpcAlarmRulesByEquipId(equip.getId()); - redisCache.setCacheObject((CacheConstants.IPC_RULES_KEY + Constant.RUNNING + CacheConstants.SEPARATOR + equip.getId()), rulesList.stream().filter(ipcAlarmRules -> Constant.RUNNING.equals(ipcAlarmRules.getType())).collect(Collectors.toList())); - redisCache.setCacheObject((CacheConstants.IPC_RULES_KEY + Constant.TRY_RUNNING + CacheConstants.SEPARATOR + equip.getId()), rulesList.stream().filter(ipcAlarmRules -> Constant.TRY_RUNNING.equals(ipcAlarmRules.getType())).collect(Collectors.toList())); - } + List rulesList = selectIpcAlarmRulesByEquipId(equip.getId()); + redisCache.setCacheObject((CacheConstants.IPC_RULES_KEY + Constant.RUNNING + CacheConstants.SEPARATOR + equip.getId()), rulesList.stream().filter(ipcAlarmRules -> Constant.RUNNING.equals(ipcAlarmRules.getType())).collect(Collectors.toList())); + redisCache.setCacheObject((CacheConstants.IPC_RULES_KEY + Constant.TRY_RUNNING + CacheConstants.SEPARATOR + equip.getId()), rulesList.stream().filter(ipcAlarmRules -> Constant.TRY_RUNNING.equals(ipcAlarmRules.getType())).collect(Collectors.toList())); } } diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/Constant.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/Constant.java index 5bffa14..7f02791 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/Constant.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/Constant.java @@ -56,4 +56,27 @@ public class Constant { * 试运行 */ public static final Integer TRY_RUNNING = 1; + + /** + * 缓存类型-参数 + */ + public static final String CACHE_TYPE_PARAMS = "params"; + + /** + * 缓存类型-规则 + */ + public static final String CACHE_TYPE_RULES = "rules"; + + /** + * 云端 + */ + public static final String MODEL_CLOUD = "cloud"; + /** + * 工控机端 + */ + public static final String MODEL_CLIENT = "client"; + /** + * 其他端 + */ + public static final String MODEL_OTHER = "other"; } diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcRedisCacheConfiguration.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcRedisCacheConfiguration.java new file mode 100644 index 0000000..05934cc --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcRedisCacheConfiguration.java @@ -0,0 +1,81 @@ +package com.inspur.industrial.utils; + +import com.inspur.cache.domain.IpcCacheSync; +import com.inspur.cache.service.IIpcCacheSyncService; +import com.inspur.common.constant.Constants; +import com.inspur.common.utils.spring.SpringUtils; +import com.inspur.industrial.service.IIpcAlarmRulesService; +import com.inspur.system.service.influx.InfluxDBService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import java.time.LocalDate; +import java.util.List; + +@Configuration +@Component("ipcRedisCacheConfiguration") +public class IpcRedisCacheConfiguration { + @Autowired + private IIpcAlarmRulesService ipcAlarmRulesService; + @Autowired + private IIpcCacheSyncService iIpcCacheSyncService; + + @Value("${zfipc.model}") + private String model; + @Value("${zfipc.deptId}") + private Long deptId; + + /** + * 预加载缓存 + */ + @PostConstruct + public void preloadedRedisCache() { + // 工控机端更新规则和设备状态 + if (Constant.MODEL_CLIENT.equals(model)) { + ipcAlarmRulesService.updateRedisCache(); + } + + } + + public void updateCache() { + // 查询是否需要更新 + IpcCacheSync ipcCacheSync = new IpcCacheSync(deptId, null, model); + List list = iIpcCacheSyncService.selectIpcCacheSyncList(ipcCacheSync); + System.out.println("缓存更新:"+deptId); + + if(!list.isEmpty()){ + for(IpcCacheSync cacheSync:list){ + switch(cacheSync.getType()){ + case Constant.CACHE_TYPE_RULES: + ipcAlarmRulesService.updateRedisCache(); + break; + case Constant.CACHE_TYPE_PARAMS: + break; + default: + break; + } + } + // 删除更新标识 + iIpcCacheSyncService.deleteIpcCacheSync(ipcCacheSync); + } + } + + public void deleteExpDataByDate(Integer params) + { + System.out.println("执行有参方法删除过期数据:" + params); + InfluxDBService i = SpringUtils.getBean(InfluxDBService.class); + StringBuffer sql1 = new StringBuffer(""); + StringBuffer sql2 = new StringBuffer(""); + StringBuffer sql3 = new StringBuffer(""); + sql1.append("SELECT * FROM ").append(Constants.MEASUREMENT_BOTTOM_CY_LINDER).append(" where isAlarm = '0' and time < '").append(LocalDate.now().toString()).append("T00:00:00Z' -8h -").append(params.toString()).append("d"); + sql2.append("SELECT * FROM ").append(Constants.MEASUREMENT_TOP_SCOLLER).append(" where isAlarm = '0' and time < '").append(LocalDate.now().toString()).append("T00:00:00Z' -8h -").append(params.toString()).append("d"); + sql3.append("SELECT * FROM ").append(Constants.MEASUREMENT_BOTTOM_SCOLLER).append(" where isAlarm = '0' and time < '").append(LocalDate.now().toString()).append("T00:00:00Z' -8h -").append(params.toString()).append("d"); + + i.query(sql1.toString()); + i.query(sql2.toString()); + i.query(sql3.toString()); + } +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcUtil.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcUtil.java index 5d85332..afc6945 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcUtil.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/industrial/utils/IpcUtil.java @@ -8,9 +8,7 @@ import com.inspur.industrial.domain.IpcAlarmRules; import org.springframework.stereotype.Component; import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; @Component public class IpcUtil { @@ -96,7 +94,7 @@ public class IpcUtil { // 默认正常数据 String isAlarm = "0"; for (IpcAlarmRules rule : rulesList) { - // 判断是否当前参数类型 0:开机 + // 判断是否当前参数类型 0:运行中,1:试运行 if (type == rule.getType()) { if (judgeAlarm(map.get(rule.getAlarmNameKey()), rule.getAlertLowerBound(), rule.getAlertUpperBound(), rule.getReferenceCon(), map.get(rule.getBaseValue()), rule.getBaseValueLowerBound(), rule.getBaseValueUpperBound())) { // 报警数据 @@ -109,7 +107,7 @@ public class IpcUtil { String name = rule.getAlarmNameKey(); ipcAlarmRecord.setAlarmValue(BigDecimal.valueOf((Float) map.get(name))); ipcAlarmRecord.setNameKey(name); - ipcAlarmRecord.setContent(type == 0 ? "(开机监测)" + rule.getReferenceName() : rule.getReferenceName()); + ipcAlarmRecord.setContent(rule.getReferenceName()); ipcAlarmRecord.setStatus(0); ipcAlarmRecord.setOperator(1L); ipcAlarmRecord.setAlarmLevel(rule.getAlarmLevel()); diff --git a/zfipc-server/zfipc-system/src/main/resources/mapper/cache/IpcCacheSyncMapper.xml b/zfipc-server/zfipc-system/src/main/resources/mapper/cache/IpcCacheSyncMapper.xml new file mode 100644 index 0000000..46d13a5 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/resources/mapper/cache/IpcCacheSyncMapper.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + select dept_id, type, model from ipc_cache_sync + + + + + + + + insert into ipc_cache_sync + + dept_id, + type, + model, + + + #{deptId}, + #{type}, + #{model}, + + + + + update ipc_cache_sync + + type = #{type}, + model = #{model}, + + where dept_id = #{deptId} + + + + delete from ipc_cache_sync where dept_id = #{deptId} + + + + delete from ipc_cache_sync where dept_id in + + #{deptId} + + + + delete from ipc_cache_sync where dept_id = #{deptId} and model = #{model} + + diff --git a/zfipc-server/zfipc-system/src/main/resources/mapper/industrial/IpcAlarmRecordMapper.xml b/zfipc-server/zfipc-system/src/main/resources/mapper/industrial/IpcAlarmRecordMapper.xml index ffcba84..e8f90a0 100644 --- a/zfipc-server/zfipc-system/src/main/resources/mapper/industrial/IpcAlarmRecordMapper.xml +++ b/zfipc-server/zfipc-system/src/main/resources/mapper/industrial/IpcAlarmRecordMapper.xml @@ -77,6 +77,27 @@ order by a.alarm_time desc + +