A股项目迁移
This commit is contained in:
215
src/main/java/cn/stock/market/infrastructure/api/AStockApis.java
Normal file
215
src/main/java/cn/stock/market/infrastructure/api/AStockApis.java
Normal file
@@ -0,0 +1,215 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.CollectionUtils;
|
||||
import com.ag.utils.DateUtils;
|
||||
import com.ag.utils.Jsons;
|
||||
import com.ag.utils.NumberUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.qutaojing.common.utils.BigDecimals;
|
||||
import cn.stock.market.dto.model.StockDetail;
|
||||
import cn.stock.market.utils.Utils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class AStockApis {
|
||||
public static final String gugdata_appkey = "K5LZKV8KAYM4";
|
||||
public static final String ig507_licence = "4CEF3CDC-3A2E-76AB-9BF1-BE856F3D4468";
|
||||
public List<StockRealTime> stockRealTime(String appKey) {
|
||||
//+ "&symbol=600031,sh000001"
|
||||
String body = HttpUtil.get("https://api.gugudata.com/stock/cn/realtime?appkey=" + appKey);
|
||||
JSONObject json = Jsons.toJSON(body);
|
||||
Integer status = Jsons.getByPath(json, "DataStatus.StatusCode", -1);
|
||||
if(NumberUtils.equals(status, 100)) {
|
||||
return Lists.newArrayList(Lists.transform(json.getJSONArray("Data"), val -> {
|
||||
return Jsons.toBean((JSONObject) val, StockRealTime.class);
|
||||
}));
|
||||
}
|
||||
|
||||
throw new SysTipsException("同步失败:" + Jsons.getByPath(json, "DataStatus.StatusDescription", null));
|
||||
}
|
||||
|
||||
public List<JSONObject> gplist(String ig507_licence) {
|
||||
String body = HttpUtil.get("https://ig507.com/data/base/gplist?licence=" + ig507_licence);
|
||||
return Jsons.toList(body, JSONObject.class);
|
||||
}
|
||||
|
||||
public List<JSONObject> sinalist(int page) {
|
||||
String body = HttpUtil.get("https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page="+page+"&num=40&sort=symbol&asc=1&node=hs_bjs&symbol=&_s_r_a=page");
|
||||
return Jsons.toList(body, JSONObject.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 历史分时交易
|
||||
* @param level 支持5分钟、15分钟、30分钟、60分钟、日周月年级别(包括前后复权),对应的值分别是 5、15、30、60、Day、Day_qfq(日线前复权)、Day_hfq(日线后复权)、Week、Week_qfq(周线前复权)、Week_hfq(周线后复权)、Month、Month_qfq(月线前复权)、Month_hfq(月线后复权)、Year、Year_qfq(年线前复权)、Year_hfq(年线后复权)
|
||||
* @return
|
||||
*/
|
||||
public List<JSONObject> stockHistoryTrade(String stockCode, String level, String ig507Licence) {
|
||||
String url = String.format("https://ig507.com/data/time/history/trade/%s/%s?licence=%s", stockCode, level, ig507Licence);
|
||||
String body = HttpUtil.get(url);
|
||||
return Jsons.toList(body, JSONObject.class);
|
||||
}
|
||||
|
||||
public static List<JSONArray> sinahy() {
|
||||
String body = HttpUtil.get("https://vip.stock.finance.sina.com.cn/q/view/newSinaHy.php");
|
||||
String replace = StringUtils.replace(body, "var S_Finance_bankuai_sinaindustry = ", "");
|
||||
JSONObject json = Jsons.toJSON(replace);
|
||||
List<JSONArray> list = Lists.newArrayList();
|
||||
for(String k : json.keySet()) {
|
||||
String[] split = StringUtils.split(json.getString(k), ",");
|
||||
list.add(new JSONArray(Lists.transform(Arrays.asList(split), val -> (Object) val))) ;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static JSONArray stock_top10() {
|
||||
String body = HttpUtil.get("https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=100&sort=changepercent&asc=0&node=hs_a&symbol=&_s_r_a=setlen");
|
||||
return JSON.parseArray(body);
|
||||
}
|
||||
|
||||
public static JSONArray stock_bot10() {
|
||||
String body = HttpUtil.get("https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=1&num=100&sort=changepercent&asc=1&node=hs_a&symbol=&_s_r_a=setlen");
|
||||
return JSON.parseArray(body);
|
||||
}
|
||||
|
||||
public static StockDetail qq(String code) {
|
||||
List<StockDetail> list = qq(Lists.newArrayList(code));
|
||||
return CollectionUtils.isNotEmpty(list) ? list.get(0) : null;
|
||||
}
|
||||
|
||||
public static List<StockDetail> qq(List<String> codeList) {
|
||||
List<StockDetail> list = Lists.newArrayList();
|
||||
if(CollectionUtils.isEmpty(codeList)) {
|
||||
return list;
|
||||
}
|
||||
|
||||
String url = "https://qt.gtimg.cn/q=" + Joiner.on(",").join(Lists.transform(codeList, val -> Utils.fenxi(val)));
|
||||
log.info(url);
|
||||
String body = HttpUtil.createGet(url)
|
||||
.header("Referer", "https://qt.gtimg.cn")
|
||||
.execute().body();
|
||||
String[] split = StringUtils.split(body, ";");
|
||||
for (String string : split) {
|
||||
if(StringUtils.contains(string, "v_pv_none_match")) {
|
||||
continue;
|
||||
}
|
||||
String content = StringUtils.replaceEach(string, new String[] { "\r\n", "\r", "\n" }, new String[] { "", "", "" });
|
||||
if(StringUtils.isBlank(content)) {
|
||||
continue;
|
||||
}
|
||||
StockDetail stockDetail = _qqParse(content);
|
||||
list.add(stockDetail);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static StockDetail _qqParse(String str) {
|
||||
//v_sh000300="1~沪深300~000300~4186.98~4191.57~4162.37~61230818~30615409~30615409~0.00~0~0.00~0~0.00~0~0.00~0~0.00~0~0.00~0~0.00~0~0.00~0~0.00~0~0.00~0~~20220415105430~-4.59~-0.11~4193.20~4152.97~4186.98/61230818/110353453060~61230818~11035345~0.22~12.30~~4193.20~4152.97~0.96~363899.25~470787.62~0.00~-1~-1~1.26~0~4175.77~~~~~~11035345.3060~0.0000~0~ ~ZS~-15.25~-1.03~~~~5378.48~3942.86~-1.58~0.74~-13.59~~~-8.92~-17.82~~"
|
||||
|
||||
/**
|
||||
* 0: 未知 1: 名字 2: 代码 3: 当前价格 4: 昨收 5: 今开 6: 成交量(手)7: 外盘 8: 内盘 9: 买一 10: 买一量(手)11-18: 买二 买五 19: 卖一 20: 卖一量 21-28: 卖二 卖五
|
||||
* 29: 最近逐笔成交 30: 时间 31: 涨跌 32: 涨跌% 33: 最高 34: 最低 35: 价格/成交量(手)/成交额 36: 成交量(手)37: 成交额(万)38: 换手率 39: 市盈率 40:
|
||||
* 41: 最高 42: 最低 43: 振幅 44: 流通市值 45: 总市值 46: 市净率 47: 涨停价 48: 跌停价
|
||||
*/
|
||||
String[] split = StringUtils.split(str, "=");
|
||||
String var = split[0];
|
||||
String content = StringUtils.substring(split[1], 1, split[1].length() - 1);
|
||||
String jys = StringUtils.substring(var, 2, 4);
|
||||
// String[] fields = StringUtils.split(content, "~");
|
||||
String[] fields = content.split("~");
|
||||
|
||||
StockDetail detail = StockDetail.builder()
|
||||
.name(fields[1])
|
||||
.code(fields[2])
|
||||
.currentPrice(BigDecimals.p(fields[3])) //3: 当前价格
|
||||
.yesterdayPrice(BigDecimals.p(fields[4])) //4: 昨收
|
||||
.openPrice(BigDecimals.p(fields[5])) //5: 今开
|
||||
|
||||
.buyOnePrice(BigDecimals.p(fields[9]))
|
||||
.buyTwoPrice(BigDecimals.p(fields[11]))
|
||||
.buyThreePrice(BigDecimals.p(fields[13]))
|
||||
.buyFourPrice(BigDecimals.p(fields[15]))
|
||||
.buyFivePrice(BigDecimals.p(fields[17]))
|
||||
|
||||
.buyOneAmount(BigDecimals.p(fields[10]))
|
||||
.buyTwoAmount(BigDecimals.p(fields[12]))
|
||||
.buyThreeAmount(BigDecimals.p(fields[14]))
|
||||
.buyFourAmount(BigDecimals.p(fields[16]))
|
||||
.buyFiveAmount(BigDecimals.p(fields[18]))
|
||||
|
||||
.sellOnePrice(BigDecimals.p(fields[19]))
|
||||
.sellTwoPrice(BigDecimals.p(fields[21]))
|
||||
.sellThreePrice(BigDecimals.p(fields[23]))
|
||||
.sellFourPrice(BigDecimals.p(fields[25]))
|
||||
.sellFivePrice(BigDecimals.p(fields[27]))
|
||||
|
||||
.sellOneAmount(BigDecimals.p(fields[20]))
|
||||
.sellTwoAmount(BigDecimals.p(fields[22]))
|
||||
.sellThreeAmount(BigDecimals.p(fields[24]))
|
||||
.sellFourAmount(BigDecimals.p(fields[26]))
|
||||
.sellFiveAmount(BigDecimals.p(fields[28]))
|
||||
|
||||
.highest(BigDecimals.p(fields[41])) //41: 最高
|
||||
.lowest(BigDecimals.p(fields[42])) //42: 最低
|
||||
.volume(BigDecimals.p(fields[36])) //36: 成交量(手)
|
||||
.turnover(BigDecimals.p(fields[37], BigDecimal.ZERO)) //37: 成交额(万)
|
||||
.time(DateUtils.format(new Date(), "HH:mm:ss"))
|
||||
.turnoverRate(BigDecimals.p(fields[38], BigDecimal.ZERO)) //38: 换手率
|
||||
.peRatio(BigDecimals.p(fields[39], BigDecimal.ZERO)) //39: 市盈率
|
||||
.circulationMarketValue(BigDecimals.p(fields[44], BigDecimal.ZERO)) //44: 流通市值
|
||||
.totalMarketValue(BigDecimals.p(fields[45], BigDecimal.ZERO)) //45: 总市值
|
||||
.pbRatio(BigDecimals.p(fields[46], BigDecimal.ZERO)) //46: 市净率
|
||||
.amplitude(BigDecimals.p(fields[43], BigDecimal.ZERO)) //43: 振幅
|
||||
.hardenPrice(fields[47]) //47: 涨停价
|
||||
.dropPrice(fields[48]) //48: 跌停价
|
||||
.jys(StringUtils.upperCase(jys))
|
||||
.build();
|
||||
|
||||
BigDecimal priceRange = BigDecimals.subtract(detail.getCurrentPrice(), detail.getYesterdayPrice()).setScale(2, RoundingMode.HALF_UP);
|
||||
BigDecimal priceRate = BigDecimal.ZERO;
|
||||
if(BigDecimals.neZero(detail.getYesterdayPrice())) {
|
||||
priceRate = BigDecimals.multiplys(BigDecimals.divide(priceRange, detail.getYesterdayPrice()), 100).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
detail.setPriceRange(priceRange); //涨幅
|
||||
detail.setPriceRate(priceRate); //涨幅百分比
|
||||
return detail;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// List<CNStockRealTime> list = new AStockApis().stockRealTime(gugdata_appkey);
|
||||
// for (CNStockRealTime stockRealTime : list) {
|
||||
// System.out.println(JSON.toJSONString(stockRealTime));
|
||||
// }
|
||||
//
|
||||
// System.out.println(1);
|
||||
|
||||
List<JSONArray> sinahy = sinahy();
|
||||
System.out.println(sinahy);
|
||||
|
||||
JSONArray stock_top10 = stock_top10();
|
||||
System.out.println(stock_top10);
|
||||
|
||||
JSONArray stock_bot10 = stock_bot10();
|
||||
System.out.println(stock_bot10);
|
||||
|
||||
StockDetail qq = qq("sh000300");
|
||||
System.out.println(qq);
|
||||
StockDetail qq2 = qq("sh000001");
|
||||
System.out.println(qq2);
|
||||
}
|
||||
}
|
||||
267
src/main/java/cn/stock/market/infrastructure/api/AliApis.java
Normal file
267
src/main/java/cn/stock/market/infrastructure/api/AliApis.java
Normal file
@@ -0,0 +1,267 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.Jsons;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.cloudauth20200618.Client;
|
||||
import com.aliyun.cloudauth20200618.models.DescribeSmartVerifyRequest;
|
||||
import com.aliyun.cloudauth20200618.models.DescribeSmartVerifyResponse;
|
||||
import com.aliyun.cloudauth20200618.models.InitSmartVerifyRequest;
|
||||
import com.aliyun.cloudauth20200618.models.InitSmartVerifyResponse;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.tea.TeaUnretryableException;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.qutaojing.common.utils.SpringUtils;
|
||||
import cn.stock.market.dto.model.LogisticsInfo;
|
||||
import cn.stock.market.web.config.Config;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class AliApis {
|
||||
public String accessKeyId = "";
|
||||
public String accessKeySecret = "";
|
||||
public String appCode = "";
|
||||
|
||||
public static final String SMS_VERIFY_CODE = "SMS_246440038";
|
||||
public static final String SMS_WARN = "SMS_248035836";
|
||||
// public static final String SMS_CLOSE = "SMS_239314374";
|
||||
public static final String SMS_SIGN_NAME = "维来世通";
|
||||
public static final String SMS_OPEN = "SMS_244600492";
|
||||
public static final String SMS_WITHDRAWAL = "SMS_244485100";
|
||||
|
||||
public static final long SCENE_SFZ_PLUS = 3730001L;
|
||||
public static final long SCENE_SFZ = 3739001L;
|
||||
public static final long SCENE = 3729001L;
|
||||
// public static final String SMS_VERIFY_CODE = "SMS_238300825";
|
||||
// public static final String SMS_WARN = "SMS_239319587";
|
||||
// public static final String SMS_CLOSE = "SMS_239314374";
|
||||
// public static final String SMS_SIGN_NAME = "兴珀证券";
|
||||
// public static final String SMS_OPEN = "SMS_239314375";
|
||||
// public static final String SMS_WITHDRAWAL = "SMS_239324551";
|
||||
|
||||
public AliApis(String accessKeyId, String accessKeySecret, String appCode) {
|
||||
this.accessKeyId = accessKeyId;
|
||||
this.accessKeySecret = accessKeySecret;
|
||||
this.appCode = appCode;
|
||||
}
|
||||
|
||||
public static AliApis ofNew() {
|
||||
return new AliApis("LTAI5tJi2z8cegG8fTW7BSQu", "fnCI9LUcqLuH7D6nkhvSHQMob1JSm8", "");
|
||||
}
|
||||
|
||||
public static AliApis of() {
|
||||
Config config = SpringUtils.getBean(Config.class);
|
||||
// return new AliApis("LTAI5tCQRp7t158TVyoF2Yhe", "glyzOno773Cv7HeWDliveu2H5gX486", "75ef2615da614eaaa71e2e2058fc53b0");
|
||||
return new AliApis(config.getAliyunAccessKeyId(), config.getAliyunAccessKeySecret(), config.getAliyunAppCode());
|
||||
}
|
||||
|
||||
// public static AliApis of_weilaizjhk() {
|
||||
// //AccessKey ID LTAI5tJi2z8cegG8fTW7BSQu
|
||||
// //AccessKey Secret fnCI9LUcqLuH7D6nkhvSHQMob1JSm8
|
||||
// return new AliApis("LTAI5tJi2z8cegG8fTW7BSQu", "fnCI9LUcqLuH7D6nkhvSHQMob1JSm8", "");
|
||||
// }
|
||||
|
||||
/**
|
||||
* {
|
||||
"code": "10000",
|
||||
"message": "成功",
|
||||
"data": {
|
||||
"state": "1" 验证结果:state: "1"为核验一致;state: "2"为核验不一致;state:"3"为异常情况
|
||||
},
|
||||
"seqNo": "4XU29Z4D1704061618"
|
||||
}
|
||||
{
|
||||
"code": "10001",
|
||||
"message": "参数传入有误",
|
||||
"data": null,
|
||||
"seqNo": "4XU29Z4D1704061618"
|
||||
}
|
||||
*/
|
||||
public void checkCommunicationPersonal(String acc_no, String idcard, String mobile, String name) {
|
||||
JSONObject json = communicationPersonal(acc_no, idcard, mobile, name);
|
||||
if(json == null) {
|
||||
throw new SysTipsException("调用异常~~~");
|
||||
}
|
||||
|
||||
if("10000".equals(json.get("code"))) {
|
||||
String state = Jsons.getByPath(json, "data.state", "");
|
||||
if("1".equals(state)) {
|
||||
return;
|
||||
}
|
||||
String content = "";
|
||||
if("2".equals(state)) {
|
||||
content = "核验不一致";
|
||||
} else {
|
||||
content = "核验异常情况";
|
||||
}
|
||||
|
||||
throw new SysTipsException(content);
|
||||
}
|
||||
|
||||
throw new SysTipsException(json.getString("message"));
|
||||
}
|
||||
|
||||
public JSONObject communicationPersonal(String acc_no, String idcard, String mobile, String name) {
|
||||
String host = "http://yhkys.market.alicloudapi.com";
|
||||
String path = "/communication/personal/1887";
|
||||
String method = "POST";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appCode);
|
||||
//根据API的要求,定义相对应的Content-Type
|
||||
headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
Map<String, String> bodys = new HashMap<String, String>();
|
||||
bodys.put("acc_no", acc_no);
|
||||
bodys.put("idcard", idcard);
|
||||
bodys.put("mobile", mobile);
|
||||
bodys.put("name", name);
|
||||
|
||||
try {
|
||||
HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
|
||||
System.out.println(response.toString());
|
||||
String content = EntityUtils.toString(response.getEntity());
|
||||
return Jsons.toJSON(content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new SysTipsException("查询失败:" + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用AK&SK初始化账号Client
|
||||
* @param accessKeyId
|
||||
* @param accessKeySecret
|
||||
* @return Client
|
||||
* @throws Exception
|
||||
*/
|
||||
public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
|
||||
com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
|
||||
// 您的AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
// 您的AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
// 访问的域名
|
||||
config.endpoint = "dysmsapi.aliyuncs.com";
|
||||
return new com.aliyun.dysmsapi20170525.Client(config);
|
||||
}
|
||||
|
||||
public JSONObject sendSms(String phone, String signName, String templateCode, JSONObject param) {
|
||||
if(param == null) param = new JSONObject();
|
||||
try {
|
||||
com.aliyun.dysmsapi20170525.Client client = createClient(accessKeyId, accessKeySecret);
|
||||
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
||||
.setSignName(signName)
|
||||
.setTemplateCode(templateCode)
|
||||
.setPhoneNumbers(phone)
|
||||
.setTemplateParam(JSON.toJSONString(param));
|
||||
// 复制代码运行请自行打印 API 的返回值
|
||||
SendSmsResponse response = client.sendSms(sendSmsRequest);
|
||||
return Jsons.toJSON(response.getBody());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean checSendSucc(JSONObject json) {
|
||||
//{"code":"OK","requestId":"62418BAE-7500-59F6-A899-BF4BD48A7FE7","bizId":"141614847682398177^0","message":"OK"}
|
||||
return json != null && StringUtils.equals("OK", json.getString("code"));
|
||||
}
|
||||
|
||||
public JSONObject showapiExpInfo(LogisticsInfo info) {
|
||||
String host = "https://ali-deliver.showapi.com";
|
||||
String path = "/showapi_expInfo";
|
||||
String method = "GET";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appCode);
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
querys.put("com", info.getLogisticsCode());
|
||||
querys.put("nu", info.getNo());
|
||||
querys.put("receiverPhone", info.getReceiverPhone());
|
||||
querys.put("senderPhone", info.getSenderPhone());
|
||||
|
||||
try {
|
||||
/**
|
||||
* 重要提示如下:
|
||||
* HttpUtils请从
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
||||
* 下载
|
||||
*
|
||||
* 相应的依赖请参照
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||
*/
|
||||
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
|
||||
// String content = response.toString();
|
||||
String content = EntityUtils.toString(response.getEntity());
|
||||
log.info(content);
|
||||
return Jsons.toJSON(content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new SysTipsException("查询失败:" + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public JSONObject fetchCom(String nu) {
|
||||
String host = "https://ali-deliver.showapi.com";
|
||||
String path = "/fetchCom";
|
||||
String method = "GET";
|
||||
Map<String, String> headers = new HashMap<String, String>();
|
||||
// 最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
|
||||
headers.put("Authorization", "APPCODE " + appCode);
|
||||
Map<String, String> querys = new HashMap<String, String>();
|
||||
querys.put("nu", nu);
|
||||
|
||||
try {
|
||||
/**
|
||||
* 重要提示如下: HttpUtils请从
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java
|
||||
* 下载
|
||||
*
|
||||
* 相应的依赖请参照
|
||||
* https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml
|
||||
*/
|
||||
HttpResponse response = HttpUtils.doGet(host, path, method, headers, querys);
|
||||
String content = EntityUtils.toString(response.getEntity());
|
||||
log.info(content);
|
||||
return Jsons.toJSON(content);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
throw new SysTipsException("查询失败:" + e.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
// AliApis apis = new AliApis("LTAI5tCQRp7t158TVyoF2Yhe", "glyzOno773Cv7HeWDliveu2H5gX486", "75ef2615da614eaaa71e2e2058fc53b0");
|
||||
// AliApis.of().checkCommunicationPersonal("6214835710237742", "362526198911135012", "15390891113", "李荣平");
|
||||
// LogisticsInfo info = LogisticsInfo.builder()
|
||||
// .logisticsCode("ems")
|
||||
// .no("9975682576513")
|
||||
// .build();
|
||||
// AliApis.of().showapiExpInfo(info);
|
||||
|
||||
// JSONObject json = new JSONObject();
|
||||
// json.put("code", "1234");
|
||||
// JSONObject j = apis.sendSms("15390891113", SMS_SIGN_NAME, SMS_WARN, json);
|
||||
// System.out.println(j);
|
||||
|
||||
// DescribeSmartVerifyResponse response = DescribeSmartVerify.describeSmart("shs3db1931cf84eda693e2c8746279d0");
|
||||
// System.out.println(JSON.toJSONString(response));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.qutaojing.common.utils.SpringUtils;
|
||||
|
||||
@Deprecated
|
||||
@Component
|
||||
@EnableAsync
|
||||
public class AliAsyncApis {
|
||||
// @Async
|
||||
// public void sendSmsSync(String phone, String signName, String templateCode, JSONObject param) {
|
||||
// AliApis.of().sendSms(phone, signName, templateCode, param);
|
||||
// }
|
||||
//
|
||||
// public static AliAsyncApis of() {
|
||||
// return SpringUtils.getBean(AliAsyncApis.class);
|
||||
// }
|
||||
}
|
||||
52
src/main/java/cn/stock/market/infrastructure/api/CApis.java
Normal file
52
src/main/java/cn/stock/market/infrastructure/api/CApis.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.Jsons;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.qutaojing.common.constant.Currency;
|
||||
import cn.qutaojing.common.utils.BigDecimals;
|
||||
import cn.stock.market.dto.model.ExchangeRate;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class CApis {
|
||||
|
||||
public CApis() {
|
||||
}
|
||||
|
||||
public ExchangeRate exchangeRate(Currency currency) {
|
||||
String text = HttpUtil.get("https://api.exchangerate-api.com/v4/latest/" + currency.code());
|
||||
JSONObject json = Jsons.toJSON(text);
|
||||
if(! json.containsKey("rates")) {
|
||||
throw new SysTipsException(json.getString("error_type"));
|
||||
}
|
||||
|
||||
Map<Currency, BigDecimal> map = Maps.newHashMap();
|
||||
json.getJSONObject("rates").forEach((k, v) -> {
|
||||
Currency of = Currency.of(k);
|
||||
if(of != null) {
|
||||
map.put(of, BigDecimals.p(v));
|
||||
}
|
||||
});
|
||||
ExchangeRate rate = new ExchangeRate();
|
||||
rate.setBase(currency);
|
||||
rate.setRates(map);
|
||||
return rate;
|
||||
}
|
||||
|
||||
public static CApis of() {
|
||||
return new CApis();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
ExchangeRate exchangerRate = of().exchangeRate(Currency.CNY);
|
||||
System.out.println(JSON.toJSONString(exchangerRate));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.aliyun.cloudauth20190307.Client;
|
||||
import com.aliyun.cloudauth20190307.models.DescribeFaceVerifyRequest;
|
||||
import com.aliyun.cloudauth20190307.models.DescribeFaceVerifyResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.tea.TeaUnretryableException;
|
||||
import com.aliyun.tearpc.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
|
||||
public class DescribeFaceVerify {
|
||||
//
|
||||
// public static DescribeFaceVerifyResponse main(String certifyId) throws Exception {
|
||||
//
|
||||
// // 通过以下代码创建API请求并设置参数。
|
||||
// DescribeFaceVerifyRequest request = new DescribeFaceVerifyRequest();
|
||||
// // 请输入场景ID+L。
|
||||
// request.setSceneId(AliApis.SMART_SCENEID);
|
||||
//
|
||||
// request.setCertifyId(certifyId);
|
||||
//
|
||||
// // 推荐,支持服务路由。
|
||||
// DescribeFaceVerifyResponse response = describeFaceVerifyAutoRoute(request);
|
||||
//
|
||||
// // 不支持服务自动路由。
|
||||
// //DescribeFaceVerifyResponse response = describeFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
|
||||
//
|
||||
// System.out.println(response.getRequestId());
|
||||
// System.out.println(response.getCode());
|
||||
// System.out.println(response.getMessage());
|
||||
// System.out.println(
|
||||
// response.getResultObject() == null ? null : response.getResultObject().getPassed());
|
||||
// System.out.println(
|
||||
// response.getResultObject() == null ? null : response.getResultObject().getSubCode());
|
||||
// System.out.println(
|
||||
// response.getResultObject() == null ? null
|
||||
// : response.getResultObject().getIdentityInfo());
|
||||
// System.out.println(
|
||||
// response.getResultObject() == null ? null
|
||||
// : response.getResultObject().getDeviceToken());
|
||||
// System.out.println(
|
||||
// response.getResultObject() == null ? null
|
||||
// : response.getResultObject().getMaterialInfo());
|
||||
//
|
||||
// return response;
|
||||
// }
|
||||
//
|
||||
// private static DescribeFaceVerifyResponse describeFaceVerifyAutoRoute(DescribeFaceVerifyRequest request) {
|
||||
// // 第一个为主区域Endpoint,第二个为备区域Endpoint。
|
||||
// List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com",
|
||||
// "cloudauth.cn-beijing.aliyuncs.com");
|
||||
// DescribeFaceVerifyResponse lastResponse = null;
|
||||
// for (String endpoint : endpoints) {
|
||||
// try {
|
||||
// DescribeFaceVerifyResponse response = describeFaceVerify(endpoint, request);
|
||||
// lastResponse = response;
|
||||
//
|
||||
// // 服务端错误,切换到下个区域调用。
|
||||
// if (response != null && "500".equals(response.getCode())) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// return response;
|
||||
// } catch (Exception e) {
|
||||
// // 网络异常,切换到下个区域调用。
|
||||
// if (e.getCause() instanceof TeaException) {
|
||||
// TeaException teaException = ((TeaException)e.getCause());
|
||||
// if (teaException.getData() != null && "ServiceUnavailable".equals(
|
||||
// teaException.getData().get("Code"))) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (e.getCause() instanceof TeaUnretryableException) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return lastResponse;
|
||||
// }
|
||||
//
|
||||
// private static DescribeFaceVerifyResponse describeFaceVerify(String endpoint, DescribeFaceVerifyRequest request)
|
||||
// throws Exception {
|
||||
// Config config = new Config();
|
||||
// config.setAccessKeyId(AliApis.ofNew().accessKeyId);
|
||||
// config.setAccessKeySecret(AliApis.ofNew().accessKeySecret);
|
||||
// config.setEndpoint(endpoint);
|
||||
// // 设置http代理。
|
||||
// //config.setHttpProxy("http://xx.xx.xx.xx:xxxx");
|
||||
// // 设置https代理。
|
||||
// //config.setHttpsProxy("http://xx.xx.xx.xx:xxxx");
|
||||
// Client client = new Client(config);
|
||||
//
|
||||
// // 创建RuntimeObject实例并设置运行参数。
|
||||
// RuntimeOptions runtime = new RuntimeOptions();
|
||||
// runtime.readTimeout = 10000;
|
||||
// runtime.connectTimeout = 10000;
|
||||
//
|
||||
// return client.describeFaceVerify(request, runtime);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyun.cloudauth20200618.Client;
|
||||
import com.aliyun.cloudauth20200618.models.DescribeSmartVerifyRequest;
|
||||
import com.aliyun.cloudauth20200618.models.DescribeSmartVerifyResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.tea.TeaUnretryableException;
|
||||
import com.aliyun.tearpc.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
|
||||
public class DescribeSmartVerify {
|
||||
public static DescribeSmartVerifyResponse describeSmart(long scene, String certifyId) throws Exception {
|
||||
|
||||
// 通过以下代码创建API请求并设置参数。
|
||||
DescribeSmartVerifyRequest request = new DescribeSmartVerifyRequest();
|
||||
// 请输入场景ID+L。
|
||||
request.setSceneId(scene);
|
||||
|
||||
request.setCertifyId(certifyId);
|
||||
|
||||
// 推荐,支持服务路由。
|
||||
//DescribeSmartVerifyResponse response = describeSmartVerifyAutoRoute(request);
|
||||
|
||||
// 不支持服务自动路由。
|
||||
DescribeSmartVerifyResponse response = describeSmartVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
|
||||
|
||||
System.out.println(response.getRequestId());
|
||||
System.out.println(response.getCode());
|
||||
System.out.println(response.getMessage());
|
||||
System.out.println(
|
||||
response.getResultObject() == null ? null : response.getResultObject().getPassed());
|
||||
System.out.println(
|
||||
response.getResultObject() == null ? null : response.getResultObject().getSubCode());
|
||||
System.out.println(response.getResultObject() == null ? null
|
||||
: response.getResultObject().getMaterialInfo());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private static DescribeSmartVerifyResponse describeSmartVerifyAutoRoute(DescribeSmartVerifyRequest request) {
|
||||
// 第一个为主区域Endpoint,第二个为备区域Endpoint。
|
||||
List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com",
|
||||
"cloudauth.cn-beijing.aliyuncs.com");
|
||||
DescribeSmartVerifyResponse lastResponse = null;
|
||||
for (String endpoint : endpoints) {
|
||||
try {
|
||||
DescribeSmartVerifyResponse response = describeSmartVerify(endpoint, request);
|
||||
lastResponse = response;
|
||||
|
||||
// 服务端错误,切换到下个区域调用。
|
||||
if ("500".equals(response.getCode())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
// 网络异常,切换到下个区域调用。
|
||||
if (e.getCause() instanceof TeaException) {
|
||||
TeaException teaException = ((TeaException)e.getCause());
|
||||
if (teaException.getData() != null && "ServiceUnavailable".equals(
|
||||
teaException.getData().get("Code"))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getCause() instanceof TeaUnretryableException) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastResponse;
|
||||
}
|
||||
|
||||
private static DescribeSmartVerifyResponse describeSmartVerify(String endpoint, DescribeSmartVerifyRequest request)
|
||||
throws Exception {
|
||||
Config config = new Config();
|
||||
config.setAccessKeyId(AliApis.ofNew().accessKeyId);
|
||||
config.setAccessKeySecret(AliApis.ofNew().accessKeySecret);
|
||||
config.setEndpoint(endpoint);
|
||||
// 设置HTTP代理。
|
||||
//config.setHttpProxy("<http://xx.xx.xx.xx:xxxx>");
|
||||
// 设置HTTPS代理。
|
||||
//config.setHttpsProxy("<https://xx.xx.xx.xx:xxxx>");
|
||||
Client client = new Client(config);
|
||||
|
||||
// 创建RuntimeObject实例并设置运行参数。
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
runtime.readTimeout = 10000;
|
||||
runtime.connectTimeout = 10000;
|
||||
|
||||
return client.describeSmartVerify(request, runtime);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
DescribeSmartVerifyResponse response = DescribeSmartVerify.describeSmart(AliApis.SCENE_SFZ_PLUS, "shs0cd820014eaef132f218f0dfc9d8c");
|
||||
System.out.println(JSON.toJSONString(response));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.DateUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.hutool.http.HttpGlobalConfig;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.qutaojing.common.PageInfo;
|
||||
import cn.qutaojing.common.PageParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class EastmoneyApi {
|
||||
public static List<JSONObject> gethotgubalist() {
|
||||
String reponse = HttpUtil.createGet("http://quote.eastmoney.com/newapi/gethotgubalist")
|
||||
.header("Referer", "http://quote.eastmoney.com")
|
||||
.execute().body();
|
||||
|
||||
return Lists.transform(JSON.parseArray(reponse), item -> (JSONObject) item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新股日历
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
public static PageInfo<JSONObject> ipoApplyDate(int pageNum, int pageSize) {
|
||||
String url = MessageFormat.format("https://datacenter-web.eastmoney.com/api/data/v1/get?sortColumns=APPLY_DATE%2CSECURITY_CODE&sortTypes=-1%2C-1&pageSize={0}&pageNumber={1}&reportName=RPTA_APP_IPOAPPLY&columns=SECURITY_CODE%2CSECURITY_NAME%2CTRADE_MARKET_CODE%2CAPPLY_CODE%2CTRADE_MARKET%2CMARKET_TYPE%2CORG_TYPE%2CISSUE_NUM%2CONLINE_ISSUE_NUM%2COFFLINE_PLACING_NUM%2CTOP_APPLY_MARKETCAP%2CPREDICT_ONFUND_UPPER%2CONLINE_APPLY_UPPER%2CPREDICT_ONAPPLY_UPPER%2CISSUE_PRICE%2CLATELY_PRICE%2CCLOSE_PRICE%2CAPPLY_DATE%2CBALLOT_NUM_DATE%2CBALLOT_PAY_DATE%2CLISTING_DATE%2CAFTER_ISSUE_PE%2CONLINE_ISSUE_LWR%2CINITIAL_MULTIPLE%2CINDUSTRY_PE_NEW%2COFFLINE_EP_OBJECT%2CCONTINUOUS_1WORD_NUM%2CTOTAL_CHANGE%2CPROFIT%2CLIMIT_UP_PRICE%2CINFO_CODE%2COPEN_PRICE%2CLD_OPEN_PREMIUM%2CLD_CLOSE_CHANGE%2CTURNOVERRATE%2CLD_HIGH_CHANG%2CLD_AVERAGE_PRICE%2COPEN_DATE%2COPEN_AVERAGE_PRICE%2CPREDICT_PE%2CPREDICT_ISSUE_PRICE2%2CPREDICT_ISSUE_PRICE%2CPREDICT_ISSUE_PRICE1%2CPREDICT_ISSUE_PE%2CPREDICT_PE_THREE%2CONLINE_APPLY_PRICE%2CMAIN_BUSINESS%2CPAGE_PREDICT_PRICE1%2CPAGE_PREDICT_PRICE2%2CPAGE_PREDICT_PRICE3%2CPAGE_PREDICT_PE1%2CPAGE_PREDICT_PE2%2CPAGE_PREDICT_PE3%2CSELECT_LISTING_DATE%2CIS_BEIJING%2CINDUSTRY_PE_RATIO%2CINDUSTRY_PE%2CIS_REGISTRATION"eColumns=f2~01~SECURITY_CODE~NEWEST_PRICE"eType=0&filter=(APPLY_DATE%3E%27{2}%27)&source=WEB&client=WEB", pageSize, pageNum, DateUtils.format(DateUtils.dayAdd(-1), DateUtils.YYYY_MM_DD));
|
||||
String reponse = null;
|
||||
try {
|
||||
reponse = HttpUtil.createGet(url)
|
||||
.header("Referer", "https://datacenter-web.eastmoney.com")
|
||||
.execute().body();
|
||||
|
||||
JSONObject json = JSON.parseObject(reponse);
|
||||
if(json.getIntValue("code") == 0) {
|
||||
JSONObject result = json.getJSONObject("result");
|
||||
Integer count = result.getInteger("count");
|
||||
JSONArray data = result.getJSONArray("data");
|
||||
List<JSONObject> list = Lists.transform(data, item -> (JSONObject) item)
|
||||
.stream()
|
||||
// .filter(j -> ! StringUtils.startsWith(j.getString("APPLY_CODE"), "8"))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
return PageInfo.with(list, new PageParam(pageNum, pageSize), count);
|
||||
} else {
|
||||
return PageInfo.with(Lists.newArrayList(), new PageParam(pageNum, pageSize));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取新股日历出错url:{},reponse: {}, 错误信息 = {}", url, reponse, e);
|
||||
// 获取股票行情出错
|
||||
throw new SysTipsException("tips.msg.185");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 沪深300
|
||||
* @return
|
||||
*/
|
||||
public static List<JSONObject> a300List() {
|
||||
String url = "http://push2.eastmoney.com/api/qt/clist/get?np=1&fltt=1&invt=2&fs=b%3ABK0500%2Bf%3A!50&fields=f14%2Cf12%2Cf13%2Cf1%2Cf2%2Cf4%2Cf3%2Cf152&fid=f3&pn=1&pz=15&po=1&ut=fa5fd1943c7b386f172d6893dbfba10b&wbp2u=%7C0%7C0%7C0%7Cweb&_=" + System.currentTimeMillis();
|
||||
return _qtListGet(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 沪深指数
|
||||
* {total, diff: []}
|
||||
* @return
|
||||
*/
|
||||
public static List<JSONObject> aIndexList() {
|
||||
int pageNum = 1;
|
||||
int pageSize = 20;
|
||||
String url = String.format("http://21.push2.eastmoney.com/api/qt/clist/get?pn=%s&pz=%s&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=|0|0|0|web&fid=&fs=b:MK0010&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f26,f22,f11,f62,f128,f136,f115,f152&_=" + System.currentTimeMillis(), pageNum, pageSize);
|
||||
return _qtListGet(url);
|
||||
}
|
||||
|
||||
public static List<JSONObject> _qtListGet(String url) {
|
||||
String reponse = null;
|
||||
try {
|
||||
reponse = HttpUtil.createGet(url)
|
||||
.header("Referer", "http://21.push2.eastmoney.com")
|
||||
.execute().body();
|
||||
log.info("url:{}", url);
|
||||
log.info(reponse);
|
||||
JSONObject json = JSON.parseObject(reponse);
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
if(data == null) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
return Lists.transform(data.getJSONArray("diff"), item -> {
|
||||
JSONObject j = (JSONObject) item;
|
||||
return j;
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票行情出错url:{},reponse: {}, 错误信息 = {}", url, reponse, e);
|
||||
// 获取股票行情出错
|
||||
throw new SysTipsException("tips.msg.185");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
PageInfo<JSONObject> ipoApplyDate = ipoApplyDate(1, 300);
|
||||
System.out.println(JSON.toJSONString(ipoApplyDate));
|
||||
|
||||
List<JSONObject> gethotgubalist = gethotgubalist();
|
||||
System.out.println(JSON.toJSONString(gethotgubalist));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.Jsons;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
public class FutunnNewsApis {
|
||||
public JSONArray market_list(String news_id) {
|
||||
String url = String.format("https://news.futunn.com/client/market-list?news_id=%s&lang=zh-cn", news_id);
|
||||
String body = HttpUtil.get(url);
|
||||
JSONObject json = Jsons.toJSON(body);
|
||||
if(json == null) {
|
||||
throw new SysTipsException("访问异常");
|
||||
}
|
||||
|
||||
if(json.getIntValue("code") != 0) {
|
||||
throw new SysTipsException(json.getString("message"));
|
||||
}
|
||||
|
||||
return json.getJSONObject("data").getJSONArray("list");
|
||||
}
|
||||
|
||||
public static FutunnNewsApis of() {
|
||||
return new FutunnNewsApis();
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(of().market_list(null));
|
||||
}
|
||||
}
|
||||
313
src/main/java/cn/stock/market/infrastructure/api/HttpUtils.java
Normal file
313
src/main/java/cn/stock/market/infrastructure/api/HttpUtils.java
Normal file
@@ -0,0 +1,313 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.conn.ClientConnectionManager;
|
||||
import org.apache.http.conn.scheme.Scheme;
|
||||
import org.apache.http.conn.scheme.SchemeRegistry;
|
||||
import org.apache.http.conn.ssl.SSLSocketFactory;
|
||||
import org.apache.http.entity.ByteArrayEntity;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class HttpUtils {
|
||||
|
||||
/**
|
||||
* get
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doGet(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpGet request = new HttpGet(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* post form
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param bodys
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
Map<String, String> bodys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (bodys != null) {
|
||||
List<NameValuePair> nameValuePairList = new ArrayList<NameValuePair>();
|
||||
|
||||
for (String key : bodys.keySet()) {
|
||||
nameValuePairList.add(new BasicNameValuePair(key, bodys.get(key)));
|
||||
}
|
||||
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(nameValuePairList, "utf-8");
|
||||
formEntity.setContentType("application/x-www-form-urlencoded; charset=UTF-8");
|
||||
request.setEntity(formEntity);
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post String
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
String body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Post stream
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPost(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
byte[] body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPost request = new HttpPost(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put String
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPut(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
String body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(body)) {
|
||||
request.setEntity(new StringEntity(body, "utf-8"));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put stream
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @param body
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doPut(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys,
|
||||
byte[] body)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpPut request = new HttpPut(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
if (body != null) {
|
||||
request.setEntity(new ByteArrayEntity(body));
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete
|
||||
*
|
||||
* @param host
|
||||
* @param path
|
||||
* @param method
|
||||
* @param headers
|
||||
* @param querys
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public static HttpResponse doDelete(String host, String path, String method,
|
||||
Map<String, String> headers,
|
||||
Map<String, String> querys)
|
||||
throws Exception {
|
||||
HttpClient httpClient = wrapClient(host);
|
||||
|
||||
HttpDelete request = new HttpDelete(buildUrl(host, path, querys));
|
||||
for (Map.Entry<String, String> e : headers.entrySet()) {
|
||||
request.addHeader(e.getKey(), e.getValue());
|
||||
}
|
||||
|
||||
return httpClient.execute(request);
|
||||
}
|
||||
|
||||
private static String buildUrl(String host, String path, Map<String, String> querys) throws UnsupportedEncodingException {
|
||||
StringBuilder sbUrl = new StringBuilder();
|
||||
sbUrl.append(host);
|
||||
if (!StringUtils.isBlank(path)) {
|
||||
sbUrl.append(path);
|
||||
}
|
||||
if (null != querys) {
|
||||
StringBuilder sbQuery = new StringBuilder();
|
||||
for (Map.Entry<String, String> query : querys.entrySet()) {
|
||||
if (0 < sbQuery.length()) {
|
||||
sbQuery.append("&");
|
||||
}
|
||||
if (StringUtils.isBlank(query.getKey()) && !StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append(query.getValue());
|
||||
}
|
||||
if (!StringUtils.isBlank(query.getKey())) {
|
||||
sbQuery.append(query.getKey());
|
||||
if (!StringUtils.isBlank(query.getValue())) {
|
||||
sbQuery.append("=");
|
||||
sbQuery.append(URLEncoder.encode(query.getValue(), "utf-8"));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (0 < sbQuery.length()) {
|
||||
sbUrl.append("?").append(sbQuery);
|
||||
}
|
||||
}
|
||||
|
||||
return sbUrl.toString();
|
||||
}
|
||||
|
||||
private static HttpClient wrapClient(String host) {
|
||||
HttpClient httpClient = new DefaultHttpClient();
|
||||
if (host.startsWith("https://")) {
|
||||
sslClient(httpClient);
|
||||
}
|
||||
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
private static void sslClient(HttpClient httpClient) {
|
||||
try {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
X509TrustManager tm = new X509TrustManager() {
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return null;
|
||||
}
|
||||
public void checkClientTrusted(X509Certificate[] xcs, String str) {
|
||||
|
||||
}
|
||||
public void checkServerTrusted(X509Certificate[] xcs, String str) {
|
||||
|
||||
}
|
||||
};
|
||||
ctx.init(null, new TrustManager[] { tm }, null);
|
||||
SSLSocketFactory ssf = new SSLSocketFactory(ctx);
|
||||
ssf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
|
||||
ClientConnectionManager ccm = httpClient.getConnectionManager();
|
||||
SchemeRegistry registry = ccm.getSchemeRegistry();
|
||||
registry.register(new Scheme("https", 443, ssf));
|
||||
} catch (KeyManagementException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.aliyun.cloudauth20190307.Client;
|
||||
import com.aliyun.cloudauth20190307.models.*;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.tea.TeaUnretryableException;
|
||||
import com.aliyun.tearpc.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
|
||||
public class InitFaceVerify {
|
||||
//
|
||||
// public static InitFaceVerifyResponse faceVerify(String phoneNo, String metaInfo, String certifyId) throws Exception {
|
||||
//
|
||||
// InitFaceVerifyRequest request = new InitFaceVerifyRequest();
|
||||
// // 请输入场景ID+L。
|
||||
// request.setSceneId(AliApis.SMART_SCENEID);
|
||||
// // 设置商户请求的唯一标识。
|
||||
// request.setOuterOrderNo(UUID.fastUUID().toString());
|
||||
// // 认证方案。
|
||||
// request.setProductCode("PV_FV");
|
||||
// request.setUserId("12345xxxx");
|
||||
// // 模式。
|
||||
// request.setModel("LIVENESS");
|
||||
// request.setCertType("IDENTITY_CARD");
|
||||
// //request.setCertName("张三");
|
||||
// //request.setCertNo("xxxx");
|
||||
// // MetaInfo环境参数。
|
||||
// request.setMetaInfo(metaInfo);
|
||||
// //request.setMobile("130xxxxxxxx");
|
||||
// //request.setIp("114.xxx.xxx.xxx");
|
||||
//
|
||||
// // 请在以下四种方式中选择其一。
|
||||
// // 1.照片Base64编码。
|
||||
// // 2.照片OSS bucket名和文件名。
|
||||
// // 3.照片OSS的URL地址。
|
||||
// // 4.已经实人认证通过的CertifyId。
|
||||
//
|
||||
// // 方式一:照片Base64。
|
||||
//// request.setFaceContrastPicture("人脸照片Base64编码");
|
||||
// // 方式二:照片OSS bucket名和文件名。
|
||||
// //request.setOssBucketName("cn-shanghai-aliyun-cloudauth-xxxxx");
|
||||
// //request.setOssObjectName("verify/xxxxx/xxxxxx.jpeg");
|
||||
// // 方式三:照片OSS的URL地址,公网可访问。
|
||||
// //request.setFaceContrastPictureUrl("https://cn-shanghai-aliyun-cloudauth-xxxxxx.oss-cn-shanghai.aliyuncs.com/verify/xxxxx/xxxxx.jpeg")
|
||||
// // 方式四:已经实人认证通过的CertifyId。
|
||||
// request.setCertifyId(certifyId);
|
||||
//
|
||||
// // 推荐,支持服务路由。
|
||||
// InitFaceVerifyResponse response = initFaceVerifyAutoRoute(request);
|
||||
//
|
||||
// // 不支持服务自动路由。
|
||||
// //InitFaceVerifyResponse response = initFaceVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
|
||||
//
|
||||
// System.out.println(response.getRequestId());
|
||||
// System.out.println(response.getCode());
|
||||
// System.out.println(response.getMessage());
|
||||
// System.out.println(response.getResultObject() == null ? null
|
||||
// : response.getResultObject().getCertifyId());
|
||||
//
|
||||
// return response;
|
||||
// }
|
||||
//
|
||||
// private static InitFaceVerifyResponse initFaceVerifyAutoRoute(InitFaceVerifyRequest request) {
|
||||
// // 第一个为主区域Endpoint,第二个为备区域Endpoint。
|
||||
// List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com",
|
||||
// "cloudauth.cn-beijing.aliyuncs.com");
|
||||
// InitFaceVerifyResponse lastResponse = null;
|
||||
// for (String endpoint : endpoints) {
|
||||
// try {
|
||||
// InitFaceVerifyResponse response = initFaceVerify(endpoint, request);
|
||||
// lastResponse = response;
|
||||
//
|
||||
// // 服务端错误,切换到下个区域调用。
|
||||
// if (response != null && "500".equals(response.getCode())) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// return response;
|
||||
// } catch (Exception e) {
|
||||
// // 网络异常,切换到下个区域调用。
|
||||
// if (e.getCause() instanceof TeaException) {
|
||||
// TeaException teaException = ((TeaException)e.getCause());
|
||||
// if (teaException.getData() != null && "ServiceUnavailable".equals(
|
||||
// teaException.getData().get("Code"))) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (e.getCause() instanceof TeaUnretryableException) {
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return lastResponse;
|
||||
// }
|
||||
//
|
||||
// private static InitFaceVerifyResponse initFaceVerify(String endpoint, InitFaceVerifyRequest request)
|
||||
// throws Exception {
|
||||
// Config config = new Config();
|
||||
// config.setAccessKeyId(AliApis.ofNew().accessKeyId);
|
||||
// config.setAccessKeySecret(AliApis.ofNew().accessKeySecret);
|
||||
// config.setEndpoint(endpoint);
|
||||
// // 设置http代理。
|
||||
// //config.setHttpProxy("http://xx.xx.xx.xx:xxxx");
|
||||
// // 设置https代理。
|
||||
// //config.setHttpsProxy("https://xx.xx.xx.xx:xxxx");
|
||||
// Client client = new Client(config);
|
||||
//
|
||||
// // 创建RuntimeObject实例并设置运行参数。
|
||||
// RuntimeOptions runtime = new RuntimeOptions();
|
||||
// runtime.readTimeout = 10000;
|
||||
// runtime.connectTimeout = 10000;
|
||||
//
|
||||
// return client.initFaceVerify(request, runtime);
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.aliyun.cloudauth20200618.Client;
|
||||
import com.aliyun.cloudauth20200618.models.InitSmartVerifyRequest;
|
||||
import com.aliyun.cloudauth20200618.models.InitSmartVerifyResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.tea.TeaUnretryableException;
|
||||
import com.aliyun.tearpc.models.Config;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
|
||||
import cn.hutool.core.lang.UUID;
|
||||
|
||||
public class InitSmartVerify {
|
||||
|
||||
public static InitSmartVerifyResponse idCardOcrPlus(String phoneNo, String metaInfo) throws Exception {
|
||||
|
||||
// 通过以下代码创建API请求并设置参数。
|
||||
InitSmartVerifyRequest request = new InitSmartVerifyRequest();
|
||||
// 请输入场景ID+L。
|
||||
request.setSceneId(AliApis.SCENE_SFZ_PLUS);
|
||||
request.setOuterOrderNo(UUID.fastUUID().toString());
|
||||
// 卡证核身类型,固定值。
|
||||
request.setMode("MARKET_SAFE");
|
||||
request.setOcr("T");
|
||||
// 证件类型,固定值。
|
||||
request.setCertType("IDENTITY_CARD");
|
||||
//request.setCertName("张三");
|
||||
//request.setCertNo("xxxx");
|
||||
// MetaInfo环境参数,需要通过客户端SDK获取。
|
||||
request.setMetaInfo(metaInfo);
|
||||
request.setMobile(phoneNo);
|
||||
//request.setIp("114.xxx.xxx.xxx");
|
||||
//request.setUserId("12345xxxx");
|
||||
//request.setCallbackUrl("https://www.aliyundoc.com");
|
||||
//request.setCallbackToken("xxxxxxx");
|
||||
|
||||
// 推荐,支持服务路由。
|
||||
InitSmartVerifyResponse response = initSmartVerifyAutoRoute(request);
|
||||
|
||||
// 不支持服务自动路由。
|
||||
//InitSmartVerifyResponse response = initSmartVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
|
||||
|
||||
System.out.println(response.getRequestId());
|
||||
System.out.println(response.getCode());
|
||||
System.out.println(response.getMessage());
|
||||
System.out.println(response.getResultObject() == null ? null
|
||||
: response.getResultObject().getCertifyId());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public static InitSmartVerifyResponse idCardOcr(String phoneNo, String metaInfo) throws Exception {
|
||||
// 通过以下代码创建API请求并设置参数。
|
||||
InitSmartVerifyRequest request = new InitSmartVerifyRequest();
|
||||
// 请输入场景ID+L。
|
||||
request.setSceneId(AliApis.SCENE_SFZ);
|
||||
|
||||
request.setOuterOrderNo(UUID.fastUUID().toString());
|
||||
// 卡证核身类型,固定值。
|
||||
request.setMode("OCR");
|
||||
// 证件类型,固定值。
|
||||
request.setCertType("IDENTITY_CARD");
|
||||
// MetaInfo环境参数,需要通过客户端SDK获取。
|
||||
request.setMetaInfo(metaInfo);
|
||||
request.setMobile(phoneNo);
|
||||
// request.setIp("114.xxx.xxx.xxx");
|
||||
// request.setUserId(phoneNo);
|
||||
// request.setCallbackUrl("https://www.aliyundoc.com");
|
||||
// request.setCallbackToken("xxxxx");
|
||||
|
||||
// 推荐,支持服务路由。
|
||||
InitSmartVerifyResponse response = initSmartVerifyAutoRoute(request);
|
||||
|
||||
// 不支持服务自动路由。
|
||||
//InitSmartVerifyResponse response = initSmartVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
|
||||
|
||||
System.out.println(response.getRequestId());
|
||||
System.out.println(response.getCode());
|
||||
System.out.println(response.getMessage());
|
||||
System.out.println(response.getResultObject() == null ? null
|
||||
: response.getResultObject().getCertifyId());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public static InitSmartVerifyResponse initSmart(String phoneNo, String metaInfo, String idCardCertifyId, String facePictureUrl) throws Exception {
|
||||
|
||||
// 通过以下代码创建API请求并设置参数。
|
||||
InitSmartVerifyRequest request = new InitSmartVerifyRequest();
|
||||
// 请输入场景ID+L。
|
||||
request.setSceneId(AliApis.SCENE);
|
||||
request.setOuterOrderNo(UUID.fastUUID().toString());
|
||||
// 卡证核身类型,固定值。
|
||||
request.setMode("LOGIN_SAFE");
|
||||
// 证件类型,固定值。
|
||||
request.setCertType("IDENTITY_CARD");
|
||||
// request.setCertName("<张三>");
|
||||
// request.setCertNo("<xxx>");
|
||||
// MetaInfo环境参数,需要通过客户端SDK获取。
|
||||
request.setMetaInfo(metaInfo);
|
||||
request.setMobile(phoneNo);
|
||||
//request.setIp("<114.xxx.xxx.xxx>");
|
||||
//request.setUserId("<12345xxxx>");
|
||||
//request.setCallbackUrl("<https://www.aliyun.com>");
|
||||
//request.setCallbackToken("<NMjvQanQgplBSaEI0sL86WnQplB>");
|
||||
|
||||
// 请在以下四种方式中选择其一。
|
||||
// 1.人脸图片的Base64编码。
|
||||
// 2.已授权OSS空间的Bucket名和已授权OSS空间的文件名。
|
||||
// 3.人脸图片的HTTPS或HTTP地址。
|
||||
// 4.已通过智能核身得到的CertifyId,认证时的图片作为比对图片。
|
||||
|
||||
// 方式一:人脸图片的Base64编码。
|
||||
// request.setFacePictureBase64("</9j/4AAQSkZJRgABAQAASxxxxxxx>");
|
||||
// 方式二:已授权OSS空间的Bucket名和已授权OSS空间的文件名。
|
||||
// request.setOssBucketName("<cn-shanghai-aliyun-cloudauth-xxxxx>");
|
||||
// request.setOssObjectName("<verify/xxxxx/xxxxxx.jpeg>");
|
||||
// 方式三:人脸图片的HTTPS或HTTP地址。
|
||||
// request.setFacePictureUrl(facePictureUrl);
|
||||
// 方式四:已通过智能核身得到的CertifyId,认证时的图片作为比对图片。
|
||||
request.setCertifyId(idCardCertifyId);
|
||||
|
||||
// 推荐,支持服务路由。
|
||||
InitSmartVerifyResponse response = initSmartVerifyAutoRoute(request);
|
||||
|
||||
// 不支持服务自动路由。
|
||||
//InitSmartVerifyResponse response = initSmartVerify("cloudauth.cn-shanghai.aliyuncs.com", request);
|
||||
System.out.println(JSON.toJSONString(request));
|
||||
System.out.println(response.getRequestId());
|
||||
System.out.println(response.getCode());
|
||||
System.out.println(response.getMessage());
|
||||
System.out.println(response.getResultObject() == null ? null
|
||||
: response.getResultObject().getCertifyId());
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private static InitSmartVerifyResponse initSmartVerifyAutoRoute(InitSmartVerifyRequest request) {
|
||||
// 第一个为主区域Endpoint,第二个为备区域Endpoint。
|
||||
List<String> endpoints = Arrays.asList("cloudauth.cn-shanghai.aliyuncs.com",
|
||||
"cloudauth.cn-beijing.aliyuncs.com");
|
||||
InitSmartVerifyResponse lastResponse = null;
|
||||
for (String endpoint : endpoints) {
|
||||
try {
|
||||
InitSmartVerifyResponse response = initSmartVerify(endpoint, request);
|
||||
lastResponse = response;
|
||||
|
||||
// 服务端错误,切换到下个区域调用。
|
||||
if (response != null && "500".equals(response.getCode())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
// 网络异常,切换到下个区域调用。
|
||||
if (e.getCause() instanceof TeaException) {
|
||||
TeaException teaException = ((TeaException)e.getCause());
|
||||
if (teaException.getData() != null && "ServiceUnavailable".equals(
|
||||
teaException.getData().get("Code"))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.getCause() instanceof TeaUnretryableException) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lastResponse;
|
||||
}
|
||||
|
||||
private static InitSmartVerifyResponse initSmartVerify(String endpoint, InitSmartVerifyRequest request)
|
||||
throws Exception {
|
||||
Config config = new Config();
|
||||
config.setAccessKeyId(AliApis.ofNew().accessKeyId);
|
||||
config.setAccessKeySecret(AliApis.ofNew().accessKeySecret);
|
||||
config.setEndpoint(endpoint);
|
||||
// 设置http代理。
|
||||
//config.setHttpProxy("http://xx.xx.xx.xx:xxxx");
|
||||
// 设置https代理。
|
||||
//config.setHttpsProxy("https://xx.xx.xx.xx:xxxx");
|
||||
Client client = new Client(config);
|
||||
|
||||
// 创建RuntimeObject实例并设置运行参数。
|
||||
RuntimeOptions runtime = new RuntimeOptions();
|
||||
runtime.readTimeout = 10000;
|
||||
runtime.connectTimeout = 10000;
|
||||
|
||||
return client.initSmartVerify(request, runtime);
|
||||
}
|
||||
}
|
||||
228
src/main/java/cn/stock/market/infrastructure/api/JuheApis.java
Normal file
228
src/main/java/cn/stock/market/infrastructure/api/JuheApis.java
Normal file
@@ -0,0 +1,228 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
public class JuheApis {
|
||||
//接口请求地址
|
||||
public static final String URL = "http://v.juhe.cn/sms/send?mobile=%s&tpl_id=%s&tpl_value=%s&key=%s";
|
||||
//申请接口的请求key
|
||||
// TODO: 您需要改为自己的请求key
|
||||
public static final String KEY = "33d215cc0c5a92e7e2d063c13300cd79";
|
||||
//此次发送短信需要使用的短信模板
|
||||
//3010模板对应的发送内容为:【聚合数据1】您的验证码是#code#.你还剩余次数#total#,如非本人操作,请忽略本短信
|
||||
//其中#code#是短信模板中的变量,用于开发者动态生成验证码
|
||||
//在运行代码的时候您需要改为自己拥有的模板
|
||||
// TODO: 您需要改为自己的模板id
|
||||
|
||||
|
||||
public static final int SMS_RECHARGE = 249103;
|
||||
public static final int SMS_WITHDRAWAL = 249105;
|
||||
public static final int SMS_OPEN = 249104;
|
||||
public static final int SMS_VERIFY_CODE = 249100;
|
||||
public static final int SMS_WARN = 250126;
|
||||
public static final int SMS_POSITION_ADD = 250318;
|
||||
|
||||
public static void main(String[] args) {
|
||||
//用于接收短信的手机号码,你需要修改此处
|
||||
// TODO: 改为自己手机号测试看看
|
||||
String mobile = "15390891113";
|
||||
//短信模板中的您自定义的变量
|
||||
// TODO: 改为您模板中的需要的变量
|
||||
String variable = "#code#=12345&#total#=100";
|
||||
// send(mobile,SMS_VERIFY_CODE, variable);
|
||||
|
||||
send(mobile,SMS_WARN, variable);
|
||||
}
|
||||
|
||||
/**
|
||||
* 打印请求结果
|
||||
*
|
||||
* @param mobile 手机号
|
||||
* @param variable 模板变量
|
||||
*/
|
||||
public static JSONObject send(String mobile, int code, String variable) {
|
||||
if(variable == null) {
|
||||
variable = "";
|
||||
}
|
||||
//发送http请求的url
|
||||
String url = null;
|
||||
try {
|
||||
url = String.format(URL, mobile, code, URLEncoder.encode(variable, "utf-8"), KEY);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String response = doGet(url);
|
||||
System.out.println(response);
|
||||
JSONObject jsonObject = JSON.parseObject(response);
|
||||
int error_code = jsonObject.getIntValue("error_code");
|
||||
if (error_code == 0) {
|
||||
System.out.println("调用接口成功");
|
||||
JSONObject result = jsonObject.getJSONObject("result");
|
||||
String sid = result.getString("sid");
|
||||
int fee = result.getIntValue("fee");
|
||||
System.out.println("本次发送的唯一标示:" + sid);
|
||||
System.out.println("本次发送消耗的次数:" + fee);
|
||||
}else{
|
||||
System.out.println("调用接口失败:"+ jsonObject.getString("reason"));
|
||||
}
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* get方式的http请求
|
||||
*
|
||||
* @param httpUrl 请求地址
|
||||
* @return 返回结果
|
||||
*/
|
||||
public static String doGet(String httpUrl) {
|
||||
HttpURLConnection connection = null;
|
||||
InputStream inputStream = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
String result = null;// 返回结果字符串
|
||||
try {
|
||||
// 创建远程url连接对象
|
||||
URL url = new URL(httpUrl);
|
||||
// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置连接方式:get
|
||||
connection.setRequestMethod("GET");
|
||||
// 设置连接主机服务器的超时时间:15000毫秒
|
||||
connection.setConnectTimeout(15000);
|
||||
// 设置读取远程返回的数据时间:60000毫秒
|
||||
connection.setReadTimeout(60000);
|
||||
// 发送请求
|
||||
connection.connect();
|
||||
// 通过connection连接,获取输入流
|
||||
if (connection.getResponseCode() == 200) {
|
||||
inputStream = connection.getInputStream();
|
||||
// 封装输入流,并指定字符集
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
// 存放数据
|
||||
StringBuilder sbf = new StringBuilder();
|
||||
String temp;
|
||||
while ((temp = bufferedReader.readLine()) != null) {
|
||||
sbf.append(temp);
|
||||
sbf.append(System.getProperty("line.separator"));
|
||||
}
|
||||
result = sbf.toString();
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != bufferedReader) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != inputStream) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.disconnect();// 关闭远程连接
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* post方式的http请求
|
||||
*
|
||||
* @param httpUrl 请求地址
|
||||
* @param param 请求参数
|
||||
* @return 返回结果
|
||||
*/
|
||||
public static String doPost(String httpUrl, String param) {
|
||||
HttpURLConnection connection = null;
|
||||
InputStream inputStream = null;
|
||||
OutputStream outputStream = null;
|
||||
BufferedReader bufferedReader = null;
|
||||
String result = null;
|
||||
try {
|
||||
URL url = new URL(httpUrl);
|
||||
// 通过远程url连接对象打开连接
|
||||
connection = (HttpURLConnection) url.openConnection();
|
||||
// 设置连接请求方式
|
||||
connection.setRequestMethod("POST");
|
||||
// 设置连接主机服务器超时时间:15000毫秒
|
||||
connection.setConnectTimeout(15000);
|
||||
// 设置读取主机服务器返回数据超时时间:60000毫秒
|
||||
connection.setReadTimeout(60000);
|
||||
// 默认值为:false,当向远程服务器传送数据/写数据时,需要设置为true
|
||||
connection.setDoOutput(true);
|
||||
// 设置传入参数的格式:请求参数应该是 name1=value1&name2=value2 的形式。
|
||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
// 通过连接对象获取一个输出流
|
||||
outputStream = connection.getOutputStream();
|
||||
// 通过输出流对象将参数写出去/传输出去,它是通过字节数组写出的
|
||||
outputStream.write(param.getBytes());
|
||||
// 通过连接对象获取一个输入流,向远程读取
|
||||
if (connection.getResponseCode() == 200) {
|
||||
inputStream = connection.getInputStream();
|
||||
// 对输入流对象进行包装:charset根据工作项目组的要求来设置
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
|
||||
StringBuilder sbf = new StringBuilder();
|
||||
String temp;
|
||||
// 循环遍历一行一行读取数据
|
||||
while ((temp = bufferedReader.readLine()) != null) {
|
||||
sbf.append(temp);
|
||||
sbf.append(System.getProperty("line.separator"));
|
||||
}
|
||||
result = sbf.toString();
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
// 关闭资源
|
||||
if (null != bufferedReader) {
|
||||
try {
|
||||
bufferedReader.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != outputStream) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (null != inputStream) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class StockRealTime {
|
||||
// @JSONField(name = "Symbol")
|
||||
String symbol; //A 股股票代码
|
||||
// @JSONField(name = "StockName")
|
||||
String stockName; //股票名称
|
||||
// @JSONField(name = "Latest")
|
||||
Double latest; //最新价,单位:元
|
||||
// @JSONField(name = "ChangePercent")
|
||||
Double changePercent; //涨跌幅,单位:%
|
||||
// @JSONField(name = "ChangeAmount")
|
||||
Double changeAmount; //涨跌额,单位:元
|
||||
// @JSONField(name = "TradingVolume")
|
||||
Double tradingVolume; //成交量,单位:手
|
||||
// @JSONField(name = "TradingAmount")
|
||||
Double tradingAmount; //成交额,单位:元
|
||||
// @JSONField(name = "Swing")
|
||||
Double swing; //振幅,单位:%
|
||||
// @JSONField(name = "High")
|
||||
Double high; //最高,单位:元
|
||||
// @JSONField(name = "Low")
|
||||
Double low; //最低,单位:元
|
||||
// @JSONField(name = "Open")
|
||||
Double open; //今日开盘价,单位:元
|
||||
// @JSONField(name = "PreClose")
|
||||
Double preClose; //昨收价,单位:元
|
||||
// @JSONField(name = "QuantityRatio")
|
||||
Double quantityRatio; //量比
|
||||
// @JSONField(name = "TurnoverRate")
|
||||
Double turnoverRate; //换手率,单位:%
|
||||
// @JSONField(name = "PERatioDynamic")
|
||||
Double peRatioDynamic; //市盈率-动态
|
||||
// @JSONField(name = "PBRatio")
|
||||
Double pbRatio; //市净率
|
||||
}
|
||||
102
src/main/java/cn/stock/market/infrastructure/api/TxApis.java
Normal file
102
src/main/java/cn/stock/market/infrastructure/api/TxApis.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package cn.stock.market.infrastructure.api;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.Jsons;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.tencentcloudapi.common.Credential;
|
||||
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
||||
import com.tencentcloudapi.common.profile.ClientProfile;
|
||||
import com.tencentcloudapi.common.profile.HttpProfile;
|
||||
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
|
||||
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
|
||||
import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;
|
||||
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoRequest;
|
||||
import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoResponse;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class TxApis {
|
||||
public String accessKeyId = "";
|
||||
public String accessKeySecret = "";
|
||||
public static String ruleId = "1";
|
||||
|
||||
public TxApis(String accessKeyId, String accessKeySecret) {
|
||||
this.accessKeyId = accessKeyId;
|
||||
this.accessKeySecret = accessKeySecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* https://cloud.tencent.com/document/product/1007/31816
|
||||
* @param ruleId
|
||||
* @return
|
||||
*/
|
||||
public DetectAuthResponse detectAuth(String ruleId) {
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
||||
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
||||
Credential cred = new Credential(accessKeyId, accessKeySecret);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("faceid.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
DetectAuthRequest req = new DetectAuthRequest();
|
||||
req.setRuleId(ruleId);
|
||||
try {
|
||||
// 返回的resp是一个DetectAuthResponse的实例,与请求对象对应
|
||||
DetectAuthResponse resp = client.DetectAuth(req);
|
||||
|
||||
return resp;
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new SysTipsException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public GetDetectInfoResponse getDetectInfo(String ruleId, String bizToken) {
|
||||
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey,此处还需注意密钥对的保密
|
||||
// 密钥可前往https://console.cloud.tencent.com/cam/capi网站进行获取
|
||||
Credential cred = new Credential(accessKeyId, accessKeySecret);
|
||||
// 实例化一个http选项,可选的,没有特殊需求可以跳过
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setEndpoint("faceid.tencentcloudapi.com");
|
||||
// 实例化一个client选项,可选的,没有特殊需求可以跳过
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||
FaceidClient client = new FaceidClient(cred, "", clientProfile);
|
||||
// 实例化一个请求对象,每个接口都会对应一个request对象
|
||||
GetDetectInfoRequest req = new GetDetectInfoRequest();
|
||||
req.setBizToken(bizToken);
|
||||
req.setRuleId(ruleId);
|
||||
|
||||
try {
|
||||
// 返回的resp是一个GetDetectInfoResponse的实例,与请求对象对应
|
||||
GetDetectInfoResponse resp = client.GetDetectInfo(req);
|
||||
return resp;
|
||||
} catch (TencentCloudSDKException e) {
|
||||
throw new SysTipsException(e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static TxApis of() {
|
||||
// return new TxApis("AKIDmOmvpUu51h9LI0TggS5TcV9YjfQyGJ7g", "MVSBfutd8NOAi03qSpxpSqzsWw72iBPN");
|
||||
return new TxApis("AKIDswxo3GIG42oeNyslUzIOIwMYbefbfYGn", "l0CAxVqxoQ0d5ZJvLYYM2Wp0znOvKVVT");
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TxApis apis = of();
|
||||
DetectAuthResponse detectAuth = apis.detectAuth(ruleId);
|
||||
System.out.println(JSON.toJSONString(detectAuth));
|
||||
|
||||
// String bizToken = "97404E85-2E9A-4E2D-9853-A912561CD2B0";
|
||||
// GetDetectInfoResponse response = TxApis.of().getDetectInfo(TxApis.ruleId, bizToken);
|
||||
// JSONObject text = Jsons.getByPath(response.getDetectInfo(), "Text", JSONObject.class);
|
||||
//
|
||||
// System.out.println(text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
package cn.stock.market.infrastructure.api.qq;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import com.ag.utils.JsonUtils;
|
||||
import com.ag.utils.Jsons;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ag.utils.NumberUtils;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.qutaojing.common.utils.BigDecimals;
|
||||
import cn.stock.market.domain.basic.entity.Stock;
|
||||
import cn.stock.market.infrastructure.api.sina.SinaStockApi;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.SinaStockMinData;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO;
|
||||
import cn.stock.market.utils.HttpClientRequest;
|
||||
import cn.stock.market.utils.PropertiesUtil;
|
||||
import cn.stock.market.utils.ServerResponse;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
public class QqStockApi {
|
||||
private static final Logger log = LoggerFactory.getLogger(SinaStockApi.class);
|
||||
|
||||
public static ServerResponse<MinDataVO> getGpStockDayK(Stock stock) {
|
||||
String minUrl = PropertiesUtil.getProperty("qq.k.min.url");
|
||||
minUrl = minUrl.replace("code",stock.getStockGid());
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = HttpClientRequest.doGet(minUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info(" qq-code = {} ", stock.getStockGid());
|
||||
if (StringUtils.isBlank(hqstr)) {
|
||||
return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
}
|
||||
String qqstr = hqstr.split("=")[1].replace("\";","").replace("\\n\\",",").replace("\n","").replace("\"","");
|
||||
String[] liststr = qqstr.split(",");
|
||||
List<SinaStockMinData> list = new ArrayList<>();
|
||||
for (int i = 1; i<liststr.length; i++){
|
||||
String[] dayarry = liststr[i].split(" ");
|
||||
SinaStockMinData model = new SinaStockMinData();
|
||||
model.setDay("20"+dayarry[0].substring(0,2)+"-"+dayarry[0].substring(2,4)+"-"+dayarry[0].substring(4,6));
|
||||
model.setOpen(dayarry[1]);
|
||||
model.setHigh(dayarry[3]);
|
||||
model.setLow(dayarry[4]);
|
||||
model.setClose(dayarry[2]);
|
||||
model.setMa_price(new BigDecimal("0").doubleValue());
|
||||
model.setMa_volume(dayarry[5]);
|
||||
model.setVolume(dayarry[5]);
|
||||
list.add(model);
|
||||
}
|
||||
int size = Integer.valueOf(PropertiesUtil.getProperty("qq.k.min.max.size"));
|
||||
if(list.size()>size){
|
||||
list = list.subList((list.size()-size-1),list.size());
|
||||
}
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
minDataVO.setStockName(stock.getStockName());
|
||||
minDataVO.setStockCode(stock.getStockCode());
|
||||
minDataVO.setGid(stock.getStockGid());
|
||||
minDataVO.setData(list);
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
// public static ServerResponse<MinDataVO> getQqStockDayK(StockFutures stock) {
|
||||
// String minUrl = PropertiesUtil.getProperty("sina.futures.day.min.url");
|
||||
// minUrl = minUrl.replace("{code}",stock.getFuturesCode());
|
||||
// SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd");//设置日期格式
|
||||
// minUrl = minUrl.replace("{date}",df.format(new Date()));
|
||||
//
|
||||
//
|
||||
// String hqstr = "";
|
||||
// try {
|
||||
// hqstr = HttpClientRequest.doGet(minUrl);
|
||||
// } catch (Exception e) {
|
||||
// log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
// }
|
||||
//
|
||||
// log.info(" 期货日线-code = {} ", stock.getFuturesGid());
|
||||
// if (StringUtils.isBlank(hqstr)) {
|
||||
// return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
// }
|
||||
// hqstr = hqstr.split("\\(")[1].replace(");","");
|
||||
// hqstr = hqstr.replaceAll("date","day");
|
||||
// hqstr = hqstr.replaceAll("\"\"", "\"");
|
||||
//
|
||||
// List<SinaStockMinData> list = (List<SinaStockMinData>) JsonUtil.string2Obj(hqstr, new TypeReference<List<SinaStockMinData>>(){});
|
||||
// int size = Integer.valueOf(PropertiesUtil.getProperty("sina.futures.day.min.max.size"));
|
||||
// if(list.size()>size){
|
||||
// list = list.subList((list.size()-size-1),list.size());
|
||||
// }
|
||||
//
|
||||
// MinDataVO minDataVO = new MinDataVO();
|
||||
// minDataVO.setStockName(stock.getFuturesName());
|
||||
// minDataVO.setStockCode(stock.getFuturesCode());
|
||||
// minDataVO.setGid(stock.getFuturesGid());
|
||||
// minDataVO.setData(list);
|
||||
// return ServerResponse.createBySuccess(minDataVO);
|
||||
// }
|
||||
//
|
||||
/*指数日线*/
|
||||
public static ServerResponse<MinDataVO> getQqIndexDayK(String stock, String type) {
|
||||
String minUrl = PropertiesUtil.getProperty("sina.index.day.min.url");
|
||||
minUrl = minUrl.replace("{code}",stock);
|
||||
minUrl = minUrl.replace("day",type);
|
||||
SimpleDateFormat df = new SimpleDateFormat("yyyy_MM_dd");//设置日期格式
|
||||
minUrl = minUrl.replace("{date}",df.format(new Date()));
|
||||
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = HttpClientRequest.doGet(minUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info(" 指数日线-code = {} ", stock);
|
||||
if (StringUtils.isBlank(hqstr)) {
|
||||
return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
}
|
||||
hqstr = hqstr.split(":\\[\\[")[1];
|
||||
hqstr = hqstr.split("]]")[0].replace("],[",";");
|
||||
String[] liststr = hqstr.split(";");
|
||||
List<SinaStockMinData> list = new ArrayList<>();
|
||||
for (int i = 1; i<liststr.length; i++){
|
||||
String[] dayarry = liststr[i].split(",");
|
||||
SinaStockMinData model = new SinaStockMinData();
|
||||
model.setDay(filterCode(dayarry[0]));
|
||||
model.setOpen(filterCode(dayarry[1]));
|
||||
model.setHigh(filterCode(dayarry[3]));
|
||||
model.setLow(filterCode(dayarry[4]));
|
||||
model.setClose(filterCode(dayarry[2]));
|
||||
model.setMa_price(new BigDecimal("0").doubleValue());
|
||||
model.setMa_volume(filterCode(dayarry[5].split("\\.")[0]));
|
||||
model.setVolume(filterCode(dayarry[5].split("\\.")[0]));
|
||||
list.add(model);
|
||||
}
|
||||
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
// minDataVO.setStockName(stock.getIndexName());
|
||||
// minDataVO.setStockCode(stock.getIndexCode());
|
||||
minDataVO.setGid(stock);
|
||||
minDataVO.setData(list);
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
/*指数分时-k线
|
||||
* stock:指数代码
|
||||
* time:5、15、30、60,单位分钟
|
||||
* */
|
||||
public static ServerResponse<MinDataVO> getIndexMinK(String stock, int time, int size) {
|
||||
String minUrl = PropertiesUtil.getProperty("sina.index.k.min.url").replace("{code}", stock).replace("{time}",String.valueOf(time));
|
||||
String stamp = String.valueOf(new Date().getTime());// new Date()为获取当前系统时间
|
||||
minUrl = minUrl.replace("{stamp}",stamp);
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = HttpClientRequest.doGet(minUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info("期货分时 - time = {} ", time);
|
||||
|
||||
hqstr = hqstr.split("\\[")[1].replace("]);","");
|
||||
|
||||
if (StringUtils.isBlank(hqstr)) {
|
||||
return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
}
|
||||
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
// minDataVO.setStockName(stock.getIndexName());
|
||||
minDataVO.setStockCode(stock);
|
||||
// minDataVO.setGid(stock.getIndexGid());
|
||||
|
||||
hqstr = hqstr.replaceAll("\"\"", "\"");
|
||||
hqstr = "[" + hqstr + "]";
|
||||
|
||||
List<SinaStockMinData> list = Jsons.toList(hqstr,SinaStockMinData.class);
|
||||
if(list.size()>size){
|
||||
list = list.subList((list.size()-size-1),list.size());
|
||||
}
|
||||
minDataVO.setData(list);
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用java正则表达式去掉多余的.与0
|
||||
* @param s
|
||||
* @return
|
||||
*/
|
||||
public static String subZeroAndDot(String s){
|
||||
BigDecimal value = new BigDecimal(s);
|
||||
BigDecimal noZeros = value.stripTrailingZeros();
|
||||
String result = noZeros.toPlainString();
|
||||
return result;
|
||||
}
|
||||
|
||||
private static String filterCode(String str) {
|
||||
return str.replace("\"","");
|
||||
}
|
||||
|
||||
/*股票月线、周线
|
||||
* type:month=月,week=周, day=天
|
||||
* */
|
||||
public static ServerResponse<MinDataVO> getGpStockMonthK(Stock stock,String type) {
|
||||
String minUrl = PropertiesUtil.getProperty("qq.month.min.url");
|
||||
minUrl = minUrl.replace("sz300750",stock.getStockGid());
|
||||
minUrl = minUrl.replace("month",type);
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = HttpClientRequest.doGet(minUrl);
|
||||
// hqstr = hqstr.replace("qfqday","day");
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info("{} type:{}, 返回信息:{}", stock.getStockCode(), type, hqstr);
|
||||
|
||||
String typeKey = "";
|
||||
/**
|
||||
* 备用Key
|
||||
*/
|
||||
String typeKeyBak = "";
|
||||
if("day".equalsIgnoreCase(type)) {
|
||||
typeKey = "qfqday";
|
||||
typeKeyBak = "day";
|
||||
} else if("week".equalsIgnoreCase(type)) {
|
||||
typeKeyBak = "week";
|
||||
typeKey = "qfqweek";
|
||||
} else if("month".equalsIgnoreCase(type)) {
|
||||
typeKeyBak = "month";
|
||||
typeKey = "qfqmonth";
|
||||
}
|
||||
|
||||
log.info(" qq-code = {} ", stock.getStockGid());
|
||||
if (StringUtils.isBlank(hqstr)) {
|
||||
return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
}
|
||||
//String qqstr = hqstr.split("=")[1];
|
||||
JSONObject json = JSONObject.fromObject(hqstr);
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
JSONObject listjson = data.getJSONObject(stock.getStockGid());
|
||||
|
||||
JSONArray jsonArray = null;
|
||||
if(listjson.has(typeKey)) {
|
||||
jsonArray = listjson.getJSONArray(typeKey);
|
||||
} else {
|
||||
jsonArray = listjson.getJSONArray(typeKeyBak);
|
||||
}
|
||||
|
||||
List<SinaStockMinData> list = new ArrayList<>();
|
||||
for (int i = 0; i<jsonArray.size(); i++){
|
||||
String string = jsonArray.getString(i).replace("\"","").replace("[","").replace("]","");
|
||||
String[] dayarry = string.split(",");
|
||||
SinaStockMinData model = new SinaStockMinData();
|
||||
model.setDay(dayarry[0]);
|
||||
model.setOpen(dayarry[1]);
|
||||
model.setHigh(dayarry[3]);
|
||||
model.setLow(dayarry[4]);
|
||||
model.setClose(dayarry[2]);
|
||||
model.setMa_price(new BigDecimal("0").doubleValue());
|
||||
model.setMa_volume(dayarry[5]);
|
||||
model.setVolume(dayarry[5]);
|
||||
list.add(model);
|
||||
}
|
||||
|
||||
// if(list.size()>50){
|
||||
// list = list.subList((list.size()-50),list.size());
|
||||
// }
|
||||
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
minDataVO.setStockName(stock.getStockName());
|
||||
minDataVO.setStockCode(stock.getStockCode());
|
||||
minDataVO.setGid(stock.getStockGid());
|
||||
minDataVO.setData(list);
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
/*股票月线、周线
|
||||
* type:month=月,week=周, day=天
|
||||
* */
|
||||
public static ServerResponse<MinDataVO> getBjsStockMonthK(Stock stock,String type) {
|
||||
String minUrl = PropertiesUtil.getProperty("eastmoney.month.url");
|
||||
minUrl = minUrl.replace("0.833429","0."+stock.getStockCode());
|
||||
minUrl = minUrl.replace("_=1699356882499","_"+System.currentTimeMillis());
|
||||
String klt = "101";
|
||||
if ("week".equals(type)){
|
||||
klt = "102";
|
||||
} else if ("month".equals(type)) {
|
||||
klt = "103";
|
||||
}
|
||||
minUrl = minUrl.replace("klt=102","klt="+klt);
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = HttpClientRequest.doGet(minUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info("{} type:{}, 返回信息:{}", stock.getStockCode(), type, hqstr);
|
||||
hqstr = hqstr.replace("jQuery3510019847947565290847_1699356882415(","");
|
||||
hqstr = hqstr.substring(0,hqstr.length()-2);
|
||||
JSONObject json = JSONObject.fromObject(hqstr);
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
JSONArray jsonArray = data.getJSONArray("klines");
|
||||
|
||||
List<SinaStockMinData> list = new ArrayList<>();
|
||||
for (int i = 0; i<jsonArray.size(); i++){
|
||||
String[] dayarry = jsonArray.getString(i).split(",");
|
||||
SinaStockMinData model = new SinaStockMinData();
|
||||
model.setDay(dayarry[0]);
|
||||
model.setOpen(dayarry[1]);
|
||||
model.setHigh(dayarry[3]);
|
||||
model.setLow(dayarry[4]);
|
||||
model.setClose(dayarry[2]);
|
||||
model.setMa_price(new BigDecimal("0").doubleValue());
|
||||
model.setMa_volume(dayarry[5]);
|
||||
model.setVolume(dayarry[5]);
|
||||
list.add(model);
|
||||
}
|
||||
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
minDataVO.setStockName(stock.getStockName());
|
||||
minDataVO.setStockCode(stock.getStockCode());
|
||||
minDataVO.setGid(stock.getStockGid());
|
||||
minDataVO.setData(list);
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上涨下跌家数统计
|
||||
*
|
||||
* 返回格式 {
|
||||
* v_bkqtRank_A_sz: [],
|
||||
* v_bkqtRank_A_xxx: [],
|
||||
* }
|
||||
* @return
|
||||
*/
|
||||
public static com.alibaba.fastjson.JSONObject bkqtRank() {
|
||||
//v_bkqtRank_A_sh="Rank_A_sh~Rank_A_sh~963~95~1160~2218~116.214~1.516~1.322~2137789642~39584245~sh688313~sh688359"; v_bkqtRank_A_sz="Rank_A_sz~Rank_A_sz~1148~139~1500~2787~49.187~0.354~0.725~417728700~58428584~sz301287~sz300842";
|
||||
String url = "https://qt.gtimg.cn/?q=bkqtRank_A_sh,bkqtRank_A_sz,&_=1686713338950";
|
||||
String response = HttpUtil.get(url);
|
||||
|
||||
String[] split = StringUtils.split(StringUtils.replace(response, "\n", ""), ";");
|
||||
|
||||
com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
|
||||
for (String string : split) {
|
||||
if(StringUtils.isEmpty(string)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String[] split2 = StringUtils.split(string, "=");
|
||||
if(split2.length != 2) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String key = split2[0];
|
||||
String field[] = StringUtils.split(StringUtils.substring(split2[1], 1, split2[1].length() - 1), "~");
|
||||
|
||||
int zhang = NumberUtils.parseInt(field[2]);
|
||||
int ping = NumberUtils.parseInt(field[3]);
|
||||
int die = NumberUtils.parseInt(field[4]);
|
||||
|
||||
int total = zhang + ping + die;
|
||||
|
||||
double zhangRate = BigDecimals.divide(zhang, total).setScale(2, RoundingMode.HALF_UP).doubleValue();
|
||||
double pingRate = BigDecimals.divide(ping, total).setScale(2, RoundingMode.HALF_UP).doubleValue();;
|
||||
double dieRate = BigDecimals.divide(die, total).setScale(2, RoundingMode.HALF_UP).doubleValue();;
|
||||
|
||||
|
||||
com.alibaba.fastjson.JSONObject item = new com.alibaba.fastjson.JSONObject();
|
||||
item.put("zhang", zhang);
|
||||
item.put("ping", ping);
|
||||
item.put("die", die);
|
||||
item.put("zhangRate", zhangRate);
|
||||
item.put("pingRate", pingRate);
|
||||
item.put("dieRate", dieRate);
|
||||
json.put(key, item);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,503 @@
|
||||
package cn.stock.market.infrastructure.api.sina;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.ag.exception.SysTipsException;
|
||||
import com.ag.utils.Jsons;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.stock.market.domain.basic.entity.Stock;
|
||||
import cn.stock.market.dto.model.StockListVO;
|
||||
import cn.stock.market.dto.model.StockVO;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.SinaStockMinData;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.k.MinDataVO;
|
||||
import cn.stock.market.infrastructure.api.sina.vo.k.echarts.EchartsDataVO;
|
||||
import cn.stock.market.utils.HttpClientRequest;
|
||||
import cn.stock.market.utils.PropertiesUtil;
|
||||
import cn.stock.market.utils.ServerResponse;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
|
||||
|
||||
public class SinaStockApi {
|
||||
// public static final String sina_url = PropertiesUtil.getProperty("sina.single.stock.url");
|
||||
private static final Logger log = LoggerFactory.getLogger(SinaStockApi.class);
|
||||
|
||||
static String get(String url) {
|
||||
return HttpClientRequest.doGet(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* 涨跌幅
|
||||
* @param asc 0-涨, 1-跌
|
||||
* @param pageNum
|
||||
* @param pageSize
|
||||
*/
|
||||
public static List<JSONObject> getHQNodeData(int asc, int pageNum, int pageSize) {
|
||||
String url = String.format("https://vip.stock.finance.sina.com.cn/quotes_service/api/json_v2.php/Market_Center.getHQNodeData?page=%s&num=%s&sort=changepercent&asc=%s&node=hs_a&symbol=&_s_r_a=setlen", pageNum, pageSize, asc);
|
||||
String reponse = "";
|
||||
try {
|
||||
reponse = get(url);
|
||||
JSONArray array = JSON.parseArray(reponse);
|
||||
//过滤bj开头
|
||||
return Lists.transform(array, item -> (JSONObject) item)
|
||||
.stream()
|
||||
// .filter(j -> ! StringUtils.startsWith(j.getString("symbol"), "bj"))
|
||||
.collect(Collectors.toList())
|
||||
;
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票行情出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
|
||||
public static String getRawSinaStock(String stockGid) {
|
||||
String sina_url = PropertiesUtil.getProperty("sina.single.stock.url");
|
||||
String sina_result = "";
|
||||
try {
|
||||
sina_result = get(sina_url + stockGid);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票行情出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
return sina_result;
|
||||
}
|
||||
|
||||
public static String getSinaStock(String stockGid) {
|
||||
String sina_result = getRawSinaStock(stockGid);
|
||||
|
||||
if(! StringUtils.contains(sina_result, "=")) {
|
||||
log.error("{}获取行情失败: {}", stockGid, sina_result);
|
||||
throw new SysTipsException("获取行情失败:" + stockGid);
|
||||
}
|
||||
return sina_result.substring(sina_result.indexOf("=") + 2);
|
||||
}
|
||||
|
||||
|
||||
public static StockListVO assembleStockListVO(String sinaResult) {
|
||||
StockListVO stockListVO = new StockListVO();
|
||||
|
||||
String[] hqarr = sinaResult.split(",");
|
||||
|
||||
if (hqarr.length > 1) {
|
||||
|
||||
stockListVO.setName(hqarr[0]);
|
||||
|
||||
stockListVO.setNowPrice(hqarr[3]);
|
||||
|
||||
BigDecimal chang_rate = new BigDecimal("0");
|
||||
if ((new BigDecimal(hqarr[2])).compareTo(new BigDecimal("0")) != 0 && new BigDecimal(hqarr[3]).compareTo(new BigDecimal("0")) != 0) {
|
||||
|
||||
chang_rate = (new BigDecimal(hqarr[3])).subtract(new BigDecimal(hqarr[2]));
|
||||
|
||||
chang_rate = chang_rate.multiply(new BigDecimal("100")).divide(new BigDecimal(hqarr[2]), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
stockListVO.setHcrate(chang_rate);
|
||||
|
||||
stockListVO.setToday_max(hqarr[4]);
|
||||
|
||||
stockListVO.setToday_min(hqarr[5]);
|
||||
|
||||
stockListVO.setBusiness_amount(hqarr[8]);
|
||||
|
||||
stockListVO.setBusiness_balance(hqarr[9]);
|
||||
|
||||
stockListVO.setPreclose_px(hqarr[2]);
|
||||
|
||||
stockListVO.setOpen_px(hqarr[1]);
|
||||
}
|
||||
|
||||
return stockListVO;
|
||||
}
|
||||
|
||||
public static StockVO assembleStockVO(String sinaResult, Stock stock) {
|
||||
if(stock == null) {
|
||||
return null;
|
||||
}
|
||||
StockVO stockVO = SinaStockApi.assembleStockVO(SinaStockApi.getSinaStock(stock.getStockGid()));
|
||||
stockVO.setId(stock.getId().intValue());
|
||||
stockVO.setCode(stock.getStockCode());
|
||||
stockVO.setSpell(stock.getStockSpell());
|
||||
stockVO.setGid(stock.getStockGid());
|
||||
return stockVO;
|
||||
}
|
||||
public static StockVO assembleStockVO(String sinaResult) {
|
||||
StockVO stockVO = new StockVO();
|
||||
|
||||
String[] hqarr = sinaResult.split(",");
|
||||
|
||||
stockVO.setName(hqarr[0]);
|
||||
|
||||
stockVO.setNowPrice(hqarr[3]);
|
||||
|
||||
BigDecimal chang_rate = new BigDecimal("0");
|
||||
if ((new BigDecimal(hqarr[2])).compareTo(new BigDecimal("0")) != 0 && new BigDecimal(hqarr[3]).compareTo(new BigDecimal("0")) != 0) {
|
||||
|
||||
chang_rate = (new BigDecimal(hqarr[3])).subtract(new BigDecimal(hqarr[2]));
|
||||
|
||||
chang_rate = chang_rate.multiply(new BigDecimal("100")).divide(new BigDecimal(hqarr[2]), 2, RoundingMode.HALF_UP);
|
||||
}
|
||||
stockVO.setHcrate(chang_rate);
|
||||
|
||||
stockVO.setToday_max(hqarr[4]);
|
||||
|
||||
stockVO.setToday_min(hqarr[5]);
|
||||
|
||||
stockVO.setBusiness_amount(hqarr[8]);
|
||||
|
||||
stockVO.setBusiness_balance(hqarr[9]);
|
||||
|
||||
stockVO.setPreclose_px(hqarr[2]);
|
||||
|
||||
stockVO.setOpen_px(hqarr[1]);
|
||||
|
||||
stockVO.setBuy1(hqarr[6]);
|
||||
stockVO.setBuy2(hqarr[13]);
|
||||
stockVO.setBuy3(hqarr[15]);
|
||||
stockVO.setBuy4(hqarr[17]);
|
||||
stockVO.setBuy5(hqarr[19]);
|
||||
|
||||
stockVO.setSell1(hqarr[7]);
|
||||
stockVO.setSell2(hqarr[23]);
|
||||
stockVO.setSell3(hqarr[25]);
|
||||
stockVO.setSell4(hqarr[27]);
|
||||
stockVO.setSell5(hqarr[29]);
|
||||
|
||||
stockVO.setBuy1_num(hqarr[10]);
|
||||
stockVO.setBuy2_num(hqarr[12]);
|
||||
stockVO.setBuy3_num(hqarr[14]);
|
||||
stockVO.setBuy4_num(hqarr[16]);
|
||||
stockVO.setBuy5_num(hqarr[18]);
|
||||
|
||||
stockVO.setSell1_num(hqarr[20]);
|
||||
stockVO.setSell2_num(hqarr[22]);
|
||||
stockVO.setSell3_num(hqarr[24]);
|
||||
stockVO.setSell4_num(hqarr[26]);
|
||||
stockVO.setSell5_num(hqarr[28]);
|
||||
|
||||
return stockVO;
|
||||
}
|
||||
|
||||
/*期货详情转换*/
|
||||
public static StockVO assembleStockFuturesVO(String sinaResult) {
|
||||
StockVO stockVO = new StockVO();
|
||||
|
||||
String[] hqarr = sinaResult.split(",");
|
||||
//伦敦金格式不正确,特殊处理
|
||||
if(hqarr.length<=14){
|
||||
String sinaResulttemp = sinaResult.replace("\"",",1\"");
|
||||
hqarr = sinaResulttemp.split(",");
|
||||
}
|
||||
stockVO.setName(hqarr[13]);
|
||||
|
||||
stockVO.setNowPrice(hqarr[0]);
|
||||
|
||||
BigDecimal rates = new BigDecimal("0");
|
||||
BigDecimal b1 = new BigDecimal(hqarr[3].toString());
|
||||
BigDecimal b2 = new BigDecimal(hqarr[2].toString());
|
||||
BigDecimal b3 = b1.subtract(b2);
|
||||
String s = hqarr[14].toString();
|
||||
int index = s.indexOf("\"");
|
||||
String substring = s.substring(0, index);
|
||||
rates = b3.multiply(new BigDecimal("100")).divide(b1,2,BigDecimal.ROUND_HALF_UP);
|
||||
stockVO.setHcrate(rates);
|
||||
|
||||
stockVO.setToday_max(hqarr[7]);
|
||||
|
||||
stockVO.setToday_min(hqarr[8]);
|
||||
|
||||
stockVO.setBusiness_amount(substring);
|
||||
|
||||
stockVO.setBusiness_balance(hqarr[9]);
|
||||
|
||||
stockVO.setPreclose_px(hqarr[11]);
|
||||
|
||||
stockVO.setOpen_px(hqarr[10]);
|
||||
|
||||
stockVO.setBuy1(hqarr[2]);
|
||||
stockVO.setBuy2("0");
|
||||
stockVO.setBuy3("0");
|
||||
stockVO.setBuy4("0");
|
||||
stockVO.setBuy5("0");
|
||||
|
||||
stockVO.setSell1(hqarr[3]);
|
||||
stockVO.setSell2("0");
|
||||
stockVO.setSell3("0");
|
||||
stockVO.setSell4("0");
|
||||
stockVO.setSell5("0");
|
||||
|
||||
stockVO.setBuy1_num(hqarr[10]);
|
||||
stockVO.setBuy2_num("0");
|
||||
stockVO.setBuy3_num("0");
|
||||
stockVO.setBuy4_num("0");
|
||||
stockVO.setBuy5_num("0");
|
||||
|
||||
stockVO.setSell1_num(hqarr[11]);
|
||||
stockVO.setSell2_num("0");
|
||||
stockVO.setSell3_num("0");
|
||||
stockVO.setSell4_num("0");
|
||||
stockVO.setSell5_num("0");
|
||||
|
||||
return stockVO;
|
||||
}
|
||||
|
||||
|
||||
public static ServerResponse<MinDataVO> getStockMinK(Stock stock, int time, int ma, int size) {
|
||||
int maxSize = Integer.parseInt(PropertiesUtil.getProperty("sina.k.min.max.size"));
|
||||
if (size > maxSize) {
|
||||
size = maxSize;
|
||||
}
|
||||
|
||||
String minUrl = PropertiesUtil.getProperty("sina.k.min.url");
|
||||
minUrl = minUrl + "?symbol=" + stock.getStockGid() + "&scale=" + time + "&ma=" + ma + "&datalen=" + size;
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = get(minUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info(" time = {} ma = {} size = {}", new Object[]{Integer.valueOf(time), Integer.valueOf(ma), Integer.valueOf(size)});
|
||||
|
||||
|
||||
hqstr = hqstr.replace("day", "\"day\"").replace("open", "\"open\"").replace("high", "\"high\"").replace("low", "\"low\"").replace("close", "\"close\"");
|
||||
|
||||
if (ma == 5) {
|
||||
|
||||
hqstr = hqstr.replace("ma_volume5", "\"ma_volume\"").replace(",volume", ",\"volume\"").replace("ma_price5", "\"ma_price\"");
|
||||
} else if (ma == 10) {
|
||||
|
||||
|
||||
hqstr = hqstr.replace("ma_volume10", "\"ma_volume\"").replace(",volume", ",\"volume\"").replace("ma_price10", "\"ma_price\"");
|
||||
} else if (ma == 15) {
|
||||
|
||||
hqstr = hqstr.replace("ma_volume15", "\"ma_volume\"").replace(",volume", ",\"volume\"").replace("ma_price15", "\"ma_price\"");
|
||||
} else {
|
||||
return ServerResponse.createByErrorMsg("ma 取值 5,10,15");
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.isBlank(hqstr)) {
|
||||
return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
}
|
||||
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
minDataVO.setStockName(stock.getStockName());
|
||||
minDataVO.setStockCode(stock.getStockCode());
|
||||
minDataVO.setGid(stock.getStockGid());
|
||||
|
||||
hqstr = hqstr.replaceAll("\"\"", "\"");
|
||||
|
||||
List<SinaStockMinData> list = Jsons.toList(hqstr, SinaStockMinData.class);
|
||||
log.info("需要查询的行情size为: {}", Integer.valueOf(size));
|
||||
|
||||
minDataVO.setData(list);
|
||||
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
|
||||
public static ServerResponse getKLine(String code) {
|
||||
String url = null;
|
||||
switch (code) {
|
||||
case "399006":
|
||||
//创业板分时接口
|
||||
url = "http://push2delay.eastmoney.com/api/qt/stock/trends2/get?secid=0.399006&fields1=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13&fields2=f51,f52,f53,f54,f55,f56,f57,f58&ut=e1e6871893c6386c5ff6967026016627&iscr=0&cb=cb_1688350355026_68094768&isqhquote=&cb_1688350355026_68094768=cb_1688350355026_68094768";
|
||||
break;
|
||||
case "399001":
|
||||
//深证指数分时接口
|
||||
url = "http://push2.eastmoney.com/api/qt/stock/trends2/get?secid=0.399001&fields1=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13&fields2=f51,f52,f53,f54,f55,f56,f57,f58&ut=e1e6871893c6386c5ff6967026016627&iscr=0&cb=cb_1688350355026_56868727&isqhquote=&cb_1688350355026_56868727=cb_1688350355026_56868727";
|
||||
break;
|
||||
case "000001":
|
||||
//上证指数分时接口
|
||||
url = "http://push2.eastmoney.com/api/qt/stock/trends2/get?secid=1.000001&fields1=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13&fields2=f51,f52,f53,f54,f55,f56,f57,f58&ut=e1e6871893c6386c5ff6967026016627&iscr=0&cb=cb_1688350355023_98652553&isqhquote=&cb_1688350355023_98652553=cb_1688350355023_98652553";
|
||||
break;
|
||||
default:
|
||||
//不支持
|
||||
return ServerResponse.createByErrorMsg("不支持的股票代码");
|
||||
}
|
||||
String reponse = get(url);
|
||||
//cb_1688350355023_98652553({ json )} 转换为json
|
||||
reponse = reponse.substring(reponse.indexOf("(") + 1, reponse.lastIndexOf(")"));
|
||||
return ServerResponse.createBySuccess(JSONObject.parseObject(reponse));
|
||||
}
|
||||
|
||||
public static EchartsDataVO assembleEchartsDataVO(MinDataVO minDataVO) {
|
||||
EchartsDataVO echartsDataVO = new EchartsDataVO();
|
||||
echartsDataVO.setStockName(minDataVO.getStockName());
|
||||
echartsDataVO.setStockCode(minDataVO.getStockCode());
|
||||
|
||||
List<SinaStockMinData> minDataList = minDataVO.getData();
|
||||
|
||||
|
||||
double[][] values = (double[][]) null;
|
||||
Object[][] volumes = (Object[][]) null;
|
||||
String[] date = null;
|
||||
|
||||
if (minDataList.size() > 0) {
|
||||
|
||||
values = new double[minDataList.size()][5];
|
||||
|
||||
volumes = new Object[minDataList.size()][3];
|
||||
|
||||
date = new String[minDataList.size()];
|
||||
|
||||
for (int i = 0; i < minDataList.size(); i++) {
|
||||
SinaStockMinData sinaStockMinData = (SinaStockMinData) minDataList.get(i);
|
||||
|
||||
for (int j = 0; j < values[i].length; j++) {
|
||||
values[i][0] = Double.valueOf(sinaStockMinData.getOpen()).doubleValue();
|
||||
values[i][1] = Double.valueOf(sinaStockMinData.getClose()).doubleValue();
|
||||
values[i][2] = Double.valueOf(sinaStockMinData.getLow()).doubleValue();
|
||||
values[i][3] = Double.valueOf(sinaStockMinData.getHigh()).doubleValue();
|
||||
values[i][4] = Double.valueOf(sinaStockMinData.getVolume()).doubleValue();
|
||||
}
|
||||
for (int k = 0; k < volumes[i].length; k++) {
|
||||
volumes[i][0] = Integer.valueOf(i);
|
||||
volumes[i][1] = Double.valueOf(sinaStockMinData.getVolume());
|
||||
|
||||
if ((new BigDecimal(sinaStockMinData.getClose()))
|
||||
.compareTo(new BigDecimal(sinaStockMinData.getOpen())) == 1) {
|
||||
volumes[i][2] = Integer.valueOf(1);
|
||||
} else {
|
||||
volumes[i][2] = Integer.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
date[i] = sinaStockMinData.getDay();
|
||||
}
|
||||
}
|
||||
|
||||
echartsDataVO.setValues(values);
|
||||
echartsDataVO.setVolumes(volumes);
|
||||
echartsDataVO.setDate(date);
|
||||
|
||||
return echartsDataVO;
|
||||
}
|
||||
|
||||
/*股票日线*/
|
||||
public static ServerResponse<MinDataVO> getStockDayK(Stock stock, int time, int ma, int size) {
|
||||
int maxSize = Integer.parseInt(PropertiesUtil.getProperty("sina.k.min.max.size"));
|
||||
if (size > maxSize) {
|
||||
size = maxSize;
|
||||
}
|
||||
|
||||
String minUrl = PropertiesUtil.getProperty("sina.k.min.url");
|
||||
minUrl = minUrl + "?symbol=" + stock.getStockGid() + "&scale=" + time + "&ma=" + ma + "&datalen=" + size;
|
||||
|
||||
String hqstr = "";
|
||||
try {
|
||||
hqstr = get(minUrl);
|
||||
} catch (Exception e) {
|
||||
log.error("获取股票K线分时图出错,错误信息 = {}", e);
|
||||
}
|
||||
|
||||
log.info(" time = {} ma = {} size = {}", new Object[]{Integer.valueOf(time), Integer.valueOf(ma), Integer.valueOf(size)});
|
||||
|
||||
|
||||
hqstr = hqstr.replace("day", "\"day\"").replace("open", "\"open\"").replace("high", "\"high\"").replace("low", "\"low\"").replace("close", "\"close\"");
|
||||
|
||||
if (ma == 5) {
|
||||
|
||||
hqstr = hqstr.replace("ma_volume5", "\"ma_volume\"").replace(",volume", ",\"volume\"").replace("ma_price5", "\"ma_price\"");
|
||||
} else if (ma == 10) {
|
||||
|
||||
|
||||
hqstr = hqstr.replace("ma_volume10", "\"ma_volume\"").replace(",volume", ",\"volume\"").replace("ma_price10", "\"ma_price\"");
|
||||
} else if (ma == 15) {
|
||||
|
||||
hqstr = hqstr.replace("ma_volume15", "\"ma_volume\"").replace(",volume", ",\"volume\"").replace("ma_price15", "\"ma_price\"");
|
||||
} else {
|
||||
return ServerResponse.createByErrorMsg("ma 取值 5,10,15");
|
||||
}
|
||||
|
||||
|
||||
if (StringUtils.isBlank(hqstr)) {
|
||||
return ServerResponse.createByErrorMsg("没有查询到行情数据");
|
||||
}
|
||||
|
||||
MinDataVO minDataVO = new MinDataVO();
|
||||
minDataVO.setStockName(stock.getStockName());
|
||||
minDataVO.setStockCode(stock.getStockCode());
|
||||
minDataVO.setGid(stock.getStockGid());
|
||||
|
||||
hqstr = hqstr.replaceAll("\"\"", "\"");
|
||||
|
||||
List<SinaStockMinData> list = Jsons.toList(hqstr, SinaStockMinData.class);
|
||||
log.info("需要查询的行情size为: {}", Integer.valueOf(size));
|
||||
|
||||
minDataVO.setData(list);
|
||||
|
||||
return ServerResponse.createBySuccess(minDataVO);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
// List list = Lists.newArrayList();
|
||||
// list.add(Integer.valueOf(1));
|
||||
// list.add(Integer.valueOf(2));
|
||||
// list.add(Integer.valueOf(3));
|
||||
// System.out.println(list.size());
|
||||
//
|
||||
// String[][] values = new String[list.size()][5];
|
||||
//
|
||||
// System.out.println("[]" + values.length);
|
||||
// System.out.println("[][]" + values[1].length);
|
||||
//
|
||||
// System.out.println(getSinaStock("sh601318"));
|
||||
//
|
||||
// String sss = "[\n{\n\"day\": \"2019-03-05 14:50:00\",\n\"open\": \"13.020\",\n\"high\": \"13.040\",\n\"low\": \"13.000\",\n\"close\": \"13.040\",\n\"volume\": \"2611513\",\n\"ma_price5\": 13.01,\n\"ma_volume5\": 3216535\n},\n{\n\"day\": \"2019-03-05 14:55:00\",\n\"open\": \"13.040\",\n\"high\": \"13.040\",\n\"low\": \"13.010\",\n\"close\": \"13.030\",\n\"volume\": \"2296000\",\n\"ma_price5\": 13.016,\n\"ma_volume5\": 3044839\n}\n]";
|
||||
//
|
||||
// sss = sss.substring(1, sss.length() - 1);
|
||||
//
|
||||
// sss = "{" + sss + "}";
|
||||
// String sinaStock = getSinaStock("s_sh600090");
|
||||
// System.out.println(sinaStock);
|
||||
|
||||
// Request request = new Request.Builder()
|
||||
// .url("https://hq.sinajs.cn/list=s_sh600090")
|
||||
// .build();
|
||||
|
||||
// Response response = new OkHttpClient().newCall(request).execute();
|
||||
// System.out.println(response.body().string());
|
||||
// System.out.println(get("https://hq.sinajs.cn/list=s_sh600090"));
|
||||
// System.out.println(get2("https://hq.sinajs.cn/list=s_sh600090"));
|
||||
// System.out.println(get("https://toolkit-server.rplees.com/info"));
|
||||
// System.out.println(get2("https://toolkit-server.rplees.com/info"));
|
||||
// String uuu = "http://hq.sinajs.cn/list=s_sh600090";
|
||||
String body = HttpUtil
|
||||
.createGet("http://hq.sinajs.cn/list=s_sh600090")
|
||||
.header("Referer", "http://finance.sina.com.cn")
|
||||
.execute()
|
||||
.body();
|
||||
System.out.println(body);
|
||||
////
|
||||
// OkHttpClient client = new OkHttpClient();//创建OkHttpClient对象
|
||||
// Request request = new Request.Builder()
|
||||
// .url("http://hq.sinajs.cn/list=s_sh600090")//请求接口。如果需要传参拼接到接口后面。
|
||||
// .addHeader("Referer", "http://finance.sina.com.cn")
|
||||
// .build();//创建Request 对象
|
||||
//
|
||||
// String string = client.newCall(request).execute().body().string();
|
||||
//
|
||||
// System.out.println(string);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package cn.stock.market.infrastructure.api.sina.vo;
|
||||
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
@ApiModel("热搜股票信息")
|
||||
public class HotSearchVO {
|
||||
|
||||
@ApiModelProperty("股票名称")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("股票简码")
|
||||
private String code;
|
||||
|
||||
@ApiModelProperty("股票代码")
|
||||
private String symbol;
|
||||
|
||||
@ApiModelProperty("权重")
|
||||
private Integer weight;
|
||||
|
||||
public HotSearchVO() {
|
||||
}
|
||||
|
||||
public HotSearchVO(String name, String code,String symbol,Integer weight) {
|
||||
this.name = name;
|
||||
this.code = code;
|
||||
this.symbol = symbol;
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getSymbol() {
|
||||
return symbol;
|
||||
}
|
||||
|
||||
public void setSymbol(String symbol) {
|
||||
this.symbol = symbol;
|
||||
}
|
||||
|
||||
public Integer getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(Integer weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
package cn.stock.market.infrastructure.api.sina.vo;
|
||||
|
||||
|
||||
public class MarketVO {
|
||||
|
||||
private String name;
|
||||
|
||||
private String nowPrice;
|
||||
|
||||
private String increaseRate;
|
||||
|
||||
private String increase;
|
||||
|
||||
private String maxHigh;
|
||||
|
||||
private String minLow;
|
||||
|
||||
private String openPrice;
|
||||
|
||||
private String closePrice;
|
||||
|
||||
private String turnOver;
|
||||
|
||||
private String turnNum;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setNowPrice(String nowPrice) {
|
||||
this.nowPrice = nowPrice;
|
||||
}
|
||||
|
||||
public void setIncreaseRate(String increaseRate) {
|
||||
this.increaseRate = increaseRate;
|
||||
}
|
||||
|
||||
public void setIncrease(String increase) {
|
||||
this.increase = increase;
|
||||
}
|
||||
|
||||
public void setMaxHigh(String maxHigh) {
|
||||
this.maxHigh = maxHigh;
|
||||
}
|
||||
|
||||
public void setMinLow(String minLow) {
|
||||
this.minLow = minLow;
|
||||
}
|
||||
|
||||
public void setOpenPrice(String openPrice) {
|
||||
this.openPrice = openPrice;
|
||||
}
|
||||
|
||||
public void setClosePrice(String closePrice) {
|
||||
this.closePrice = closePrice;
|
||||
}
|
||||
|
||||
public void setTurnOver(String turnOver) {
|
||||
this.turnOver = turnOver;
|
||||
}
|
||||
|
||||
public void setTurnNum(String turnNum) {
|
||||
this.turnNum = turnNum;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof MarketVO)) return false;
|
||||
MarketVO other = (MarketVO) o;
|
||||
if (!other.canEqual(this)) return false;
|
||||
Object this$name = getName(), other$name = other.getName();
|
||||
if ((this$name == null) ? (other$name != null) : !this$name.equals(other$name)) return false;
|
||||
Object this$nowPrice = getNowPrice(), other$nowPrice = other.getNowPrice();
|
||||
if ((this$nowPrice == null) ? (other$nowPrice != null) : !this$nowPrice.equals(other$nowPrice)) return false;
|
||||
Object this$increaseRate = getIncreaseRate(), other$increaseRate = other.getIncreaseRate();
|
||||
if ((this$increaseRate == null) ? (other$increaseRate != null) : !this$increaseRate.equals(other$increaseRate))
|
||||
return false;
|
||||
Object this$maxHigh= getMaxHigh(), other$maxHigh = other.getMaxHigh();
|
||||
if ((this$maxHigh == null) ? (other$maxHigh != null) : !this$maxHigh.equals(other$maxHigh))
|
||||
return false;
|
||||
Object this$minLow = getMinLow(), other$minLow = other.getMinLow();
|
||||
if ((this$minLow == null) ? (other$minLow != null) : !this$minLow.equals(other$minLow))
|
||||
return false;
|
||||
Object this$openPrice = getOpenPrice(), other$openPrice = other.getOpenPrice();
|
||||
if ((this$openPrice == null) ? (other$openPrice != null) : !this$openPrice.equals(other$openPrice))
|
||||
return false;
|
||||
Object this$closePrice = getClosePrice(), other$closePrice = other.getClosePrice();
|
||||
if ((this$closePrice == null) ? (other$closePrice != null) : !this$closePrice.equals(other$closePrice))
|
||||
return false;
|
||||
Object this$turnOver = getTurnOver(), other$turnOver = other.getTurnOver();
|
||||
if ((this$turnOver == null) ? (other$turnOver != null) : !this$turnOver.equals(other$turnOver))
|
||||
return false;
|
||||
Object this$turnNum = getTurnNum(), other$turnNum= other.getTurnNum();
|
||||
if ((this$turnNum == null) ? (other$turnNum != null) : !this$turnNum.equals(other$turnNum))
|
||||
return false;
|
||||
Object this$increase = getIncrease(), other$increase = other.getIncrease();
|
||||
return !((this$increase == null) ? (other$increase != null) : !this$increase.equals(other$increase));
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof MarketVO;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 59;
|
||||
int result = 1;
|
||||
Object $name = getName();
|
||||
result = result * 59 + (($name == null) ? 43 : $name.hashCode());
|
||||
Object $nowPrice = getNowPrice();
|
||||
result = result * 59 + (($nowPrice == null) ? 43 : $nowPrice.hashCode());
|
||||
Object $increaseRate = getIncreaseRate();
|
||||
result = result * 59 + (($increaseRate == null) ? 43 : $increaseRate.hashCode());
|
||||
Object $maxHigh = getMaxHigh();
|
||||
result = result * 59 + (($maxHigh == null) ? 43 : $maxHigh.hashCode());
|
||||
Object $minLow = getMinLow();
|
||||
result = result * 59 + (($minLow == null) ? 43 : $minLow.hashCode());
|
||||
Object $openPrice = getOpenPrice();
|
||||
result = result * 59 + (($openPrice == null) ? 43 : $openPrice.hashCode());
|
||||
Object $closePrice = getClosePrice();
|
||||
result = result * 59 + (($closePrice == null) ? 43 : $closePrice.hashCode());
|
||||
Object $turnOver = getTurnOver();
|
||||
result = result * 59 + (($turnOver == null) ? 43 : $turnOver.hashCode());
|
||||
Object $turnNum = getTurnNum();
|
||||
result = result * 59 + (($turnNum == null) ? 43 : $turnNum.hashCode());
|
||||
Object $increase = getIncrease();
|
||||
return result * 59 + (($increase == null) ? 43 : $increase.hashCode());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "MarketVO(name=" + getName() + ", nowPrice=" + getNowPrice() + ", increaseRate=" + getIncreaseRate() + ", increase=" + getIncrease() + ", maxHigh=" + getMaxHigh() +", minLow=" + getMinLow() +", openPrice=" + getOpenPrice() +", closePrice=" + getClosePrice() +", turnOver=" + getTurnOver() +", turnNum=" + getTurnNum() +")";
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
public String getNowPrice() {
|
||||
return this.nowPrice;
|
||||
}
|
||||
|
||||
|
||||
public String getIncreaseRate() {
|
||||
return this.increaseRate;
|
||||
}
|
||||
|
||||
|
||||
public String getIncrease() {
|
||||
return this.increase;
|
||||
}
|
||||
|
||||
public String getMaxHigh() {
|
||||
return this.maxHigh;
|
||||
}
|
||||
|
||||
public String getMinLow() {
|
||||
return this.minLow;
|
||||
}
|
||||
|
||||
public String getOpenPrice() {
|
||||
return this.openPrice;
|
||||
}
|
||||
|
||||
public String getClosePrice() {
|
||||
return this.closePrice;
|
||||
}
|
||||
|
||||
public String getTurnOver() {
|
||||
return this.turnOver;
|
||||
}
|
||||
|
||||
public String getTurnNum() {
|
||||
return this.turnNum;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package cn.stock.market.infrastructure.api.sina.vo;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class MarketVOResult {
|
||||
|
||||
List<MarketVO> market;
|
||||
|
||||
|
||||
public String toString() {
|
||||
return "MarketVOResult(market=" + getMarket() + ")";
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 59;
|
||||
int result = 1;
|
||||
Object $market = getMarket();
|
||||
return result * 59 + (($market == null) ? 43 : $market.hashCode());
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof MarketVOResult;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof MarketVOResult)) return false;
|
||||
MarketVOResult other = (MarketVOResult) o;
|
||||
if (!other.canEqual(this)) return false;
|
||||
Object this$market = getMarket(), other$market = other.getMarket();
|
||||
return !((this$market == null) ? (other$market != null) : !this$market.equals(other$market));
|
||||
}
|
||||
|
||||
public void setMarket(List<MarketVO> market) {
|
||||
this.market = market;
|
||||
}
|
||||
|
||||
|
||||
public List<MarketVO> getMarket() {
|
||||
return this.market;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
package cn.stock.market.infrastructure.api.sina.vo;
|
||||
|
||||
public class SinaStockMinData {
|
||||
private String day;
|
||||
private String open;
|
||||
private String high;
|
||||
private String low;
|
||||
private String close;
|
||||
private String volume;
|
||||
private double ma_price;
|
||||
private String ma_volume;
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof SinaStockMinData)) return false;
|
||||
SinaStockMinData other = (SinaStockMinData) o;
|
||||
if (!other.canEqual(this)) return false;
|
||||
Object this$day = getDay(), other$day = other.getDay();
|
||||
if ((this$day == null) ? (other$day != null) : !this$day.equals(other$day)) return false;
|
||||
Object this$open = getOpen(), other$open = other.getOpen();
|
||||
if ((this$open == null) ? (other$open != null) : !this$open.equals(other$open)) return false;
|
||||
Object this$high = getHigh(), other$high = other.getHigh();
|
||||
if ((this$high == null) ? (other$high != null) : !this$high.equals(other$high)) return false;
|
||||
Object this$low = getLow(), other$low = other.getLow();
|
||||
if ((this$low == null) ? (other$low != null) : !this$low.equals(other$low)) return false;
|
||||
Object this$close = getClose(), other$close = other.getClose();
|
||||
if ((this$close == null) ? (other$close != null) : !this$close.equals(other$close)) return false;
|
||||
Object this$volume = getVolume(), other$volume = other.getVolume();
|
||||
return ((this$volume == null) ? (other$volume != null) : !this$volume.equals(other$volume)) ? false : ((Double.compare(getMa_price(), other.getMa_price()) != 0) ? false : (!(getMa_volume() != other.getMa_volume())));
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof SinaStockMinData;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 59;
|
||||
int result = 1;
|
||||
Object $day = getDay();
|
||||
result = result * 59 + (($day == null) ? 43 : $day.hashCode());
|
||||
Object $open = getOpen();
|
||||
result = result * 59 + (($open == null) ? 43 : $open.hashCode());
|
||||
Object $high = getHigh();
|
||||
result = result * 59 + (($high == null) ? 43 : $high.hashCode());
|
||||
Object $low = getLow();
|
||||
result = result * 59 + (($low == null) ? 43 : $low.hashCode());
|
||||
Object $close = getClose();
|
||||
result = result * 59 + (($close == null) ? 43 : $close.hashCode());
|
||||
Object $volume = getVolume();
|
||||
result = result * 59 + (($volume == null) ? 43 : $volume.hashCode());
|
||||
long $ma_price = Double.doubleToLongBits(getMa_price());
|
||||
result = result * 59 + (int) ($ma_price >>> 32 ^ $ma_price);
|
||||
Object $ma_volume = getMa_volume();
|
||||
return result * 59 + (($ma_volume == null) ? 43 : $volume.hashCode());
|
||||
//return result * 59 + getMa_volume();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "SinaStockMinData(day=" + getDay() + ", open=" + getOpen() + ", high=" + getHigh() + ", low=" + getLow() + ", close=" + getClose() + ", volume=" + getVolume() + ", ma_price=" + getMa_price() + ", ma_volume=" + getMa_volume() + ")";
|
||||
}
|
||||
|
||||
public String getDay() {
|
||||
return this.day;
|
||||
}
|
||||
|
||||
public void setDay(String day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
public String getOpen() {
|
||||
return this.open;
|
||||
}
|
||||
|
||||
public void setOpen(String open) {
|
||||
this.open = open;
|
||||
}
|
||||
|
||||
public String getHigh() {
|
||||
return this.high;
|
||||
}
|
||||
|
||||
public void setHigh(String high) {
|
||||
this.high = high;
|
||||
}
|
||||
|
||||
public String getLow() {
|
||||
return this.low;
|
||||
}
|
||||
|
||||
public void setLow(String low) {
|
||||
this.low = low;
|
||||
}
|
||||
|
||||
public String getClose() {
|
||||
return this.close;
|
||||
}
|
||||
|
||||
public void setClose(String close) {
|
||||
this.close = close;
|
||||
}
|
||||
|
||||
public String getVolume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public void setVolume(String volume) {
|
||||
this.volume = volume;
|
||||
}
|
||||
|
||||
public double getMa_price() {
|
||||
return this.ma_price;
|
||||
}
|
||||
|
||||
public void setMa_price(double ma_price) {
|
||||
this.ma_price = ma_price;
|
||||
}
|
||||
|
||||
public String getMa_volume() {
|
||||
return this.ma_volume;
|
||||
}
|
||||
|
||||
public void setMa_volume(String ma_volume) {
|
||||
this.ma_volume = ma_volume;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package cn.stock.market.infrastructure.api.sina.vo.k;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import cn.stock.market.infrastructure.api.sina.vo.SinaStockMinData;
|
||||
|
||||
|
||||
public class MinDataVO {
|
||||
|
||||
private String stockName;
|
||||
|
||||
private String stockCode;
|
||||
|
||||
private String gid;
|
||||
|
||||
private List<SinaStockMinData> data;
|
||||
|
||||
|
||||
public void setStockName(String stockName) {
|
||||
this.stockName = stockName;
|
||||
}
|
||||
|
||||
public void setStockCode(String stockCode) {
|
||||
this.stockCode = stockCode;
|
||||
}
|
||||
|
||||
public void setGid(String gid) {
|
||||
this.gid = gid;
|
||||
}
|
||||
|
||||
public void setData(List<SinaStockMinData> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof MinDataVO)) return false;
|
||||
MinDataVO other = (MinDataVO) o;
|
||||
if (!other.canEqual(this)) return false;
|
||||
Object this$stockName = getStockName(), other$stockName = other.getStockName();
|
||||
if ((this$stockName == null) ? (other$stockName != null) : !this$stockName.equals(other$stockName))
|
||||
return false;
|
||||
Object this$stockCode = getStockCode(), other$stockCode = other.getStockCode();
|
||||
if ((this$stockCode == null) ? (other$stockCode != null) : !this$stockCode.equals(other$stockCode))
|
||||
return false;
|
||||
Object this$gid = getGid(), other$gid = other.getGid();
|
||||
if ((this$gid == null) ? (other$gid != null) : !this$gid.equals(other$gid)) return false;
|
||||
Object this$data = getData(), other$data = other.getData();
|
||||
return !((this$data == null) ? (other$data != null) : !this$data.equals(other$data));
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof MinDataVO;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 59;
|
||||
int result = 1;
|
||||
Object $stockName = getStockName();
|
||||
result = result * 59 + (($stockName == null) ? 43 : $stockName.hashCode());
|
||||
Object $stockCode = getStockCode();
|
||||
result = result * 59 + (($stockCode == null) ? 43 : $stockCode.hashCode());
|
||||
Object $gid = getGid();
|
||||
result = result * 59 + (($gid == null) ? 43 : $gid.hashCode());
|
||||
Object $data = getData();
|
||||
return result * 59 + (($data == null) ? 43 : $data.hashCode());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "MinDataVO(stockName=" + getStockName() + ", stockCode=" + getStockCode() + ", gid=" + getGid() + ", data=" + getData() + ")";
|
||||
}
|
||||
|
||||
|
||||
public String getStockName() {
|
||||
return this.stockName;
|
||||
}
|
||||
|
||||
|
||||
public String getStockCode() {
|
||||
return this.stockCode;
|
||||
}
|
||||
|
||||
|
||||
public String getGid() {
|
||||
return this.gid;
|
||||
}
|
||||
|
||||
|
||||
public List<SinaStockMinData> getData() {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.stock.market.infrastructure.api.sina.vo.k.echarts;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class EchartsDataVO {
|
||||
private String stockName;
|
||||
private String stockCode;
|
||||
private double[][] values;
|
||||
private Object[][] volumes;
|
||||
private String[] date;
|
||||
|
||||
public void setStockName(String stockName) {
|
||||
this.stockName = stockName;
|
||||
}
|
||||
|
||||
public void setStockCode(String stockCode) {
|
||||
this.stockCode = stockCode;
|
||||
}
|
||||
|
||||
public void setValues(double[][] values) {
|
||||
this.values = values;
|
||||
}
|
||||
|
||||
public void setVolumes(Object[][] volumes) {
|
||||
this.volumes = volumes;
|
||||
}
|
||||
|
||||
public void setDate(String[] date) {
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof EchartsDataVO)) return false;
|
||||
EchartsDataVO other = (EchartsDataVO) o;
|
||||
if (!other.canEqual(this)) return false;
|
||||
Object this$stockName = getStockName(), other$stockName = other.getStockName();
|
||||
if ((this$stockName == null) ? (other$stockName != null) : !this$stockName.equals(other$stockName))
|
||||
return false;
|
||||
Object this$stockCode = getStockCode(), other$stockCode = other.getStockCode();
|
||||
return ((this$stockCode == null) ? (other$stockCode != null) : !this$stockCode.equals(other$stockCode)) ? false : (!Arrays.deepEquals(getValues(), other.getValues()) ? false : (!Arrays.deepEquals(getVolumes(), other.getVolumes()) ? false : (!!Arrays.deepEquals(getDate(), other.getDate()))));
|
||||
}
|
||||
|
||||
protected boolean canEqual(Object other) {
|
||||
return other instanceof EchartsDataVO;
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
int PRIME = 59;
|
||||
int result = 1;
|
||||
Object $stockName = getStockName();
|
||||
result = result * 59 + (($stockName == null) ? 43 : $stockName.hashCode());
|
||||
Object $stockCode = getStockCode();
|
||||
result = result * 59 + (($stockCode == null) ? 43 : $stockCode.hashCode());
|
||||
result = result * 59 + Arrays.deepHashCode(getValues());
|
||||
result = result * 59 + Arrays.deepHashCode(getVolumes());
|
||||
return result * 59 + Arrays.deepHashCode(getDate());
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "EchartsDataVO(stockName=" + getStockName() + ", stockCode=" + getStockCode() + ", values=" + Arrays.deepToString(getValues()) + ", volumes=" + Arrays.deepToString(getVolumes()) + ", date=" + Arrays.deepToString(getDate()) + ")";
|
||||
}
|
||||
|
||||
|
||||
public String getStockName() {
|
||||
return this.stockName;
|
||||
}
|
||||
|
||||
|
||||
public String getStockCode() {
|
||||
return this.stockCode;
|
||||
}
|
||||
|
||||
|
||||
public double[][] getValues() {
|
||||
return this.values;
|
||||
}
|
||||
|
||||
public Object[][] getVolumes() {
|
||||
return this.volumes;
|
||||
}
|
||||
|
||||
public String[] getDate() {
|
||||
return this.date;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.stock.market.infrastructure.db;
|
||||
|
||||
public class DataSourceContextHolder {
|
||||
|
||||
private static final ThreadLocal<String> holder = new ThreadLocal<>();
|
||||
|
||||
public static void setDataSource(String type) {
|
||||
holder.set(type);
|
||||
}
|
||||
|
||||
public static String getDataSource() {
|
||||
String lookUpKey = holder.get();
|
||||
// return lookUpKey == null ? DatasourceConfig.STOCK_MARKET : lookUpKey;
|
||||
return lookUpKey;
|
||||
}
|
||||
|
||||
public static void clear() {
|
||||
holder.remove();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package cn.stock.market.infrastructure.db;
|
||||
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;
|
||||
|
||||
public class DynamicDataSourceRouter extends AbstractRoutingDataSource {
|
||||
@Override
|
||||
protected Object determineCurrentLookupKey() {
|
||||
return DataSourceContextHolder.getDataSource();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package cn.stock.market.infrastructure.db.config;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.web.servlet.ServletRegistrationBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.web.config.EnableSpringDataWebSupport;
|
||||
|
||||
import com.alibaba.druid.support.http.StatViewServlet;
|
||||
import com.rp.spring.jpa.FreemarkerSqlTemplates;
|
||||
|
||||
/**
|
||||
*
|
||||
* title: JpaConfig.java jpa通用配置
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @version 1.0
|
||||
* @created Jan 26, 2018 3:57:59 PM
|
||||
*/
|
||||
@Configuration
|
||||
@EnableSpringDataWebSupport
|
||||
public class JpaConfig {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public FreemarkerSqlTemplates freemarkerSqlTemplates() {
|
||||
FreemarkerSqlTemplates templates = new FreemarkerSqlTemplates();
|
||||
templates.setTemplateBasePackage("");
|
||||
templates.setSuffix(".sftl");
|
||||
return templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置监控服务器
|
||||
* @return 返回监控注册的servlet对象
|
||||
* @author SimpleWu
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Bean
|
||||
public ServletRegistrationBean statViewServlet() {
|
||||
ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
|
||||
// 添加IP白名单
|
||||
// servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
|
||||
// 添加IP黑名单,当白名单和黑名单重复时,黑名单优先级更高
|
||||
// servletRegistrationBean.addInitParameter("deny", "127.0.0.1");
|
||||
// 添加控制台管理用户
|
||||
// servletRegistrationBean.addInitParameter(ResourceServlet.PARAM_NAME_USERNAME, "admin");
|
||||
// servletRegistrationBean.addInitParameter(ResourceServlet.PARAM_NAME_PASSWORD, "admin");
|
||||
// 是否能够重置数据
|
||||
servletRegistrationBean.addInitParameter("resetEnable", "false");
|
||||
return servletRegistrationBean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置服务过滤器
|
||||
*
|
||||
* @return 返回过滤器配置对象
|
||||
*/
|
||||
// @Bean
|
||||
// public FilterRegistrationBean statFilter() {
|
||||
// FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
|
||||
// // 添加过滤规则
|
||||
// filterRegistrationBean.addUrlPatterns("/*");
|
||||
// // 忽略过滤格式
|
||||
// filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*,");
|
||||
// return filterRegistrationBean;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.stock.market.infrastructure.db.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
import com.rp.spring.jpa.GenericJpaRepositoryFactoryBean;
|
||||
import com.rp.spring.jpa.GenericJpaRepositoryImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* title: PlatformDatasourceConfig.java
|
||||
* 平台数据源设置
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @version 1.0
|
||||
* @created Jan 26, 2018 3:57:47 PM
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan({ "cn.stock.**.db.po", "com.stock.**.db.repo","cn.qutaojing.**.po", "cn.qutaojing.**.repo" })
|
||||
@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory",
|
||||
transactionManagerRef = "transactionManager",
|
||||
repositoryBaseClass = GenericJpaRepositoryImpl.class,
|
||||
repositoryFactoryBeanClass = GenericJpaRepositoryFactoryBean.class,
|
||||
basePackages = {
|
||||
"cn.qutaojing.ipay.infrastructure.db.po", "cn.qutaojing.ipay.infrastructure.db.repo",
|
||||
"cn.stock.trade.infrastructure.db.po", "cn.stock.trade.infrastructure.db.repo",
|
||||
"cn.stock.market.infrastructure.db.po", "cn.stock.market.infrastructure.db.repo"})
|
||||
public class MarketDatasourceConfig {
|
||||
@Autowired HibernateProperties hibernateProperties;
|
||||
|
||||
@Primary
|
||||
@Bean(name = "marketDataSource")
|
||||
@ConfigurationProperties(prefix="spring.datasource.stock-market")
|
||||
public DataSource stockMarketDataSource() {
|
||||
return DruidDataSourceBuilder.create().build();
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean(name = "marketJpaProperties")
|
||||
@ConfigurationProperties(prefix = "spring.jpa")
|
||||
public JpaProperties jpaProperties() {
|
||||
return new JpaProperties();
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean(name = {"marketEntityManagerFactory", "entityManagerFactory"})
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
|
||||
EntityManagerFactoryBuilder builder,
|
||||
@Qualifier("marketJpaProperties") JpaProperties jpaProperties,
|
||||
@Qualifier("marketDataSource") DataSource dataSource, Environment env) {
|
||||
Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
|
||||
|
||||
return builder
|
||||
.dataSource(dataSource)
|
||||
.properties(properties)
|
||||
.packages( "cn.stock.**.po","cn.qutaojing.**.po")
|
||||
.persistenceUnit("market")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Primary
|
||||
@Bean(name = {"marketTransactionManager", "transactionManager"})
|
||||
public PlatformTransactionManager transactionManager(@Qualifier("marketEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
|
||||
return new JpaTransactionManager(entityManagerFactory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* CityPO
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @created 2021/06/16
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "city")
|
||||
public class CityPO {
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
/**
|
||||
* 父级ID
|
||||
*/
|
||||
String parentId;
|
||||
|
||||
/**
|
||||
* 名称
|
||||
*/
|
||||
String name;
|
||||
|
||||
/**
|
||||
* 城市路径
|
||||
*/
|
||||
String path;
|
||||
|
||||
/**
|
||||
* 短名
|
||||
*/
|
||||
String shortName;
|
||||
|
||||
/**
|
||||
* 1省2市3区/县
|
||||
*/
|
||||
String levelType;
|
||||
|
||||
/**
|
||||
* 城市代码
|
||||
*/
|
||||
String cityCode;
|
||||
|
||||
/**
|
||||
* 邮编
|
||||
*/
|
||||
String zipCode;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
String longitude;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
String latitude;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
String remark;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
*
|
||||
* 计数器
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @version 1.0
|
||||
* @created Oct 15, 2020 10:37:50 AM
|
||||
*/
|
||||
@Data
|
||||
@SuperBuilder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "counter")
|
||||
public class Counter {
|
||||
@Id
|
||||
String k;
|
||||
String type;
|
||||
String fkId;
|
||||
Long count;
|
||||
@CreationTimestamp
|
||||
@Column(updatable = false)
|
||||
Date createTime;
|
||||
@UpdateTimestamp
|
||||
Date updateTime;
|
||||
}
|
||||
43
src/main/java/cn/stock/market/infrastructure/db/po/Dic.java
Normal file
43
src/main/java/cn/stock/market/infrastructure/db/po/Dic.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
*
|
||||
* title: DictionarySetting.java 动态键值对表
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @version 1.0
|
||||
* @created Oct 15, 2020 10:37:50 AM
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "dic")
|
||||
public class Dic {
|
||||
@Id
|
||||
String k;
|
||||
String val;
|
||||
@CreationTimestamp
|
||||
@Column(updatable = false)
|
||||
Date createTime;
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* JsonInfoPO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2022/08/16
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(
|
||||
name = "json_info"
|
||||
)
|
||||
public class JsonInfoPO {
|
||||
@Id
|
||||
@GeneratedValue(
|
||||
strategy = GenerationType.IDENTITY
|
||||
)
|
||||
Integer id;
|
||||
|
||||
String type;
|
||||
|
||||
String ext;
|
||||
|
||||
@CreationTimestamp
|
||||
@Column(
|
||||
updatable = false
|
||||
)
|
||||
Date createAt;
|
||||
|
||||
@UpdateTimestamp
|
||||
Date updateAt;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.lang.Double;
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* RealtimePO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "realtime")
|
||||
public class RealtimePO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
String time;
|
||||
|
||||
Integer volumes;
|
||||
|
||||
Double price;
|
||||
|
||||
Double rates;
|
||||
|
||||
Integer amounts;
|
||||
|
||||
String stockCode;
|
||||
|
||||
/**
|
||||
* 均价
|
||||
*/
|
||||
Double averagePrice;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
import java.util.Date;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* SiteArticlePO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "site_article")
|
||||
public class SiteArticlePO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
@ApiModelProperty("公告标题")
|
||||
String artTitle;
|
||||
|
||||
@ApiModelProperty("公告类型")
|
||||
String artType;
|
||||
|
||||
@ApiModelProperty("公告图片")
|
||||
String artImg;
|
||||
|
||||
@ApiModelProperty("公告作者")
|
||||
String author;
|
||||
|
||||
@ApiModelProperty("点击次数")
|
||||
Integer hitTimes;
|
||||
|
||||
@ApiModelProperty("是否展示")
|
||||
Integer isShow;
|
||||
|
||||
@ApiModelProperty("增加时间")
|
||||
Date addTime;
|
||||
|
||||
@ApiModelProperty("")
|
||||
String artSummary;
|
||||
|
||||
@ApiModelProperty("")
|
||||
String artCnt;
|
||||
|
||||
@ApiModelProperty("")
|
||||
String spiderUrl;
|
||||
|
||||
/**
|
||||
* 来源id
|
||||
*/
|
||||
@ApiModelProperty("来源id")
|
||||
String sourceId;
|
||||
|
||||
/**
|
||||
* 浏览量
|
||||
*/
|
||||
@ApiModelProperty("浏览量")
|
||||
Integer views;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* SiteNewsPO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/19
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(
|
||||
name = "site_news"
|
||||
)
|
||||
public class SiteNewsPO {
|
||||
/**
|
||||
* 新闻主键id */
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
/**
|
||||
* 新闻类型:1、财经要闻,2、经济数据,3、全球股市,4、7*24全球,5、商品资讯,6、上市公司,7、全球央行 */
|
||||
@ApiModelProperty("闻类型:1、财经要闻,2、经济数据,3、全球股市,4、7*24全球,5、商品资讯,6、上市公司,7、全球央行")
|
||||
Integer type;
|
||||
|
||||
/**
|
||||
* 新闻标题 */
|
||||
@ApiModelProperty("新闻标题")
|
||||
String title;
|
||||
|
||||
/**
|
||||
* 来源id */
|
||||
@ApiModelProperty("来源id")
|
||||
String sourceId;
|
||||
|
||||
/**
|
||||
* 来源名称 */
|
||||
@ApiModelProperty("来源名称")
|
||||
String sourceName;
|
||||
|
||||
/**
|
||||
* 浏览量 */
|
||||
@ApiModelProperty("浏览量")
|
||||
Integer views;
|
||||
|
||||
/**
|
||||
* 状态:1、启用,0、停用 */
|
||||
@ApiModelProperty("状态:1、启用,0、停用 ")
|
||||
Integer status;
|
||||
|
||||
/**
|
||||
* 显示时间 */
|
||||
@ApiModelProperty("显示时间")
|
||||
Date showTime;
|
||||
|
||||
/**
|
||||
* 添加时间 */
|
||||
@ApiModelProperty("添加时间")
|
||||
Date addTime;
|
||||
|
||||
/**
|
||||
* 修改时间 */
|
||||
@ApiModelProperty("修改时间")
|
||||
@UpdateTimestamp
|
||||
Date updateTime;
|
||||
|
||||
/**
|
||||
* 图片地址 */
|
||||
@ApiModelProperty("图片地址")
|
||||
String imgurl;
|
||||
|
||||
/**
|
||||
* 描述 */
|
||||
@ApiModelProperty("描述")
|
||||
String description;
|
||||
|
||||
/**
|
||||
* 新闻内容 */
|
||||
@ApiModelProperty("新闻内容")
|
||||
String content;
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package cn.stock.market.infrastructure.db.po;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
import java.util.Date;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.CreationTimestamp;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.hibernate.annotations.UpdateTimestamp;
|
||||
|
||||
/**
|
||||
* SysLogPO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2021/06/18
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "sys_log")
|
||||
public class SysLogPO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
/**
|
||||
* 模块
|
||||
*/
|
||||
String module;
|
||||
|
||||
/**
|
||||
* 动作类型
|
||||
*/
|
||||
String actionType;
|
||||
|
||||
/**
|
||||
* 操作角色
|
||||
*/
|
||||
String roleType;
|
||||
|
||||
Integer storeId;
|
||||
|
||||
String operatorId;
|
||||
|
||||
String operatorName;
|
||||
|
||||
String operatorPhone;
|
||||
|
||||
String uniqueId;
|
||||
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
String title;
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
String content;
|
||||
|
||||
/**
|
||||
* 扩展
|
||||
*/
|
||||
String ext;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@CreationTimestamp
|
||||
@Column(updatable = false)
|
||||
Date createAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@UpdateTimestamp
|
||||
Date updateAt;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.CityPO;
|
||||
|
||||
/**
|
||||
* CityRepo
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @created 2021/06/16
|
||||
*/
|
||||
public interface CityRepo extends GenericJpaRepository<CityPO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.Counter;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @version 1.0
|
||||
* @created Oct 15, 2020 10:46:45 AM
|
||||
*/
|
||||
public interface CounterRepo extends GenericJpaRepository<Counter, String> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.Dic;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author xlfd
|
||||
* @email xlfd@gmail.com
|
||||
* @version 1.0
|
||||
* @created Oct 15, 2020 10:46:45 AM
|
||||
*/
|
||||
public interface DicRepo extends GenericJpaRepository<Dic, String> {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.JsonInfoPO;
|
||||
|
||||
import java.lang.Integer;
|
||||
|
||||
/**
|
||||
* JsonInfoRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2022/08/16
|
||||
*/
|
||||
public interface JsonInfoRepo extends GenericJpaRepository<JsonInfoPO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
import com.rp.spring.jpa.TemplateQuery;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.RealtimePO;
|
||||
|
||||
/**
|
||||
* RealtimeRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
public interface RealtimeRepo extends GenericJpaRepository<RealtimePO, Integer> {
|
||||
/*删除股票*/
|
||||
@Modifying
|
||||
@TemplateQuery
|
||||
void deleteStockCode();
|
||||
|
||||
/*删除期货*/
|
||||
@Modifying
|
||||
@TemplateQuery
|
||||
void deleteStockFuturesCode();
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.SiteArticlePO;
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
import java.lang.Integer;
|
||||
|
||||
/**
|
||||
* SiteArticleRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
public interface SiteArticleRepo extends GenericJpaRepository<SiteArticlePO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.SiteNewsPO;
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
import java.lang.Integer;
|
||||
|
||||
/**
|
||||
* SiteNewsRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/19
|
||||
*/
|
||||
public interface SiteNewsRepo extends GenericJpaRepository<SiteNewsPO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.db.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.db.po.SysLogPO;
|
||||
|
||||
/**
|
||||
* SysLogRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2021/06/18
|
||||
*/
|
||||
public interface SysLogRepo extends GenericJpaRepository<SysLogPO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.stock.market.infrastructure.job;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
|
||||
import cn.qutaojing.common.utils.MdcUtil;
|
||||
import cn.stock.market.domain.basic.service.SiteArticleService;
|
||||
import cn.stock.market.domain.basic.service.SiteNewsService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class JobBoot {
|
||||
/**
|
||||
* cronExpression表达式定义:
|
||||
字段 允许值 允许的特殊字符
|
||||
秒 0-59 , - * /
|
||||
分 0-59 , - * /
|
||||
小时 0-23 , - * /
|
||||
日期 1-31 , - * ? / L W C
|
||||
月份 1-12 或者 JAN-DEC , - * /
|
||||
星期 1-7 或者 SUN-SAT , - * ? / L C #
|
||||
年(可选) 留空, 1970-2099 , - * /
|
||||
|
||||
https://blog.csdn.net/ClementAD/article/details/42042111
|
||||
*/
|
||||
// @Scheduled(cron="0 0/1 * * * ? ")
|
||||
@Scheduled(cron="0/30 * * * * ? ")
|
||||
public void batchStockTrust() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
// log.info("batchStockTrust执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
@Scheduled(cron="0/30 * * * * ? ")
|
||||
public void batchStockPosition() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
// log.info("batchStockPosition执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
/*
|
||||
* 新闻资讯抓取
|
||||
* */
|
||||
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
||||
public void artInfoTask() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
int count = SiteArticleService.of().grabArticle();
|
||||
log.info("artInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
/*
|
||||
* 新闻资讯抓取
|
||||
* */
|
||||
@Scheduled(cron = "0 0/30 9-20 * * ?")
|
||||
public void newsInfoTask() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
int count = SiteNewsService.of().grabNews();
|
||||
log.info("newsInfoTask执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package cn.stock.market.infrastructure.job;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import cn.stock.market.infrastructure.db.repo.RealtimeRepo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class RealTimeTask {
|
||||
@Resource RealtimeRepo repo;
|
||||
|
||||
/*每天9点定时删除股票k线数据*/
|
||||
@Transactional
|
||||
@Scheduled(cron = "0 00 9 * * MON-FRI")
|
||||
public void deleteStockCode() {
|
||||
log.info("每天9点定时删除股票k线数据");
|
||||
repo.deleteStockCode();
|
||||
}
|
||||
|
||||
/*每天0点定时删除期货k线数据*/
|
||||
@Transactional
|
||||
@Scheduled(cron = "0 00 0 * * MON-FRI")
|
||||
public void deleteStockFuturesCode() {
|
||||
log.info("每天0点定时删除期货k线数据");
|
||||
repo.deleteStockFuturesCode();
|
||||
}
|
||||
}
|
||||
342
src/main/java/cn/stock/market/infrastructure/job/StockTask.java
Normal file
342
src/main/java/cn/stock/market/infrastructure/job/StockTask.java
Normal file
@@ -0,0 +1,342 @@
|
||||
package cn.stock.market.infrastructure.job;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ag.utils.CollectionUtils;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import cn.qutaojing.common.PageInfo;
|
||||
import cn.qutaojing.common.utils.MdcUtil;
|
||||
import cn.qutaojing.common.utils.SpringUtils;
|
||||
import cn.stock.market.domain.basic.entity.Realtime;
|
||||
import cn.stock.market.domain.basic.entity.Stock;
|
||||
import cn.stock.market.domain.basic.repository.RealtimeRepository;
|
||||
import cn.stock.market.domain.basic.repository.StockRepository;
|
||||
import cn.stock.market.domain.basic.service.SiteArticleService;
|
||||
import cn.stock.market.infrastructure.api.AStockApis;
|
||||
import cn.stock.market.infrastructure.api.EastmoneyApi;
|
||||
import cn.stock.market.infrastructure.api.sina.SinaStockApi;
|
||||
import cn.stock.market.utils.Utils;
|
||||
import cn.stock.market.web.config.Config;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class StockTask {
|
||||
@Autowired RealtimeRepository realtimeRepository;
|
||||
@Autowired StockRepository stockRepository;
|
||||
ThreadPoolExecutor pool;
|
||||
|
||||
@PostConstruct
|
||||
public void initPool() {
|
||||
this.pool = new ThreadPoolExecutor(50, 70, 20L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(240));
|
||||
this.pool.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardOldestPolicy());
|
||||
}
|
||||
|
||||
/*股票走势图定时任务-15*/
|
||||
// @Scheduled(cron = "0 0/1 9-15 * * ?")
|
||||
public void z1() {
|
||||
// if(! Utils.isTradeTime()) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// MdcUtil.setTraceIdIfAbsent();
|
||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
// int count = SiteArticleService.of().grabArticle();
|
||||
//
|
||||
// List<Stock> list = stockRepository.findAll();
|
||||
// log.info("stockCodeSizes: {}", list.size());
|
||||
//
|
||||
// List<List<Stock>> partition = Lists.partition(list, 200);
|
||||
// for (List<Stock> itemList : partition) {
|
||||
// List<Realtime> realtimeList = Lists.newArrayList();
|
||||
// for (Stock stock : itemList) {
|
||||
// String stockGid = stock.getStockGid();
|
||||
// String sinaStock = SinaStockApi.getSinaStock("s_" + stockGid);
|
||||
//
|
||||
// try {
|
||||
// String[] split = sinaStock.split(",");
|
||||
// Double averagePrice = 0.0;
|
||||
//
|
||||
// Realtime realTime = new Realtime();
|
||||
// realTime.setPrice(Double.parseDouble(split[1].toString()));
|
||||
// realTime.setRates(Double.parseDouble(split[3].toString()));
|
||||
// SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
||||
// String time = sdf.format(new Date());
|
||||
// realTime.setTime(time);
|
||||
// realTime.setVolumes(Integer.parseInt(split[4].toString()));
|
||||
// String s = split[5].toString();
|
||||
// int index = s.indexOf("\"");
|
||||
// String substring = s.substring(0, index);
|
||||
// int amounts = Integer.parseInt(substring);
|
||||
// realTime.setAmounts(amounts);
|
||||
// realTime.setStockCode(stockGid);
|
||||
// realTime.setAveragePrice(averagePrice);
|
||||
//
|
||||
// realtimeList.add(realTime);
|
||||
// } catch(Exception e) {
|
||||
// log.error("解析出错, stockGid:{}, result: {}", stockGid, sinaStock);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// this.pool.submit(() -> {
|
||||
// realtimeRepository.saveAll(realtimeList);
|
||||
// });
|
||||
// }
|
||||
//
|
||||
// log.info("z1执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
/*同步股票列表*/
|
||||
@Scheduled(cron = "0 0 6 * * ?")
|
||||
public void syncAFutureStockList() {
|
||||
PageInfo<JSONObject> info = EastmoneyApi.ipoApplyDate(1, 300);
|
||||
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
List<Stock> list = Lists.newArrayList();
|
||||
for(JSONObject json : info.getItems()) {
|
||||
String code = json.getString("SECURITY_CODE");
|
||||
String name = json.getString("SECURITY_NAME");
|
||||
String jys = Utils.jys(code);
|
||||
if (stockMap.containsKey(code)) {
|
||||
log.info("已经存在 {} 信息, 跳过", code);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! Utils.isShOrSzOrBJ(code)) {
|
||||
log.info("{} 非 sh 或者 sz 或者 bj , 跳过", code);
|
||||
continue;
|
||||
}
|
||||
|
||||
Stock stock = new Stock();
|
||||
|
||||
stock.setStockName(name);
|
||||
stock.setStockCode(code);
|
||||
stock.setIsLock(0);
|
||||
stock.setIsShow(0);
|
||||
stock.setAddTime(new Date());
|
||||
stock.setStockState(0);
|
||||
|
||||
stock.setStockSpell(Utils.converterToFirstSpell(name));
|
||||
stock.setStockGid(jys + code);
|
||||
stock.setStockType(jys);
|
||||
list.add(stock);
|
||||
}
|
||||
if(CollectionUtils.isNotEmpty(list)) {
|
||||
StockRepository.of().saveAll(list);
|
||||
}
|
||||
int count = list.size();
|
||||
log.info("syncAFutureStockList执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
/*同步股票列表*/
|
||||
@Scheduled(cron = "0 0 6 * * ?")
|
||||
public void syncAStockList() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
Config config = SpringUtils.getBean(Config.class);
|
||||
List<JSONObject> gplist = new AStockApis().gplist(config.getIg507Licence());
|
||||
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
log.info("syncAStockList返回信息: {}", JSON.toJSONString(gplist));
|
||||
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||
List<Stock> list = Lists.newArrayList();
|
||||
for (JSONObject t : gplist) {
|
||||
String code = t.getString("dm");
|
||||
String mc = t.getString("mc");
|
||||
String jys = t.getString("jys");
|
||||
|
||||
if (stockMap.containsKey(code)) {
|
||||
Stock stock = stockMap.get(code);
|
||||
if(! StringUtils.equals(mc, stock.getStockName())) {
|
||||
stock.setStockName(mc);
|
||||
log.info("已经存在 {} 信息, 名称不一样, 订正: {}", code, JSON.toJSONString(stock));
|
||||
list.add(stock);
|
||||
} else {
|
||||
log.info("已经存在 {} 信息, 跳过", code);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(! Utils.isShOrSzOrBjByJys(jys)) {
|
||||
log.info("{} 非 sh 或者 sz , 跳过", code);
|
||||
continue;
|
||||
}
|
||||
|
||||
Stock stock = new Stock();
|
||||
|
||||
stock.setStockName(mc);
|
||||
stock.setStockCode(code);
|
||||
stock.setIsLock(0);
|
||||
stock.setIsShow(0);
|
||||
stock.setAddTime(new Date());
|
||||
stock.setStockState(0);
|
||||
|
||||
stock.setStockSpell(Utils.converterToFirstSpell(mc));
|
||||
stock.setStockGid(jys + code);
|
||||
stock.setStockType(jys);
|
||||
list.add(stock);
|
||||
}
|
||||
|
||||
if(CollectionUtils.isNotEmpty(list)) {
|
||||
StockRepository.of().saveAll(list);
|
||||
}
|
||||
int count = list.size();
|
||||
log.info("syncAStockList执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
|
||||
/*同步股票列表*/
|
||||
@Scheduled(cron = "0 5 6 * * ?")
|
||||
public void syncBjsStockList() {
|
||||
MdcUtil.setTraceIdIfAbsent();
|
||||
boolean flag = true;
|
||||
int count = 0;
|
||||
Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
int page = 1;
|
||||
do {
|
||||
List<JSONObject> gplist = new AStockApis().sinalist(page);
|
||||
if (gplist.isEmpty()){
|
||||
flag = false;
|
||||
continue;
|
||||
}
|
||||
page++;
|
||||
log.info("syncAStockList返回信息: {}", JSON.toJSONString(gplist));
|
||||
Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||
List<Stock> list = Lists.newArrayList();
|
||||
for (JSONObject t : gplist) {
|
||||
String code = t.getString("code");
|
||||
String mc = t.getString("name");
|
||||
String jys = t.getString("symbol");
|
||||
|
||||
if (stockMap.containsKey(code)) {
|
||||
Stock stock = stockMap.get(code);
|
||||
if(! StringUtils.equals(mc, stock.getStockName())) {
|
||||
stock.setStockName(mc);
|
||||
log.info("已经存在 {} 信息, 名称不一样, 订正: {}", code, JSON.toJSONString(stock));
|
||||
list.add(stock);
|
||||
} else {
|
||||
log.info("已经存在 {} 信息, 跳过", code);
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Stock stock = new Stock();
|
||||
|
||||
stock.setStockName(mc);
|
||||
stock.setStockCode(code);
|
||||
stock.setIsLock(0);
|
||||
stock.setIsShow(0);
|
||||
stock.setAddTime(new Date());
|
||||
stock.setStockState(0);
|
||||
|
||||
stock.setStockSpell(Utils.converterToFirstSpell(mc));
|
||||
stock.setStockGid(jys);
|
||||
stock.setStockType("bj");
|
||||
list.add(stock);
|
||||
}
|
||||
count+=list.size();
|
||||
if(CollectionUtils.isNotEmpty(list)) {
|
||||
StockRepository.of().saveAll(list);
|
||||
}
|
||||
}while(flag);
|
||||
log.info("syncBjsStockList执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
}
|
||||
// @Scheduled(cron = "0 0 6 * * ?")
|
||||
// public void syncAStockList() {
|
||||
// MdcUtil.setTraceIdIfAbsent();
|
||||
// int count = 0;
|
||||
//
|
||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
// String url = "http://api.waditu.com";
|
||||
// Map<String,Object> param = new HashMap<>();
|
||||
// param.put("api_name","stock_basic");
|
||||
// param.put("token","c30c5266b67ce2e0b93e12ddb18926150b777331e22568b07cabcca3");
|
||||
// param.put("fields","");
|
||||
//
|
||||
// String data = HttpUtil.createPost(url)
|
||||
// .body(JSON.toJSONString(param))
|
||||
// .header("Content-Type", "application/json")
|
||||
// .execute()
|
||||
// .body()
|
||||
// ;
|
||||
//
|
||||
// JSONObject json = Jsons.toJSONAnyway(data);
|
||||
// log.info("syncAStockList返回信息: {}", data);
|
||||
// if(NumberUtils.ne(json.getInteger("code"), 0)) {
|
||||
// log.info("返回错误码");
|
||||
// } else {
|
||||
// Map<String, Stock> stockMap = StockRepository.of().cacheCodeMap();
|
||||
// JSONArray items = json.getJSONObject("data").getJSONArray("items");
|
||||
// List<Stock> list = Lists.newArrayList();
|
||||
// for (Object t : items) {
|
||||
// List<String> arr = (List<String>) t;
|
||||
// String code = arr.get(1);
|
||||
// if (stockMap.containsKey(code)) {
|
||||
// log.info("已经存在 {} 信息, 跳过", code);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// Stock stock = new Stock();
|
||||
//
|
||||
// stock.setStockName(arr.get(2));
|
||||
// stock.setStockCode(arr.get(1));
|
||||
// stock.setStockName(arr.get(2));
|
||||
// stock.setIsLock(0);
|
||||
// stock.setIsShow(0);
|
||||
// stock.setAddTime(new Date());
|
||||
// stock.setStockState(0);
|
||||
//
|
||||
// stock.setStockSpell(Utils.converterToFirstSpell(arr.get(2)));
|
||||
// if ("主板".equals(arr.get(5)) || "创业板".equals(arr.get(5))) {
|
||||
// String strings = arr.get(0).substring(7, 9);
|
||||
// if ("SH".equals(strings)) {
|
||||
// stock.setStockGid("sh" + arr.get(1));
|
||||
// stock.setStockType("sh");
|
||||
// stock.setStockPlate("沪市");
|
||||
// } else if ("SZ".equals(strings)) {
|
||||
// stock.setStockGid("sz" + arr.get(1));
|
||||
// stock.setStockType("sz");
|
||||
// stock.setStockPlate("深市");
|
||||
// }
|
||||
// } else if ("创业板".equals(arr.get(5))) {
|
||||
// stock.setStockGid("sz" + arr.get(1));
|
||||
// stock.setStockType("sz");
|
||||
// stock.setStockPlate("创业板");
|
||||
// } else if ("科创板".equals(arr.get(5))) {
|
||||
// stock.setStockGid("sh" + arr.get(1));
|
||||
// stock.setStockType("sh");
|
||||
// stock.setStockPlate("科创板");
|
||||
// } else {
|
||||
// log.info("无法识别{} 信息, 跳过", code);
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// if(StringUtils.isNotBlank(stock.getStockType())) {
|
||||
// list.add(stock);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// StockRepository.of().saveAll(list);
|
||||
// count = list.size();
|
||||
// }
|
||||
//
|
||||
// log.info("syncAStockList执行, 受影响数{}, 耗时:{}毫秒", count, stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (C) 2018 Wanghaobin<463540703@qq.com>
|
||||
*
|
||||
* * AG-Enterprise 企业版源码
|
||||
* * 郑重声明:
|
||||
* * 如果你从其他途径获取到,请告知老A传播人,奖励1000。
|
||||
* * 老A将追究授予人和传播人的法律责任!
|
||||
*
|
||||
* * This program is free software; you can redistribute it and/or modify
|
||||
* * it under the terms of the GNU General Public License as published by
|
||||
* * the Free Software Foundation; either version 2 of the License, or
|
||||
* * (at your option) any later version.
|
||||
*
|
||||
* * This program is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* * GNU General Public License for more details.
|
||||
*
|
||||
* * You should have received a copy of the GNU General Public License along
|
||||
* * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package cn.stock.market.infrastructure.oss;
|
||||
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.aliyun.oss.OSSClient;
|
||||
import com.aliyun.oss.model.ObjectMetadata;
|
||||
|
||||
/**
|
||||
* 阿里云存储
|
||||
* @author ace
|
||||
*/
|
||||
public class AliyunCloudStorageService extends CloudStorageService {
|
||||
|
||||
private OSSClient client;
|
||||
|
||||
public AliyunCloudStorageService(CloudStorageConfig config) {
|
||||
this.config = config;
|
||||
|
||||
//初始化
|
||||
init();
|
||||
}
|
||||
|
||||
private void init(){
|
||||
client = new OSSClient(config.getAliyunEndPoint(), config.getAliyunAccessKeyId(),
|
||||
config.getAliyunAccessKeySecret());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(byte[] data, String path) {
|
||||
return upload(new ByteArrayInputStream(data), path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String upload(InputStream inputStream, String path) {
|
||||
try {
|
||||
|
||||
ObjectMetadata metadata = new ObjectMetadata();
|
||||
metadata.setContentDisposition("inline");
|
||||
metadata.setContentType(getContType(path));
|
||||
client.putObject(config.getAliyunBucketName(), path, inputStream,metadata);
|
||||
|
||||
} catch (Exception e){
|
||||
throw new RuntimeException("上传文件失败,请检查配置信息. " + e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
return config.getAliyunDomain() + "/" + path;
|
||||
}
|
||||
|
||||
|
||||
//通过文件名判断并获取OSS服务文件上传时文件的contentType 默认设置jpg格式
|
||||
public String getContType(String path) {
|
||||
int lastIndexOf = StringUtils.lastIndexOf(path, ".");
|
||||
if(lastIndexOf < 0) {
|
||||
return "image/jpeg";
|
||||
}
|
||||
String typeName = path.substring(lastIndexOf);
|
||||
if(StringUtils.isBlank(typeName)){
|
||||
return "image/jpeg";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".jpeg") ||
|
||||
typeName.equalsIgnoreCase(".jpg") ||
|
||||
typeName.equalsIgnoreCase(".png")) {
|
||||
return "image/jpeg";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".gif")) {
|
||||
return "image/gif";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".svg")) {
|
||||
return "image/svg";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".bmp")) {
|
||||
return "application/x-bmp";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".tif")) {
|
||||
return "image/tiff";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".pcx")) {
|
||||
return "image/pcx";
|
||||
}
|
||||
if (typeName.equalsIgnoreCase(".tga")) {
|
||||
return "image/tga";
|
||||
}
|
||||
if(typeName.equalsIgnoreCase(".mp4")){
|
||||
return "video/mpeg4";
|
||||
}
|
||||
return "image/jpeg";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String uploadSuffix(byte[] data, String suffix) {
|
||||
return upload(data, getPath(config.getAliyunPrefix(), suffix));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadSuffix(InputStream inputStream, String suffix) {
|
||||
return upload(inputStream, getPath(config.getAliyunPrefix(), suffix));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (C) 2018 Wanghaobin<463540703@qq.com>
|
||||
*
|
||||
* * AG-Enterprise 企业版源码
|
||||
* * 郑重声明:
|
||||
* * 如果你从其他途径获取到,请告知老A传播人,奖励1000。
|
||||
* * 老A将追究授予人和传播人的法律责任!
|
||||
*
|
||||
* * This program is free software; you can redistribute it and/or modify
|
||||
* * it under the terms of the GNU General Public License as published by
|
||||
* * the Free Software Foundation; either version 2 of the License, or
|
||||
* * (at your option) any later version.
|
||||
*
|
||||
* * This program is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* * GNU General Public License for more details.
|
||||
*
|
||||
* * You should have received a copy of the GNU General Public License along
|
||||
* * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package cn.stock.market.infrastructure.oss;
|
||||
|
||||
import java.io.Serializable;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 云存储配置信息
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "oss")
|
||||
public class CloudStorageConfig implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
//类型 1:七牛 2:阿里云 3:腾讯云
|
||||
private Integer type;
|
||||
|
||||
// //七牛绑定的域名
|
||||
// private String qiniuDomain;
|
||||
// //七牛路径前缀
|
||||
// private String qiniuPrefix;
|
||||
// //七牛ACCESS_KEY
|
||||
// private String qiniuAccessKey;
|
||||
// //七牛SECRET_KEY
|
||||
// private String qiniuSecretKey;
|
||||
// //七牛存储空间名
|
||||
// private String qiniuBucketName;
|
||||
|
||||
//阿里云绑定的域名
|
||||
private String aliyunDomain;
|
||||
//阿里云路径前缀
|
||||
private String aliyunPrefix;
|
||||
//阿里云EndPoint
|
||||
private String aliyunEndPoint;
|
||||
//阿里云AccessKeyId
|
||||
private String aliyunAccessKeyId;
|
||||
//阿里云AccessKeySecret
|
||||
private String aliyunAccessKeySecret;
|
||||
//阿里云BucketName
|
||||
private String aliyunBucketName;
|
||||
|
||||
//腾讯云绑定的域名
|
||||
// private String qcloudDomain;
|
||||
// //腾讯云路径前缀
|
||||
// private String qcloudPrefix;
|
||||
// //腾讯云AppId
|
||||
// private Integer qcloudAppId;
|
||||
// //腾讯云SecretId
|
||||
// private String qcloudSecretId;
|
||||
// //腾讯云SecretKey
|
||||
// private String qcloudSecretKey;
|
||||
// //腾讯云BucketName
|
||||
// private String qcloudBucketName;
|
||||
// //腾讯云COS所属地区
|
||||
// private String qcloudRegion;
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Integer type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getAliyunDomain() {
|
||||
return aliyunDomain;
|
||||
}
|
||||
|
||||
public void setAliyunDomain(String aliyunDomain) {
|
||||
this.aliyunDomain = aliyunDomain;
|
||||
}
|
||||
|
||||
public String getAliyunPrefix() {
|
||||
return aliyunPrefix;
|
||||
}
|
||||
|
||||
public void setAliyunPrefix(String aliyunPrefix) {
|
||||
this.aliyunPrefix = aliyunPrefix;
|
||||
}
|
||||
|
||||
public String getAliyunEndPoint() {
|
||||
return aliyunEndPoint;
|
||||
}
|
||||
|
||||
public void setAliyunEndPoint(String aliyunEndPoint) {
|
||||
this.aliyunEndPoint = aliyunEndPoint;
|
||||
}
|
||||
|
||||
public String getAliyunAccessKeyId() {
|
||||
return aliyunAccessKeyId;
|
||||
}
|
||||
|
||||
public void setAliyunAccessKeyId(String aliyunAccessKeyId) {
|
||||
this.aliyunAccessKeyId = aliyunAccessKeyId;
|
||||
}
|
||||
|
||||
public String getAliyunAccessKeySecret() {
|
||||
return aliyunAccessKeySecret;
|
||||
}
|
||||
|
||||
public void setAliyunAccessKeySecret(String aliyunAccessKeySecret) {
|
||||
this.aliyunAccessKeySecret = aliyunAccessKeySecret;
|
||||
}
|
||||
|
||||
public String getAliyunBucketName() {
|
||||
return aliyunBucketName;
|
||||
}
|
||||
|
||||
public void setAliyunBucketName(String aliyunBucketName) {
|
||||
this.aliyunBucketName = aliyunBucketName;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (C) 2018 Wanghaobin<463540703@qq.com>
|
||||
*
|
||||
* * AG-Enterprise 企业版源码
|
||||
* * 郑重声明:
|
||||
* * 如果你从其他途径获取到,请告知老A传播人,奖励1000。
|
||||
* * 老A将追究授予人和传播人的法律责任!
|
||||
*
|
||||
* * This program is free software; you can redistribute it and/or modify
|
||||
* * it under the terms of the GNU General Public License as published by
|
||||
* * the Free Software Foundation; either version 2 of the License, or
|
||||
* * (at your option) any later version.
|
||||
*
|
||||
* * This program is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* * GNU General Public License for more details.
|
||||
*
|
||||
* * You should have received a copy of the GNU General Public License along
|
||||
* * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package cn.stock.market.infrastructure.oss;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import com.ag.utils.DateUtils;
|
||||
import com.ag.utils.FileUtils;
|
||||
|
||||
/**
|
||||
* 云存储(支持七牛、阿里云、腾讯云、又拍云)
|
||||
*
|
||||
*/
|
||||
public abstract class CloudStorageService {
|
||||
|
||||
/** 云存储配置信息 */
|
||||
CloudStorageConfig config;
|
||||
|
||||
/**
|
||||
* 文件路径
|
||||
* @param rootPath 前缀
|
||||
* @param suffix 后缀
|
||||
* @return 返回上传路径
|
||||
*/
|
||||
public String getPath(String rootPath, String suffix) {
|
||||
// 生成uuid
|
||||
String path = DateUtils.nowDate("yyyyMMdd") + "/" + UUID.randomUUID().toString().replaceAll("-", "");
|
||||
// 文件路径
|
||||
if (StringUtils.isNotBlank(rootPath)) {
|
||||
path = FileUtils.splicePaths(rootPath, path);
|
||||
}
|
||||
|
||||
return path + "." +suffix;
|
||||
}
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param data 文件字节数组
|
||||
* @param path 文件路径,包含文件名
|
||||
* @return 返回http地址
|
||||
*/
|
||||
public abstract String upload(byte[] data, String path);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param data 文件字节数组
|
||||
* @param suffix 后缀
|
||||
* @return 返回http地址
|
||||
*/
|
||||
public abstract String uploadSuffix(byte[] data, String suffix);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param inputStream 字节流
|
||||
* @param path 文件路径,包含文件名
|
||||
* @return 返回http地址
|
||||
*/
|
||||
public abstract String upload(InputStream inputStream, String path);
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @param inputStream 字节流
|
||||
* @param suffix 后缀
|
||||
* @return 返回http地址
|
||||
*/
|
||||
public abstract String uploadSuffix(InputStream inputStream, String suffix);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (C) 2018 Wanghaobin<463540703@qq.com>
|
||||
*
|
||||
* * AG-Enterprise 企业版源码
|
||||
* * 郑重声明:
|
||||
* * 如果你从其他途径获取到,请告知老A传播人,奖励1000。
|
||||
* * 老A将追究授予人和传播人的法律责任!
|
||||
*
|
||||
* * This program is free software; you can redistribute it and/or modify
|
||||
* * it under the terms of the GNU General Public License as published by
|
||||
* * the Free Software Foundation; either version 2 of the License, or
|
||||
* * (at your option) any later version.
|
||||
*
|
||||
* * This program is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* * GNU General Public License for more details.
|
||||
*
|
||||
* * You should have received a copy of the GNU General Public License along
|
||||
* * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package cn.stock.market.infrastructure.oss;
|
||||
|
||||
/**
|
||||
* @author ace
|
||||
* @create 2018/3/4.
|
||||
*/
|
||||
public class OSSConstant {
|
||||
//类型 1:七牛 2:阿里云 3:腾讯云
|
||||
public final static Integer TYPE_QINIU = 1;
|
||||
public final static Integer TYPE_ALIYUN = 2;
|
||||
public final static Integer TYPE_QCLOUD = 3;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* * Copyright (C) 2018 Wanghaobin<463540703@qq.com>
|
||||
*
|
||||
* * AG-Enterprise 企业版源码
|
||||
* * 郑重声明:
|
||||
* * 如果你从其他途径获取到,请告知老A传播人,奖励1000。
|
||||
* * 老A将追究授予人和传播人的法律责任!
|
||||
*
|
||||
* * This program is free software; you can redistribute it and/or modify
|
||||
* * it under the terms of the GNU General Public License as published by
|
||||
* * the Free Software Foundation; either version 2 of the License, or
|
||||
* * (at your option) any later version.
|
||||
*
|
||||
* * This program is distributed in the hope that it will be useful,
|
||||
* * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* * GNU General Public License for more details.
|
||||
*
|
||||
* * You should have received a copy of the GNU General Public License along
|
||||
* * with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
package cn.stock.market.infrastructure.oss;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 文件上传Factory
|
||||
*
|
||||
* @author ace
|
||||
*/
|
||||
@Component
|
||||
public class OSSFactory {
|
||||
|
||||
@Autowired
|
||||
private CloudStorageConfig config;
|
||||
|
||||
public CloudStorageService build() {
|
||||
if (config.getType().equals(OSSConstant.TYPE_QINIU)) {
|
||||
// return new QiniuCloudStorageService(config);
|
||||
} else if (config.getType().equals(OSSConstant.TYPE_ALIYUN)) {
|
||||
return new AliyunCloudStorageService(config);
|
||||
} else if (config.getType().equals(OSSConstant.TYPE_QCLOUD)) {
|
||||
// return new QcloudCloudStorageService(config);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
//package cn.stock.market.infrastructure.redis;
|
||||
//
|
||||
//import java.time.LocalDateTime;
|
||||
//import java.time.format.DateTimeFormatter;
|
||||
//import java.util.Map;
|
||||
//import java.util.Map.Entry;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//
|
||||
//import org.redisson.api.RLock;
|
||||
//import org.redisson.api.RedissonClient;
|
||||
//
|
||||
//import com.google.common.base.Stopwatch;
|
||||
//import com.google.common.collect.Maps;
|
||||
//
|
||||
//import cn.qutaojing.common.aop.distributedlock.DistributedLockCallback;
|
||||
//import cn.qutaojing.common.aop.distributedlock.DistributedLockInfo;
|
||||
//import cn.qutaojing.common.aop.distributedlock.DistributedLockTemplate;
|
||||
//import lombok.extern.slf4j.Slf4j;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * title: SingleDistributedLockTemplate.java
|
||||
// *
|
||||
// * @author xlfd
|
||||
// * @email xlfd@gmail.com
|
||||
// * @version 1.0
|
||||
// * @created Sep 1, 2020 5:03:20 PM
|
||||
// */
|
||||
//@Slf4j
|
||||
//public class SingleDistributedLockTemplate implements DistributedLockTemplate {
|
||||
// private RedissonClient redisson;
|
||||
// DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSS");
|
||||
//
|
||||
// public SingleDistributedLockTemplate() {
|
||||
// }
|
||||
//
|
||||
// public SingleDistributedLockTemplate(RedissonClient redisson) {
|
||||
// this.redisson = redisson;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public <T> T lock(DistributedLockCallback<T> callback, DistributedLockInfo... lockInfoList) throws Throwable {
|
||||
// Stopwatch stopwatch = Stopwatch.createStarted();
|
||||
// Map<RLock, DistributedLockInfo> lockMap = Maps.newConcurrentMap();
|
||||
//
|
||||
// for (DistributedLockInfo info : lockInfoList) {
|
||||
// RLock lock = getLock(info.getLockName(), info.getFairLock());
|
||||
// lockMap.put(lock, info);
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// for (Entry<RLock, DistributedLockInfo> entry : lockMap.entrySet()) {
|
||||
// RLock lock = entry.getKey();
|
||||
// DistributedLockInfo info = entry.getValue();
|
||||
// log.info("{}-准备获取{}分布式锁:{}", dateTimeFormatter.format(LocalDateTime.now()), info.getMessage(), info.getLockName());
|
||||
// lock.lock(info.getLeaseTime(), info.getTimeUnit());
|
||||
// log.info("{}-{}分布式锁:{}获取成功, 耗时:{} ms", dateTimeFormatter.format(LocalDateTime.now()), info.getMessage(), info.getLockName(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
// }
|
||||
//
|
||||
// return callback.process();
|
||||
// } finally {
|
||||
// for (Entry<RLock, DistributedLockInfo> entry : lockMap.entrySet()) {
|
||||
// RLock lock = entry.getKey();
|
||||
// DistributedLockInfo info = entry.getValue();
|
||||
// if (lock != null && lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
// lock.unlock();
|
||||
// log.info("{}-{}分布式锁:{}释放成功, 耗时:{} ms", dateTimeFormatter.format(LocalDateTime.now()), info.getMessage(), info.getLockName(), stopwatch.elapsed(TimeUnit.MILLISECONDS));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// private RLock getLock(String lockName, boolean fairLock) {
|
||||
// RLock lock;
|
||||
// if (fairLock) {
|
||||
// lock = redisson.getFairLock(lockName);
|
||||
// } else {
|
||||
// lock = redisson.getLock(lockName);
|
||||
// }
|
||||
// return lock;
|
||||
// }
|
||||
//
|
||||
// public void setRedisson(RedissonClient redisson) {
|
||||
// this.redisson = redisson;
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,70 @@
|
||||
//package cn.stock.market.infrastructure.redis.config;
|
||||
//
|
||||
//import java.time.Duration;
|
||||
//
|
||||
//import org.redisson.api.RedissonClient;
|
||||
//import org.springframework.cache.CacheManager;
|
||||
//import org.springframework.cache.annotation.EnableCaching;
|
||||
//import org.springframework.context.annotation.Bean;
|
||||
//import org.springframework.context.annotation.Configuration;
|
||||
//import org.springframework.data.redis.cache.RedisCacheConfiguration;
|
||||
//import org.springframework.data.redis.cache.RedisCacheManager;
|
||||
//import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
//import org.springframework.data.redis.core.RedisTemplate;
|
||||
//import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
//import org.springframework.data.redis.serializer.RedisSerializationContext;
|
||||
//import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
//
|
||||
//import cn.qutaojing.common.aop.distributedlock.DistributedLockTemplate;
|
||||
//import cn.stock.market.infrastructure.redis.SingleDistributedLockTemplate;
|
||||
//
|
||||
///**
|
||||
// *
|
||||
// * @author xlfd
|
||||
// * @email xlfd@gmail.com
|
||||
// * @version 1.0
|
||||
// * @created Jun 3, 2021 4:56:28 PM
|
||||
// */
|
||||
//@Configuration
|
||||
//@EnableCaching
|
||||
//public class RedisConfig {
|
||||
//
|
||||
// @Bean
|
||||
// public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
// RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>();
|
||||
// redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
// redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
|
||||
// redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
//
|
||||
// redisTemplate.setHashValueSerializer(new Jackson2JsonRedisSerializer<>(Object.class));
|
||||
// redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
//
|
||||
// return redisTemplate;
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
|
||||
// // 配置序列化
|
||||
// RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig();
|
||||
// config.serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(new StringRedisSerializer()));
|
||||
// config.serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(new Jackson2JsonRedisSerializer<>(Object.class)));
|
||||
//
|
||||
// // 设置缓存的默认过期时间 ,30分钟
|
||||
// config.entryTtl(Duration.ofMinutes(30));
|
||||
// // 不缓存空值
|
||||
// config.disableCachingNullValues();
|
||||
// RedisCacheManager cacheManager = RedisCacheManager.builder(redisConnectionFactory).cacheDefaults(config)
|
||||
// .build();
|
||||
// return cacheManager;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 分布式锁实现
|
||||
// * @param redissonClient
|
||||
// * @return
|
||||
// */
|
||||
// @Bean
|
||||
// public DistributedLockTemplate distributedLockTemplate(RedissonClient redissonClient) {
|
||||
// return new SingleDistributedLockTemplate(redissonClient);
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,77 @@
|
||||
package cn.stock.market.infrastructure.stockdb.config;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
import org.springframework.orm.jpa.JpaTransactionManager;
|
||||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||
import com.rp.spring.jpa.GenericJpaRepositoryFactoryBean;
|
||||
import com.rp.spring.jpa.GenericJpaRepositoryImpl;
|
||||
|
||||
/**
|
||||
*
|
||||
* title: ErpDatasourceConfig.java
|
||||
* ERP 数据源设置
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @version 1.0
|
||||
* @created Jan 5, 2018 11:44:49 AM
|
||||
*/
|
||||
@Configuration
|
||||
@ComponentScan({ "cn.stock.market.infrastructure.stockdb.po", "cn.stock.market.infrastructure.stockdb.repo"})
|
||||
@EnableJpaRepositories(
|
||||
repositoryBaseClass = GenericJpaRepositoryImpl.class,
|
||||
repositoryFactoryBeanClass = GenericJpaRepositoryFactoryBean.class,
|
||||
entityManagerFactoryRef = "stockEntityManagerFactory",
|
||||
transactionManagerRef = "stockTransactionManager",
|
||||
basePackages = { "cn.stock.market.infrastructure.stockdb.po", "cn.stock.market.infrastructure.stockdb.repo"})
|
||||
public class StockDatasourceConfig {
|
||||
@Autowired HibernateProperties hibernateProperties;
|
||||
@Bean(name = "stockDataSource")
|
||||
@ConfigurationProperties(prefix="spring.datasource.stock")
|
||||
public DataSource dataSource() {
|
||||
return DruidDataSourceBuilder.create().build();
|
||||
}
|
||||
|
||||
@Bean(name = "stockJpaProperties")
|
||||
@ConfigurationProperties(prefix = "spring.jpa")
|
||||
public JpaProperties jpaProperties() {
|
||||
return new JpaProperties();
|
||||
}
|
||||
|
||||
@Bean(name = "stockEntityManagerFactory")
|
||||
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
|
||||
EntityManagerFactoryBuilder builder,
|
||||
@Qualifier("stockJpaProperties") JpaProperties jpaProperties,
|
||||
@Qualifier("stockDataSource") DataSource dataSource) {
|
||||
Map<String, Object> properties = hibernateProperties.determineHibernateProperties(jpaProperties.getProperties(), new HibernateSettings());
|
||||
return builder
|
||||
.dataSource(dataSource)
|
||||
.properties(properties)
|
||||
.packages("cn.stock.market.infrastructure.stockdb.po")
|
||||
.persistenceUnit("stock")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean(name = "stockTransactionManager")
|
||||
public PlatformTransactionManager transactionManager(@Qualifier("stockEntityManagerFactory") EntityManagerFactory entityManagerFactory) {
|
||||
return new JpaTransactionManager(entityManagerFactory);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.stock.market.infrastructure.stockdb.po;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
/**
|
||||
* StockPO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "site_setting")
|
||||
public class SiteSettingPO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
String marketServerList;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package cn.stock.market.infrastructure.stockdb.po;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.hibernate.annotations.DynamicInsert;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
|
||||
/**
|
||||
* StockPO
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
@SuperBuilder
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Entity
|
||||
@DynamicInsert
|
||||
@DynamicUpdate
|
||||
@Table(name = "stock")
|
||||
public class StockPO {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id;
|
||||
|
||||
String stockName;
|
||||
|
||||
String stockCode;
|
||||
|
||||
String stockSpell;
|
||||
|
||||
String stockType;
|
||||
|
||||
String stockGid;
|
||||
|
||||
String stockPlate;
|
||||
|
||||
Integer isLock;
|
||||
|
||||
Integer isShow;
|
||||
|
||||
Date addTime;
|
||||
|
||||
/**
|
||||
* 点差费率
|
||||
*/
|
||||
BigDecimal spreadRate;
|
||||
|
||||
/**
|
||||
* 涨幅比例
|
||||
*/
|
||||
BigDecimal increaseRatio;
|
||||
|
||||
Integer stockState;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.stock.market.infrastructure.stockdb.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.stockdb.po.SiteSettingPO;
|
||||
|
||||
/**
|
||||
* StockRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
public interface SiteSettingRepo extends GenericJpaRepository<SiteSettingPO, Integer> {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cn.stock.market.infrastructure.stockdb.repo;
|
||||
|
||||
import com.rp.spring.jpa.GenericJpaRepository;
|
||||
|
||||
import cn.stock.market.infrastructure.stockdb.po.StockPO;
|
||||
|
||||
import java.lang.Integer;
|
||||
|
||||
/**
|
||||
* StockRepo
|
||||
*
|
||||
* @author rplees
|
||||
* @email rplees.i.ly@gmail.com
|
||||
* @created 2023/06/17
|
||||
*/
|
||||
public interface StockRepo extends GenericJpaRepository<StockPO, Integer> {
|
||||
}
|
||||
Reference in New Issue
Block a user