Browse Source

add finance

master
独行之狼 4 years ago
parent
commit
3a7f795ca3
  1. 2
      build.gradle
  2. BIN
      fr-plugin-MarketUpdate-1.0/fr-plugin-MarketUpdate-1.0.jar
  3. BIN
      install/fr-plugin-MarketUpdate-1.0.zip
  4. 8
      src/main/java/com/fr/plugin/market/update/FRExchangeRate.java
  5. 3
      src/main/java/com/fr/plugin/market/update/FRFinanceFunction.java
  6. 68
      src/main/java/com/fr/plugin/market/update/FRStockMarket.java
  7. 38
      src/main/java/com/fr/plugin/market/update/FunConstants.java
  8. 17
      src/main/java/com/fr/plugin/market/update/TestFun.java

2
build.gradle

@ -3,5 +3,5 @@
*/
dependencies {
system 'com.fr.com.fr.plugin.imageProcess:gson:1.0'
system 'com.fr.com.fr.plugin.com.fr.plugin.image.process:gson:1.0'
}

BIN
fr-plugin-MarketUpdate-1.0/fr-plugin-MarketUpdate-1.0.jar

Binary file not shown.

BIN
install/fr-plugin-MarketUpdate-1.0.zip

Binary file not shown.

8
src/main/java/com/fr/plugin/market/update/FRExchangeRate.java

