1
sunshine
2024-11-05 92a9e53e82c74d36a72eb92f93777bbb16e2db73
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
package com.nova.sankuai.domain.entity;
 
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableId;
import com.nova.sankuai.domain.api.aizhudai.AiZhuDaiResponse;
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiCommitResponse;
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiHitResponse;
import com.nova.sankuai.domain.api.jinRiTouTiao.JinRiTouTiaoResponse;
import com.nova.sankuai.domain.api.jinxiushuke.JinXiuShuKeResponse;
import com.nova.sankuai.domain.api.jinxiushuke.JinXiuShuKeUtil;
import com.nova.sankuai.domain.api.jinzhanggui.JinZhangGuiResponse;
import com.nova.sankuai.domain.api.jinzhanggui.JinZhangGuiUtil;
import com.nova.sankuai.domain.api.minsheng.MinShengResponse;
import com.nova.sankuai.domain.api.nanjingmingtuo.NanJingMingTuoResp;
import com.nova.sankuai.domain.api.nanjingmingtuo.NanJingMingTuoUtil;
import com.nova.sankuai.domain.api.rongduoduo.RongDuoDuoResponse;
import com.nova.sankuai.domain.api.rongduoduo.RongDuoDuoUtil;
import com.nova.sankuai.domain.api.shanghaizhongzan.ShangHaiZhongZanResponse;
import com.nova.sankuai.domain.api.sujinsuo.SuJinSuoResponse;
import com.nova.sankuai.domain.api.tianshi.TianShiResponse;
import com.nova.sankuai.domain.api.tianshi.TianShiUtil;
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaResponse;
import com.nova.sankuai.domain.api.xinyeyoupin.XyypResponse;
import com.nova.sankuai.domain.api.yidai.YiDaiResponse;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
 
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
 
/**
 * @author weikangdi
 * @create 2021/11/12
 */
@Data
@ApiModel(value = "接口公司客户推送记录表")
@Slf4j
public class ApiCompanyRecord {
 
    public static final int SUCCESS = 1;
 
    public static final int FAIL = 0;
 
    @ApiModelProperty(value = "主键")
    @TableId
    private Long id;
 
    @ApiModelProperty(value = "接口公司id")
    private Long companyId;
 
    @ApiModelProperty(value = "客户记录id")
    private Long customerRecordId;
 
    @ApiModelProperty(value = "创建日期")
    private Date creationDate;
 
    @ApiModelProperty(value = "状态")
    private Integer status;
 
    @ApiModelProperty(value = "推送结果信息")
    private String message;
 
    @ApiModelProperty(value = "推送结果json")
    private String result;
 
    public ApiCompanyRecord(Long companyId, Long customerRecordId, String result) {
        this.companyId = companyId;
        this.customerRecordId = customerRecordId;
        this.result = result;
        this.creationDate = new Date();
    }
 
