Bläddra i källkod

Merge remote-tracking branch 'origin/dev' into dev2

wangmh 7 år sedan
förälder
incheckning
46e6494c20

+ 1 - 0
sso-manage-console/build.gradle

@@ -23,6 +23,7 @@ dependencies {
   compile project(":sso-common")
   compile project(path: ":sso-server", configuration: "persist")  // Project Lib
 
+  compile("com.google.guava:guava:23.6-jre")
   compile("org.springframework.boot:spring-boot-starter-web")
   compile("org.springframework.boot:spring-boot-starter-thymeleaf")
   compile("org.springframework.boot:spring-boot-starter-data-jpa")

+ 28 - 0
sso-manage-console/src/main/java/com/uas/sso/sso/backend/config/ThreadPoolConfig.java

@@ -0,0 +1,28 @@
+package com.uas.sso.sso.backend.config;
+
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * 线程池配置类
+ *
+ * @author huxz
+ */
+@Configuration
+public class ThreadPoolConfig {
+
+    @Bean
+    public ExecutorService threadPool() {
+        ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
+                .setNameFormat("demo-pool-%d").build();
+        return new ThreadPoolExecutor(4, 6,
+                0L, TimeUnit.MILLISECONDS,
+                new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy());
+    }
+}

+ 86 - 1
sso-manage-console/src/main/java/com/uas/sso/sso/backend/service/impl/AppealServiceImpl.java

@@ -2,12 +2,16 @@ package com.uas.sso.sso.backend.service.impl;
 
 import static com.uas.sso.sso.backend.AuthenticationUtils.getEncryPassword;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.uas.sso.common.util.HttpUtil;
 import com.uas.sso.core.Const;
 import com.uas.sso.core.ICallable;
+import com.uas.sso.dao.AppDao;
 import com.uas.sso.dao.AppealDao;
 import com.uas.sso.dao.UserDao;
 import com.uas.sso.dao.UserspaceDao;
+import com.uas.sso.entity.App;
 import com.uas.sso.entity.Appeal;
 import com.uas.sso.entity.User;
 import com.uas.sso.entity.Userspace;
@@ -30,6 +34,7 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.ExecutorService;
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Order;
@@ -45,6 +50,7 @@ import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.Assert;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 /**
@@ -71,19 +77,25 @@ public class AppealServiceImpl implements AppealService {
 
     private final AdminChangeRecordDao recordDao;
 
+    private final AppDao appDao;
+
     private final UserBackendService userService;
 
     private final MailService mailService;
 
+    private final ExecutorService executorService;
+
     @Autowired
     public AppealServiceImpl(AppealDao appealDao, UserDao userDao,
-                             UserspaceDao spaceDao, AdminChangeRecordDao recordDao, UserBackendService userService, MailService mailService) {
+                             UserspaceDao spaceDao, AdminChangeRecordDao recordDao, AppDao appDao, UserBackendService userService, MailService mailService, ExecutorService executorService) {
         this.appealDao = appealDao;
         this.userDao = userDao;
         this.spaceDao = spaceDao;
         this.recordDao = recordDao;
+        this.appDao = appDao;
         this.userService = userService;
         this.mailService = mailService;
+        this.executorService = executorService;
     }
 
     @Override
@@ -257,12 +269,85 @@ public class AppealServiceImpl implements AppealService {
             space.setValidCode((short) 2);
             spaceDao.save(space);
 
+            JSONObject data = JacksonUtils.fromJson(JacksonUtils.toJson(space), JSONObject.class);
+            transferDataToOtherPlatforms("BackChangeAdmin", data, "同步更换管理员信息");
             synSendMail(appeal.getContactEmail(), appeal.getType(), appeal.getContactName(), space.getSpaceName(), isPass);
         } else {
             logger.info("暂无支持申诉类型");
         }
     }
 
+    private void transferDataToOtherPlatforms(String type, JSONObject data, String message) {
+
+        List<String> urls = new ArrayList<>();
+        if ("BackUser".equals(type)) {
+            urls = getBackUrl(new BackAppUrl() {
+                @Override
+                public String getUrl(App app) {
+                    return app.getBackUserUrl();
+                }
+            });
+        } else if ("BackChangeAdmin".equals(type)) {
+            urls = getBackUrl(new BackAppUrl() {
+                @Override
+                public String getUrl(App app) {
+                    return app.getBackChangeAdminUrl();
+                }
+            });
+        }
+
+        for (String backUrl : urls) {
+            executorService.execute(new Runnable() {
+                @Override
+                public void run() {
+                    String[] split = backUrl.split("_");
+                    String appId = split[0];
+                    try {
+                        String url = split[1];
+                        logger.info(String.format("Back Url: %s", url));
+
+                        HttpUtil.ResponseWrap res = HttpUtil.doPost(url, data, 30000);
+                        if (!res.isSuccess()) {
+                            logger.error(String.format("%s:同步信息失败, %s, %s, %s", message, appId,
+                                    JSON.toJSONString(data), res.getContent()));
+                        } else {
+                            logger.info(String.format("%s:同步信息成功, %s, %s", message, appId,
+                                    JSON.toJSONString(data)));
+                        }
+                    } catch (Exception e) {
+                        logger.error(String.format("%s:同步信息失败, %s, %s, %s", message, appId,
+                                JSON.toJSONString(data), e.getMessage()));
+                    }
+                }
+            });
+        }
+    }
+
+    private List<String> getBackUrl(BackAppUrl backAppUrl) {
+        List<String> urls = new ArrayList<>();
+
+        List<App> appList = getAppList();
+        for (App app : appList) {
+            if (StringUtils.hasText(app.getBackChangeAdminUrl())) {
+                urls.add(app.getUid() + "_" + backAppUrl.getUrl(app));
+            }
+        }
+        return urls;
+    }
+
+    private interface BackAppUrl {
+        String getUrl(App app);
+    }
+
+    private List<App> getAppList() {
+        List<App> appList = appDao.findAll();
+
+        if (CollectionUtils.isEmpty(appList)) {
+            return Collections.emptyList();
+        }
+        return appList;
+    }
+
     private void synSendMail(String receipt, String appealType, String appealName, String spaceName, Boolean isPass) {
         HashMap<String, String> params = new HashMap<>();
         params.put("appealName", appealName);

+ 1 - 1
sso-manage-console/src/main/resources/config/application-dev.properties

@@ -18,7 +18,7 @@ app.datasource.maxPoolPreparedStatementPerConnectionSize=20
 app.datasource.filters=stat,slf4j
 app.datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMillis=5000
 
-spring.jpa.show-sql=true
+spring.jpa.show-sql=false
 spring.jpa.hibernate.ddl-auto=update
 
 management.security.enabled=false

+ 1 - 1
sso-manage-console/src/main/resources/config/application-test.properties

@@ -18,7 +18,7 @@ app.datasource.maxPoolPreparedStatementPerConnectionSize=20
 app.datasource.filters=stat,slf4j
 app.datasource.connectionProperties=druid.stat.mergeSql=false;druid.stat.slowSqlMillis=5000
 
-spring.jpa.show-sql=true
+spring.jpa.show-sql=false
 spring.jpa.hibernate.ddl-auto=update
 
 management.security.enabled=false