xiaogang
2021-05-21 05f5fcc1efbd628f08c868fdaf622554ff85271a
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
package com.java110.api.listener;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.constant.ServiceCodeConstant;
import com.java110.utils.util.Assert;
import com.java110.core.annotation.Java110Listener;
import com.java110.core.context.DataFlowContext;
import com.java110.entity.center.AppService;
import com.java110.core.event.service.api.ServiceDataFlowEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
 
/**
 * 订单类信息处理 侦听
 * Created by wuxw on 2018/5/18.
 */
@Java110Listener("orderServiceListener")
public class OrderServiceListener extends AbstractServiceApiDataFlowListener{
 
    private final static Logger logger = LoggerFactory.getLogger(OrderServiceListener.class);
 
 
 
    @Override
    public String getServiceCode() {
        return ServiceCodeConstant.SERVICE_CODE_DO_SERVICE_ORDER;
    }
 
    @Override
    public HttpMethod getHttpMethod() {
        return HttpMethod.POST;
    }
 
 
    @Override
    public int getOrder() {
        return 0;
    }
 
 
    @Override
    public void soService(ServiceDataFlowEvent event) {
        //获取数据上下文对象
        DataFlowContext dataFlowContext = event.getDataFlowContext();
        AppService service = event.getAppService();
        String paramIn = dataFlowContext.getReqData();
        Assert.jsonObjectHaveKey(paramIn,"orders","请求参数中未包含");
        JSONObject paramInObj = JSONObject.parseObject(paramIn);
        HttpHeaders header = new HttpHeaders();
        for(String key : dataFlowContext.getRequestCurrentHeaders().keySet()){
            header.add(key,dataFlowContext.getRequestCurrentHeaders().get(key));
 
            if(CommonConstant.HTTP_APP_ID.equals(key)) {
                paramInObj.put("appId", dataFlowContext.getRequestCurrentHeaders().get(key));
            }
            if(CommonConstant.HTTP_TRANSACTION_ID.equals(key)) {
                paramInObj.put("transactionId", dataFlowContext.getRequestCurrentHeaders().get(key));
            }
            if(CommonConstant.HTTP_SIGN.equals(key)) {
                paramInObj.put("sign", dataFlowContext.getRequestCurrentHeaders().get(key));
            }
 
            if(CommonConstant.HTTP_SIGN.equals(key)) {
                paramInObj.put("requestTime", dataFlowContext.getRequestCurrentHeaders().get(key));
            }
        }
 
        HttpEntity<String> httpEntity = new HttpEntity<String>(paramInObj.toJSONString(), header);
        //http://user-service/test/sayHello
        super.doRequest(dataFlowContext, service, httpEntity);
    }
 
 
 
 
 
}