ab
2024-11-05 0c6faf64f2a02ae94b0d719729754f7ca29da416
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
package com.nova.sankuai.domain.api.xinyeyoupin;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpStatus;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.nova.sankuai.domain.entity.Customer;
import com.nova.sankuai.domain.enums.ProfessionInfoEnum;
import com.nova.sankuai.domain.enums.customerinfo.*;
import com.nova.sankuai.infra.constants.Constants;
import com.nova.sankuai.infra.utils.AesSecretUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Author Lilinhong
 * @Date 2022/5/31 15:39
 */
@Component
public class XinYeYouPinUtil {
 
    @Value("${xyyp.channelcode}")
    private String channelCode;
 
    @Value("${xyyp.aes_key}")
    private String aesKey;
 
    @Value("${xyyp.url}")
    public String url;
 
    private static final Logger logger = LoggerFactory.getLogger("capitalLogger");
 
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
 
    public String parseParam(Customer customer, String tradeno) {
        // 请求体
        Map<String, Object> body = new HashMap<>(16);
        // 原始参数
        Map<String, Object> param = new HashMap<>(16);
        param.put("phone", customer.getPhone());
        param.put("applyname", customer.getName());
        param.put("idcard", customer.getIdCard());
        param.put("age", customer.getAge());
        //居住城市
        param.put("city", customer.getCityName());
        loanParse(param, customer);
        professionalParse(param, customer);
        param.put("huabei", 1);
        creditParse(param, customer);
        //芝麻信用分
        zhimaParse(param, customer);
        //社保
        socialParse(param, customer);
        //公积金
        fundParse(param, customer);
        //微粒贷
        param.put("microloan", 2);
        insuranceParse(param, customer);
        //房产信息
        houseParse(param, customer);
        //车辆信息
        carParse(param, customer);
        //京东白条
        param.put("baitiao", 1);
        String paramString = null;
        logger.info("手机号为:" + customer.getPhone() + ",信业优品原始date入参序列化前数据->:{}", param);
        try {
            paramString = OBJECT_MAPPER.writeValueAsString(param);
            logger.info("手机号为:" + customer.getPhone() + ",信业优品原始date入参序列化后数据->:{}", paramString);
        } catch (JsonProcessingException e) {
            logger.info("手机号为:" + customer.getPhone() + ",信业优品原始date入参序列化后数据错误");
            e.printStackTrace();
            return null;
        }
        String data = null;
        try {
            data = AesSecretUtils.encrypt(paramString, aesKey);
            logger.info("手机号为:" + customer.getPhone() + ",信业优品原始date入参加密数据->:{}", data);
        } catch (Exception e) {
            logger.info("手机号为:" + customer.getPhone() + ",信业优品原始date入参加密错误");
            e.printStackTrace();
            return null;
        }
        body.put("channelcode", channelCode);
        body.put("tradeno", tradeno);
        body.put("data", data);
        String bodyParam = null;
        logger.info("手机号为:" + customer.getPhone() + ",信业优品原始入参序列化前数据->:{}", body);
        try {
            bodyParam = OBJECT_MAPPER.writeValueAsString(body);
            logger.info("手机号为:" + customer.getPhone() + ",信业优品原始入参序列化前后数据->:{}", body);
        } catch (JsonProcessingException e) {
            logger.info("手机号为:" + customer.getPhone() + ",信业优品原始入参序列化后数据错误");
            e.printStackTrace();
            return null;
        }
        return bodyParam;
    }
 
 
    public XyypResponse push(Customer customer, String tradeno) {
        String bodyParam = parseParam(customer, tradeno);
        HttpResponse execute = HttpRequest.post(url)
                .timeout(Constants.TIME_OUT)
                .contentType("application/x-www-form-urlencoded")
                .body(bodyParam).execute();
        if (execute == null) {
            logger.info("手机号为:" + customer.getPhone() + ",信业优品请求返回为空->:{}", execute);
            return null;
        }
        if (execute.getStatus() != HttpStatus.HTTP_OK) {
            logger.info("手机号为:" + customer.getPhone() + ",信业优品请求返回数据失败->:{}", execute.toString());
            return null;
        }
        logger.info("手机号为:" + customer.getPhone() + ",信业优品返回数据->:{}", execute.body());
        XyypResponse xyypResponse = null;
        try {
            xyypResponse = JSONUtil.toBean(execute.body(), XyypResponse.class);
        } catch (Exception e) {
            logger.info("手机号为:" + customer.getPhone() + ",信业优品请求返回数据转换失败->:{}", xyypResponse);
            e.printStackTrace();
            return null;
        }
        return xyypResponse;
    }
 
