fix(项目管理): 创建环境问题

--bug=1017878 --user=李玉号 【项目设置】项目环境-导入环境-点击确定没反应-导入失败
https://www.tapd.cn/55049933/s/1260412
This commit is contained in:
shiziyuan9527 2022-10-13 12:48:20 +08:00 committed by lyh
parent cedc873062
commit ad33d5932d
3 changed files with 10 additions and 9 deletions

View File

@ -350,9 +350,9 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
if (StringUtils.isNotEmpty(config)) { if (StringUtils.isNotEmpty(config)) {
Map<String, Object> map = JSON.parseObject(config, Map.class); Map<String, Object> map = JSON.parseObject(config, Map.class);
JSONObject commonConfig = new JSONObject(map).optJSONObject("commonConfig"); JSONObject commonConfig = new JSONObject(map).optJSONObject("commonConfig");
if (commonConfig!=null){ if (commonConfig != null) {
JSONArray variables = commonConfig.optJSONArray("variables"); JSONArray variables = commonConfig.optJSONArray("variables");
if (variables!=null){ if (variables != null) {
List<ScenarioVariable> list = JSON.parseArray(variables.toString(), ScenarioVariable.class); List<ScenarioVariable> list = JSON.parseArray(variables.toString(), ScenarioVariable.class);
list.stream().filter(ScenarioVariable::isCSVValid).forEach(keyValue -> { list.stream().filter(ScenarioVariable::isCSVValid).forEach(keyValue -> {
files.addAll(keyValue.getFiles().stream().filter(BodyFile::isRef).collect(Collectors.toList())); files.addAll(keyValue.getFiles().stream().filter(BodyFile::isRef).collect(Collectors.toList()));
@ -420,12 +420,13 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
private TestEnvironmentDTO updateConfig(TestEnvironmentDTO request, boolean isMock) { private TestEnvironmentDTO updateConfig(TestEnvironmentDTO request, boolean isMock) {
if (StringUtils.isNotEmpty(request.getConfig())) { if (StringUtils.isNotEmpty(request.getConfig())) {
try { try {
JSONObject configObj = new JSONObject(JSON.parseObject(request.getConfig())); Map<Object, Object> map = JSON.parseObject(request.getConfig(), Map.class);
JSONObject configObj = new JSONObject(map);
if (configObj.has("httpConfig")) { if (configObj.has("httpConfig")) {
JSONObject httpObj = configObj.getJSONObject("httpConfig"); JSONObject httpObj = configObj.getJSONObject("httpConfig");
httpObj.put("isMock", isMock); httpObj.put("isMock", isMock);
} }
request.setConfig(JSON.toJSONString(configObj)); request.setConfig(configObj.toString());
} catch (Exception e) { } catch (Exception e) {
LogUtil.error("设置是否为mock环境出错!参数:" + request.getConfig(), e); LogUtil.error("设置是否为mock环境出错!参数:" + request.getConfig(), e);
} }
@ -626,7 +627,7 @@ public class BaseEnvironmentService extends NodeTreeService<ApiModuleDTO> {
ipStr = urlArr[0]; ipStr = urlArr[0];
} }
if (tcpConfigObj.has("server")) { if (tcpConfigObj.has("server")) {
if(!StringUtils.equals(tcpConfigObj.optString("server"), ipStr)){ if (!StringUtils.equals(tcpConfigObj.optString("server"), ipStr)) {
needUpdate = true; needUpdate = true;
} }
} else { } else {

View File

@ -392,7 +392,7 @@ export default {
} }
return ""; return "";
} else { } else {
if (config.httpConfig.conditions.length === 1) { if (config.httpConfig && config.httpConfig.conditions.length === 1) {
if (config.tcpConfig && config.tcpConfig.server) { if (config.tcpConfig && config.tcpConfig.server) {
return "SHOW_INFO"; return "SHOW_INFO";
} }
@ -400,7 +400,7 @@ export default {
if (obj.protocol && obj.socket) { if (obj.protocol && obj.socket) {
return obj.protocol + "://" + obj.socket; return obj.protocol + "://" + obj.socket;
} }
} else if (config.httpConfig.conditions.length > 1) { } else if (config.httpConfig && config.httpConfig.conditions.length > 1) {
return "SHOW_INFO"; return "SHOW_INFO";
} else if (config.tcpConfig && config.tcpConfig.server) { } else if (config.tcpConfig && config.tcpConfig.server) {
return config.tcpConfig.server; return config.tcpConfig.server;

View File

@ -419,7 +419,7 @@ export default {
} }
return ""; return "";
} else { } else {
if (config.httpConfig.conditions.length === 1) { if (config.httpConfig && config.httpConfig.conditions.length === 1) {
if (config.tcpConfig && config.tcpConfig.server) { if (config.tcpConfig && config.tcpConfig.server) {
return "SHOW_INFO"; return "SHOW_INFO";
} }
@ -427,7 +427,7 @@ export default {
if (obj.protocol && obj.socket) { if (obj.protocol && obj.socket) {
return obj.protocol + "://" + obj.socket; return obj.protocol + "://" + obj.socket;
} }
} else if (config.httpConfig.conditions.length > 1) { } else if (config.httpConfig && config.httpConfig.conditions.length > 1) {
return "SHOW_INFO"; return "SHOW_INFO";
} else if (config.tcpConfig && config.tcpConfig.server) { } else if (config.tcpConfig && config.tcpConfig.server) {
return config.tcpConfig.server; return config.tcpConfig.server;