BackPassService.java
1.78 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
package com.huaheng.api.backPass;
import com.alibaba.fastjson.JSON;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.http.HttpUtils;
import com.huaheng.framework.aspectj.ApiLogAspect;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.service.ConfigService;
import com.huaheng.pc.monitor.apilog.domain.ApiLog;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class BackPassService {
@Resource
private ConfigService configService;
public AjaxResult back(String url,String jsonParam,String warehouseCode){
String back = configService.getKey(QuantityConstant.CONNECT_BACK);
Integer isBack = Integer.valueOf(back);
if(QuantityConstant.IS_BACK != isBack){
return AjaxResult.success();
}
AjaxResult ajaxResult = null;
String msg = "";
ApiLog log = null;
HttpHeaders headers = new HttpHeaders();
try {
log = ApiLogAspect.initApiLog("post", url,
jsonParam, headers, warehouseCode);
String result = HttpUtils.bodypost(url, jsonParam,warehouseCode);
if(StringUtils.isEmpty(result)){
return AjaxResult.error("接口地址错误或服务器连接不到或返回为空");
}
ajaxResult = JSON.parseObject(result, AjaxResult.class);
}catch (Exception e) {
e.printStackTrace();
ApiLogAspect.setApiLogException(log, e);
} finally {
ApiLogAspect.finishApiLog(log, headers, msg);
}
return ajaxResult;
}
}