Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增盯盘提醒功能 #147

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.huage2580'
version '2.0.1'
version '2.1.0'

sourceCompatibility = 1.8

Expand Down
41 changes: 38 additions & 3 deletions src/main/java/bean/StockBean.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
package bean;

import org.apache.commons.lang3.StringUtils;

import utils.PinYinUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Map;
import java.util.Objects;

import com.intellij.ide.util.PropertiesComponent;

public class StockBean {
private String code;
private String name;
Expand All @@ -25,11 +28,16 @@ public class StockBean {
private String min;

private String costPrise;//成本价
// private String cost;//成本
// private String cost;//成本
private String bonds;//持仓
private String incomePercent;//收益率
private String income;//收益

//盯盘低价
private String lowRemind;
//盯盘高价
private String highRemind;

public StockBean() {
}

Expand All @@ -52,11 +60,18 @@ public StockBean(String code) {
this.code = code;
}
this.name = "--";

PropertiesComponent instance = PropertiesComponent.getInstance();
String remindPrice = instance.getValue(code + "_remind");
if (StringUtils.isNotBlank(remindPrice)) {
this.lowRemind = remindPrice.split("_")[0];
this.highRemind = remindPrice.split("_")[1];
}
}

public StockBean(String code, Map<String, String[]> codeMap){
public StockBean(String code, Map<String, String[]> codeMap) {
this.code = code;
if(codeMap.containsKey(code)){
if (codeMap.containsKey(code)) {
String[] codeStr = codeMap.get(code);
if (codeStr.length > 2) {
this.code = codeStr[0];
Expand Down Expand Up @@ -171,6 +186,22 @@ public void setIncome(String income) {
this.income = income;
}

public String getLowRemind() {
return lowRemind;
}

public void setLowRemind(String lowRemind) {
this.lowRemind = lowRemind;
}

public String getHighRemind() {
return highRemind;
}

public void setHighRemind(String highRemind) {
this.highRemind = highRemind;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down Expand Up @@ -224,6 +255,10 @@ public String getValueByColumn(String colums, boolean colorful) {
return this.getCostPrise() != null ? this.getIncomePercent() + "%" : this.getIncomePercent();
case "收益":
return this.getIncome();
case "盯盘低价":
return "0".equals(this.getLowRemind()) ? null : this.getLowRemind();
case "盯盘高价":
return "0".equals(this.getHighRemind()) ? null : this.getHighRemind();
case "更新时间":
String timeStr = "--";
if (this.getTime() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="CoinWindow">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="form.CoinWindow">
<grid id="27dc6" binding="mPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package form;

import com.intellij.icons.AllIcons;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.ActionToolbarPosition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="FundWindow">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="form.FundWindow">
<grid id="27dc6" binding="mPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package form;

import com.intellij.icons.AllIcons;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.ActionToolbarPosition;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="SettingsWindow">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="form.SettingsWindow">
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="FormLayout">
<rowspec value="center:max(d;4px):noGrow"/>
<rowspec value="top:4dlu:noGrow"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package form;

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.options.Configurable;
import com.intellij.openapi.options.ConfigurationException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="StockWindow">
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="form.StockWindow">
<grid id="27dc6" binding="mPanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="500" height="400"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package form;

import com.intellij.icons.AllIcons;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.ActionToolbarPosition;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
Expand Down Expand Up @@ -29,7 +36,6 @@
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.net.MalformedURLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;

Expand Down Expand Up @@ -94,7 +100,12 @@ public void mousePressed(MouseEvent e) {
@Override
public @Nullable PopupStep onChosen(PopupsUiUtil.StockShowType selectedValue, boolean finalChoice) {
try {
PopupsUiUtil.showImageByStockCode(code, selectedValue, new Point(e.getXOnScreen(), e.getYOnScreen()));
if (PopupsUiUtil.StockShowType.remind.getType().equals(selectedValue.getType())){
PopupsUiUtil.showRemindPanel(code, selectedValue, new Point(e.getXOnScreen(), e.getYOnScreen()));

}else {
PopupsUiUtil.showImageByStockCode(code, selectedValue, new Point(e.getXOnScreen(), e.getYOnScreen()));
}
} catch (MalformedURLException ex) {
ex.printStackTrace();
LogUtil.info(ex.getMessage());
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/handler/SinaStockHandler.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package handler;

import bean.StockBean;

import com.google.common.base.Joiner;
import com.google.common.base.Strings;
import com.intellij.ide.util.PropertiesComponent;

import org.apache.commons.lang.StringUtils;

import utils.HttpClientPool;
import utils.LogUtil;

import javax.swing.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
Expand Down Expand Up @@ -92,6 +97,13 @@ public void handleResponse(String response, Map<String, String[]> codeMap) {
bean.setMax(split[4]);
bean.setMin(split[5]);

PropertiesComponent instance = PropertiesComponent.getInstance();
String remindPrice = instance.getValue(code + "_remind");
if (StringUtils.isNotBlank(remindPrice)) {
bean.setLowRemind(remindPrice.split("_")[0]);
bean.setHighRemind(remindPrice.split("_")[1]);
}

String costPriceStr = bean.getCostPrise();
if (StringUtils.isNotEmpty(costPriceStr)) {
BigDecimal costPriceDec = new BigDecimal(costPriceStr);
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/handler/StockRefreshHandler.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package handler;

import bean.StockBean;

import com.intellij.ide.util.PropertiesComponent;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.Notifications;
import com.intellij.openapi.ui.MessageType;
import com.intellij.ui.JBColor;
import com.intellij.ui.table.JBTable;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.math.NumberUtils;

import utils.LogUtil;
import utils.PinYinUtils;
import utils.WindowUtils;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableRowSorter;

import java.awt.*;
import java.math.BigDecimal;
import java.util.List;
import java.util.*;

Expand Down Expand Up @@ -167,6 +178,28 @@ protected void updateData(StockBean bean) {
} else {
addRow(convertData);
}

//盯盘提醒
PropertiesComponent instance = PropertiesComponent.getInstance();
String remindPrice = instance.getValue(bean.getCode() + "_remind");
if (StringUtils.isNotBlank(remindPrice) && StringUtils.isNotBlank(bean.getNow())) {
String lowPrice = remindPrice.split("_")[0];
String highPrice = remindPrice.split("_")[1];

BigDecimal nowValue = new BigDecimal(bean.getNow());
String remindText = "";
if (!StringUtils.equals("0", lowPrice) && new BigDecimal(lowPrice).compareTo(nowValue) > -1) {
remindText = "低价提醒!" + bean.getCode() + bean.getName() + ",现价:" + nowValue + ",低于盯盘价:" + lowPrice;
instance.setValue(bean.getCode() + "_remind", "0_" + highPrice);
LogUtil.info(remindText);
LogUtil.notify(remindText, true);
} else if (!StringUtils.equals("0", highPrice) && new BigDecimal(highPrice).compareTo(nowValue) < 1) {
remindText = "高价提醒!" + bean.getCode() + bean.getName() + ",现价:" + nowValue + ",高于盯盘价:" + highPrice;
instance.setValue(bean.getCode() + "_remind", lowPrice + "_0");
LogUtil.info(remindText);
LogUtil.notify(remindText, true);
}
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/handler/TencentStockHandler.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
package handler;

import bean.StockBean;

import org.apache.commons.lang.StringUtils;

import utils.HttpClientPool;
import utils.LogUtil;

import javax.swing.*;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.intellij.ide.util.PropertiesComponent;

public class TencentStockHandler extends StockRefreshHandler {
private String urlPara;
private HashMap<String, String[]> codeMap;
Expand Down Expand Up @@ -86,6 +91,13 @@ private void parse(String result) {
bean.setMax(values[33]);//33
bean.setMin(values[34]);//34

PropertiesComponent instance = PropertiesComponent.getInstance();
String remindPrice = instance.getValue(code + "_remind");
if (StringUtils.isNotBlank(remindPrice)) {
bean.setLowRemind(remindPrice.split("_")[0]);
bean.setHighRemind(remindPrice.split("_")[1]);
}

BigDecimal now = new BigDecimal(values[3]);
String costPriceStr = bean.getCostPrise();
if (StringUtils.isNotEmpty(costPriceStr)) {
Expand Down
Loading