1、swagger接口文档

beetlsql3-dev
陈沅
parent 1950343e20
commit ea9215e134

@ -9,12 +9,14 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.WebApplicationInitializer;
@SpringBootApplication
@EnableCaching
@ComponentScan(basePackages= {"cn.jlw","com.ibeetl.admin","com.ibeetl.jlw"})
@ServletComponentScan(basePackages = {"cn.jlw.cors", "cn.jlw.filter"})
@EnableScheduling
public class WebApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
public static void main(String[] args) {

@ -13,4 +13,6 @@ import java.util.Date;
public interface HsValuesDao extends BaseMapper<HsValues> {
HsValues findByCreateTime(String createTime);
HsValues findByTimeStr(String timeStr);
}

@ -20,6 +20,8 @@ public class HsValues extends BaseEntity {
private Date createTime;
private String createTimeStr;
public Integer getId() {
return id;
}
@ -43,4 +45,12 @@ public class HsValues extends BaseEntity {
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getCreateTimeStr() {
return createTimeStr;
}
public void setCreateTimeStr(String createTimeStr) {
this.createTimeStr = createTimeStr;
}
}

@ -1,14 +1,23 @@
package com.ibeetl.jlw.service;
import cn.hutool.core.util.IdUtil;
import com.ibeetl.jlw.dao.HsValuesDao;
import com.ibeetl.jlw.entity.HsValues;
import com.ibeetl.jlw.util.HttpJsonRequest;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
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 java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
@Service
@Transactional
@ -18,9 +27,53 @@ public class HsValuesService {
private HsValuesDao hsValuesDao;
public HsValues findByCreateTime(String createTime) {
return hsValuesDao.findByCreateTime(createTime);
}
public HsValues findByCreateTime(String createTime){
return hsValuesDao.findByCreateTime(createTime);
// 每天早上9点执行一次任务
@Scheduled(cron = "0 0 9 * * *")
public void getHsValues() throws JSONException, ParseException {
LocalDate startTime = LocalDate.now().minusDays(5);
LocalDate endTime = LocalDate.now().plusDays(1);
String urlTwo = "https://api.myquant.cn:9001/ds-history-rpcgw/v3/data-history/benchmark-return"
+ "?symbol=SHSE.000300&frequency=1d&startTime=" + startTime.toString()
+ "&endTime=" + endTime.toString() + "&adjust=0";
String authorizationHeader = "bearer ee2c685459aa218ded58d0d7ad2ef2faf6f0d0d4";
String jsonResponse = HttpJsonRequest.sendGetRequest(urlTwo, authorizationHeader);
JSONArray dataArray = HttpJsonRequest.extractDataArray(jsonResponse);
//循环dataArray处理数据
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
SimpleDateFormat stringDateFormat = new SimpleDateFormat("yyyy-MM-dd");
for (int i = 0; i < dataArray.length(); i++) {
JSONObject jsonObject = dataArray.getJSONObject(i);
String createdAt = jsonObject.getString("created_at");
Date createdDate = dateFormat.parse(createdAt);
String dateString = stringDateFormat.format(createdDate);
if(findByTimeStr(dateString)!=null)
continue;
HsValues hsValues = new HsValues();
if(jsonObject.has("ratio")){
hsValues.setHsValue(Double.valueOf(jsonObject.getString("ratio")));
}else{
hsValues.setHsValue(0.0);
}
hsValues.setCreateTime(createdDate);
hsValues.setCreateTimeStr(dateString);
hsValuesDao.insert(hsValues);
}
}
public HsValues findByTimeStr(String timeStr) {
return hsValuesDao.findByTimeStr(timeStr);
}
public List<HsValues> findAll(){
return hsValuesDao.all();
}
}

@ -20,6 +20,7 @@ import com.ibeetl.jlw.service.*;
import com.ibeetl.jlw.service.api.ApiIndexBaseService;
import com.ibeetl.jlw.web.query.TeacherOpenCourseMergeStudentQuery;
import com.ibeetl.jlw.web.query.TeacherOpenCourseNoticeQuery;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -69,6 +70,8 @@ public class ApiStudentService {
private CoreUserService coreUserService;
@Autowired
private SysLogService sysLogService;
@Autowired
private HsValuesService hsValuesService;
/**
* -
@ -156,36 +159,53 @@ public class ApiStudentService {
// pieMaps.add(map6);
// pieMaps.add(map7);
//我的收益率
List<HsValues> all = hsValuesService.findAll();
Map<String, Object> lineMap = new HashMap<>();
List<String> xList = new ArrayList<>();
List<List<String>> yLists = new ArrayList<>();
List<String> yList1 = new ArrayList<>();
List<String> yList2 = new ArrayList<>();
xList.add("2022.1.7");
xList.add("2022.3.14");
xList.add("2022.6.2");
xList.add("2022.8.21");
xList.add("2022.10.9");
xList.add("2022.11.28");
xList.add("2022.12.18");
yList1.add("100");
yList1.add("150");
yList1.add("100");
yList1.add("100");
yList1.add("135");
yList1.add("150");
yList1.add("135");
yList2.add("100");
yList2.add("150");
yList2.add("100");
yList2.add("100");
yList2.add("135");
yList2.add("150");
yList2.add("135");
yLists.add(yList1);
yLists.add(yList2);
lineMap.put("xList", xList);
lineMap.put("yList", yLists);
if(all!=null&&all.size()>0){
List<String> xList = new ArrayList<>();
List<String> yList = new ArrayList<>();
List<String> yList1 = new ArrayList<>();
List<List<String>> yLists = new ArrayList<>();
for(HsValues values:all){
xList.add(values.getCreateTimeStr());
yList.add(String.valueOf(values.getHsValue()*100));
}
yLists.add(yList);
yLists.add(yList1);
lineMap.put("xList", xList);
lineMap.put("yList", yLists);
}
// List<String> xList = new ArrayList<>();
// List<List<String>> yLists = new ArrayList<>();
// List<String> yList1 = new ArrayList<>();
// List<String> yList2 = new ArrayList<>();
// xList.add("2022.1.7");
// xList.add("2022.3.14");
// xList.add("2022.6.2");
// xList.add("2022.8.21");
// xList.add("2022.10.9");
// xList.add("2022.11.28");
// xList.add("2022.12.18");
// yList1.add("100");
// yList1.add("150");
// yList1.add("100");
// yList1.add("100");
// yList1.add("135");
// yList1.add("150");
// yList1.add("135");
// yList2.add("100");
// yList2.add("150");
// yList2.add("100");
// yList2.add("100");
// yList2.add("135");
// yList2.add("150");
// yList2.add("135");
// yLists.add(yList1);
// yLists.add(yList2);
// lineMap.put("xList", xList);
// lineMap.put("yList", yLists);
return StudentIndexData.builder()
.noticeList(noticeList)

@ -0,0 +1,45 @@
package com.ibeetl.jlw.util;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class HttpJsonRequest {
public static String sendGetRequest(String urlString, String authorizationHeader) {
StringBuilder response = new StringBuilder();
try {
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("Authorization", authorizationHeader);
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
} else {
System.out.println("HTTP GET request failed with response code: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
return response.toString();
}
public static JSONArray extractDataArray(String jsonResponse) throws JSONException {
JSONObject jsonObject = new JSONObject(jsonResponse);
return jsonObject.getJSONArray("data");
}
}

@ -1,3 +1,8 @@
findByCreateTime
===
select * from hs_values where DATE_FORMAT(create_time, '%Y-%m-%d') = #createTime#
select * from hs_values where DATE_FORMAT(create_time, '%Y-%m-%d') = #createTime#
findByTimeStr
===
select * from hs_values where create_time_str = #timeStr#
Loading…
Cancel
Save