|
|
@@ -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);
|