wuxw7
2018-11-17 ab9b63cd51ade836a883a59bff6c419c771a9d98
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
package com.java110.core.context;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.java110.common.constant.CommonConstant;
import com.java110.common.util.DateUtil;
import com.java110.common.util.StringUtil;
import com.java110.core.factory.GenerateCodeFactory;
import com.java110.entity.center.AppRoute;
import com.java110.entity.center.Business;
import org.springframework.http.ResponseEntity;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
/**
 * 主要用于离散成对象 httpApi service 请求过程消息记录和返回记录
 * Created by wuxw on 2018/4/13.
 */
public class ApiDataFlow extends AbstractDataFlowContext {
 
    private String appId;
 
    private String ip;
 
    private String apiCurrentService;
 
    private String reqSign;
 
    private String resSign;
 
    private String requestURL;
 
 
    private List<AppRoute> appRoutes = new ArrayList<AppRoute>();
    //请求业务系统报文
    private JSONObject requestBusinessJson;
 
    //业务系统返回报文
    private JSONObject responseBusinessJson;
    //rest 返回对象
    private ResponseEntity responseEntity;
 
 
 
 
 
    public ApiDataFlow(Date startDate, String code){
        super(startDate,code);
    }
 
    public void setAppId(String appId) {
        this.appId = appId;
    }
 
 
 
    public void setReqSign(String reqSign) {
        this.reqSign = reqSign;
    }
 
 
 
    public void setResSign(String resSign) {
        this.resSign = resSign;
    }
 
 
 
 
    public String getAppId() {
        return appId;
    }
 
 
 
    public String getReqSign() {
        return reqSign;
    }
 
    @Override
    public Orders getOrder() {
        return this;
    }
 
    public String getResSign() {
        return resSign;
    }
 
 
 
    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 ApiDataFlow doBuilder(String reqInfo, Map<String,String> headerAll) throws Exception{
 
        try{
            JSONObject reqInfoObj = JSONObject.parseObject(reqInfo);
 
            this.setReqData(reqInfo);
            this.setReqJson(reqInfoObj);
            this.setDataFlowId("-1");
            this.setAppId(headerAll.get(CommonConstant.HTTP_APP_ID));
            this.setTransactionId(headerAll.get(CommonConstant.HTTP_TRANSACTION_ID));
            this.setReqSign(headerAll.get(CommonConstant.HTTP_SIGN));
            this.setRequestTime(headerAll.get(CommonConstant.HTTP_REQ_TIME));
 
            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 ApiDataFlow builderTransfer(String reqInfo, Map<String,String> headerAll) throws Exception{
 
        try{
            this.setReqData(reqInfo);
            this.setDataFlowId("-1");
            this.setAppId(headerAll.get(CommonConstant.HTTP_APP_ID));
            this.setTransactionId(headerAll.get(CommonConstant.HTTP_TRANSACTION_ID));
            this.setReqSign(headerAll.get(CommonConstant.HTTP_SIGN));
            this.setRequestTime(headerAll.get(CommonConstant.HTTP_REQ_TIME));
 
            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;
    }
 
    @Override
    public String getServiceCode() {
        return apiCurrentService;
    }
 
    public void setApiCurrentService(String apiCurrentService) {
        this.apiCurrentService = apiCurrentService;
    }
 
 
    @Override
    public void setResponseEntity(ResponseEntity responseEntity){
        this.responseEntity = responseEntity;
    }
 
 
    public ResponseEntity getResponseEntity(){
        return responseEntity;
    }
}