diff --git a/tyr-server/pom.xml b/tyr-server/pom.xml
index 7b7f6217..49da2119 100644
--- a/tyr-server/pom.xml
+++ b/tyr-server/pom.xml
@@ -144,6 +144,12 @@
alibaba-dingtalk-service-sdk
2.0.0
+
+
+ cn.axzo.platform
+ axzo-log-api
+ 1.0.0-SNAPSHOT
+
diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/config/RocketMQEventConfiguration.java b/tyr-server/src/main/java/cn/axzo/tyr/server/config/RocketMQEventConfiguration.java
index 86ff70f1..6f7170b9 100644
--- a/tyr-server/src/main/java/cn/axzo/tyr/server/config/RocketMQEventConfiguration.java
+++ b/tyr-server/src/main/java/cn/axzo/tyr/server/config/RocketMQEventConfiguration.java
@@ -15,6 +15,7 @@ import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import java.util.function.Consumer;
@@ -63,6 +64,7 @@ public class RocketMQEventConfiguration {
return new DefaultEventConsumer(appName, eventHandlerRepository, callback);
}
+ @Profile("!unittest")
@Slf4j
@Component
@RocketMQMessageListener(topic = "topic_thrones_${spring.profiles.active}",
@@ -81,6 +83,7 @@ public class RocketMQEventConfiguration {
}
}
+ @Profile("!unittest")
@Slf4j
@Component
@RocketMQMessageListener(topic = "topic_tyr_${spring.profiles.active}",
@@ -99,6 +102,7 @@ public class RocketMQEventConfiguration {
}
}
+ @Profile("!unittest")
@Slf4j
@Component
@RocketMQMessageListener(topic = "topic_apisix_plat_${spring.profiles.active}",
diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/config/exception/BizResultCode.java b/tyr-server/src/main/java/cn/axzo/tyr/server/config/exception/BizResultCode.java
index 656ea649..656f8860 100644
--- a/tyr-server/src/main/java/cn/axzo/tyr/server/config/exception/BizResultCode.java
+++ b/tyr-server/src/main/java/cn/axzo/tyr/server/config/exception/BizResultCode.java
@@ -13,7 +13,8 @@ public enum BizResultCode implements IResultCode {
REDIS_ROLE_NOT_NULL("100003", "角色id不能为空"),
REDIS_PRODUCT_NOT_NULL("100004", "产品不能为空"),
FEATURE_RESOURCE_NOT_FOUND("100005", "菜单资源不存在"),
- WORKSPACE_ID_NOT_NULL("100006", "项目id不能为空");
+ WORKSPACE_ID_NOT_NULL("100006", "项目id不能为空"),
+ REMOVE_USER_ROLE_ERROR("100007", "删除用户角色数据异常");
private String errorCode;
private String errorMessage;
diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/event/inner/EventTypeEnum.java b/tyr-server/src/main/java/cn/axzo/tyr/server/event/inner/EventTypeEnum.java
index 3883080e..ab8f938b 100644
--- a/tyr-server/src/main/java/cn/axzo/tyr/server/event/inner/EventTypeEnum.java
+++ b/tyr-server/src/main/java/cn/axzo/tyr/server/event/inner/EventTypeEnum.java
@@ -11,6 +11,7 @@ public enum EventTypeEnum {
SAAS_FEATURE_UPSERT("saas-feature", "saas-feature-upsert", "旧菜单树更新"),
SAAS_FEATURE_RESOURCE_UPSERT("saas-feature-resource", "saas-feature-resource-upsert", "新菜单树更新"),
PAGE_ELEMENT_FEATURE_RESOURCE_UPSERT("page-element-feature-resource", "page-element-feature-resource-upsert", "菜单-页面元素绑定关系更新"),
+ SAAS_ROLE_USER_RELATION_REMOVED("saas-role-user-relation", "saas-role-user-relation-removed", "删除用户角色信息"),
;
EventTypeEnum(String model, String name, String desc) {
diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/event/payload/SaasRoleUserRelationRemovePayload.java b/tyr-server/src/main/java/cn/axzo/tyr/server/event/payload/SaasRoleUserRelationRemovePayload.java
new file mode 100644
index 00000000..6fd72f87
--- /dev/null
+++ b/tyr-server/src/main/java/cn/axzo/tyr/server/event/payload/SaasRoleUserRelationRemovePayload.java
@@ -0,0 +1,19 @@
+package cn.axzo.tyr.server.event.payload;
+
+import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import java.io.Serializable;
+import java.util.List;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class SaasRoleUserRelationRemovePayload implements Serializable {
+
+ private List values;
+}
diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleUserRelationService.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleUserRelationService.java
index 6a8a6089..52b4a13b 100644
--- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleUserRelationService.java
+++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/SaasRoleUserRelationService.java
@@ -5,8 +5,13 @@ import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import com.baomidou.mybatisplus.extension.service.IService;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
import java.util.List;
+import java.util.Set;
/**
* @author haiyangjin
@@ -19,4 +24,17 @@ public interface SaasRoleUserRelationService extends IService page(PageRoleUserRelationParam param);
void upsert(List saasRoleUserRelations);
+
+ void batchRemove(BatchRemoveParam param);
+
+ @Data
+ @Builder
+ @NoArgsConstructor
+ @AllArgsConstructor
+ class BatchRemoveParam {
+
+ private Set ids;
+
+ private Long operator;
+ }
}
diff --git a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleUserRelationServiceImpl.java b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleUserRelationServiceImpl.java
index 1a05911c..c710ee64 100644
--- a/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleUserRelationServiceImpl.java
+++ b/tyr-server/src/main/java/cn/axzo/tyr/server/service/impl/SaasRoleUserRelationServiceImpl.java
@@ -1,13 +1,19 @@
package cn.axzo.tyr.server.service.impl;
+import cn.axzo.basics.common.constant.enums.TableIsDeleteEnum;
import cn.axzo.basics.profiles.api.UserProfileServiceApi;
import cn.axzo.basics.profiles.dto.basic.PersonProfileDto;
import cn.axzo.foundation.dao.support.converter.PageConverter;
import cn.axzo.foundation.dao.support.mysql.QueryWrapperHelper;
+import cn.axzo.foundation.exception.Axssert;
+import cn.axzo.framework.rocketmq.Event;
+import cn.axzo.log.platform.client.LogPlatClient;
import cn.axzo.tyr.client.model.res.SaasRoleRes;
import cn.axzo.tyr.client.model.roleuser.dto.SaasRoleUserV2DTO;
import cn.axzo.tyr.client.model.roleuser.req.ListRoleUserRelationParam;
import cn.axzo.tyr.client.model.roleuser.req.PageRoleUserRelationParam;
+import cn.axzo.tyr.server.config.MqProducer;
+import cn.axzo.tyr.server.event.payload.SaasRoleUserRelationRemovePayload;
import cn.axzo.tyr.server.repository.entity.SaasRoleUserRelation;
import cn.axzo.tyr.server.repository.mapper.SaasRoleUserRelationMapper;
import cn.axzo.tyr.server.service.RoleService;
@@ -36,6 +42,9 @@ import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
+import static cn.axzo.tyr.server.config.exception.BizResultCode.REMOVE_USER_ROLE_ERROR;
+import static cn.axzo.tyr.server.event.inner.EventTypeEnum.SAAS_ROLE_USER_RELATION_REMOVED;
+
/**
* @author haiyangjin
* @date 2023/9/14
@@ -49,6 +58,12 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl listV2(ListRoleUserRelationParam param) {
@@ -98,6 +113,36 @@ public class SaasRoleUserRelationServiceImpl extends ServiceImpl saasRoleUserRelations = this.listByIds(param.getIds());
+
+ // 不做准确的提示,防止恶意删数据
+ Axssert.check(Objects.equals(param.getIds().size(), saasRoleUserRelations.size()),
+ REMOVE_USER_ROLE_ERROR);
+
+ this.lambdaUpdate()
+ .in(SaasRoleUserRelation::getId, param.getIds())
+ .set(SaasRoleUserRelation::getIsDelete, TableIsDeleteEnum.DELETE.value)
+ .set(Objects.nonNull(param.getOperator()), SaasRoleUserRelation::getUpdateBy, param.getOperator())
+ .update();
+
+ Event event = Event.builder()
+ .targetType(TARGET_TYPE)
+ .eventCode(SAAS_ROLE_USER_RELATION_REMOVED.getEventCode())
+ .data(SaasRoleUserRelationRemovePayload.builder()
+ .values(saasRoleUserRelations)
+ .build())
+ .build();
+ mqProducer.send(event);
+ }
+
private Set resolveRoleIds(PageRoleUserRelationParam param) {
if (CollectionUtils.isEmpty(param.getRoleCodes())) {
return Optional.ofNullable(param.getRoleIds())
diff --git a/tyr-server/src/test/java/cn/axzo/tyr/base/TestConfig.java b/tyr-server/src/test/java/cn/axzo/tyr/base/TestConfig.java
index 177fd203..802471b6 100644
--- a/tyr-server/src/test/java/cn/axzo/tyr/base/TestConfig.java
+++ b/tyr-server/src/test/java/cn/axzo/tyr/base/TestConfig.java
@@ -1,16 +1,20 @@
package cn.axzo.tyr.base;
+import cn.axzo.framework.rocketmq.Event;
+import cn.axzo.framework.rocketmq.EventProducer;
import cn.axzo.thrones.client.saas.ServicePkgClient;
-import cn.axzo.tyr.base.MysqlDataLoader;
+import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Primary;
import redis.embedded.RedisServer;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
+import java.util.Map;
@Slf4j
@TestConfiguration
@@ -38,4 +42,25 @@ public class TestConfig {
@MockBean
private ServicePkgClient servicePkgClient;
+
+ @Bean
+ @Primary
+ public EventProducer