Commit ef3b1124 authored by 郝彦辉's avatar 郝彦辉

百行每天的重新报送优化成定时任务3

parent 4aeb8643
...@@ -5,16 +5,11 @@ import cn.quantgroup.report.service.common.CommonQueryService; ...@@ -5,16 +5,11 @@ import cn.quantgroup.report.service.common.CommonQueryService;
import cn.quantgroup.report.service.manualTool.CleanningTransactionLogService; import cn.quantgroup.report.service.manualTool.CleanningTransactionLogService;
import cn.quantgroup.report.service.manualTool.ManualToolService; import cn.quantgroup.report.service.manualTool.ManualToolService;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.collect.ImmutableMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;
import java.util.Map; import java.util.Map;
@Slf4j @Slf4j
...@@ -197,57 +192,4 @@ public class ManualToolController { ...@@ -197,57 +192,4 @@ public class ManualToolController {
return "deleteTidbCallRecordCF调度完成"; return "deleteTidbCallRecordCF调度完成";
} }
@RequestMapping("/deleteRedisKey")
public Map<String,Object> deleteRedisKey(String key1, String key2, String key3){
try{
manualToolService.deleteRedisKey(key1, key2, key3);
return ImmutableMap.of("code", 0, "msg", "手动删除redisKey成功");
}catch(Exception e){
return ImmutableMap.of("code", 1, "msg", "手动设置redisKey异常");
}
}
@RequestMapping("/getRedisVal")
public String getRedisVal(String key){
try{
return manualToolService.getRedisVal(key);
}catch(Exception e){
return "获取redis值异常";
}
}
@RequestMapping("/getIp")
public String getIp(){
try{
return getServerIp();
}catch(Exception e){
return "获取本地ip异常";
}
}
private String getServerIp() {
try {
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress ip = (InetAddress) addresses.nextElement();
if (ip != null
&& ip instanceof Inet4Address
&& !ip.isLoopbackAddress() /* loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255 */
&& ip.getHostAddress().indexOf(":") == -1) {
System.out.println("本机的IP = " + ip.getHostAddress());
return ip.getHostAddress();
}
}
}
} catch (Exception e) {
log.error("获取本地ip异常", e);
}
return null;
}
} }
package cn.quantgroup.report.job; package cn.quantgroup.report.job;
import cn.quantgroup.report.response.RiskHttpResponse;
import cn.quantgroup.report.service.baihang.BaiHangZhuDaiService; import cn.quantgroup.report.service.baihang.BaiHangZhuDaiService;
import cn.quantgroup.report.service.manualTool.ManualToolService;
import cn.quantgroup.report.utils.dingtalk.DingTalk; import cn.quantgroup.report.utils.dingtalk.DingTalk;
import cn.quantgroup.report.utils.http.HttpRequestUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Stopwatch; import com.google.common.base.Stopwatch;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -15,14 +14,16 @@ import org.springframework.scheduling.annotation.Async; ...@@ -15,14 +14,16 @@ import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.HashMap; import java.util.Enumeration;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* -----------------------------------------------------------------------------<br> * -----------------------------------------------------------------------------<br>
* 描述: 一些繁琐的日正常工作task<br> * 描述: 一些繁琐的日正常工作task<br>
...@@ -38,12 +39,21 @@ public class RoutineWorkTask { ...@@ -38,12 +39,21 @@ public class RoutineWorkTask {
private static final Logger log = LoggerFactory.getLogger(RoutineWorkTask.class); private static final Logger log = LoggerFactory.getLogger(RoutineWorkTask.class);
@Autowired @Autowired
private RedisTemplate<String,String> redisTemplate; private RedisTemplate<String, String> redisTemplate;
@Autowired @Autowired
private DingTalk dingTalk; private DingTalk dingTalk;
/** 百行报送工程RoutineWorkTask锁key */ @Autowired
private ManualToolService manualToolService;
@Autowired
BaiHangZhuDaiService baiHangZhuDaiService;
/**
* 百行报送工程RoutineWorkTask锁key
*/
public static final String ROUTINE_WORK_BH_LOCK_KEY_1 = "ROUTINE_WORK_BH_LOCK_KEY_1"; public static final String ROUTINE_WORK_BH_LOCK_KEY_1 = "ROUTINE_WORK_BH_LOCK_KEY_1";
public static final String ROUTINE_WORK_BH_LOCK_KEY_2 = "ROUTINE_WORK_BH_LOCK_KEY_2"; public static final String ROUTINE_WORK_BH_LOCK_KEY_2 = "ROUTINE_WORK_BH_LOCK_KEY_2";
...@@ -54,44 +64,46 @@ public class RoutineWorkTask { ...@@ -54,44 +64,46 @@ public class RoutineWorkTask {
@Async @Async
@Scheduled(cron = "0 0 17 * * ?") @Scheduled(cron = "0 10 18 * * ?")
public void downloadLog() { public void downloadLog() {
if (increment(ROUTINE_WORK_BH_LOCK_KEY_1)) { //if (increment(ROUTINE_WORK_BH_LOCK_KEY_1)) {
redisTemplate.expire(ROUTINE_WORK_BH_LOCK_KEY_1, 10, TimeUnit.SECONDS); // redisTemplate.expire(ROUTINE_WORK_BH_LOCK_KEY_1, 10, TimeUnit.SECONDS);
String ip = getServerIp();
if (StringUtils.isNotEmpty(ip) && (StringUtils.equalsAnyIgnoreCase(ip, "172.21.10.8", "172.17.0.122"))) {
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
//yyyy-MM-dd //yyyy-MM-dd
String newDatenyr = LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ISO_DATE); //String beforeDatenyr = LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ISO_DATE);
String newDatenyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
newDatenyr = newDatenyr.replace("-", ""); newDatenyr = newDatenyr.replace("-", "");
//指定只有172.21.10.8服务器 //指定只有172.21.10.8服务器
String downloadUrl = "http://172.21.10.8:9021/manualtool/send/baihang?key=b5140fb2-2c85-4b5a-abcf-3e97528014db"; //String downloadUrl = "http://172.21.10.8:9021/manualtool/send/baihang?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
Map<String, Object> body = new HashMap<>(); String p1 = "L0hNMklnTjNPenA1aDdqSHpreld1UT09";
body.put("p1", "L0hNMklnTjNPenA1aDdqSHpreld1UT09"); String p2 = "UTg1UFN4SjN3TThuVXFIVEFUUFR0QT09";
body.put("p2", "UTg1UFN4SjN3TThuVXFIVEFUUFR0QT09"); String p3 = "Mm12NTBKU1JkVFE3MjlCK3RnZTNRdz09";
body.put("p3", "Mm12NTBKU1JkVFE3MjlCK3RnZTNRdz09"); String p4 = "MmJJMzNUQVRMSXQ4V3VDbUswZGNlUT09";
body.put("p4", "MmJJMzNUQVRMSXQ4V3VDbUswZGNlUT09"); String p5 = newDatenyr;
body.put("p5", newDatenyr); String secretKey = "UY1I5dHb3iq/DtEAm1f3yu7emYzlSvpFNPkxpOMSegqYJ08M2drTtNiqLyaxjbERWR0yS5CHPKpHwGjTXWHP3DEEDfXX4LhRtmiN1LIpZPdl87YWpDJ1qg07EN671JcY406oPbh7KsHFO0I0B32Hee1iZanKL4tzqmgF4dvsUNs=";
body.put("secretKey", "UY1I5dHb3iq/DtEAm1f3yu7emYzlSvpFNPkxpOMSegqYJ08M2drTtNiqLyaxjbERWR0yS5CHPKpHwGjTXWHP3DEEDfXX4LhRtmiN1LIpZPdl87YWpDJ1qg07EN671JcY406oPbh7KsHFO0I0B32Hee1iZanKL4tzqmgF4dvsUNs=");
body.put("isSend", "false");//不自动报送 String isSend = "false";//不自动报送
body.put("sendIncludeType", "D2,D3");//不不自动报送,该参数没有用 String sendIncludeType = "D2,D3";//不不自动报送,该参数没有用
body.put("isProduct", "true"); String isProduct = "true";
body.put("errorCode", "D3_035,");//以后发现其他错误code,可以追加 String errorCode = "D3_035,";//以后发现其他错误code,可以追加
log.info("下载(众信利民助贷)百行反馈日志开始, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr); log.info("下载(众信利民助贷)百行反馈日志开始, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr);
try { try {
Stopwatch stopwatch1 = Stopwatch.createStarted(); Stopwatch stopwatch1 = Stopwatch.createStarted();
RiskHttpResponse riskHttpResponse = HttpRequestUtil.doPost(downloadUrl, body); Map<String, String> resultMap = manualToolService.sendBaiHangData(p1, p2, p3, p4, p5, secretKey, isSend, errorCode, isProduct, sendIncludeType);
//manualToolService.sendBaiHangData log.info("处理结束, result: {} , 耗时: {} ", JSONObject.toJSONString(resultMap), stopwatch1.stop().elapsed(TimeUnit.MILLISECONDS));
log.info("处理结束, result: {} , 耗时: {} ", JSONObject.toJSONString(riskHttpResponse), stopwatch1.stop().elapsed(TimeUnit.MILLISECONDS));
int statusCode = riskHttpResponse.getCode(); if (resultMap != null) {
JSONObject jsonObject = riskHttpResponse.getJsonObject(); String success = resultMap.get("success");
if (statusCode == 200 && jsonObject != null) { String alarm = resultMap.get("alarm");
String success = jsonObject.getString("success");
String alarm = jsonObject.getString("alarm");
if (StringUtils.isNotEmpty(success)) { if (StringUtils.isNotEmpty(success)) {
if (StringUtils.isNotEmpty(alarm)) { if (StringUtils.isNotEmpty(alarm)) {
...@@ -102,20 +114,20 @@ public class RoutineWorkTask { ...@@ -102,20 +114,20 @@ public class RoutineWorkTask {
log.info("下载(众信利民助贷)百行反馈日志结束, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); log.info("下载(众信利民助贷)百行反馈日志结束, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
return; return;
} else { } else {
dingTalk.talk("Info", "下载&处理" + newDatenyr + "(众信利民助贷)百行反馈日志结束", success + "————10分钟后将会自动重新报送,若有问题请及时停止!"); dingTalk.talk("Info", "下载&处理" + newDatenyr + "(众信利民助贷)百行反馈日志结束", success + "————10分钟后将会自动重新报送,若有问题请及时停止!");
String json_sq_A1 = jsonObject.getString("json_sq_A1"); String json_sq_A1 = resultMap.get("json_sq_A1");
if(StringUtils.isNotEmpty(json_sq_A1) && "true".equals(json_sq_A1)){ if (StringUtils.isNotEmpty(json_sq_A1) && "true".equals(json_sq_A1)) {
setRedisValStr(ZXLM_A1_INTERFACE_SEND); setRedisValStr(ZXLM_A1_INTERFACE_SEND);
} }
String json_fk_D2 = jsonObject.getString("json_fk_D2"); String json_fk_D2 = resultMap.get("json_fk_D2");
if(StringUtils.isNotEmpty(json_fk_D2) && "true".equals(json_fk_D2)){ if (StringUtils.isNotEmpty(json_fk_D2) && "true".equals(json_fk_D2)) {
setRedisValStr(ZXLM_D2_INTERFACE_SEND); setRedisValStr(ZXLM_D2_INTERFACE_SEND);
} }
String json_hk_D3 = jsonObject.getString("json_hk_D3"); String json_hk_D3 = resultMap.get("json_hk_D3");
if(StringUtils.isNotEmpty(json_hk_D3) && "true".equals(json_hk_D3)){ if (StringUtils.isNotEmpty(json_hk_D3) && "true".equals(json_hk_D3)) {
setRedisValStr(ZXLM_D3_INTERFACE_SEND); setRedisValStr(ZXLM_D3_INTERFACE_SEND);
} }
...@@ -126,12 +138,13 @@ public class RoutineWorkTask { ...@@ -126,12 +138,13 @@ public class RoutineWorkTask {
} }
} catch (Exception e) { } catch (Exception e) {
log.error("下载(众信利民助贷)百行反馈日志异常, newDatenyr: {} ", newDatenyr, e); log.error("下载(众信利民助贷)百行反馈日志异常, newDatenyr: {} ", newDatenyr, e);
dingTalk.talk("Error", "报送服务内部异常", e); dingTalk.talk("Error", "报送服务内部异常", "(" + newDatenyr + ") 异常信息:" + e.toString());
dingTalk.talk_ToUser("数据报送异常", "报送服务内部异常,请尽快手动处理!"); dingTalk.talk_ToUser("数据报送异常", "报送服务内部异常,请尽快手动处理!");
return;
} }
dingTalk.talk_ToUser("下载(众信利民助贷)百行反馈日志未知异常", "下载" + newDatenyr + "反馈日志失败,请尽快手动处理!"); dingTalk.talk_ToUser("下载(众信利民助贷)百行反馈日志未知异常", "下载 (" + newDatenyr + ") 反馈日志失败,请尽快手动处理!");
log.info("下载(众信利民助贷)百行反馈日志结束, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); log.info("下载(众信利民助贷)百行反馈日志结束, newDatenyr: {}, 耗时: {} ", newDatenyr, stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
} }
...@@ -139,71 +152,74 @@ public class RoutineWorkTask { ...@@ -139,71 +152,74 @@ public class RoutineWorkTask {
@Async @Async
@Scheduled(cron = "0 15 17 * * ?") @Scheduled(cron = "0 20 18 * * ?")
public void sendBaoSong() { public void sendBaoSong() {
if (increment(ROUTINE_WORK_BH_LOCK_KEY_2)) { //if (increment(ROUTINE_WORK_BH_LOCK_KEY_2)) {
redisTemplate.expire(ROUTINE_WORK_BH_LOCK_KEY_2, 10, TimeUnit.SECONDS); // redisTemplate.expire(ROUTINE_WORK_BH_LOCK_KEY_2, 10, TimeUnit.SECONDS);
String ip = getServerIp();
if (StringUtils.isNotEmpty(ip) && (StringUtils.equalsAnyIgnoreCase(ip, "172.21.10.8", "172.17.0.122"))) {
Stopwatch stopwatch = Stopwatch.createStarted(); Stopwatch stopwatch = Stopwatch.createStarted();
//yyyy-MM-dd //yyyy-MM-dd
String newDatenyr = LocalDateTime.now().plusDays(-1).format(DateTimeFormatter.ISO_DATE); String newDatenyr = LocalDateTime.now().format(DateTimeFormatter.ISO_DATE);
newDatenyr = newDatenyr.replace("-", ""); newDatenyr = newDatenyr.replace("-", "");
//指定只有172.21.10.8服务器 172.21.10.8:9021 //指定只有172.21.10.8服务器 172.21.10.8:9021
String send_A1_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainApplySend?key=b5140fb2-2c85-4b5a-abcf-3e97528014db"; //String send_A1_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainApplySend?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
String send_D2_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainLoanInfoSend?key=b5140fb2-2c85-4b5a-abcf-3e97528014db"; //String send_D2_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainLoanInfoSend?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
String send_D3_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainRepaymentLoanInfo?key=b5140fb2-2c85-4b5a-abcf-3e97528014db"; //String send_D3_url = "http://172.21.10.8:9021/zhudai/re_send/manual/buquan/mainRepaymentLoanInfo?key=b5140fb2-2c85-4b5a-abcf-3e97528014db";
log.info("众信利民助贷-百行重新报送开始, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr); log.info("众信利民助贷-百行重新报送开始, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr);
if(getRedisValStr(ZXLM_A1_INTERFACE_SEND)){ if (getRedisValStr(ZXLM_A1_INTERFACE_SEND)) {
try { try {
redisTemplate.delete(ZXLM_A1_INTERFACE_SEND); redisTemplate.delete(ZXLM_A1_INTERFACE_SEND);
String result = HttpRequestUtil.doPostTool(send_A1_url, new HashMap<>()); String result = baiHangZhuDaiService.sendHandApplyToBaiHang(true, null);
log.info("众信利民助贷-百行重新报送A1结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result); log.info("众信利民助贷-百行重新报送A1结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result);
dingTalk.talk("Info", "众信利民助贷-重新报送 A1 结束", "("+newDatenyr+")"+result); dingTalk.talk("Info", "众信利民助贷-重新报送 A1 结束", "(" + newDatenyr + ")" + result);
Thread.sleep(10*1000);//10秒 Thread.sleep(10 * 1000);//10秒
}catch (Exception e){ } catch (Exception e) {
log.info("(众信利民助贷)重新报送A1异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e); log.info("(众信利民助贷)重新报送A1异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e);
dingTalk.talk_ToUser("众信利民助贷-重新报送 A1 异常", "("+newDatenyr+") A1报送异常,请尽快查看处理!"); dingTalk.talk_ToUser("众信利民助贷-重新报送 A1 异常", "(" + newDatenyr + ") A1报送异常,请尽快查看处理!");
} }
} }
if(getRedisValStr(ZXLM_D2_INTERFACE_SEND)){ if (getRedisValStr(ZXLM_D2_INTERFACE_SEND)) {
try { try {
redisTemplate.delete(ZXLM_D2_INTERFACE_SEND); redisTemplate.delete(ZXLM_D2_INTERFACE_SEND);
String result = HttpRequestUtil.doPostTool(send_D2_url, new HashMap<>()); String result = baiHangZhuDaiService.sendHandLoaInfoReportToBaiHang2(true, null, null);
;
log.info("众信利民助贷-百行重新报送D2结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result); log.info("众信利民助贷-百行重新报送D2结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result);
dingTalk.talk("Info", "众信利民助贷-重新报送 D2 结束", "("+newDatenyr+")"+result); dingTalk.talk("Info", "众信利民助贷-重新报送 D2 结束", "(" + newDatenyr + ")" + result);
Thread.sleep(10*1000);//10秒 Thread.sleep(10 * 1000);//10秒
}catch (Exception e){ } catch (Exception e) {
log.info("(众信利民助贷)重新报送D2异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e); log.info("(众信利民助贷)重新报送D2异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e);
dingTalk.talk_ToUser("众信利民助贷-重新报送 D2 异常", "("+newDatenyr+") D2报送异常,请尽快查看处理!"); dingTalk.talk_ToUser("众信利民助贷-重新报送 D2 异常", "(" + newDatenyr + ") D2报送异常,请尽快查看处理!");
} }
} }
if(getRedisValStr(ZXLM_D3_INTERFACE_SEND)){ if (getRedisValStr(ZXLM_D3_INTERFACE_SEND)) {
try { try {
redisTemplate.delete(ZXLM_D3_INTERFACE_SEND); redisTemplate.delete(ZXLM_D3_INTERFACE_SEND);
String result = HttpRequestUtil.doPostTool(send_D3_url, new HashMap<>()); String result = baiHangZhuDaiService.sendHandRepaymentReportToBaiHang1(true, null);
log.info("众信利民助贷-百行重新报送D3结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result); log.info("众信利民助贷-百行重新报送D3结束, newTime: {} , newDatenyr: {} , result: {} ", LocalDateTime.now(), newDatenyr, result);
dingTalk.talk("Info", "众信利民助贷-重新报送 D2 结束", "("+newDatenyr+")"+result); dingTalk.talk("Info", "众信利民助贷-重新报送 D2 结束", "(" + newDatenyr + ")" + result);
Thread.sleep(10*1000);//10秒 Thread.sleep(10 * 1000);//10秒
}catch (Exception e){ } catch (Exception e) {
log.info("(众信利民助贷)重新报送D3异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e); log.info("(众信利民助贷)重新报送D3异常, newTime: {} , newDatenyr: {} ", LocalDateTime.now(), newDatenyr, e);
dingTalk.talk_ToUser("众信利民助贷-重新报送 D3 异常", "("+newDatenyr+") D3报送异常,请尽快查看处理!"); dingTalk.talk_ToUser("众信利民助贷-重新报送 D3 异常", "(" + newDatenyr + ") D3报送异常,请尽快查看处理!");
} }
} }
...@@ -212,37 +228,57 @@ public class RoutineWorkTask { ...@@ -212,37 +228,57 @@ public class RoutineWorkTask {
} }
private Boolean increment(String key) {
private Boolean increment(String key){
Long increment = redisTemplate.opsForValue().increment(key, 1); Long increment = redisTemplate.opsForValue().increment(key, 1);
return increment <= 1; return increment <= 1;
} }
private void setRedisValStr(String key){ private void setRedisValStr(String key) {
try { try {
redisTemplate.opsForValue().set(key, "true", 15, TimeUnit.MINUTES); redisTemplate.opsForValue().set(key, "true", 15, TimeUnit.MINUTES);
}catch (Exception e){ } catch (Exception e) {
log.error("Redis中set值异常, key: {} ", key, e); log.error("Redis中set值异常, key: {} ", key, e);
} }
} }
private boolean getRedisValStr(String key){ private boolean getRedisValStr(String key) {
String value = null; String value = null;
try { try {
value = redisTemplate.opsForValue().get(key); value = redisTemplate.opsForValue().get(key);
}catch (Exception e){ } catch (Exception e) {
log.error("Redis中get值异常, key: {} ", key, e); log.error("Redis中get值异常, key: {} ", key, e);
} }
if(StringUtils.isNotEmpty(value) && "true".equals(value)){ if (StringUtils.isNotEmpty(value) && "true".equals(value)) {
return true; return true;
}else{ } else {
return false; return false;
} }
} }
private static String getServerIp() {
try {
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces();
while (allNetInterfaces.hasMoreElements()) {
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement();
Enumeration<InetAddress> addresses = netInterface.getInetAddresses();
while (addresses.hasMoreElements()) {
InetAddress ip = (InetAddress) addresses.nextElement();
if (ip != null
&& ip instanceof Inet4Address
&& !ip.isLoopbackAddress() // loopback地址即本机地址,IPv4的loopback范围是127.0.0.0 ~ 127.255.255.255
&& ip.getHostAddress().indexOf(":") == -1) {
log.info("本机的IP = " + ip.getHostAddress());
return ip.getHostAddress();
}
}
}
} catch (Exception e) {
log.error("获取本地ip异常", e);
}
return null;
}
} }
...@@ -825,34 +825,42 @@ public class HttpRequestUtil { ...@@ -825,34 +825,42 @@ public class HttpRequestUtil {
} }
} }
//重新报送的工具使用,可能慢
public static String doPostTool(String apiUrl, Map<String, Object> params) { public static String doPostTool(String apiUrl, Map<String, Object> params) {
String result = ""; String response = "";
httpClient = getHttpClient();
HttpPost httpPost = new HttpPost(apiUrl);
try { try {
List<NameValuePair> pairList = new ArrayList<>(params.size()); String bodyStr = JSON.toJSONString(params);
for (Map.Entry<String, Object> entry : params.entrySet()) { byte[] body = bodyStr.getBytes("UTF-8");
NameValuePair pair = new BasicNameValuePair(entry.getKey(), entry java.net.URL parsedUrl = new java.net.URL(apiUrl);
.getValue().toString()); java.net.HttpURLConnection conn = (java.net.HttpURLConnection) parsedUrl.openConnection();
pairList.add(pair);
}
httpPost.setEntity(new UrlEncodedFormEntity(pairList, Charset.forName("UTF-8")));
HttpResponse response = httpClient.execute(httpPost);
//int statusCode = response.getStatusLine().getStatusCode(); conn.setConnectTimeout(6000);
HttpEntity entity = response.getEntity(); conn.setReadTimeout(60000);//60秒
conn.setUseCaches(false);
result = EntityUtils.toString(entity); conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
conn.setRequestProperty("Content-Length", String.valueOf(body.length));
OutputStream outStream = conn.getOutputStream();
outStream.write(body);
outStream.flush();
outStream.close();
EntityUtils.consume(entity); if(conn.getResponseCode() == 200){
BufferedReader in = new BufferedReader(new InputStreamReader((InputStream) conn.getInputStream(), "UTF-8"));
response = in.readLine();
in.close();
}
conn.disconnect();
return response;
} catch (Exception e) {
log.error("doPostTool httpRequest, apiUrl: "+apiUrl+"请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString()+";url="+apiUrl);
}finally {
} catch (IOException e) {
log.error("doPostTool请求apiUrl: " + apiUrl + "请求失败", e);
throw new QGException(QGExceptionType.COMMON_THIRD_PART_CALL_EXCEPTION, e.toString() + ";url:" + apiUrl);
} finally {
httpPost.releaseConnection();
} }
return result;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment