From 78dbf52f61ace94ba86ea320894518fb7c938a09 Mon Sep 17 00:00:00 2001 From: gaoxihui Date: Fri, 26 Dec 2025 18:27:43 +0800 Subject: [PATCH 1/2] refactor: extend the id column in the hera_app_role table to the bigint type --- .../app/api/service/HeraAppService.java | 2 +- .../apache/ozhera/app/dao/HeraAppRoleDao.java | 2 +- .../app/dao/mapper/HeraAppRoleMapper.java | 4 ++-- .../apache/ozhera/app/model/HeraAppRole.java | 8 +++---- .../ozhera/app/model/HeraAppRoleExample.java | 20 ++++++++--------- .../app/service/HeraAppRoleService.java | 2 +- .../app/service/impl/HeraAppServiceImpl.java | 2 +- .../service/mq/RocketMqHeraAppConsumer.java | 9 ++++++++ .../resources/mapper/HeraAppRoleMapper.xml | 22 +++++++++---------- .../controller/AppMonitorController.java | 2 +- .../monitor/service/HeraBaseInfoService.java | 2 +- .../service/impl/HeraBaseInfoServiceImpl.java | 2 +- 12 files changed, 43 insertions(+), 34 deletions(-) diff --git a/ozhera-app/app-api/src/main/java/org/apache/ozhera/app/api/service/HeraAppService.java b/ozhera-app/app-api/src/main/java/org/apache/ozhera/app/api/service/HeraAppService.java index d160c97db..cb438b83b 100644 --- a/ozhera-app/app-api/src/main/java/org/apache/ozhera/app/api/service/HeraAppService.java +++ b/ozhera-app/app-api/src/main/java/org/apache/ozhera/app/api/service/HeraAppService.java @@ -63,7 +63,7 @@ public interface HeraAppService { Long getAppCount(); - Integer delRoleById(Integer id); + Integer delRoleById(Long id); Integer addRole(HeraAppRoleModel roleModel); diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/HeraAppRoleDao.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/HeraAppRoleDao.java index 8feb8b0f1..5e33ef7f7 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/HeraAppRoleDao.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/HeraAppRoleDao.java @@ -37,7 +37,7 @@ public class HeraAppRoleDao { @Resource private HeraAppRoleMapper heraAppRoleMapper; - public Integer delById(Integer id){ + public Integer delById(Long id){ if(id == null){ log.error("HeraAppRoleDao.delById invalid param,id is null"); } diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/mapper/HeraAppRoleMapper.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/mapper/HeraAppRoleMapper.java index 2812b5d70..860a84595 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/mapper/HeraAppRoleMapper.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/dao/mapper/HeraAppRoleMapper.java @@ -33,7 +33,7 @@ public interface HeraAppRoleMapper extends BaseMapper { int deleteByExample(HeraAppRoleExample example); - int deleteByPrimaryKey(Integer id); + int deleteByPrimaryKey(Long id); int insert(HeraAppRole record); @@ -41,7 +41,7 @@ public interface HeraAppRoleMapper extends BaseMapper { List selectByExample(HeraAppRoleExample example); - HeraAppRole selectByPrimaryKey(Integer id); + HeraAppRole selectByPrimaryKey(Long id); int updateByExampleSelective(@Param("record") HeraAppRole record, @Param("example") HeraAppRoleExample example); diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRole.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRole.java index 2148bc9ab..a4eba2391 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRole.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRole.java @@ -31,7 +31,7 @@ @TableName("hera_app_role") public class HeraAppRole { @TableId(value = "id", type = IdType.AUTO) - private Integer id; + private Long id; private String appId; @@ -47,11 +47,11 @@ public class HeraAppRole { private Date updateTime; - public Integer getId() { + public Long getId() { return id; } - public void setId(Integer id) { + public void setId(Long id) { this.id = id; } @@ -112,7 +112,7 @@ public void setUpdateTime(Date updateTime) { } public enum Column { - id("id", "id", "INTEGER", false), + id("id", "id", "LONG", false), appId("app_id", "appId", "VARCHAR", false), appPlatform("app_platform", "appPlatform", "INTEGER", false), user("user", "user", "VARCHAR", false), diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRoleExample.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRoleExample.java index 419a254bb..f137c0675 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRoleExample.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/model/HeraAppRoleExample.java @@ -153,52 +153,52 @@ public Criteria andIdIsNotNull() { return (Criteria) this; } - public Criteria andIdEqualTo(Integer value) { + public Criteria andIdEqualTo(Long value) { addCriterion("id =", value, "id"); return (Criteria) this; } - public Criteria andIdNotEqualTo(Integer value) { + public Criteria andIdNotEqualTo(Long value) { addCriterion("id <>", value, "id"); return (Criteria) this; } - public Criteria andIdGreaterThan(Integer value) { + public Criteria andIdGreaterThan(Long value) { addCriterion("id >", value, "id"); return (Criteria) this; } - public Criteria andIdGreaterThanOrEqualTo(Integer value) { + public Criteria andIdGreaterThanOrEqualTo(Long value) { addCriterion("id >=", value, "id"); return (Criteria) this; } - public Criteria andIdLessThan(Integer value) { + public Criteria andIdLessThan(Long value) { addCriterion("id <", value, "id"); return (Criteria) this; } - public Criteria andIdLessThanOrEqualTo(Integer value) { + public Criteria andIdLessThanOrEqualTo(Long value) { addCriterion("id <=", value, "id"); return (Criteria) this; } - public Criteria andIdIn(List values) { + public Criteria andIdIn(List values) { addCriterion("id in", values, "id"); return (Criteria) this; } - public Criteria andIdNotIn(List values) { + public Criteria andIdNotIn(List values) { addCriterion("id not in", values, "id"); return (Criteria) this; } - public Criteria andIdBetween(Integer value1, Integer value2) { + public Criteria andIdBetween(Long value1, Long value2) { addCriterion("id between", value1, value2, "id"); return (Criteria) this; } - public Criteria andIdNotBetween(Integer value1, Integer value2) { + public Criteria andIdNotBetween(Long value1, Long value2) { addCriterion("id not between", value1, value2, "id"); return (Criteria) this; } diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/HeraAppRoleService.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/HeraAppRoleService.java index 217f707cb..9f1d6c182 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/HeraAppRoleService.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/HeraAppRoleService.java @@ -41,7 +41,7 @@ public class HeraAppRoleService { @Autowired HeraAppRoleDao dao; - public Integer delById(Integer id){ + public Integer delById(Long id){ return dao.delById(id); } diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/impl/HeraAppServiceImpl.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/impl/HeraAppServiceImpl.java index 6d886ac7b..8bc926578 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/impl/HeraAppServiceImpl.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/impl/HeraAppServiceImpl.java @@ -311,7 +311,7 @@ public Long getAppCount() { } @Override - public Integer delRoleById(Integer id) { + public Integer delRoleById(Long id) { return roleService.delById(id); } diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java index aea6ccdf9..297f67eb6 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java @@ -79,6 +79,10 @@ public class RocketMqHeraAppConsumer { @NacosValue(value = "${rocketmq.sk}", autoRefreshed = true) private String sk; + //默认为空,根据需要配置 + @NacosValue(value = "${stop.mq:false}", autoRefreshed = true) + private Boolean stopMq; + private DefaultMQPushConsumer heraAppMQPushConsumer; @Autowired @@ -208,6 +212,11 @@ private HeraAppBaseInfo matchExistHeraApp(HeraAppBaseInfo heraAppBaseInfo){ private void saveOrUpdateHeraAppRole(List members, String appId, Integer platFormType) { + if(stopMq){ + log.info("Mq consumer stop ..."); + return; + } + log.info("RocketMqHeraAppConsumer#saveOrUpdateHeraAppRole appId:{},platFormType:{},members:{}", appId, platFormType, members); if (CollectionUtils.isEmpty(members)) { return; diff --git a/ozhera-app/app-service/src/main/resources/mapper/HeraAppRoleMapper.xml b/ozhera-app/app-service/src/main/resources/mapper/HeraAppRoleMapper.xml index 63abc713b..32ccc3565 100644 --- a/ozhera-app/app-service/src/main/resources/mapper/HeraAppRoleMapper.xml +++ b/ozhera-app/app-service/src/main/resources/mapper/HeraAppRoleMapper.xml @@ -22,7 +22,7 @@ - + @@ -109,15 +109,15 @@ limit #{offset} , #{limit} - select from hera_app_role - where id = #{id,jdbcType=INTEGER} + where id = #{id,jdbcType=BIGINT} - + delete from hera_app_role - where id = #{id,jdbcType=INTEGER} + where id = #{id,jdbcType=BIGINT} delete from hera_app_role @@ -126,7 +126,7 @@ - + SELECT LAST_INSERT_ID() insert into hera_app_role (app_id, app_platform, user, @@ -137,7 +137,7 @@ #{updateTime,jdbcType=TIMESTAMP}) - + SELECT LAST_INSERT_ID() insert into hera_app_role @@ -198,7 +198,7 @@ update hera_app_role - id = #{record.id,jdbcType=INTEGER}, + id = #{record.id,jdbcType=BIGINT}, app_id = #{record.appId,jdbcType=VARCHAR}, @@ -228,7 +228,7 @@ update hera_app_role - set id = #{record.id,jdbcType=INTEGER}, + set id = #{record.id,jdbcType=BIGINT}, app_id = #{record.appId,jdbcType=VARCHAR}, app_platform = #{record.appPlatform,jdbcType=INTEGER}, user = #{record.user,jdbcType=VARCHAR}, @@ -265,7 +265,7 @@ update_time = #{updateTime,jdbcType=TIMESTAMP}, - where id = #{id,jdbcType=INTEGER} + where id = #{id,jdbcType=BIGINT} update hera_app_role @@ -276,7 +276,7 @@ status = #{status,jdbcType=INTEGER}, create_time = #{createTime,jdbcType=TIMESTAMP}, update_time = #{updateTime,jdbcType=TIMESTAMP} - where id = #{id,jdbcType=INTEGER} + where id = #{id,jdbcType=BIGINT} insert into hera_app_role diff --git a/ozhera-monitor/ozhera-monitor-server/src/main/java/org/apache/ozhera/monitor/controller/AppMonitorController.java b/ozhera-monitor/ozhera-monitor-server/src/main/java/org/apache/ozhera/monitor/controller/AppMonitorController.java index 5dc3ca0c7..a563e0b10 100644 --- a/ozhera-monitor/ozhera-monitor-server/src/main/java/org/apache/ozhera/monitor/controller/AppMonitorController.java +++ b/ozhera-monitor/ozhera-monitor-server/src/main/java/org/apache/ozhera/monitor/controller/AppMonitorController.java @@ -130,7 +130,7 @@ public Result addHeraRole(HeraAppRoleModel role) { @ResponseBody @GetMapping("/mimonitor/delHeraRole") - public Result delHeraRole(Integer id) { + public Result delHeraRole(Long id) { return heraBaseInfoService.delRole(id); diff --git a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/HeraBaseInfoService.java b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/HeraBaseInfoService.java index 593e8ab8b..b7597a5ca 100644 --- a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/HeraBaseInfoService.java +++ b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/HeraBaseInfoService.java @@ -34,7 +34,7 @@ public interface HeraBaseInfoService { Result addRole(HeraAppRoleModel model); - Result delRole(Integer id); + Result delRole(Long id); Result queryRole(HeraAppRoleModel model, Integer pageNo, Integer pageCount); diff --git a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/HeraBaseInfoServiceImpl.java b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/HeraBaseInfoServiceImpl.java index 5ae5dd5fb..de5f0eede 100644 --- a/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/HeraBaseInfoServiceImpl.java +++ b/ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/HeraBaseInfoServiceImpl.java @@ -89,7 +89,7 @@ public Result addRole(HeraAppRoleModel model) { } @Override - public Result delRole(Integer id) { + public Result delRole(Long id) { Integer i = hearAppService.delRoleById(id); if (i.intValue() > 0) { From 4621480ece87f64029f79598acbe3bb1c17058c2 Mon Sep 17 00:00:00 2001 From: gaoxihui Date: Thu, 8 Jan 2026 10:51:38 +0800 Subject: [PATCH 2/2] feat: allow configuring platform codes to prohibit MQ messages from accessing the database --- .../service/mq/RocketMqHeraAppConsumer.java | 48 +++++++++++++++---- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java index 297f67eb6..203192731 100644 --- a/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java +++ b/ozhera-app/app-service/src/main/java/org/apache/ozhera/app/service/mq/RocketMqHeraAppConsumer.java @@ -20,6 +20,7 @@ import com.alibaba.nacos.api.config.annotation.NacosValue; import com.google.gson.Gson; +import org.apache.commons.collections.CollectionUtils; import org.apache.ozhera.app.api.message.HeraAppInfoModifyMessage; import org.apache.ozhera.app.api.message.HeraAppModifyType; import org.apache.ozhera.app.api.model.HeraAppBaseInfoModel; @@ -30,7 +31,6 @@ import org.apache.ozhera.app.service.impl.HeraAppBaseInfoService; import org.apache.ozhera.app.service.mq.model.HeraAppMessage; import lombok.extern.slf4j.Slf4j; -import org.apache.dubbo.common.utils.CollectionUtils; import org.apache.dubbo.common.utils.StringUtils; import org.apache.rocketmq.acl.common.AclClientRPCHook; import org.apache.rocketmq.acl.common.SessionCredentials; @@ -47,6 +47,7 @@ import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; +import java.util.Arrays; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -79,10 +80,13 @@ public class RocketMqHeraAppConsumer { @NacosValue(value = "${rocketmq.sk}", autoRefreshed = true) private String sk; - //默认为空,根据需要配置 + //stop mq consumer @NacosValue(value = "${stop.mq:false}", autoRefreshed = true) private Boolean stopMq; + @NacosValue(value = "${stop.mq.message.plat.code:}", autoRefreshed = true) + private String mqStopPlatCode; + private DefaultMQPushConsumer heraAppMQPushConsumer; @Autowired @@ -157,6 +161,35 @@ private void consumeMessage(MessageExt message) { log.info("RocketMqHeraAppConsumer# consumeMessage convert heraAppMessage : {}", heraAppMessage.toString()); HeraAppBaseInfo changeHeraApp = heraAppMessage.baseInfo(); + + + if(stopMq){ + + log.info("Mq consumer stop ..."); + if(StringUtils.isBlank(mqStopPlatCode)){ + log.info("mqStopPlatCode is blank, stop all mq message access db!"); + return; + } + + + List platCodes = Arrays.stream(mqStopPlatCode.split(",")) + .map(String::trim) + .map(Integer::parseInt) + .collect(Collectors.toList()); + + if(CollectionUtils.isEmpty(platCodes)){ + log.info("platCodes is empty, stop all mq message access db!"); + return; + } + + if(platCodes.contains(changeHeraApp.getPlatformType())){ + log.info("stop mq access db by plat code : " + changeHeraApp.getPlatformType() + " ; config plat codes " + platCodes); + return; + } + + } + + HeraAppBaseInfo origHeraApp = matchExistHeraApp(heraAppMessage.baseInfo()); if (heraAppMessage.getDelete() != null && heraAppMessage.getDelete().intValue() == 1) { @@ -210,17 +243,14 @@ private HeraAppBaseInfo matchExistHeraApp(HeraAppBaseInfo heraAppBaseInfo){ return query.get(0); } - private void saveOrUpdateHeraAppRole(List members, String appId, Integer platFormType) { + private void saveOrUpdateHeraAppRole(List membersP, String appId, Integer platFormType) { - if(stopMq){ - log.info("Mq consumer stop ..."); + log.info("RocketMqHeraAppConsumer#saveOrUpdateHeraAppRole appId:{},platFormType:{},members:{}", appId, platFormType, membersP); + if (CollectionUtils.isEmpty(membersP)) { return; } - log.info("RocketMqHeraAppConsumer#saveOrUpdateHeraAppRole appId:{},platFormType:{},members:{}", appId, platFormType, members); - if (CollectionUtils.isEmpty(members)) { - return; - } + List members = membersP.stream().distinct().collect(Collectors.toList()); HeraAppRole role = new HeraAppRole(); role.setRole(0);