HzRemoteManager.java
4.25 KB
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
package cn.com.glsx.manager;
import cn.com.glsx.config.HzProperty;
import cn.com.glsx.config.SystemProperty;
import cn.com.glsx.dj.insure.model.InsureOrder;
import cn.com.glsx.framework.core.util.DateUtils;
import cn.com.glsx.util.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.http.entity.ContentType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
* @author zhoudan
*/
@Service
public class HzRemoteManager {
private final static Logger LOGGER = LoggerFactory.getLogger(HzRemoteManager.class);
@Autowired
private HzProperty hzProperty;
@Autowired
private Environment env;
@Autowired
private SystemProperty systemProperty;
public void insureResultNotice(InsureOrder order) {
// String url = "http://iov.szhaizhen.com/anon/carboxvin/syncCarInsuranceStatus.dev";
String url = env.getProperty("insure_result_hz_notice");
JSONObject requestBody = this.getRequestBody(order);
LOGGER.info("调用海圳远程通知api参数:{}",requestBody);
JSONObject response = null;
//尝试三次回调,解决连接超时问题
int tryCount = systemProperty.getReinvokeTimes();
int i = 0;
while(i++ < tryCount){
try{
response = HttpUtil.postJSON(url,requestBody, ContentType.APPLICATION_JSON,null);
LOGGER.info("海圳远程通知api返回结果:{}",response);
}catch(Exception e){
LOGGER.error("序列号:{},回调失败:{}", order.getSeqNo(), e.getMessage(), e);
}
if(response!=null && response.getString("success").equals("true")){
break;
}
LOGGER.info("{}海圳第{}次回调,延时时间:{}", order.getSeqNo(), i, 2 * i * systemProperty.getReinvokeSleepTime());
try {
Thread.sleep(2 * i * systemProperty.getReinvokeSleepTime());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
private JSONObject getRequestBody(InsureOrder order) {
JSONObject requestBody = new JSONObject();
requestBody.put("boxImei",order.getSubDeviceSn());
if("1".equals(order.getInsuranceStatus())){
requestBody.put("serviceStatus", "已生效");
}else if("6".equals(order.getInsuranceStatus())){
requestBody.put("serviceStatus", "已取消");
}
requestBody.put("serviceType", "保险");
requestBody.put("serviceName", "盗抢险");
requestBody.put("serviceCompany", "中国人保");
requestBody.put("thirdId", order.getFullInsuranceNo());
requestBody.put("effectiveTime", DateUtils.formatDate(order.getEffectDate(),DateUtils.DEFAULT_DATE_FORMAT));
requestBody.put("periodUnit", 2);
requestBody.put("periodValue", order.getInsurePeriod());
requestBody.put("serviceUrl", order.getPdfUrl());
return requestBody;
}
public static void main(String[] args) {
HzRemoteManager manager = new HzRemoteManager();
System.out.println(new Long(System.currentTimeMillis()).toString().substring(0,10));
Map<String,String> params = new HashMap<String,String>(16);
JSONObject requestBody = new JSONObject();
params.put("boxImei", "1780124097");
params.put("serviceType", "保险");
params.put("serviceName", "盗抢险");
params.put("serviceCompany", "中国人保");
requestBody.put("serviceStatus", "已生效");
requestBody.put("effectiveTime", "2020-02-26");
requestBody.put("periodUnit", 2);
requestBody.put("periodValue", 36);
requestBody.put("serviceUrl", "");
requestBody.put("thirdId", "111111111111");
}
public Map<String,String> getBaseParams() {
Map<String,String> params = new HashMap<String,String>(8);
params.put("serviceType", hzProperty.getServiceType());
params.put("serviceName", hzProperty.getServiceName());
params.put("serviceCompany", hzProperty.getServiceCompany());
return params;
}
}