    public static ApiCompanyRecord getMinShengRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        MinShengResponse response = JSONUtil.toBean(result, MinShengResponse.class);
        if (ApiCompanyRecord.SUCCESS == response.getResStatus()) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(response.getResMsg());
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getAiZhuDaiRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        AiZhuDaiResponse response = JSONUtil.toBean(result, AiZhuDaiResponse.class);
        if (ApiCompanyRecord.SUCCESS == response.getCode()) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(response.getMessage());
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getXiaMenZhongHeYinHuaRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        XiaMenZhongHeYinHuaResponse response = JSONUtil.toBean(result, XiaMenZhongHeYinHuaResponse.class);
        if (HttpStatus.HTTP_OK == response.getCode()) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(response.getMsg());
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getRongDuoDuoRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        RongDuoDuoResponse response = RongDuoDuoUtil.getResponse(result);
        if (response != null && RongDuoDuoResponse.SUCCESS == response.getStatus()) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        if (response != null) {
            apiCompanyRecord.setMessage(response.getMes());
        }
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getTianShiRecord(Long companyId, Long customerRecordId, Integer result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, Integer.toString(result));
        TianShiResponse response = new TianShiResponse();
        response.setCode(result);
        if (TianShiResponse.SUCCESS == response.getCode()) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
            apiCompanyRecord.setMessage(TianShiResponse.SUCCESS_MESSAGE);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
            apiCompanyRecord.setMessage(TianShiUtil.getFailMessage(response.getCode()));
        }
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getJinXiuShuKeRecord(Long companyId, Long customerRecordId, String response) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, response);
        if ("success".equals(response)) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
            apiCompanyRecord.setMessage("成功");
        } else {
            String code = "";
            try {
                JinXiuShuKeResponse toBean = JSONUtil.toBean(response, JinXiuShuKeResponse.class);
                code = toBean.getMsg();
            } catch (Exception e) {
                if (response.length() > 255) {
                    code = response.subSequence(0, 254).toString();
                } else {
                    code = response;
                }
            }
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
            apiCompanyRecord.setMessage(JinXiuShuKeUtil.getFailMessage(code));
        }
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getSuJinSuoRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        SuJinSuoResponse response = JSONUtil.toBean(result, SuJinSuoResponse.class);
        JSONObject jsonObject = JSONObject.parseObject(result);
        List susses = (List) jsonObject.getJSONObject("data").get("successIdList");
        if (susses.size() > 0) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(response.getMsg());
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getJinRiTouTiaoRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        JinRiTouTiaoResponse response = JSONUtil.toBean(result, JinRiTouTiaoResponse.class);
        if (response.getErrno() == 0) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(response.getMsg());
        return apiCompanyRecord;
    }
 
 
    public static ApiCompanyRecord getHuiZhongZhiDai(Long companyId, Long customerRecordId, String response) {
        String code = "";
        String msg = "";
        try {
            JSONObject data = (JSONObject) JSONObject.parseObject(response).get("data");
            code = data.get("error_no").toString();
            msg = (String) data.get("error_info");
        } catch (Exception e) {
            try {
                HuiZhongZhiDaiHitResponse hitResponse = JSONObject.parseObject(response, HuiZhongZhiDaiHitResponse.class);
                code = hitResponse.getCode();
                msg = hitResponse.getMsg();
            } catch (Exception ex) {
                ApiCompanyRecord record = new ApiCompanyRecord(companyId, customerRecordId, response);
                record.setStatus(ApiCompanyRecord.FAIL);
                record.setMessage("解析惠众直贷响应失败,响应内容" + response);
                return record;
            }
        }
        ApiCompanyRecord record = new ApiCompanyRecord(companyId, customerRecordId, response);
        if (Integer.toString(HuiZhongZhiDaiCommitResponse.SUCCESS).equals(code)) {
            record.setStatus(ApiCompanyRecord.SUCCESS);
            record.setMessage(msg);
        } else {
            record.setStatus(ApiCompanyRecord.FAIL);
            record.setMessage(msg);
        }
        return record;
    }
 
    public static ApiCompanyRecord getYiDaiRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        YiDaiResponse yiDaiResponse = JSONUtil.toBean(result, YiDaiResponse.class);
        if (YiDaiResponse.SUCCESS.equals(yiDaiResponse.getRetCode())) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
            apiCompanyRecord.setMessage("成功");
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
            apiCompanyRecord.setMessage(yiDaiResponse.getRetDesc());
        }
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getShangHaiZhongZanRecord(Long companyId, Long customerRecordId, String result) {
        result = Optional.ofNullable(result).map(String::trim).orElse(null);
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        if (ShangHaiZhongZanResponse.SUCCESS.equals(result)) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
            apiCompanyRecord.setMessage("成功");
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
            apiCompanyRecord.setMessage(result);
        }
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getNanJingMingTuoRecord(Long companyId, Long customerRecordId, String result) {
        result = Optional.ofNullable(result).orElse("{}");
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        NanJingMingTuoResp resp = JSON.parseObject(result, NanJingMingTuoResp.class);
        if (Objects.equals(NanJingMingTuoUtil.HIT_RESP_OK, resp.getCode())) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(resp.getMsg());
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getXinYeYouPinRecord(Long companyId, Long customerRecordId, String result) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, result);
        XyypResponse xyypResponse = JSONUtil.toBean(result, XyypResponse.class);
        Integer code = 200;
        if (xyypResponse.getCode().equals(code)) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
        } else {
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
        }
        apiCompanyRecord.setMessage(xyypResponse.getMsg());
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getDoudouMoneyRecord(Long companyId, Long customerRecordId, String msg, boolean ok) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, msg);
        apiCompanyRecord.setStatus(ok ? ApiCompanyRecord.SUCCESS : ApiCompanyRecord.FAIL);
        apiCompanyRecord.setMessage(msg);
        return apiCompanyRecord;
    }
 
    public static ApiCompanyRecord getJinZhangGuiRecord(Long companyId, Long customerRecordId, String response) {
        ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(companyId, customerRecordId, response);
        JinZhangGuiResponse jinZhangGuiResponse = null;
        try {
            jinZhangGuiResponse = JSONObject.parseObject(response, JinZhangGuiResponse.class);
        } catch (Exception e) {
            log.error("金掌柜对接失败");
        }
        if (jinZhangGuiResponse != null && JinZhangGuiUtil.SUCCESS.equals(jinZhangGuiResponse.getErrno())) {
            apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
            apiCompanyRecord.setMessage("成功");
        } else {
            String code = "";
            try {
                code = jinZhangGuiResponse.getMsg();
            } catch (Exception e) {
                if (response.length() > 255) {
                    code = response.subSequence(0, 254).toString();
                } else {
                    code = response;
                }
            }
            apiCompanyRecord.setStatus(ApiCompanyRecord.FAIL);
            apiCompanyRecord.setMessage(code);
        }
        return apiCompanyRecord;
    }
}