1、swagger接口文档

beetlsql3-dev
陈沅 1 year ago
parent c8634e695f
commit 96a7e96e4f

@ -41,6 +41,9 @@ public interface SchoolClassDao extends BaseMapper<SchoolClass> {
List<Map<String,Object>> getClassesBySchoolId(Long schoolId);
List<Map<String,Object>> findClassesByTeacherId(Long teacherId);
List<SchoolClass>getClassesByOldSchoolId(Long oldSchoolId);
List<Map<String,Object>> getClassIdsByZhiyun(Long userId);

@ -17,4 +17,7 @@ public interface UserStockTradesDao extends BaseMapper<UserStockTrades> {
List<UserStockTrades> findListByStudentIdAndTime(Long studentId,String strTime);
List<Map<String,Object>> findListByStudentId(Long studentId);
UserStockTrades findBySecTypeAndStudentIdAndCreateTime(Long studentId,Integer secType,String time);
}

@ -275,6 +275,10 @@ public class SchoolClassService extends CoreBaseService<SchoolClass> {
return schoolClassDao.getClassesByOrgId(orgId);
}
public List<Map<String,Object>> findClassesByTeacherId(Long teacherId){
return schoolClassDao.findClassesByTeacherId(teacherId);
}
public List<Map<String,Object>> getClassesBySchoolId(Long schoolId){
return schoolClassDao.getClassesBySchoolId(schoolId);
}

@ -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;
}
}

