Merge branch 'develop' into 'main'

更改数据库连接

See merge request india/india_market_java!32
This commit is contained in:
Gavin g
2024-07-26 07:15:17 +00:00
7 changed files with 61 additions and 35 deletions

View File

@@ -2,7 +2,7 @@ stages:
# 构建
- build
- dockerize
- webhook
- deploy
build:
image: maven:3.6.3-openjdk-8
@@ -60,16 +60,20 @@ dockerize:
- docker push juyoutech/india_stock_market:latest
- docker push juyoutech/india_stock_market:$CI_PIPELINE_ID
- docker push juyoutech/india_stock_market:$CI_COMMIT_BRANCH
webhook:
stage: webhook
deploy-dev:
stage: deploy
only:
- develop
script:
- echo ">>>>>>Start Deploy<<<<<<"
- echo "Deploying application..."
- ls
- apt-get update
- apt-get install -y curl
- curl --max-time 30 http://149.88.86.7:11113/api/webhook/justpull?project=india_market_java\&setenv_file=alpha.sh\&publish_env=alpha\&shell=deploy-test.sh
- echo ">>>>>>Start Deploy Finish<<<<<<"
- |
curl -X POST \
-H "Content-Type: application/json" \
-d '{"namespace":"yddev", "deployment_name":"india-stock-market"}' \
https://updater-yddev.moneytj.com/restart-deployment
- echo "Application successfully deployed."

View File

