AppEnum-moliparty
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package com.accompany.common.constant;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -16,10 +18,12 @@ public enum AppEnum {
|
||||
Map.of(Pattern.compile("baishun.minigame.*"), "baishun.minigame.moliparty.com")),
|
||||
molistar("molistar", "molistar google马甲包", "api.molistar.xyz", "image.molistar.xyz", "api.molistar.xyz", "molistar",
|
||||
Map.of(Pattern.compile("baishun.minigame.*"), "baishun.minigame.molistar.xyz")),
|
||||
moliparty("MoliParty", "moliparty google马甲包", "api.moliparty.com", "cdn.moliparty.com", "api.moliparty.com", "moliparty",
|
||||
Map.of(Pattern.compile("baishun.minigame.*"), "baishun.minigame.moliparty.com")),
|
||||
;
|
||||
|
||||
public static AppEnum getCurApp(){
|
||||
return AppEnum.molistar;
|
||||
return AppEnum.moliparty;
|
||||
}
|
||||
|
||||
private String value;
|
||||
@@ -74,4 +78,15 @@ public enum AppEnum {
|
||||
return patternMap;
|
||||
}
|
||||
|
||||
|
||||
public static List<AppEnum> getOtherAppEnums(AppEnum currentApp) {
|
||||
List<AppEnum> otherApps = new ArrayList<>();
|
||||
// 遍历所有枚举,排除传入的 app 对应的枚举
|
||||
for (AppEnum app : AppEnum.values()) {
|
||||
if (!app.equals(currentApp)) {
|
||||
otherApps.add(app);
|
||||
}
|
||||
}
|
||||
return otherApps;
|
||||
}
|
||||
}
|
||||
|
@@ -1473,10 +1473,6 @@ public enum RedisKey {
|
||||
charge_user_x_detail,//嫌疑用户
|
||||
;
|
||||
|
||||
public String getKey() {
|
||||
return ("molistar_" + name()).toLowerCase();
|
||||
}
|
||||
|
||||
public String getKey(String suffix) {
|
||||
if (StringUtils.isEmpty(suffix)) {
|
||||
return getKey();
|
||||
@@ -1504,8 +1500,12 @@ public enum RedisKey {
|
||||
}
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return ("moliparty_" + name()).toLowerCase();
|
||||
}
|
||||
|
||||
public static String getCacheSign() {
|
||||
return "molistar_";
|
||||
return "moliparty_";
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,93 @@
|
||||
package com.accompany.business.interceptor;
|
||||
|
||||
import com.accompany.common.constant.AppEnum;
|
||||
import com.accompany.common.result.BusiResult;
|
||||
import com.accompany.common.utils.EnvComponent;
|
||||
import com.accompany.core.vo.BaseResponseVO;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.MethodParameter;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@RestControllerAdvice
|
||||
@Slf4j
|
||||
public class ResponseDataHandler implements ResponseBodyAdvice {
|
||||
|
||||
@Autowired
|
||||
private EnvComponent envComponent;
|
||||
|
||||
@Override
|
||||
public boolean supports(MethodParameter methodParameter, Class aClass) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object beforeBodyWrite(Object body, MethodParameter methodParameter, MediaType mediaType, Class selectedConverterType,
|
||||
ServerHttpRequest serverHttpRequest, ServerHttpResponse serverHttpResponse) {
|
||||
if (envComponent.getDevOrNativeEnv()) {
|
||||
return body;
|
||||
}
|
||||
if (body == null) {
|
||||
return body;
|
||||
}
|
||||
try {
|
||||
String uri = serverHttpRequest.getURI().getPath();
|
||||
if (body instanceof BusiResult) {
|
||||
BusiResult result = (BusiResult) body;
|
||||
Object data = result.getData();
|
||||
if (null != data) {
|
||||
String json = JSONObject.toJSONString(data);
|
||||
json = handlerDomain(json);
|
||||
|
||||
log.info("app:{}, uri:{} ResponseDataHandler 实际返回内容:{}" , AppEnum.getCurApp().getValue(), uri, json);
|
||||
|
||||
result.setData(JSONObject.parseObject(json, Object.class));
|
||||
return result;
|
||||
}
|
||||
} else if (body instanceof BaseResponseVO) {
|
||||
BaseResponseVO result = (BaseResponseVO) body;
|
||||
Object data = result.getData();
|
||||
if (null != data) {
|
||||
String json = JSONObject.toJSONString(data);
|
||||
json = handlerDomain(json);
|
||||
log.info("app:{}, uri:{} ResponseDataHandler 实际返回内容:{}" , AppEnum.getCurApp().getValue(), uri, json);
|
||||
result.setData(JSONObject.parseObject(json, Object.class));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("ResponseDataHandler error, e:{}" , e.getMessage(), e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return body;
|
||||
}
|
||||
|
||||
private String handlerDomain(String json) {
|
||||
AppEnum curApp = AppEnum.getCurApp();
|
||||
String apiDomain = curApp.getApiDomain();
|
||||
String resourceDomain = curApp.getResourceDomain();
|
||||
|
||||
List<AppEnum> otherTwoAppEnums = AppEnum.getOtherAppEnums(curApp);
|
||||
for (AppEnum otherApp : otherTwoAppEnums) {
|
||||
String diffResourceDomain = otherApp.getResourceDomain();
|
||||
String diffApiDomain = otherApp.getApiDomain();
|
||||
if (json.contains(diffResourceDomain)) {
|
||||
json = json.replaceAll(diffResourceDomain, resourceDomain);
|
||||
}
|
||||
if (json.contains(diffApiDomain)) {
|
||||
json = json.replaceAll(diffApiDomain, apiDomain);
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user