@ -18,9 +18,10 @@ public class HttpJsonRequest {
public static String sendGetRequest(String urlString, String authorizationHeader) {
StringBuilder response = new StringBuilder();
HttpURLConnection con = null;
try {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", authorizationHeader);
@ -34,11 +35,15 @@ public class HttpJsonRequest {
}
in.close();
} else {
log.info("-----------------send接口请求失败-------"+responseCode);
throw new IllegalArgumentException("HTTP GET request failed with response code: " + responseCode);
log.info("-----------------send接口请求失败-------" + responseCode);
// throw new IllegalArgumentException("HTTP GET request failed with response code: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (con!=null){
con.disconnect();
}
}
return response.toString();
}
@ -49,7 +54,7 @@ public class HttpJsonRequest {
}
public static String sendPostRequest(String urlString, String authorizationHeader, String postData,String contentType) {
public static String sendPostRequest(String urlString, String authorizationHeader, String postData, String contentType) {
StringBuilder response = new StringBuilder();
try {
URL url = new URL(urlString);

@ -875,6 +875,13 @@ public class AccountController {
return JsonResult.success(schoolClassService.findClassByOrgId(schoolId));
}
@ApiOperation("根据教师id查询班级列表")
@GetMapping("findClassesByTeacherId.json")
public JsonResult<List<Map<String, Object>>> findClassesByTeacherId(Long teacherId) {
return JsonResult.success(schoolClassService.findClassesByTeacherId(teacherId));
}
@ApiOperation("根据学校id查询专业列表")
@GetMapping("findMajorsBySchoolId.json")
@ -922,7 +929,7 @@ public class AccountController {
@PostMapping("updateUserId.json")
public JsonResult updateUserId() throws SQLException {
CoreUser coreUser = new CoreUser();
// coreUser.setOrgId(248L);
coreUser.setOrgId(206L);
List<CoreUser> coreUsers = userService.getCoreUserList(coreUser);
int i = 0;
for (CoreUser user : coreUsers) {

@ -99,7 +99,7 @@ public class TestController {
" join EduUsers on EduSchools.Id=EduUsers.SchoolId \n" +
" join EduUserRoles on EduUsers.Id = EduUserRoles.UserId \n" +
" join EduLevel on EduSchools.LevelId=EduLevel.Id where \n" +
" EduUserRoles.RoleId=2 and EduSchools.Name = '张家口学院'";
" EduUserRoles.RoleId=2 and EduSchools.Name = '广西农业职业技术大学'";
ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
while (resultSet.next()) {
@ -154,7 +154,7 @@ public class TestController {
" EduColleges col" +
" JOIN EduSchools sch " +
"ON" +
" col.SchoolId = sch.id where sch.Name='张家口学院'";
" col.SchoolId = sch.id where sch.Name='广西农业职业技术大学'";
ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
int i = 0;
@ -229,7 +229,7 @@ public class TestController {
"FROM " +
" EduMajors ma " +
" JOIN EduColleges col ON ma.CollegeId = col.Id " +
" JOIN EduSchools sch ON col.schoolId = sch.id where sch.Name='张家口学院'";
" JOIN EduSchools sch ON col.schoolId = sch.id where sch.Name='广西农业职业技术大学'";
ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
int i = 0;
@ -303,7 +303,7 @@ public class TestController {
" cla.id," +
" cla.schoolId \n" +
" FROM \n" +
" EduClasses cla where schoolId=171";
" EduClasses cla where schoolId=125";
ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
int i = 0;
@ -385,7 +385,7 @@ public class TestController {
" EduTeachers tea " +
" JOIN EduColleges col ON tea.CollegeId = col.Id " +
" JOIN EduMajors maj ON tea.MajorId = maj.Id " +
" JOIN EduSchools sch ON tea.SchoolId = sch.Id where sch.Name='张家口学院'";
" JOIN EduSchools sch ON tea.SchoolId = sch.Id where sch.Name='广西农业职业技术大学'";
ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
int i = 0;
@ -457,13 +457,15 @@ public class TestController {
" stu.IsDeleted, " +
" cla.Name ," +
" col.Id," +
" maj.Id,cla.id " +
" maj.Id,cla.id ,\n" +
" us.Id as userId " +
"FROM " +
" EduStudents stu " +
" JOIN EduColleges col ON stu.CollegeId = col.Id " +
" JOIN EduMajors maj ON stu.MajorId = maj.Id " +
" JOIN EduSchools sch ON stu.SchoolId = sch.Id " +
" JOIN EduClasses cla ON stu.ClassId = cla.Id where sch.Name='张家口学院'";
" JOIN EduClasses cla ON stu.ClassId = cla.Id" +
" join EduUsers us on stu.StudentNo = us.UserName where sch.Name='广西农业职业技术大学'";
ps = conn.prepareStatement(sql);
ResultSet resultSet = ps.executeQuery();
int i = 0;
@ -507,7 +509,8 @@ public class TestController {
continue;
}
student.setClassId(schoolClass.getClassId());
studentService.add(student);
Long oldId = resultSet.getLong("userId");
studentService.add(student,oldId);
}
} catch (Exception ex) {
ex.printStackTrace();
@ -683,7 +686,7 @@ public class TestController {
public void updateTeacherId() {
List<Teacher> teachers = teacherService.findAll();
for (Teacher teacher : teachers) {
String sql = "select * from EduTeachers where TeacherNo =" + teacher.getTeacherSn();
String sql = "select * from EduTeachers where TeacherNo ='" + teacher.getTeacherJobNumber()+"'";
try {
Connection connection = ZhiYunJDBCUtil.openConn();
PreparedStatement ps = connection.prepareStatement(sql);
@ -692,6 +695,10 @@ public class TestController {
teacher.setOldId(rs.getLong("id"));
teacherService.updateTemplate(teacher);
}
if(teacher.getOldId()==null){
teacher.setOldId(5000L+teacher.getTeacherId());
teacherService.updateTemplate(teacher);
}
connection.close();
ps.close();
}catch (Exception ex){

@ -250,3 +250,11 @@ teacher.teacher_id;
findClassNameByClassId
===
SELECT class_name as name FROM school_class WHERE old_class_id = #classId#
findClassesByTeacherId
===
select school_class.class_id as classId,school_class.class_name as className
from school_class
join universities_colleges uc on school_class.universities_colleges_id = uc.universities_colleges_id
join teacher t on uc.universities_colleges_id = t.universities_colleges_id
where t.old_id = #teacherId#

@ -6,3 +6,9 @@ select * from user_stock_trades where student_id=#studentId# and str_create_time
findListByStudentId
===
select str_create_time,accumulated_income_rate from user_stock_trades where student_id=#studentId#
findBySecTypeAndStudentIdAndCreateTime
===
select * from user_stock_trades where student_id = #studentId# and str_create_time = #time# and sec_type = #secType#
Loading…
Cancel
Save