@@ -255,7 +255,7 @@ public class StockService {
.header("Accept-Language", "en-US,en;q=0.9")
.get();
// result = doc.html().substring(doc.html().indexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">"),doc.html().lastIndexOf("<div class=\"listingstyle_shortvideoimg__0TWuX shortvideoimg\">")+500);
Elements divElements = doc.select("div.listingstyle_cardlistlist__Cr4Ym");
Elements divElements = doc.select("div.listingstyle_cardlistlist__dfq57");
StringBuilder sb = new StringBuilder();
for (Element divElement : divElements) {
sb.append(divElement.outerHtml()).append("\n");
@@ -982,7 +982,7 @@ public class StockService {
String exchange = "bse";
IndiaIndexVo vo1 = new IndiaIndexVo();
String coCode = "20558";
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
JSONObject object = TodayApis.getStockDetail("in%3BSEN", coCode);
IndiaStockVO market = objToVo(object);
market.setName("BSESENSEX指数");
vo1.setIndexVo(market);
@@ -1012,7 +1012,7 @@ public class StockService {
String exchange = "nse";
IndiaIndexVo vo1 = new IndiaIndexVo();
String coCode = "20559";
JSONObject object = TodayApis.getStockDetail(exchange, coCode);
JSONObject object = TodayApis.getStockDetail("in%3BNSX", coCode);
IndiaStockVO market = objToVo(object);
market.setName("NIFTY50指数");
vo1.setIndexVo(market);
@@ -1042,23 +1042,23 @@ public class StockService {
}
private IndiaStockVO objToVo(JSONObject object){
IndiaStockVO market = new IndiaStockVO();
if(object.containsKey("prev_close")){
market.setClose(object.getString("prev_close"));
if(object.containsKey("priceprevclose")){
market.setClose(object.getString("priceprevclose"));
}
if(object.containsKey("price")){
market.setNowPrice(object.getString("price"));
if(object.containsKey("pricecurrent")){
market.setNowPrice(object.getString("pricecurrent"));
}
if(object.containsKey("perchg")){
market.setRate(object.getString("perchg"));
if(object.containsKey("pricepercentchange")){
market.setRate(object.getString("pricepercentchange"));
}
if(object.containsKey("high_price")){
market.setHigh(object.getString("high_price"));
if(object.containsKey("HIGH")){
market.setHigh(object.getString("HIGH"));
}
if(object.containsKey("low_price")){
market.setLow(object.getString("low_price"));
if(object.containsKey("LOW")){
market.setLow(object.getString("LOW"));
}
if(object.containsKey("open_price")){
market.setOpen(object.getString("open_price"));
if(object.containsKey("OPEN")){
market.setOpen(object.getString("OPEN"));
}
return market;
// stockListVO.setName(jsonObject.getString("companyname"));

View File

@@ -187,18 +187,17 @@ public class TodayApis {
//获取详情
public static JSONObject getStockDetail(String exchange,String coCode){
String url = String.format("https://marketapi.intoday.in/widget/stockdetail/pullview?co_code=%s&exchange=%s",coCode,exchange);
String url = String.format("https://priceapi.moneycontrol.com/pricefeed/notapplicable/inidicesindia/%s",exchange);
String str = get(url);
JSONObject object = JSON.parseObject(str);
boolean bool = false;
if(object.containsKey("success")){
bool = object.getBoolean("success");
if(object.containsKey("code")){
bool = object.getInteger("code") == 200;
}
if(!bool){
return new JSONObject();
}
JSONArray jsonArray = JSON.parseArray(object.getString("data"));
JSONObject entity = JSON.parseObject(jsonArray.get(0).toString());
JSONObject entity = JSON.parseObject(object.getString("data"));
return entity;
}

View File

@@ -7,6 +7,7 @@ import cn.stock.market.domain.basic.repository.StockRepository;
import cn.stock.market.domain.basic.service.StockService;
import cn.stock.market.infrastructure.api.investing.InvestingInvokerApis;
import cn.stock.market.infrastructure.db.po.QSiteNewsPO;
import cn.stock.market.utils.DateTimeUtil;
import cn.stock.market.utils.Utils;
import com.ag.utils.CollectionUtils;
import com.alibaba.fastjson.JSON;
@@ -123,11 +124,11 @@ public class InvestingTask {
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
// Extract the date and time using regex
Pattern pattern = Pattern.compile("Updated On : <!-- --> <!-- -->(.*?)<!-- -->");
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
Matcher matcher = pattern.matcher(n);
String time = "";
if (matcher.find()) {
time = matcher.group(1).trim();
time = DateTimeUtil.formatDateTimeFor24H(matcher.group(1).trim(),"dd MMM yyyy | hh:mm a");
}
SiteNews siteNews = new SiteNews();

View File

@@ -5,6 +5,8 @@ import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;
import java.util.Locale;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -186,6 +188,25 @@ public class DateTimeUtil {
}
public static String formatDateTimeFor24H(String inputDateTime,String inputFormatStr){
String outputDateTime = "";
// 1. 解析日期时间
SimpleDateFormat inputFormat = new SimpleDateFormat(inputFormatStr, Locale.ENGLISH);
Date date = null;
try {
date = inputFormat.parse(inputDateTime);
} catch (Exception e) {
e.printStackTrace();
}
if (date != null) {
// 2. 转换为24小时制
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
outputDateTime = outputFormat.format(date);
}
return outputDateTime;
}
public static void main(String[] args) {
parseToDateByMinute(10);
}

View File

@@ -179,8 +179,9 @@ public class StockApiController {
String contentUrl = n.substring(1, n.indexOf("class=\"img-smllnews\"") - 2);
String id = contentUrl.substring(contentUrl.lastIndexOf("-") + 1, contentUrl.lastIndexOf("_"));
String imgUrl = n.substring(n.indexOf("img loading=\"lazy\" src=") + 24, n.indexOf("?"));
// String time = n.substring(n.indexOf("Last Updated") + 23, n.indexOf("IST") - 9);
// Extract the date and time using regex
Pattern pattern = Pattern.compile("Updated On : <!-- --> <!-- -->(.*?)<!-- -->");
Pattern pattern = Pattern.compile("Updated On :<!-- --> <!-- -->(.*?)<!-- -->");
Matcher matcher = pattern.matcher(n);
String time = "";
if (matcher.find()) {
@@ -246,7 +247,7 @@ public class StockApiController {
@ResponseBody
public ServerResponse getIndiaIndexByToday() {
String INDEX_CODE = "TODAY_INDEX";
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,60000, (string) -> {
return RequestCacheUtils.cache("getIndiaIndexByToday.do", INDEX_CODE,6000, (string) -> {
return this.stockService.getIndexByBtoday();
});
}

View File

@@ -3,9 +3,9 @@ spring:
show-sql: true
# Redis配置
redis:
host: 43.132.212.180
password: ruTZ9J3gaDhknJ
port: 36379
host: lb-b6sze686-7db6hgvsx05ef8nz.clb.sg-tencentclb.net
password: a5v8b86P4mVzFlUqJV
port: 56379
database: 1
lettuce:
pool:
@@ -17,9 +17,9 @@ spring:
datasource:
stock-market:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://149.88.86.7:33306/india_stock?useUnicode=true&characterEncoding=utf-8
url: jdbc:mysql://lb-1ju43bvw-p0ecnv4by9ju8six.clb.ap-singapore.tencentclb.com:53306/india_stock?useUnicode=true&characterEncoding=utf-8
username: root
password: 33BsUUcnXRYgwtIND
password: uNejHIFQGJOUtYTmE
maxActive: 500
testWhileIdle: true
validationQuery: SELECT 1