wuxw
2022-07-19 05683f2b2bdbdbe21cf17ad523c21ab338bd1c54
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
package com.java110.core.context;
 
import com.alibaba.fastjson.JSONObject;
import com.java110.utils.constant.CommonConstant;
import com.java110.utils.util.Assert;
import com.java110.utils.util.DateUtil;
import com.java110.utils.util.StringUtil;
import org.springframework.http.ResponseEntity;
 
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
 
/**
 * Cmd上下文实现
 * Created by wuxw on 2018/4/13.
 */
public class CmdDataFlow extends AbstractCmdDataFlowContext {
 
    public CmdDataFlow() {
    }
 
    public CmdDataFlow(Date startDate, String code) {
        super(startDate, code);
    }
 
    private String serviceCode;
 
    //rest 返回对象
    private ResponseEntity responseEntity;
 
    /**
     * 构建 OrderDataFlow 对象
     *
     * @param reqInfo
     * @param headerAll
     * @return
     * @throws Exception
     */
    public CmdDataFlow doBuilder(String reqInfo, Map<String, String> headerAll) throws Exception {
        String serviceCode = headerAll.get(CommonConstant.HTTP_SERVICE);
        Assert.hasLength(serviceCode, "未包含服务编码");
        this.setDataFlowId(UUID.randomUUID().toString().replace("-", "").toLowerCase());
        if (StringUtil.isJsonObject(reqInfo)) {
            //赋值请求报文
            this.setReqJson(JSONObject.parseObject(reqInfo));
        } else {
            this.setReqJson(new JSONObject());
        }
        this.setReqData(reqInfo);
 
        this.setServiceCode(serviceCode);
        //赋值 请求头信息
        this.setReqHeaders(headerAll);
        //构建返回头
        builderResHeaders();
 
        return this;
    }
 
    /**
     * 构建返回头信息
     */
    private void builderResHeaders() {
        Map<String, String> tmpResHeaders = new HashMap<String, String>();
        tmpResHeaders.put(CommonConstant.HTTP_TRANSACTION_ID, this.getReqHeaders().get(CommonConstant.HTTP_TRANSACTION_ID));
        tmpResHeaders.put(CommonConstant.HTTP_RES_TIME, DateUtil.getyyyyMMddhhmmssDateString());
        this.setResHeaders(tmpResHeaders);
    }
 
    @Override
    public String getServiceCode() {
        return serviceCode;
    }
 
    public void setServiceCode(String serviceCode) {
        this.serviceCode = serviceCode;
    }
 
    public ResponseEntity getResponseEntity() {
        return responseEntity;
    }
 
    public void setResponseEntity(ResponseEntity responseEntity) {
        this.responseEntity = responseEntity;
    }
}