Commit 6311108a authored by 黎博's avatar 黎博

新增实时日志

parent 7d24b368
......@@ -159,6 +159,12 @@
<version>1.6</version>
</dependency>
<!-- websocket -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
</dependencies>
<build>
......
package cn.qg.qaplatform.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
import javax.websocket.server.ServerEndpointConfig;
@Configuration
public class WebSocketConfig {
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
}
package cn.qg.qaplatform.config;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;
@ServerEndpoint(value = "/websocket/{userId}")
@Component
@Slf4j
public class WebSocketServer {
private static ConcurrentHashMap<String, WebSocketServer> webSocketMap = new ConcurrentHashMap<>();
/**
* 与某个客户端的连接会话,需要通过它来给客户端发送数据
*/
private Session session;
/**
* 接收userId
*/
private String userId = "";
@OnOpen
public void onOpen(Session session, @PathParam("userId") String userId) {
this.session = session;
this.userId = userId;
if (webSocketMap.containsKey(userId)) {
webSocketMap.remove(userId);
webSocketMap.put(userId, this);
} else {
webSocketMap.put(userId, this);
}
try {
log.info("用户连接:" + userId);
sendMessage("与服务器连接成功...");
} catch (IOException e) {
log.error("用户:" + userId + ",网络异常!!!!!!");
}
}
@OnClose
public void onClose() {
if (webSocketMap.containsKey(userId)) {
webSocketMap.remove(userId);
}
log.info("用户退出:" + userId);
}
@OnMessage
public void onMessage(String message, Session session) {
log.info("用户消息:" + userId + ",报文:" + message);
//可以群发消息
//消息保存到数据库、redis
if (StringUtils.isNotBlank(message)) {
try {
//解析发送的报文
JSONObject jsonObject = JSON.parseObject(message);
//追加发送人(防止串改)
jsonObject.put("fromUserId", this.userId);
String toUserId = jsonObject.getString("toUserId");
//传送给对应toUserId用户的websocket
if (StringUtils.isNotBlank(toUserId) && webSocketMap.containsKey(toUserId)) {
webSocketMap.get(toUserId).sendMessage(jsonObject.toJSONString());
} else {
log.error("请求的userId:" + toUserId + "不在该服务器上");
//否则不在这个服务器上,发送到mysql或者redis
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
@OnError
public void onError(Session session, Throwable error) {
log.error("用户错误:" + this.userId + ",原因:" + error.getMessage());
error.printStackTrace();
}
public void sendMessage(String message) throws IOException {
this.session.getBasicRemote().sendText(message);
}
public static void sendInfo(String message, @PathParam("userId") String userId) {
log.info("发送消息到:" + userId + ",报文:" + message);
if (StringUtils.isNotBlank(userId) && webSocketMap.containsKey(userId)) {
try {
webSocketMap.get(userId).sendMessage(message);
} catch (IOException e) {
e.printStackTrace();
}
} else {
log.error("用户" + userId + ",不在线!");
}
}
}
......@@ -43,4 +43,9 @@ public class ApplyLoanInfo {
*/
private Integer term;
/**
* websocket通信标志位
*/
private String symbol;
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,6 +3,7 @@ package cn.qg.qaplatform.service;
import cn.qg.qaplatform.domain.ApplyLoanInfo;
import cn.qg.qaplatform.domain.GenLoanUser;
import java.io.IOException;
import java.sql.SQLException;
public interface GenUserDataService {
......@@ -10,7 +11,7 @@ public interface GenUserDataService {
/**
* 分配资金方
*/
boolean assignFundCorp(String namespace, Integer fundId);
boolean assignFundCorp(String namespace, Integer fundId, String symbol) throws IOException;
/**
* 授信
......@@ -48,4 +49,5 @@ public interface GenUserDataService {
* @return
*/
GenLoanUser queryUserStatus(String namespace, String phoneNo);
}
package cn.qg.qaplatform.service.impl;
import cn.qg.qaplatform.config.WebSocketServer;
import cn.qg.qaplatform.domain.ApplyLoanInfo;
import cn.qg.qaplatform.domain.GenLoanUser;
import cn.qg.qaplatform.process.xyqb.MainProcess;
......@@ -11,6 +12,7 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Map;
......@@ -32,7 +34,8 @@ public class GenUserDataServiceImpl implements GenUserDataService {
* @return
*/
@Override
public boolean assignFundCorp(String namespace, Integer fundId) {
public boolean assignFundCorp(String namespace, Integer fundId, String symbol) throws IOException {
MainProcess.symbol = symbol;
// 登录资金方OP
String fundOpToken = MainProcess.loginFundOP(namespace);
boolean isAleadyAssign = false;
......@@ -73,6 +76,7 @@ public class GenUserDataServiceImpl implements GenUserDataService {
Integer fundId = applyLoanInfo.getFundId();
Integer amount = applyLoanInfo.getAmount();
Integer term = applyLoanInfo.getTerm();
String symbol = applyLoanInfo.getSymbol();
// 登录
String token = MainProcess.login(namespace, channelId, phoneNo);
......@@ -105,16 +109,17 @@ public class GenUserDataServiceImpl implements GenUserDataService {
String orderNo = authResult.get("order_no").toString().trim();
String productId = authResult.get("product_id").toString();
// 风控授信回调
boolean result = MainProcess.creditAuthNotify(namespace, token, uuid, channelId, fundId, orderNo, 0, auditResult, amount, term);
boolean creditResult = MainProcess.creditAuthNotify(namespace, token, uuid, channelId, fundId, orderNo, 0, auditResult, amount, term);
WebSocketServer.sendInfo("风控授信回调:" + creditResult, symbol);
String redisKey = namespace + "_" + phoneNo;
if (result) {
if (creditResult) {
redisTemplate.opsForValue().set(redisKey, 0);
log.info("风控授信回调接口返回成功,设置redis缓存:" + redisKey + ": 0");
} else {
redisTemplate.opsForValue().set(redisKey, 1);
log.info("风控授信回调接口返回失败,设置redis缓存:" + redisKey + ": 1");
}
return result;
return creditResult;
}
/**
......@@ -226,13 +231,17 @@ public class GenUserDataServiceImpl implements GenUserDataService {
return result;
}
@Override
public boolean genLoanUser(ApplyLoanInfo applyLoanInfo) throws Exception {
Integer status = applyLoanInfo.getStatus();
String namespace = applyLoanInfo.getNamespace();
Integer fundId = applyLoanInfo.getFundId();
String symbol = applyLoanInfo.getSymbol();
String phoneNo = applyLoanInfo.getPhoneNo();
boolean assignFundResult = assignFundCorp(namespace, fundId);
boolean assignFundResult = assignFundCorp(namespace, fundId, symbol);
log.info("分配资金方的结果为:" + assignFundResult);
/**
......@@ -257,7 +266,20 @@ public class GenUserDataServiceImpl implements GenUserDataService {
if (!result) {
return false;
}
Thread.sleep(300000);
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) {
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId);
log.info(searchResult.toString());
if (fundId.equals(searchResult)) {
log.info("资方分配成功!");
WebSocketServer.sendInfo("资方分配成功!", symbol);
break;
} else {
log.info("资方仍未分配成功!");
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
Thread.sleep(10000);
}
}
return withDraw(applyLoanInfo);
}
......@@ -269,13 +291,30 @@ public class GenUserDataServiceImpl implements GenUserDataService {
if (!quotaAuthResult) {
return false;
}
Thread.sleep(300000);
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) {
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId);
log.info(searchResult.toString());
if (fundId.equals(searchResult)) {
log.info("资方分配成功!");
WebSocketServer.sendInfo("资方分配成功!", symbol);
break;
} else {
log.info("资方仍未分配成功!");
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
Thread.sleep(10000);
}
}
boolean withDrawResult = withDraw(applyLoanInfo);
if (!withDrawResult) {
WebSocketServer.sendInfo("提现失败!", symbol);
return false;
}
WebSocketServer.sendInfo("提现成功,10秒后放款!", symbol);
Thread.sleep(10000);
return makeLoan(applyLoanInfo, true);
boolean makeLoanResult = makeLoan(applyLoanInfo, true);
WebSocketServer.sendInfo("放款成功!", symbol);
return makeLoanResult;
}
/**
......@@ -286,13 +325,31 @@ public class GenUserDataServiceImpl implements GenUserDataService {
if (!quotaAuthResult) {
return false;
}
Thread.sleep(300000);
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) {
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId);
log.info(searchResult.toString());
if (fundId.equals(searchResult)) {
log.info("资方分配成功!");
WebSocketServer.sendInfo("查询到资方为:" + searchResult +",资方分配成功!", symbol);
break;
} else {
log.info("资方仍未分配成功!");
WebSocketServer.sendInfo("查询到资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
Thread.sleep(10000);
}
}
boolean withDrawResult = withDraw(applyLoanInfo);
if (!withDrawResult) {
WebSocketServer.sendInfo("提现失败!", symbol);
return false;
}
WebSocketServer.sendInfo("提现成功,10秒后放款!", symbol);
Thread.sleep(10000);
return makeLoan(applyLoanInfo, false);
boolean makeLoanResult = makeLoan(applyLoanInfo, false);
WebSocketServer.sendInfo("放款失败!", symbol);
return makeLoanResult;
}
return false;
}
......
......@@ -620,6 +620,9 @@ public class xyqb {
JSONObject result = HttpClientUtils.doGetReturnJson(url, null, headers);
System.out.println(result);
Map data = (Map) result.get("data");
if (data.isEmpty()) {
return false;
}
List<Map> dataList = (List<Map>) data.get(fundId.toString());
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
......
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