wuxw7
2018-06-16 7afa32638bd4c1eec05a19a6586af3f4b1ce8ccb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package com.java110.core.context;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.common.util.DateUtil;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.common.util.StringUtil;
import com.java110.entity.center.AppRoute;
import com.java110.entity.center.Business;
 
 
import java.util.*;
 
/**
 * 主要用于离散成对象 httpApi service 请求过程消息记录和返回记录
 * Created by wuxw on 2018/4/13.
 */
public class DataFlow extends AbstractDataFlowContext {
 
    private String oId;
 
    private String appId;
 
    private String userId;
 
    private String ip;
 
    private String remark;
 
    private String reqSign;
 
    private JSONObject reqOrders;
 
    private JSONArray reqBusiness;
 
    private String resSign;
 
    private JSONObject resOrders;
 
 
 
    private String requestURL;
 
    /*private AppRoute appRoute;*/
 
    private List<AppRoute> appRoutes = new ArrayList<AppRoute>();
    //请求业务系统报文
    private JSONObject requestBusinessJson;
 
    //业务系统返回报文
    private JSONObject responseBusinessJson;
 
    public String getoId() {
        return oId;
    }
 
    public void setoId(String oId) {
        this.oId = oId;
    }
 
    //public DataFlow(){}
 
    public DataFlow(Date startDate,String code){
        super(startDate,code);
    }
 
    public void setAppId(String appId) {
        this.appId = appId;
    }
 
    public void setUserId(String userId) {
        this.userId = userId;
    }
 
    public void setRemark(String remark) {
        this.remark = remark;
    }
 
    public void setReqSign(String reqSign) {
        this.reqSign = reqSign;
    }
 
    public void setReqOrders(JSONObject reqOrders) {
        this.reqOrders = reqOrders;
    }
 
    public void setReqBusiness(JSONArray reqBusiness) {
        this.reqBusiness = reqBusiness;
    }
 
    public void setResSign(String resSign) {
        this.resSign = resSign;
    }
 
    public void setResOrders(JSONObject resOrders) {
        this.resOrders = resOrders;
    }
 
 
 
    public String getAppId() {
        return appId;
    }
 
    public String getUserId() {
        return userId;
    }
 
    public String getRemark() {
        return remark;
    }
 
    public String getReqSign() {
        return reqSign;
    }
 
    @Override
    public Orders getOrder() {
        return this;
    }
 
    public JSONObject getReqOrders() {
        return reqOrders;
    }
 
    public JSONArray getReqBusiness() {
        return reqBusiness;
    }
 
    public String getResSign() {
        return resSign;
    }
 
    public JSONObject getResOrders() {
        return resOrders;
    }
 
 
 
    public String getRequestURL() {
        return requestURL;
    }
 
    public void setRequestURL(String requestURL) {
        this.requestURL = requestURL;
    }
 
 
    public List<AppRoute> getAppRoutes() {
        return appRoutes;
    }
 
    public void addAppRoutes(AppRoute appRoute) {
        this.appRoutes.add(appRoute);
    }
 
    public String getIp() {
        return ip;
    }
 
    public void setIp(String ip) {
        this.ip = ip;
    }
 
 
    public JSONObject getRequestBusinessJson() {
        return requestBusinessJson;
    }
 
    public void setRequestBusinessJson(JSONObject requestBusinessJson) {
        this.requestBusinessJson = requestBusinessJson;
    }
 
    public JSONObject getResponseBusinessJson() {
        return responseBusinessJson;
    }
 
    public void setResponseBusinessJson(JSONObject responseBusinessJson) {
        this.responseBusinessJson = responseBusinessJson;
    }
 
    public DataFlow builderByBusiness(String businessInfo) throws Exception{
        try{
            Business business = null;
            JSONObject reqInfoObj = JSONObject.parseObject(businessInfo);
            this.setReqJson(reqInfoObj);
            this.setReqData(businessInfo);
            this.setDataFlowId(reqInfoObj.containsKey("dataFlowId")?reqInfoObj.getString("dataFlowId"):"-1");
            //this.setAppId(orderObj.getString("appId"));
            this.setTransactionId(reqInfoObj.getString("transactionId"));
            this.setOrderTypeCd(reqInfoObj.getString("orderTypeCd"));
            this.setRequestTime(reqInfoObj.getString("responseTime"));
            this.setBusinessType(reqInfoObj.getString("businessType"));
            //this.setReqOrders(orderObj);
            JSONObject businessObj = new JSONObject();
            businessObj.put("bId",reqInfoObj.getString("bId"));
            businessObj.put("serviceCode",reqInfoObj.getString("serviceCode"));
            JSONArray reqBusinesses = new JSONArray();
            reqBusinesses.add(businessInfo);
            this.setReqBusiness(reqBusinesses);
            JSONObject response = reqInfoObj.getJSONObject("response");
            this.setCode(response.getString("code"));
            this.setMessage(response.getString("message"));
            businessObj.put("response",response);
            this.businesses = new ArrayList<Business>();
            business = new Business().builder(businessObj);
            businesses.add(business);
            this.setCurrentBusiness(business);
        }catch (Exception e){
 
            throw e;
        }
        return this;
    }
 
    public DataFlow doBuilder(String reqInfo, Map<String,String> headerAll) throws Exception{
 
        try{
            Business business = null;
            JSONObject reqInfoObj = JSONObject.parseObject(reqInfo);
            JSONObject orderObj = reqInfoObj.getJSONObject("orders");
            Object businessObj = reqInfoObj.get("business");
            JSONArray businessArray = null;
            if(businessObj instanceof JSONObject){
                businessArray = new JSONArray();
                businessArray.add(reqInfoObj.getJSONObject("business"));
            }else if(businessObj instanceof JSONArray){
                businessArray = reqInfoObj.getJSONArray("business");
            }else{
                // 不做处理
            }
 
            this.setReqData(reqInfo);
            this.setReqJson(reqInfoObj);
            this.setDataFlowId(orderObj.containsKey("dataFlowId")?orderObj.getString("dataFlowId"):"-1");
            this.setAppId(orderObj.getString("appId"));
            this.setTransactionId(orderObj.getString("transactionId"));
            this.setUserId(orderObj.getString("userId"));
            this.setOrderTypeCd(orderObj.getString("orderTypeCd"));
            this.setRemark(orderObj.getString("remark"));
            this.setReqSign(orderObj.getString("sign"));
            this.setRequestTime(orderObj.getString("requestTime"));
            this.setReqOrders(orderObj);
            this.setReqBusiness(businessArray);
            this.businesses = new ArrayList<Business>();
            if(businessArray != null && businessArray.size() > 0){
                for(int businessIndex = 0;businessIndex < businessArray.size();businessIndex++) {
                    business = new Business().builder(businessArray.getJSONObject(businessIndex));
                    businesses.add(business);
                }
            }
 
            if (headerAll != null){
                this.requestHeaders.putAll(headerAll);
                this.requestCurrentHeaders.putAll(headerAll);
                this.setRequestURL(requestHeaders.get("REQUEST_URL"));
                this.setIp(requestHeaders.get("IP"));
            }
 
 
        }catch (Exception e){
 
            throw e;
        }
        return this;
    }
 
    /**
     * 透传时构建对象
     * @param reqInfo
     * @param headerAll
     * @return
     * @throws Exception
     */
    public DataFlow builderTransfer(String reqInfo, Map<String,String> headerAll) throws Exception{
 
        try{
            Business business = null;
            this.setReqData(reqInfo);
            this.setDataFlowId("-1");
            this.setAppId(headerAll.get("appId"));
            this.setTransactionId(StringUtil.isNullOrNone(headerAll.get("transactionId"))? GenerateCodeFactory.getTransactionId():headerAll.get("transactionId"));
            this.setUserId(StringUtil.isNullOrNone(headerAll.get("userId"))? "-1":headerAll.get("userId"));
            this.setOrderTypeCd("T");
            this.setRemark(StringUtil.isNullOrNone(headerAll.get("remark"))? "":headerAll.get("remark"));
            this.setReqSign(StringUtil.isNullOrNone(headerAll.get("sign"))? "":headerAll.get("sign"));
            this.setRequestTime(StringUtil.isNullOrNone(headerAll.get("requestTime"))? DateUtil.getyyyyMMddhhmmssDateString():headerAll.get("requestTime"));
            String serviceCode = headerAll.get("serviceCode");
            this.businesses = new ArrayList<Business>();
            if(!StringUtil.isNullOrNone(serviceCode)){
                JSONObject bInfo = new JSONObject();
                bInfo.put("serviceCode",serviceCode);
                bInfo.put("transferData",reqInfo);
                    business = new Business().builder(bInfo);
                    businesses.add(business);
                this.setCurrentBusiness(business);
            }
 
            if (headerAll != null){
                this.requestHeaders.putAll(headerAll);
                this.requestCurrentHeaders.putAll(headerAll);
                this.setRequestURL(requestHeaders.get("REQUEST_URL"));
                this.setIp(requestHeaders.get("IP"));
            }
 
 
        }catch (Exception e){
 
            throw e;
        }
        return this;
    }
 
}