    public void loanParse(Map<String, Object> param, Customer customer) {
        Double first = 100000.00;
        Double second = 200000.00;
        Double third = 500000.00;
        Double fourth = 1000000.00;
        if (customer.getLoanAmount() == null) {
            param.put("loan", 10);
        } else {
            if (customer.getLoanAmount() <= first) {
                param.put("loan", 10);
            } else if (customer.getLoanAmount() > first && customer.getLoanAmount() <= second) {
                param.put("loan", 20);
            } else if (customer.getLoanAmount() > second && customer.getLoanAmount() <= third) {
                param.put("loan", 50);
            } else if (customer.getLoanAmount() > third && customer.getLoanAmount() <= fourth) {
                param.put("loan", 100);
            } else {
                param.put("loan", 200);
            }
        }
    }
 
    public void professionalParse(Map<String, Object> param, Customer customer) {
        if (customer.getProfessionInfo() == null) {
            param.put("professional", 1);
        } else {
            if (ProfessionInfoEnum.BUSINESS_OWNERS.getCode().equals(customer.getProfessionInfo())) {
                param.put("professional", 2);
            } else {
                param.put("professional", 1);
            }
        }
    }
 
    public void creditParse(Map<String, Object> param, Customer customer) {
        if (customer.getCreditCard() == null) {
            param.put("credit", 2);
        } else {
            if (CreditCardStatusEnum.CreditCard_1.getCode().equals(customer.getCreditCard())) {
                param.put("credit", 2);
            } else {
                param.put("credit", 1);
            }
        }
    }
 
    public void zhimaParse(Map<String, Object> param, Customer customer) {
        if (customer.getSesame() == null) {
            param.put("zhima", 5);
        } else {
            if (SesameStatusEnum.Sesame_2.getCode().equals(customer.getSesame())) {
                param.put("zhima", 1);
            } else if (SesameStatusEnum.Sesame_3.getCode().equals(customer.getSesame())) {
                param.put("zhima", 2);
            } else if (SesameStatusEnum.Sesame_4.getCode().equals(customer.getSesame())) {
                param.put("zhima", 3);
            } else {
                param.put("zhima", 4);
            }
        }
    }
 
    public void socialParse(Map<String, Object> param, Customer customer) {
        if (customer.getSocialSecurity() == null) {
            param.put("social", 2);
        } else {
            if (SocialSecurityStatusEnum.SocialSecurity_1.getCode().equals(customer.getSocialSecurity())) {
                param.put("social", 2);
            } else {
                param.put("social", 1);
            }
        }
    }
 
    public void fundParse(Map<String, Object> param, Customer customer) {
        if (customer.getProvidentFund() == null) {
            param.put("fund", 2);
        } else {
            if (ProvidentFundStatusEnum.ProvidentFund_1.getCode().equals(customer.getProvidentFund())) {
                param.put("fund", 2);
            } else {
                param.put("fund", 1);
            }
        }
    }
 
    public void insuranceParse(Map<String, Object> param, Customer customer) {
        if (customer.getInsurancePolicy() == null) {
            param.put("insurance", 2);
        } else {
            if (InsuranceStatusEnum.BusinessInsurance_1.getCode().equals(customer.getInsurancePolicy())) {
                param.put("insurance", 2);
            } else {
                param.put("insurance", 1);
            }
        }
    }
 
    public void houseParse(Map<String, Object> param, Customer customer) {
        if (customer.getHouseStatus() == null) {
            param.put("house", 4);
        } else {
            if (HouseStatusEnum.House_1.getCode().equals(customer.getHouseStatus())) {
                param.put("house", 4);
            } else if (HouseStatusEnum.House_2.getCode().equals(customer.getHouseStatus())) {
                param.put("house", 2);
            } else if (HouseStatusEnum.House_3.getCode().equals(customer.getHouseStatus())) {
                param.put("house", 1);
            } else {
                param.put("house", 5);
            }
        }
    }
 
    public void carParse(Map<String, Object> param, Customer customer) {
        if (customer.getCarStatus() == null) {
            param.put("car", 3);
        } else {
            if (CarStatusEnum.Car_1.getCode().equals(customer.getCarStatus())) {
                param.put("car", 3);
            } else if (CarStatusEnum.Car_2.getCode().equals(customer.getCarStatus())) {
                param.put("car", 2);
            } else if (CarStatusEnum.Car_3.getCode().equals(customer.getCarStatus())) {
                param.put("car", 1);
            } else {
                param.put("car", 2);
            }
        }
    }
 
}