|
@@ -0,0 +1,77 @@
|
|
|
|
|
+package com.inspur.customer.service.tenant;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.cola.exception.BizException;
|
|
|
|
|
+import com.inspur.customer.client.keycloak.KeycloakService;
|
|
|
|
|
+import com.inspur.customer.client.tenant.TenantExceptionInformStrategyService;
|
|
|
|
|
+import com.inspur.customer.client.tenant.UserInformService;
|
|
|
|
|
+import com.inspur.customer.context.inform.InformLevelEnum;
|
|
|
|
|
+import com.inspur.customer.context.inform.InformTypeEnum;
|
|
|
|
|
+import com.inspur.customer.object.inform.InformAddresseeCO;
|
|
|
|
|
+import com.inspur.customer.object.keycloak.KeycloakUserCO;
|
|
|
|
|
+import com.inspur.customer.object.tenant.TenantExceptionInformStrategyCO;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
|
|
+import org.apache.dubbo.config.annotation.DubboService;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Nullable;
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
+import java.util.Collections;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * @author linwenhua
|
|
|
|
|
+ * @date 2022-12-02 16:19
|
|
|
|
|
+ **/
|
|
|
|
|
+@Slf4j
|
|
|
|
|
+@DubboService(interfaceClass = UserInformService.class)
|
|
|
|
|
+public class UserInformServiceImpl implements UserInformService {
|
|
|
|
|
+
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private KeycloakService keycloakService;
|
|
|
|
|
+ @DubboReference
|
|
|
|
|
+ private TenantExceptionInformStrategyService tenantExceptionInformStrategyService;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public InformAddresseeCO getInformAddresseesByInformLevel(@Nullable String userId, String tenant, List<String> org, InformLevelEnum informLevel) {
|
|
|
|
|
+ // get base user
|
|
|
|
|
+ List<KeycloakUserCO> users = new ArrayList<>();
|
|
|
|
|
+ InformAddresseeCO informAddressee = new InformAddresseeCO();
|
|
|
|
|
+ if (userId != null) {
|
|
|
|
|
+ users.addAll(keycloakService.getUsersByIds(Collections.singletonList(userId)));
|
|
|
|
|
+ }
|
|
|
|
|
+ // get and set inform strategy
|
|
|
|
|
+ log.info("tenant: {}", tenant);
|
|
|
|
|
+ TenantExceptionInformStrategyCO informStrategy = tenantExceptionInformStrategyService.getTenantInformStrategyCache(tenant);
|
|
|
|
|
+ informAddressee.setInformStrategy(informStrategy.getInformStrategy(String.valueOf(informLevel.getId())));
|
|
|
|
|
+ // get additional user
|
|
|
|
|
+ switch (informLevel) {
|
|
|
|
|
+ case HINT: {
|
|
|
|
|
+ log.info("hint");
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case INTERMEDIATE: {
|
|
|
|
|
+ log.info("intermediate");
|
|
|
|
|
+ //todo replace get user method
|
|
|
|
|
+ users.addAll(keycloakService.getUsersInRole("ROLE_SUPER_ADMIN"));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case URGENT: {
|
|
|
|
|
+ log.info("urgent");
|
|
|
|
|
+ //todo replace get user method
|
|
|
|
|
+ users.addAll(keycloakService.getUsersInRole("ROLE_SUPER_ADMIN"));
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ default: {
|
|
|
|
|
+ log.info("not support");
|
|
|
|
|
+ throw new BizException("500", "类型错误");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ informAddressee.setUsers(users);
|
|
|
|
|
+ return informAddressee;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public InformAddresseeCO getInformAddresseesByInformType(@Nullable String userId, String tenant, List<String> orgs, InformTypeEnum informType) {
|
|
|
|
|
+ return getInformAddresseesByInformLevel(userId, tenant, orgs, informType.getLevel());
|
|
|
|
|
+ }
|
|
|
|
|
+}
|