TASK: 全局异常处理,代码优化,测试数据库连接信息变更;
This commit is contained in:
@@ -16,6 +16,7 @@ import com.ai.da.service.PythonTAllInfoService;
|
||||
import com.ai.da.service.SysFileService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONException;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.serializer.SerializerFeature;
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -1581,29 +1582,34 @@ public class PythonService {
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
String bodyStr = null;
|
||||
Response response;
|
||||
String bodyStr;
|
||||
try {
|
||||
log.info("generateAttributeRetrieval请求入参content###{}", JSON.toJSONString(content));
|
||||
response = client.newCall(request).execute();
|
||||
bodyStr = response.body().string();
|
||||
} catch (IOException ioException) {
|
||||
AccessLimitUtils.validateOut("generateAttributeRetrieval");
|
||||
log.error("generateAttributeRetrieval异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
}
|
||||
//去除限流
|
||||
AccessLimitUtils.validateOut("generateAttributeRetrieval");
|
||||
if (Objects.isNull(response)) {
|
||||
log.error("generateAttributeRetrieval异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("system error!");
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
if (Objects.nonNull(response.body())) {
|
||||
bodyStr = response.body().string();
|
||||
return resolveDesignAttributeRetrievalDTO(bodyStr);
|
||||
}
|
||||
//生成失败
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
} catch (JSONException | IOException e) {
|
||||
log.error("generateAttributeRetrieval异常###{}", e.getMessage());
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
}
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
||||
Boolean result = jsonObject.getBoolean("successful");
|
||||
if (result) {
|
||||
return resolveDesignAttributeRetrievalDTO(bodyStr);
|
||||
}
|
||||
log.info("attribute_retrieval失败###{}", bodyStr);
|
||||
log.error("generateAttributeRetrieval异常###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("system error!");
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
}
|
||||
|
||||
private static DesignAttributeRetrievalDTO resolveDesignAttributeRetrievalDTO(String bodyStr) {
|
||||
@@ -1612,20 +1618,20 @@ public class PythonService {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (data != null) {
|
||||
JSONObject jsonObjectSys = data.getJSONObject("sys_lib_dict");
|
||||
if (null == jsonObjectSys || jsonObjectSys.size() == 0) {
|
||||
if (null == jsonObjectSys || jsonObjectSys.isEmpty()) {
|
||||
log.error("generateAttributeRetrieval异常###{}", "jsonObjectSys is empty!");
|
||||
throw new BusinessException("system error!");
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
}
|
||||
setUrls(jsonObjectSys, response.getSysFileUrlS());
|
||||
JSONObject jsonObjectLibrary = data.getJSONObject("user_lib_dict");
|
||||
if (null == jsonObjectLibrary || jsonObjectLibrary.size() == 0) {
|
||||
if (null == jsonObjectLibrary || jsonObjectLibrary.isEmpty()) {
|
||||
log.error("generateAttributeRetrieval异常###{}", "jsonObjectLibrary is empty!");
|
||||
throw new BusinessException("system error!");
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
}
|
||||
setUrls(jsonObjectLibrary, response.getLibraryUrls());
|
||||
return response;
|
||||
}
|
||||
throw new BusinessException("AttributeRetrieval response data is null");
|
||||
throw new BusinessException("attributeRetrieval.interface.exception");
|
||||
}
|
||||
|
||||
private static void setUrls(JSONObject jsonObjectSys, List<String> urls) {
|
||||
@@ -1918,7 +1924,7 @@ public class PythonService {
|
||||
|
||||
public JSONObject designNew(DesignPythonObjects designPythonObjects) {
|
||||
// todo 限流校验
|
||||
// AccessLimitUtils.validate("design",5);
|
||||
AccessLimitUtils.validate("design",5);
|
||||
OkHttpClient client = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒)
|
||||
@@ -1937,39 +1943,34 @@ public class PythonService {
|
||||
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
Response response = null;
|
||||
Response response;
|
||||
String responseBody;
|
||||
try {
|
||||
response = client.newCall(request).execute();
|
||||
// log.info("PythonService##response###{}", response);
|
||||
// log.info("PythonService##responseBodyStr###{}", response.body().string());
|
||||
// log.info("PythonService##responseBodyJson###{}", JSON.toJSONString(response.body()));
|
||||
String responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
return responseObject;
|
||||
} catch (IOException ioException) {
|
||||
AccessLimitUtils.validateOut("design");
|
||||
log.error("PythonService##design异常###{}", ExceptionUtil.getThrowableList(ioException));
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
//去除限流
|
||||
// AccessLimitUtils.validateOut("design");
|
||||
if (Objects.isNull(response)) {
|
||||
log.error("PythonService##design异常###{}", "response or body is empty!");
|
||||
throw new BusinessException("system error!");
|
||||
}
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(response));
|
||||
log.info("PythonService##jsonObject###{}", jsonObject);
|
||||
Boolean result = jsonObject.getBoolean("successful");
|
||||
AccessLimitUtils.validateOut("design");
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
String responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
return responseObject;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
if (Objects.nonNull(response.body())) {
|
||||
responseBody = response.body().string();
|
||||
JSONObject responseObject = JSON.parseObject(responseBody);
|
||||
log.info("PythonService##responseObject###{}", responseObject);
|
||||
return responseObject;
|
||||
}
|
||||
throw new BusinessException("design.interface.exception");
|
||||
} catch (IOException | JSONException e) {
|
||||
log.error("PythonService##design异常###{}", e.getMessage());
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
}
|
||||
log.info("PythonService##design异常jsonObject###{}", jsonObject);
|
||||
log.error("PythonService##design异常response###{}", response);
|
||||
//生成失败
|
||||
throw new BusinessException("generate design exception!");
|
||||
throw new BusinessException("design.interface.exception");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -74,9 +74,15 @@ public class DesignPythonItem {
|
||||
public static List<String> OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(),
|
||||
CollectionLevel2TypeEnum.DRESS.getRealName(), CollectionLevel2TypeEnum.BLOUSE.getRealName());
|
||||
|
||||
public static List<String> DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.DRESS.getRealName(),
|
||||
CollectionLevel2TypeEnum.BLOUSE.getRealName());
|
||||
|
||||
public static List<String> SKIRT_TROUSERS = Arrays.asList(
|
||||
CollectionLevel2TypeEnum.SKIRT.getRealName(), CollectionLevel2TypeEnum.TROUSERS.getRealName());
|
||||
|
||||
public static List<String> OUTERWEAR = Arrays.asList(
|
||||
"OuterWear");
|
||||
|
||||
public static List<String> TOPS = Arrays.asList(
|
||||
"Tops");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user