@ -3,6 +3,7 @@ package com.fr.plugin.market.update;
import com.alibaba.fastjson.JSONObject;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.market.update.FunConstants;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
@ -17,6 +18,7 @@ import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRExchangeRate extends AbstractFunction {
@ -31,6 +33,7 @@ public class FRExchangeRate extends AbstractFunction {
}
String currencyMain = args[0].toString();
String currencyOther = args[1].toString();
FineLoggerFactory.getLogger().info("input:{}",currencyMain+currencyOther);
float result;
try {
result= getRate(currencyMain,currencyOther);
@ -45,13 +48,14 @@ public class FRExchangeRate extends AbstractFunction {
private final float getRate(String currencyMain ,String currencyOther) throws IOException {
if(!ArrayUtils.contains(FunConstants.CurrencyCodeList,currencyMain)||!ArrayUtils.contains(FunConstants.CurrencyCodeList,currencyOther)){
FineLoggerFactory.getLogger().info(currencyMain+currencyOther);
return 0.0f;
}
final String URI = "https://api.exchangerate-api.com/v4/latest/"+currencyMain;
final String URI = "https://v6.exchangerate-api.com/v6/ea38228941df52ee76c767cd/latest/"+currencyMain;
Document doc = Jsoup.connect(URI).ignoreContentType(true).get();
final String body = doc.getElementsByTag("body").first().text();
JSONObject j=JSONObject.parseObject(body);
final String rates = JSONObject.parseObject(j.get("rates").toString()).get(currencyOther).toString();
final String rates = JSONObject.parseObject(j.get("conversion_rates").toString()).get(currencyOther).toString();
return Float.parseFloat(rates);
}
}

3
src/main/java/com/fr/plugin/market/update/FRFinanceFunction.java

@ -10,7 +10,8 @@ public class FRFinanceFunction extends AbstractFunctionDefContainer {
@Focus(id=FunConstants.PLUGIN_ID, text="金融行情数据")
public FunctionDef[] getFunctionDefs() {
return new FunctionDef[]{
new FunctionDef("FRExchangeRate", "功能:。", FRExchangeRate.class.getName())
new FunctionDef("FRExchangeRate", "功能:。", FRExchangeRate.class.getName()),
new FunctionDef("FRStockMarket", "功能:。", FRStockMarket.class.getName())
};
}

68
src/main/java/com/fr/plugin/market/update/FRStockMarket.java

@ -0,0 +1,68 @@
package com.fr.plugin.market.update;
import com.alibaba.fastjson.JSONObject;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.log.FineLoggerFactory;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.script.AbstractFunction;
import com.fr.stable.ArrayUtils;
import com.fr.stable.Primitive;
import com.fr.stable.fun.Authorize;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
import java.util.regex.Pattern;
@EnableMetrics
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FRStockMarket extends AbstractFunction {
@Focus(id = FunConstants.PLUGIN_ID, text = "Plugin-Test_Function_FRStockMarket", source = Original.PLUGIN)
public Object run(Object[] args) {
if(!FunConstants.author()){
return FunConstants.AUTHOR_ERROR;
}
String checkRes = FunConstants.CheckArgs(args,3 );
if (!checkRes.equals(FunConstants.CHECK_PASS)) {
return Primitive.ERROR_VALUE + checkRes;
}
String city = args[0].toString();
String stockCode = args[1].toString();
String stockArgs = args[2].toString();
FineLoggerFactory.getLogger().info("stockArgs:{}",stockArgs);
String result;
try {
result= getStock(city,stockCode,stockArgs);
} catch (IOException e) {
FineLoggerFactory.getLogger().info("getStock");
return Primitive.ERROR_VALUE;
}
if(result==FunConstants.ARGS_ERROR){
return Primitive.ERROR_VALUE;
}
return result;
}
private final String getStock(String city ,String stockCode,String stockArgs) throws IOException {
if(!ArrayUtils.contains(FunConstants.StockCity,city)||!ArrayUtils.contains(FunConstants.StockArgs,stockArgs)){
FineLoggerFactory.getLogger().info("contains");
return FunConstants.ARGS_ERROR;
}
if(!FunConstants.CheckStockCode(stockCode)){
FineLoggerFactory.getLogger().info("isMatched");
return FunConstants.ARGS_ERROR;
}
final String cityCode=city.equals("上海")?"sh":"sz";
final String CHINA_BANK_URI = "http://hq.sinajs.cn/list="+cityCode+stockCode;
FineLoggerFactory.getLogger().info("CHINA_BANK_URI:{}",CHINA_BANK_URI);
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).get();
final String s = doc.text().split("\"")[1];
final String[] stocks = s.split(",");
final int stockArgsIndex = ArrayUtils.indexOf(FunConstants.StockArgs, stockArgs);
final String result = stocks[stockArgsIndex];
return result;
}
}

38
src/main/java/com/fr/plugin/market/update/FunConstants.java

@ -1,29 +1,45 @@
package com.fr.plugin.market.update;
import com.fr.plugin.PluginLicenseManager;
import com.fr.plugin.context.PluginContexts;
import com.fr.stable.ArrayUtils;
import com.fr.stable.fun.Authorize;
//import static com.fr.design.i18n.Toolkit.i18nText;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.regex.Pattern;
@Authorize(callSignKey = FunConstants.PLUGIN_ID)
public class FunConstants {
static final String PLUGIN_ID="com.fr.plugin.function.market.update";
static final String AUTHOR_ERROR="Plugin.Function.Market_upate_AUTHOR_ERROR";
static final String CHECK_PASS="Plugin.Function.ImagProcess_CHECK_PASS";
static final String[] CurrencyCodeList=new String[]{
"HKD","MOP","TWD","EUR","USD","GBP","AUD","KRW","JPY","CNH","CAD","RUB","THB","PHP","ALL","ARS","AWG","AED","ANG","AZN","AOA","BSD","BHD","BBD","BYR","BZD","BMD","BTN","BOB","BWP","BRL","BGN","BIF","BDT","BND","CVE","COP","CRC","CUP","CZK","CHF","CYP","CLP","DZD","DKK","DOP","DJF","EGP","ETB","ECS","ERN","FKP","FJD","GMD","GYD","GHS","GNF","GTQ","GIP","HTG","HNL","HRK","HUF","ISK","INR","IDR","IRR","IQD","ILS","JMD","JOD","KPW","KZT","KHR","KYD","KMF","KES","KWD","LAK","LVL","LBP","LSL","LRD","LYD","LTL","LKR","MKD","MWK","MYR","MVR","MRO","MUR","MXN","MDL","MNT","MAD","MMK","MGA","NAD","NPR","NIO","NGN","NOK","NZD","OMR","PKR","PAB","PGK","PYG","PLN","PEN","QAR","RON","RWF","SEK","SVC","STD","SAR","SCR","SLL","SIT","SBD","SOS","SHP","SDG","SZL","SGD","SYP","TRY","TZS","TOP","TTD","TND","TJS","UAH","UYU","UGX","VUV","VEF","VND","WST","XOF","XAF","XCD","XPF","YER","ZWD","ZAR","ZMW"
static final String PLUGIN_ID = "com.fr.plugin.market.update";
static final String AUTHOR_ERROR = "Plugin.Function.Market_upate_AUTHOR_ERROR";
static final String CHECK_PASS = "Plugin.Function.ImagProcess_CHECK_PASS";
static final String ARGS_ERROR= "args_error";
static final String[] CurrencyCodeList = new String[]{
"USD", "AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLP", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "FOK", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KID", "KMF", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STN", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TVD", "TWD", "TZS", "UAH", "UGX", "UYU", "UZS", "VES", "VND", "VUV", "WST", "XAF", "XCD", "XDR", "XOF", "XPF", "YER", "ZAR", "ZMW"
};
static final String[] CurrencyNameList=new String[]{
"港元","澳门元","台币","欧元","美元","英镑","澳元","韩元","日元","离岸人民币","加拿大元","俄罗斯卢布","泰国铢","菲律宾比索","阿尔巴尼亚列克","阿根廷比索","阿鲁巴岛弗罗林","阿联酋迪拉姆","列斯荷兰盾","阿塞拜疆新马纳特","安哥拉宽扎","巴哈马元","巴林第纳尔","巴巴多斯元","白俄罗斯卢","伯利兹元","百慕大元","不丹卢比","玻利维亚诺","博茨瓦纳普拉","巴西里亚伊","保加利亚列瓦","布隆迪法郎","孟加拉塔卡","文莱元","佛得角埃斯库多","哥伦比亚比索","哥斯达黎加科朗","古巴比索","捷克克朗","瑞士法郎","塞浦路斯镑","智利比索","阿尔及利亚第纳尔","丹麦克朗","多米尼加比索","吉布提法郎","埃及镑","埃塞俄比亚比尔","厄瓜多尔苏克雷","厄立特里亚","福克兰群岛镑","斐济元","冈比亚达拉西","圭亚那元","加纳塞地","几内亚法郎","危地马拉格查尔","直布罗陀镑","海地古德","洪都拉斯伦皮拉","克罗地亚库纳","匈牙利福林","冰岛克朗","印度卢比","印度尼西亚卢比盾","伊朗里亚尔","伊拉克第纳尔","以色列镑","牙买加元","约旦第纳尔","朝鲜圆","哈萨克斯坦腾格","柬埔寨利尔斯","开曼岛元","科摩罗法郎","肯尼亚先令","科威特第纳尔","老挝基普","拉脱维亚拉图","黎巴嫩镑","莱索托洛提","利比里亚元","利比亚第纳尔","立陶宛里塔斯","斯里兰卡卢比","马其顿第纳尔","马拉维克瓦查","马来西亚林吉特","马尔代夫卢非亚","毛里塔尼亚乌吉亚","毛里求斯卢比","墨西哥比索","摩尔多瓦列伊","蒙古图格里克","摩洛哥道拉姆","缅甸元","马达加斯加阿里亚里","纳米比亚元","尼泊尔卢比","尼加拉瓜科多巴","尼日利亚奈拉","挪威克朗","新西兰元","阿曼里亚尔","巴基斯坦卢比","巴拿马巴尔博亚","巴布亚新几内亚基那","巴拉圭瓜拉尼","波兰兹罗提","秘鲁索尔","卡塔尔利尔","罗马尼亚新列伊","卢旺达法郎","瑞典克朗","萨尔瓦多科朗","圣多美多布拉","沙特阿拉伯里亚尔","塞舌尔法郎","塞拉利昂利昂","斯洛文尼亚托拉捷夫","所罗门群岛元","索马里先令","圣赫勒拿群岛磅","苏丹第纳尔","斯威士兰里兰吉尼","新加坡元","叙利亚镑","土耳其新里拉","坦桑尼亚先令","汤加潘加","特立尼达和多巴哥元","突尼斯第纳尔","塔吉克斯坦索莫尼","乌克兰赫夫米","乌拉圭新比索","乌干达先令","瓦努阿图瓦图","委内瑞拉博利瓦","越南盾","萨摩亚塔拉","多哥非洲共同体法郎","刚果中非共同体法郎","格林纳达东加勒比元","太平洋法郎","也门里亚尔","津巴布韦元","南非兰特","赞比亚克瓦查"
static final String[] StockArgs={
"股票名字","今日开盘价","昨日收盘价","当前价格","今日最高价","今日最低价","竞买价","竞卖价","成交股票数","成交金额","买一手数","买一报价","买二手数","买二报价","买三手数","买三报价","买四手数","买四报价","买五手数","买五报价","卖一手数","卖一报价","卖二手数","卖二报价","卖三手数","卖三报价","卖四手数","卖四报价","卖五手数","卖五报价","日期","时间"
};
static final String[] StockCity={
"上海","深圳"
};
static final boolean author() {
return PluginContexts.currentContext().isAvailable();
return PluginLicenseManager.getInstance().getPluginLicenseByID(PLUGIN_ID).isAvailable();
}
static String CheckArgs(Object[] args,int num){
String res=FunConstants.CHECK_PASS;
static final boolean CheckStockCode(String code){
final String regExp="^002[\\d]{3}|000[\\d]{3}|300[\\d]{3}|600[\\d]{3}|60[\\d]{4}$ ";
final boolean isMatched = Pattern.compile(regExp).matcher(code).matches();
return isMatched;
}
static String CheckArgs(Object[] args, int num) {
String res = FunConstants.CHECK_PASS;
int len = ArrayUtils.getLength(args);
if (len != num) {
return "Plugin.Function.ImagProcess_ArgsCountError";
return "Plugin.Function.FRFinanceFunction_ArgsCountError";
}
return res;
}

17
src/main/java/com/fr/plugin/market/update/TestFun.java

@ -13,6 +13,7 @@ import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;
public class TestFun {
public static void main(String args[]) throws Exception {
@ -35,15 +36,21 @@ public class TestFun {
//// JSONObject j=JSONObject.parseObject(s);
// System.out.println(s);
final String CHINA_BANK_URI = "https://api.exchangerate-api.com/v4/latest/USD";
if(!ArrayUtils.contains(FunConstants.CurrencyCodeList,"UD")){
final String CHINA_BANK_URI = "http://hq.sinajs.cn/list=sh600928";
if((!ArrayUtils.contains(FunConstants.CurrencyCodeList,"USD"))||(!ArrayUtils.contains(FunConstants.CurrencyCodeList,"USD"))){
System.out.printf("00");
}
Document doc = Jsoup.connect(CHINA_BANK_URI).ignoreContentType(true).get();
final String body = doc.getElementsByTag("body").first().text();
JSONObject j=JSONObject.parseObject(body);
System.out.printf(JSONObject.parseObject(j.get("rates").toString()).get("CNY").toString());
// final String body = doc.getElementsByTag("body").first().text();
// JSONObject j=JSONObject.parseObject(body);
// System.out.printf(JSONObject.parseObject(j.get("conversion_rates").toString()).get("CNY").toString());
final String s = doc.text().split("\"")[1];
final String[] stocks = s.split(",");
final int stockArgsIndex = ArrayUtils.indexOf(FunConstants.StockArgs, "日期");
final String regExp="^002[\\d]{3}|000[\\d]{3}|300[\\d]{3}|600[\\d]{3}|60[\\d]{4}$ ";
final boolean isMatched = Pattern.compile(regExp).matcher("600928").matches();
System.out.printf("isMatched:"+isMatched);
}
}

Loading…
Cancel
Save