|
|
|
@ -1,14 +1,22 @@
|
|
|
|
|
package com.ibeetl.jlw.service;
|
|
|
|
|
|
|
|
|
|
import cn.jlw.oldAliPay.pc.util.Stringutils;
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import com.ibeetl.admin.core.entity.CoreUser;
|
|
|
|
|
import com.ibeetl.admin.core.service.CoreBaseService;
|
|
|
|
|
import com.ibeetl.admin.core.service.CoreUserService;
|
|
|
|
|
import com.ibeetl.jlw.dao.UserStockTradesDao;
|
|
|
|
|
import com.ibeetl.jlw.entity.*;
|
|
|
|
|
import com.ibeetl.jlw.util.HttpJsonRequest;
|
|
|
|
|
import com.ibeetl.jlw.util.ZhiYunJDBCUtil;
|
|
|
|
|
import com.ibeetl.jlw.web.query.StudentQuery;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
import java.sql.Connection;
|
|
|
|
@ -39,6 +47,10 @@ public class UserStockTradesService extends CoreBaseService<UserStockTrades> {
|
|
|
|
|
@Autowired
|
|
|
|
|
SchoolClassService schoolClassService;
|
|
|
|
|
|
|
|
|
|
private static final String TOKEN = "bearer 157e2484a38880effebe57c4ee95d6c29984e2f8";
|
|
|
|
|
|
|
|
|
|
private static final String url = "https://sim.sztzjy.com/perfweb-rpcgw/api/v1";
|
|
|
|
|
|
|
|
|
|
public void insertByZhiyun2() {
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
@ -157,9 +169,9 @@ public class UserStockTradesService extends CoreBaseService<UserStockTrades> {
|
|
|
|
|
List<Student> students = studentService.getAll();
|
|
|
|
|
Connection conn = null;
|
|
|
|
|
PreparedStatement ps = null;
|
|
|
|
|
int i =0;
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (Student student : students) {
|
|
|
|
|
if(student.getAccountIdByStock()!=null&&student.getAccountIdByFuture()!=null){
|
|
|
|
|
if (student.getAccountIdByStock() != null && student.getAccountIdByFuture() != null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
CoreUser user = coreUserService.getUserById(student.getUserId());
|
|
|
|
@ -178,13 +190,136 @@ public class UserStockTradesService extends CoreBaseService<UserStockTrades> {
|
|
|
|
|
ZhiYunJDBCUtil.closeConn(conn);
|
|
|
|
|
ps.close();
|
|
|
|
|
System.out.println("-------------------------------已处理--" + i++);
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
ZhiYunJDBCUtil.closeConn(conn);
|
|
|
|
|
}finally {
|
|
|
|
|
} finally {
|
|
|
|
|
ZhiYunJDBCUtil.closeConn(conn);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//定时获取交易数据
|
|
|
|
|
@Scheduled(cron = "0 32 11 * * ?")
|
|
|
|
|
public void fetchTransactionData() {
|
|
|
|
|
List<Student> students = studentService.getAll();
|
|
|
|
|
int i =0;
|
|
|
|
|
SimpleDateFormat stringDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
|
|
for (Student student : students) {
|
|
|
|
|
System.out.println("-------------------已处理:"+i++);
|
|
|
|
|
if (StringUtils.hasText(student.getAccountIdByStock())) {
|
|
|
|
|
if (userStockTradesDao.findBySecTypeAndStudentIdAndCreateTime(student.getStudentId(), 1, stringDateFormat.format(new java.util.Date())) == null) {
|
|
|
|
|
UserStockTrades userStockTrades = getUserStockTrades(student.getAccountIdByStock());
|
|
|
|
|
if (userStockTrades != null) {
|
|
|
|
|
userStockTrades.setSecType(1);
|
|
|
|
|
userStockTrades.setStudentId(student.getStudentId());
|
|
|
|
|
userStockTrades.setCompetitionId(0L);
|
|
|
|
|
userStockTrades.setCreateTime(new java.util.Date());
|
|
|
|
|
userStockTrades.setStrCreateTime(stringDateFormat.format(new java.util.Date()));
|
|
|
|
|
userStockTradesDao.insert(userStockTrades);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (StringUtils.hasText(student.getAccountIdByFuture())) {
|
|
|
|
|
if (userStockTradesDao.findBySecTypeAndStudentIdAndCreateTime(student.getStudentId(), 4, stringDateFormat.format(new java.util.Date())) == null) {
|
|
|
|
|
UserStockTrades future = getUserStockTrades(student.getAccountIdByFuture());
|
|
|
|
|
if (future != null) {
|
|
|
|
|
future.setSecType(4);
|
|
|
|
|
future.setCreateTime(new java.util.Date());
|
|
|
|
|
future.setStudentId(student.getStudentId());
|
|
|
|
|
future.setCompetitionId(0L);
|
|
|
|
|
future.setStrCreateTime(stringDateFormat.format(new java.util.Date()));
|
|
|
|
|
userStockTradesDao.insert(future);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserStockTrades getUserStockTrades(String accountId) {
|
|
|
|
|
try {
|
|
|
|
|
String getReportUrl = url + "/sim/detail/" + accountId + "?title=''";
|
|
|
|
|
String reportStr = HttpJsonRequest.sendGetRequest(getReportUrl, TOKEN);
|
|
|
|
|
if (!StringUtils.hasText(reportStr)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
|
|
|
JsonNode root = mapper.readTree(reportStr);
|
|
|
|
|
JsonNode reportIdNode = root.path("report_id");
|
|
|
|
|
if (reportIdNode.isMissingNode()) {
|
|
|
|
|
throw new IllegalArgumentException("未找到report_id字段");
|
|
|
|
|
}
|
|
|
|
|
String text = reportIdNode.asText();
|
|
|
|
|
String resultUrl = url + "/report/summaries?report_ids=" + text;
|
|
|
|
|
String resultStr = HttpJsonRequest.sendGetRequest(resultUrl, TOKEN);
|
|
|
|
|
if (!StringUtils.hasText(resultStr)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
ObjectMapper resultMapper = new ObjectMapper();
|
|
|
|
|
JsonNode resultRoot = resultMapper.readTree(resultStr);
|
|
|
|
|
JsonNode dataNode = resultRoot.path("data").get(0);
|
|
|
|
|
JsonNode cashNode = dataNode.path("cash");
|
|
|
|
|
JsonNode indicatorNode = dataNode.path("indicator");
|
|
|
|
|
if (cashNode != null && indicatorNode != null) {
|
|
|
|
|
return buildUserStockTrades(cashNode, indicatorNode);
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public UserStockTrades buildUserStockTrades(JsonNode cashNode, JsonNode indicatorNode) {
|
|
|
|
|
double pnl = 0;
|
|
|
|
|
double nav = 0;
|
|
|
|
|
double risk_ratio = 0;
|
|
|
|
|
double available = 0;
|
|
|
|
|
double cum_commission = 0;
|
|
|
|
|
double fpnl = 0;
|
|
|
|
|
double pnl_ratio = 0;
|
|
|
|
|
double max_drawdown = 0;
|
|
|
|
|
double calmar_ratio = 0;
|
|
|
|
|
double sharp_ratio = 0;
|
|
|
|
|
int open_count = 0;
|
|
|
|
|
int close_count = 0;
|
|
|
|
|
double Pnl_ratio_annual = 0;
|
|
|
|
|
double win_ratio;
|
|
|
|
|
pnl = cashNode.path("pnl").asDouble();
|
|
|
|
|
nav = cashNode.path("nav").asDouble();
|
|
|
|
|
risk_ratio = indicatorNode.path("risk_ratio").asDouble();
|
|
|
|
|
available = cashNode.path("available").asDouble();
|
|
|
|
|
cum_commission = cashNode.path("cum_commission").asDouble();
|
|
|
|
|
fpnl = cashNode.path("fpnl").asDouble();
|
|
|
|
|
pnl_ratio = indicatorNode.path("pnl_ratio").asDouble();
|
|
|
|
|
max_drawdown = indicatorNode.path("max_drawdown").asDouble();
|
|
|
|
|
calmar_ratio = indicatorNode.path("calmar_ratio").asDouble();
|
|
|
|
|
sharp_ratio = indicatorNode.path("sharp_ratio").asDouble();
|
|
|
|
|
open_count = indicatorNode.path("open_count").asInt();
|
|
|
|
|
close_count = indicatorNode.path("close_count").asInt();
|
|
|
|
|
win_ratio = indicatorNode.path("win_ratio").asDouble();
|
|
|
|
|
Pnl_ratio_annual = indicatorNode.path("Pnl_ratio_annual").asDouble();
|
|
|
|
|
UserStockTrades trades = new UserStockTrades();
|
|
|
|
|
trades.setFpnl(fpnl);
|
|
|
|
|
trades.setInitialCapital(nav - pnl);
|
|
|
|
|
trades.setTotalAssets(nav * risk_ratio + available);
|
|
|
|
|
trades.setAvailableCapital(available);
|
|
|
|
|
trades.setMarketValue(nav - available);
|
|
|
|
|
trades.setAccumulatedTotalProfitLoss(pnl - cum_commission);
|
|
|
|
|
trades.setAccumulatedCommission(cum_commission);
|
|
|
|
|
trades.setFpnl(fpnl);
|
|
|
|
|
trades.setAccumulatedIncomeRate(pnl_ratio);
|
|
|
|
|
trades.setMaxDrawdown(max_drawdown);
|
|
|
|
|
trades.setCalmarRatio(calmar_ratio);
|
|
|
|
|
trades.setSharpeRatio(sharp_ratio);
|
|
|
|
|
trades.setOpenCount(open_count);
|
|
|
|
|
trades.setCloseCount(close_count);
|
|
|
|
|
trades.setPnlRatioAnnual(Pnl_ratio_annual);
|
|
|
|
|
trades.setWinRate(win_ratio);
|
|
|
|
|
return trades;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|