📄 userattention.java
字号:
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: Sep 18, 2003
* Time: 2:33:13 PM
* To change this template use Options | File Templates.
*/
package ConnectAdapter;
import DBConnection.DBBridge;
import java.util.Vector;
import java.util.Enumeration;
import java.sql.ResultSet;
import Kernel.TradeInfo;
import Kernel.comTool;
import Kernel.AttentionInfo;
public class UserAttention extends Thread{
private int refreshtype_minute = 5;
private String ID;
private Clienter clienter;
private boolean flag = true;
private Vector AttentionInfoVec = new Vector();
public UserAttention(String userid,Clienter clienter){
this.ID = userid;
this.clienter = clienter;
getAttentionVecFromDB(this.ID);
}
public void run(){
while (flag){
if (refreshtype_minute != 0){
try{
Thread.sleep(refreshtype_minute*60000);
System.out.println("User Attention "+refreshtype_minute);
}catch(Exception ex){
ex.printStackTrace();
}
if ((flag)&&(refreshtype_minute != 0))
clienter.sendMessage("ATTENTIONLIST","");
}else{
try{
Thread.sleep(60000);
}catch(Exception ex){
ex.printStackTrace();
}
}
}
}
private void updateRefreshtype(String refreshtype){
for (Enumeration e = this.AttentionInfoVec.elements(); e.hasMoreElements();) {
((AttentionInfo)e.nextElement()).setRefreshType(refreshtype);
}
}
public void cancleAttention(String tradetype,String kind, String commodity, String keywords){
for (Enumeration e = this.AttentionInfoVec.elements(); e.hasMoreElements();) {
AttentionInfo attentionInfo = (AttentionInfo)e.nextElement();
if ((attentionInfo.getTradeType().equals(tradetype))&&(attentionInfo.getKind().equals(kind))
&&(attentionInfo.getCommodity().equals(commodity))&&(attentionInfo.getKeywords().equals(keywords))){
this.AttentionInfoVec.remove(attentionInfo);
break;
}
}
}
public void clearAttention(){
this.AttentionInfoVec.clear();
}
public void addAttention(String tradetype,String kind,String commodity, String keywords,String recentvisit){
AttentionInfo attentionInfo = new AttentionInfo(this.ID,tradetype,kind,commodity,keywords,recentvisit,String.valueOf(this.refreshtype_minute));
this.AttentionInfoVec.add(attentionInfo);
}
public void updateRecentVisit(String tradetype,String kind,String commodity,String keywords,String recentvisit){
int index = 0;
for (Enumeration e = this.AttentionInfoVec.elements(); e.hasMoreElements();) {
AttentionInfo attentionInfo = (AttentionInfo)e.nextElement();
if ((attentionInfo.getTradeType().equals(tradetype))&&(attentionInfo.getKind().equals(kind))
&&(attentionInfo.getCommodity().equals(commodity))&&(attentionInfo.getKeywords().equals(keywords))){
attentionInfo.setRecentVisit(recentvisit);
this.AttentionInfoVec.set(index,attentionInfo);
break;
}
index++;
}
}
public String getInitAttentionList(){
TradeInfo tradeInfo = new TradeInfo();
Vector attentionListVec = new Vector();
String str = "INITATTENTIONLIST";
for (Enumeration e = this.AttentionInfoVec.elements(); e.hasMoreElements();) {
AttentionInfo attentionInfo = (AttentionInfo)e.nextElement();
String tradetype = attentionInfo.getTradeType();
String kind = attentionInfo.getKind();
String commodity = attentionInfo.getCommodity();
String keywords = attentionInfo.getKeywords();
String recentvisit = attentionInfo.getRecentVisit();
Vector vec = tradeInfo.getTradeInfoNum(this.ID,tradetype,commodity,recentvisit);
String count = (String)vec.get(0);
String newPostDate = (String)vec.get(1);
attentionListVec.add(tradetype+" "+kind+" "+commodity+" "+keywords+" "+count);
updateRecentVisit(tradetype,kind,commodity,keywords,newPostDate);
}
str = str+"%"+this.refreshtype_minute;
for (Enumeration e = attentionListVec.elements(); e.hasMoreElements();) {
str = str+"%"+e.nextElement();
}
return str;
}
//ATTENTIONLIST%REFRESHTIME%TRADETYPE KIND KEYWORD1|KEYWORD2|KEYWORD3… COMMODITY COMMODITYNO%TRADETYPE KIND COMMODITYTYPE KEYWORD1|KEYWORD2|KEYWORD3… COMMODITYNO%...
public String getAttentionList(){
TradeInfo tradeInfo = new TradeInfo();
Vector attentionListVec = new Vector();
String str = "ATTENTIONLIST";
boolean canSubmit = false;
for (Enumeration e = this.AttentionInfoVec.elements(); e.hasMoreElements();) {
AttentionInfo attentionInfo = (AttentionInfo)e.nextElement();
String tradetype = attentionInfo.getTradeType();
String kind = attentionInfo.getKind();
String commodity = attentionInfo.getCommodity();
String keywords = attentionInfo.getKeywords();
String recentvisit = attentionInfo.getRecentVisit();
Vector vec = tradeInfo.getTradeInfoNum(this.ID,tradetype,commodity,recentvisit);
String count = (String)vec.get(0);
String newPostDate = (String)vec.get(1);
attentionListVec.add(tradetype+" "+kind+" "+commodity+" "+keywords+" "+count);
updateRecentVisit(tradetype,kind,commodity,keywords,newPostDate);
//****if (count != 0)
canSubmit = true;
}
if (canSubmit){
str = str+"%"+this.refreshtype_minute;
for (Enumeration e = attentionListVec.elements(); e.hasMoreElements();) {
str = str+"%"+e.nextElement();
}
}else str = null;
return str;
}
public boolean save2DB(){
DBBridge bridge = new DBBridge();
try{
String sql = "delete from ATTENTION where ID ='"+this.ID+"'";
bridge.getStmt().execute(sql);
for (Enumeration e = this.AttentionInfoVec.elements(); e.hasMoreElements();) {
AttentionInfo attentionInfo = (AttentionInfo)e.nextElement();
sql = "INSERT INTO ATTENTION " +
"(ID,TRADETYPE,KIND,COMMODITY,KEYWORDS,RECENTVISIT,REFRESHTYPE) " +
"VALUES ('"+ID+"', '"+attentionInfo.getTradeType()+"', '"+attentionInfo.getKind()+"', '"+attentionInfo.getCommodity()+"', '"+
attentionInfo.getKeywords()+"', '"+attentionInfo.getRecentVisit()+"',"+attentionInfo.getRefreshType()+")";
System.out.println(sql);
bridge.getStmt().execute(sql);
}
bridge.setConnectionSwitch("off");
return true;
}catch(Exception ex){
ex.printStackTrace();
}
bridge.setConnectionSwitch("off");
return false;
}
public void getAttentionVecFromDB(String userid){
DBBridge bridge = new DBBridge();
try{
String sql = "select * from ATTENTION WHERE ID='"+userid+"'";
ResultSet rs = bridge.getStmt().executeQuery(sql);
while (rs.next()){
String tradetype = rs.getString("TRADETYPE");
String kind = comTool.getChineseStr(rs.getString("KIND"));
String commodity = comTool.getChineseStr(rs.getString("COMMODITY"));
String keywords = comTool.getChineseStr(rs.getString("KEYWORDS"));
String recentvisit = rs.getString("RECENTVISIT");
this.refreshtype_minute = rs.getInt("REFRESHTYPE");
this.addAttention(tradetype,kind,commodity,keywords,recentvisit);
}
}catch(Exception ex){
ex.printStackTrace();
}
bridge.setConnectionSwitch("off");
}
public int getRefreshtype() {
return refreshtype_minute;
}
public void setRefreshtype(int refreshtype) {
this.updateRefreshtype(String.valueOf(refreshtype));
this.refreshtype_minute = refreshtype;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public boolean isFlag() {
return flag;
}
public void setFlag(boolean flag) {
this.flag = flag;
}
public static void main(String[] args) {
UserAttention ua = new UserAttention("letter",null);
ua.getInitAttentionList();
}
/*
public String getInitAttentionList(String userid){
TradeInfo tradeInfo = new TradeInfo();
DBBridge bridge = new DBBridge();
Vector attentionListVec = new Vector();
String str = "ATTENTIONLIST";
try{
String sql = "select * from ATTENTION WHERE ID='"+userid+"'";
//System.out.println(sql);
ResultSet rs = bridge.getStmt().executeQuery(sql);
bridge.setConnectionSwitch("off");
String refreshtype = "1";
while (rs.next()){
String tradetype = rs.getString("TRADETYPE");
String commodity = comTool.getChineseStr(rs.getString("COMMODITY"));
String recentvisit = rs.getString("RECENTVISIT");
refreshtype = rs.getString("REFRESHTYPE");
int count = tradeInfo.getTradeInfoNum(userid,tradetype,commodity,recentvisit);
attentionListVec.add(tradetype+" "+commodity+" "+count);
}
str = str+"%"+refreshtype;
for (Enumeration e = attentionListVec.elements(); e.hasMoreElements();) {
str = str+"%"+e.nextElement();
}
}catch(Exception ex){
ex.printStackTrace();
}
return str;
}
public String getAttentionList(String userid){
TradeInfo tradeInfo = new TradeInfo();
DBBridge bridge = new DBBridge();
Vector attentionListVec = new Vector();
String str = "ATTENTIONLIST";
try{
String sql = "select * from ATTENTION WHERE ID='"+userid+"'";
//System.out.println(sql);
ResultSet rs = bridge.getStmt().executeQuery(sql);
bridge.setConnectionSwitch("off");
String refreshtype = "1";
boolean canSubmit = false;
while (rs.next()){
String tradetype = rs.getString("TRADETYPE");
String commodity = comTool.getChineseStr(rs.getString("COMMODITY"));
String recentvisit = rs.getString("RECENTVISIT");
refreshtype = rs.getString("REFRESHTYPE");
int count = tradeInfo.getTradeInfoNum(userid,tradetype,commodity,recentvisit);
attentionListVec.add(tradetype+" "+commodity+" "+count);
//if (count != 0)
canSubmit = true;
}
if (canSubmit){
str = str+"%"+refreshtype;
for (Enumeration e = attentionListVec.elements(); e.hasMoreElements();) {
str = str+"%"+e.nextElement();
}
}else str = null;
}catch(Exception ex){
ex.printStackTrace();
}
return str;
}
*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -