From 9df40dad0fd0f52f108b598ac78b3bbff5eda1f9 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期六, 10 八月 2019 21:50:28 +0800
Subject: [PATCH] 加入 服务绑定扩展信息
---
Api/src/main/java/com/java110/api/listener/service/BindingServiceListener.java | 82 +++++++++++++++++++++++++----------------
1 files changed, 50 insertions(+), 32 deletions(-)
diff --git a/Api/src/main/java/com/java110/api/listener/service/BindingServiceListener.java b/Api/src/main/java/com/java110/api/listener/service/BindingServiceListener.java
index e308bd3..a6cae4a 100644
--- a/Api/src/main/java/com/java110/api/listener/service/BindingServiceListener.java
+++ b/Api/src/main/java/com/java110/api/listener/service/BindingServiceListener.java
@@ -4,11 +4,13 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.api.listener.AbstractServiceApiListener;
+import com.java110.common.constant.CommonConstant;
import com.java110.common.constant.ResponseConstant;
import com.java110.common.constant.ServiceCodeServiceConstant;
import com.java110.common.exception.ListenerExecuteException;
import com.java110.common.util.Assert;
import com.java110.common.util.BeanConvertUtil;
+import com.java110.common.util.StringUtil;
import com.java110.core.annotation.Java110Listener;
import com.java110.core.context.DataFlowContext;
import com.java110.core.factory.GenerateCodeFactory;
@@ -45,8 +47,12 @@
JSONArray infos = reqJson.getJSONArray("data");
- if(infos == null || infos.size() !=2){
- throw new IllegalArgumentException("璇锋眰鍙傛暟閿欒锛屼负鍖呭惈 搴旂敤鎴栨湇鍔′俊鎭�");
+ Assert.hasKeyByFlowData(infos, "addRouteView", "orderTypeCd", "蹇呭~锛岃濉啓璁㈠崟绫诲瀷");
+ Assert.hasKeyByFlowData(infos, "addRouteView", "invokeLimitTimes", "蹇呭~锛岃濉啓璋冪敤娆℃暟");
+ Assert.hasKeyByFlowData(infos, "addRouteView", "invokeModel", "鍙~锛岃濉啓娑堟伅闃熷垪锛岃鍗曞湪寮傛璋冪敤鏃朵娇鐢�");
+
+ if(infos == null || infos.size() !=3){
+ throw new IllegalArgumentException("璇锋眰鍙傛暟閿欒锛屼负鍖呭惈 搴旂敤锛屾湇鍔℃垨鎵╁睍淇℃伅");
}
}
@@ -55,47 +61,30 @@
JSONArray infos = reqJson.getJSONArray("data");
- JSONObject appInfo = null; //搴旂敤淇℃伅
- JSONObject serviceInfo = null; // 鏈嶅姟淇℃伅
+ JSONObject viewAppInfo = getObj(infos, "App");
+ JSONObject viewServiceInfo = getObj(infos, "Service");
+ JSONObject addRouteView = getObj(infos, "addRouteView");
- for(int infoIndex = 0 ; infoIndex < infos.size(); infoIndex ++){
-
- Assert.hasKeyAndValue(infos.getJSONObject(infoIndex), "flowComponent", "鏈寘鍚湇鍔℃祦绋嬬粍浠跺悕绉�");
-
- if("App".equals(infos.getJSONObject(infoIndex).getString("flowComponent"))){
- appInfo = infos.getJSONObject(infoIndex);
- }
- if("Service".equals(infos.getJSONObject(infoIndex).getString("flowComponent"))){
- serviceInfo = infos.getJSONObject(infoIndex);
- }
- }
-
- Assert.notNull(appInfo, "鏈寘鍚簲鐢ㄤ俊鎭�");
- Assert.notNull(serviceInfo, "鏈寘鍚湇鍔′俊鎭�");
+ Assert.notNull(viewAppInfo, "鏈寘鍚簲鐢ㄤ俊鎭�");
+ Assert.notNull(viewServiceInfo, "鏈寘鍚湇鍔′俊鎭�");
+ Assert.notNull(addRouteView, "鏈寘鍚墿灞曚俊鎭�");
//澶勭悊 搴旂敤淇℃伅
- if(!appInfo.containsKey("appId")
- || StringUtils.isEmpty(appInfo.getString("appId"))
- || appInfo.getString("appId").startsWith("-")){
- appInfo.put("appId", saveAppInfo(reqJson, appInfo));
+ if(!hasKey(viewAppInfo, "appId")){
+ viewAppInfo.put("appId", saveAppInfo(reqJson, viewAppInfo));
}
//澶勭悊 鏈嶅姟淇℃伅
- if(!serviceInfo.containsKey("serviceId")
- || StringUtils.isEmpty(serviceInfo.getString("serviceId"))
- || serviceInfo.getString("serviceId").startsWith("-")){
- serviceInfo.put("serviceId", saveServiceInfo(reqJson, serviceInfo));
+ if(!hasKey(viewServiceInfo, "serviceId")){
+ viewServiceInfo.put("serviceId", saveServiceInfo(reqJson, viewServiceInfo));
}
//澶勭悊璺敱淇℃伅
- RouteDto routeDto = new RouteDto();
- routeDto.setAppId(appInfo.getString("appId"));
- routeDto.setServiceId(serviceInfo.getString("serviceId"));
- routeDto.setInvokeLimitTimes("1000");
- routeDto.setInvokeModel("S");
- routeDto.setOrderTypeCd("Q");
+ RouteDto routeDto = BeanConvertUtil.covertBean(addRouteView, RouteDto.class);
+ routeDto.setAppId(viewAppInfo.getString("appId"));
+ routeDto.setServiceId(viewServiceInfo.getString("serviceId"));
int count = routeInnerServiceSMOImpl.saveRoute(routeDto);
@@ -156,6 +145,35 @@
return serviceDto.getServiceId();
}
+ private JSONObject getObj(JSONArray infos , String flowComponent){
+
+ JSONObject serviceInfo = null;
+
+ for(int infoIndex = 0 ; infoIndex < infos.size(); infoIndex ++){
+
+ Assert.hasKeyAndValue(infos.getJSONObject(infoIndex), "flowComponent", "鏈寘鍚湇鍔℃祦绋嬬粍浠跺悕绉�");
+
+ if(flowComponent.equals(infos.getJSONObject(infoIndex).getString("flowComponent"))){
+ serviceInfo = infos.getJSONObject(infoIndex);
+ Assert.notNull(serviceInfo, "鏈寘鍚湇鍔′俊鎭�");
+ return serviceInfo;
+ }
+ }
+
+ throw new IllegalArgumentException("鏈壘鍒扮粍浠剁紪鐮佷负銆�" + flowComponent + "銆戞暟鎹�");
+ }
+
+ private boolean hasKey(JSONObject info, String key){
+ if(!info.containsKey(key)
+ || StringUtil.isEmpty(info.getString(key))
+ || info.getString(key).startsWith("-")){
+ return false;
+ }
+ return true;
+
+ }
+
+
@Override
public String getServiceCode() {
return ServiceCodeServiceConstant.BINDING_SERVICE;
--
Gitblit v1.8.0