📄 onlinemessage.java
字号:
package com.gforce.gfoa;
import com.gforce.currency.database.*;
import com.gforce.currency.*;
import java.util.*;
/**
*
* <p>Title: 吉力科技办公自动化系统</p>
* <p>Description: 吉力科技办公自动化系统</p>
* <p>Copyright: 版权所有 2003 (c) 西安吉力科技发展有限公司 Copyright (c) 2003 GForce Sceince & Technology</p>
* <p>Company: 西安吉力科技发展有限公司 (GForce Sceince & Technology)</p>
* @author 马登军
* @version 1.0
*/
public class OnlineMessage
extends RecordManager
{
int intMsgKind = 0;
String strSQLWhere = "";
String strOrderBy = "";
static public int SentMsg = 1;
static public int RecievedMsg = 2;
static public int SavedMsg = 3;
static public int AllMsg = 0;
public OnlineMessage()
{
}
protected final static String TableName = "OnlineMessage"; //定义声明本类操作表名称
protected final static String IDFieldName = "ID"; //定义声明主键或者可以确定唯一记录的字段名称为“ID”,必须为自增整型
protected final static String[] NumericFieldsName =
{
"SendUserID", "RecieveUserID", "IsReaded", "IsSenderDel", "IsRecieverDel", "IsSecret", "IsPigeonhole", "MessageID","Isreminded"}; //声明数值型字段名称
protected final static String[] DatetimeFieldsName =
{
"SendTime"}; //声明日期时间型字段名称
protected final static String[] StringFieldsName =
{
"Title"}; //声明字符型字段名称
protected final static String[] TextFieldsName =
{
"Content"}; //声明大字符串型字段名称
/* * 根据字段名称获取插入数据时表单元素名称
* @param strFieldName 字段名称
* @return 表单素名称
*/
protected String InsertParament(String strFieldName)
{
return "" + strFieldName + ""; //可以根据需要加前缀、后缀
}
/**
* 根据字段名称获取修改数据时表单元素名称
* @param strFieldName 字段名称
* @return 表单素名称
*/
protected String UpdateParament(String strFieldName)
{
return "" + strFieldName + ""; //可以根据需要加前缀、后缀
}
/**
* 获取本类操作表名称
* @return 表名称
*/
public String getTableName()
{ //获取本类操作表名称
return TableName;
}
protected String getIDFieldName()
{ //获取主键或者可以确定唯一记录的字段名称
return IDFieldName;
}
protected String[] getNumericFieldsName()
{ //获取数值型字段名称
return NumericFieldsName;
}
protected String[] getStringFieldsName()
{ //获取字符型字段名称
return StringFieldsName;
}
protected String[] getDatetimeFieldsName()
{ //获取日期时间型字段名称
return DatetimeFieldsName;
}
protected String[] getTextFieldsName()
{ //获取大字符串型字段名称
return TextFieldsName;
}
/**
* 获取指定用户未读的短信息列表向量集
* @param iUserID 用户ID
* @return 指定用户未读的短信息列表向量集
*/
public static Vector getNewMessage(int iUserID)
{
Vector vt = SQLManager.GetResultSet("Select * from " + TableName + " where SendUserID<>" + iUserID + " and RecieveUserID=" + iUserID + " and (IsReaded<>1 or IsReaded is null) and (IsRecieverDel=0 or IsRecieverDel is Null) order by ID desc");
return vt;
}
/**
* 获取指定用户未提醒的短信息列表
* @param iUserID 用户ID
* @return 指定用户未提醒的短信息列表
*/
public static Vector getUnRemindedMsg(int iUserID)
{
Vector vt = SQLManager.GetResultSet("Select * from " + TableName + " where SendUserID<>" + iUserID + " and RecieveUserID=" + iUserID + " and (IsReminded<>1 or IsReminded is null) and (IsRecieverDel=0 or IsRecieverDel is Null) and (IsReaded<>1 or IsReaded is null) order by ID desc");
return vt;
}
/**
* 获取与指定用户相关的指定类型的所有记录向量集
* @param iUserID 用户ID
* @param iMsgKind 短信息类型
* @return 所有记录向量集
*/
public static Vector getAllRecord(int iUserID, int iMsgKind)
{
String strSQL = "";
switch (iMsgKind)
{
case 1:
{
strSQL = "Select * from " + TableName + " where RecieveUserID<>" + iUserID + " and SendUserID=" + iUserID + " and (IsSenderDel=0 or IsSenderDel is null) order by ID desc";
break;
}
case 2:
{
strSQL = "Select * from " + TableName + " where SendUserID<>" + iUserID + " and RecieveUserID=" + iUserID + " and (IsRecieverDel=0 or IsRecieverDel is Null) order by ID desc";
break;
}
case 3:
{
strSQL = "Select * from " + TableName + " where RecieveUserID=" + iUserID + " and (IsRecieverDel=0 or IsRecieverDel is Null) and SendUserID=" + iUserID + " and (IsSenderDel=0 or IsSenderDel is null) order by ID desc";
break;
}
default:
{
strSQL = "Select * from " + TableName + " where (SendUserID=" + iUserID
+ " and (IsSenderDel=0 or IsSenderDel is null)) or (RecieveUserID=" + iUserID + " and (IsRecieverDel=0 or IsRecieverDel is Null)) order by ID desc";
break;
}
}
Vector vt = SQLManager.GetResultSet(strSQL);
return vt;
}
/**
* 获取指定MessageID的附件列表
* @param iMessageID 短信息标识
* @return 指定MessageID的附件列表向量集
*/
public static Vector getAttInfo(int iMessageID)
{
String strSQL = "select * from ArticleAttInfo where FartherID=" + iMessageID + " and FartherTable='" + TableName
+ "'";
Vector vt = SQLManager.GetResultSet(strSQL);
return vt;
}
/**
* 发送端信息
* @param strTitle 短信息标题
* @param strContent 短信息内容
* @param strRecieves 接收者ID字符串
* @param iSendUserID 发送者ID
* @param strAttachments 附件名称
* @param iIsSecret 是否密送
* @return 错误代码
*/
public int SendMessage(String strTitle, String strContent, String strRecieves, int iSendUserID,String strAccessoriesNames
, String strAccessoriesURLs, int iIsSecret)
{
/**
* 发送短信息的个数
*/
int intSentMsg = 0;
/**
* 短信息唯一标识
*/
int intMsgID = 0;
try
{
String[] strRecieve = strRecieves.split(",");
for (int i = 0; i < strRecieve.length; i++)
{
int intRecieve = 0;
try
{
intRecieve = Integer.parseInt(strRecieve[i]);
if (intRecieve > 0)
{
int iNewsID = AddNewMessage(strTitle, strContent, intRecieve, iSendUserID, iIsSecret, intMsgID);
if (iNewsID > 0)
{
if (i == 0)
{
intMsgID = iNewsID;
SQLManager.ExcuteSQL("Update " + TableName + " set MessageID=" + intMsgID + " where ID=" + iNewsID);
try
{
if(strAccessoriesURLs.length()>0)
{
String[] strAccessoriesURL = strAccessoriesURLs.split(",");
String[] strAccessoriesName = strAccessoriesNames.split(",");
for (int j = 0; j < strAccessoriesURL.length; j++)
{
if (strAccessoriesURL[j].trim().length() > 0)
{
if (AddAttment(intMsgID, strAccessoriesName[j], strAccessoriesURL[j].trim()) <= 0)
{
SystemOut.ErrOut("新增短信息附件时出错!附加名称:" + strAccessoriesName[j].trim() + ";短信息标题:" + strTitle + "");
}
}
}
}
}
catch (Exception e)
{
SystemOut.ErrOut("新增短信息附件时出错!短信息标题:" + strTitle + "");
}
}
intSentMsg++;
}
else
{
SystemOut.ErrOut("新增短信息时出错!短信息标题:" + strTitle + "");
}
}
else
{
SystemOut.ErrOut("获取短信息接收者ID时出错!短信息标题:" + strTitle + "");
}
}
catch (Exception e)
{
SystemOut.ErrOut("获取短信息接收者ID时出错!短信息标题:" + strTitle + "");
}
}
}
catch (Exception e)
{
SystemOut.ErrOut("获取短信息接收者ID时出错!短信息标题:" + strTitle + "");
}
return intSentMsg;
}
/**
* 新增一条短信息记录
* @param strTitle 短信息标题
* @param strContent 短信息内容
* @param intRecieveUserID 接收者用户ID
* @param intSendUserID 发送者用户ID
* @param iIsSecret 是否密送
* @param intMsgID 唯一标识ID
* @return 新记录ID或者错误代码
*/
private int AddNewMessage(String strTitle, String strContent, int intRecieveUserID, int intSendUserID, int iIsSecret
, int intMsgID)
{
int intNewsID = 0;
String strNow = StringNew.GetDateString(new Date(), "yyyy-MM-dd HH:mm:ss");
String strSQLInsert = "insert into " + TableName
+ " (Title,SendTime,Content,SendUserID,RecieveUserID,IsSecret,MessageID) values ('" +
strTitle + "','" + strNow + "','" + strContent + "'," + intSendUserID + "," + intRecieveUserID + "," + iIsSecret
+ "," + intMsgID + ")";
intNewsID = SQLManager.ExcuteSQL(strSQLInsert);
if (intNewsID > -1)
{
String strSQLSelect = "select max(ID) from " + TableName + " where Title='" + strTitle + "' and SendTime='"
+ strNow + "' and SendUserID=" + intSendUserID + " and RecieveUserID=" + intRecieveUserID + "";
Vector vt = SQLManager.GetResultSet(strSQLSelect);
if (vt.size() == 1)
{
return Integer.parseInt( ( (Vector) vt.get(0)).get(0).toString());
}
else
{
return -2; //表示新插入的记录不存在,新记录插入没有成功
}
}
else
{
return intNewsID;
}
}
/**
* 新增短信息附件
* @param iMsgID 短信息唯一标识ID
* @param strAttURL 短信息附件URL
* @return 附件ID或者错误代码
*/
private int AddAttment(int iMsgID, String strAttURL)
{
String strAttName = strAttURL.substring(strAttURL.lastIndexOf("/") + 1);
return AddAttment(iMsgID, strAttName, strAttURL);
}
/**
* 新增短信息附件
* @param iMsgID 短信息唯一标识ID
* @param strAttName 短信息附件名称
* @param strAttURL 短信息附件URL
* @return 附件ID或者错误代码
*/
private int AddAttment(int iMsgID, String strAttName, String strAttURL)
{
int iAttmentID = 0;
String strSQLInsert = "Insert into ArticleAttInfo (AttName,AttURL,FartherID,FartherTable) values ('" + strAttName
+ "','" + strAttURL + "'," + iMsgID + ",'" + TableName + "')";
iAttmentID = SQLManager.ExcuteSQL(strSQLInsert);
if (iAttmentID > 0)
{
String strSQLSelect = "select max(ID) from ArticleAttInfo where AttName='" + strAttName + "' and AttURL='"
+ strAttURL + "' and FartherID=" + iMsgID + " and FartherTable='" + TableName + "'";
Vector vt = SQLManager.GetResultSet(strSQLSelect);
if (vt.size() == 1)
{
return Integer.parseInt( ( (Vector) vt.get(0)).get(0).toString());
}
else
{
return -2; //表示新插入的记录不存在,新记录插入没有成功
}
}
else
{
return iAttmentID;
}
}
/**
* 获取指定MessageID的短信息接收人员列表向量集
* @param iMessageID 短信息唯一标识ID
* @return 指定MessageID的短信息接收人员列表向量集
*/
public static Vector getRecieverInfo(int iMessageID)
{
String strSQL = "Select a.RecieveUserID,c.Name as RecievePersonName from " + TableName + " as a left outer join UserInfo as b on (b.ID=a.RecieveUserID) left outer join PersonnelInfo as c on (b.PersonnelID=c.ID) where a.MessageID="
+ iMessageID;
return SQLManager.GetResultSet(strSQL);
}
/**
* 删除和指定ID用户相关的指定ID的短信息记录
* @param strMsgIDs 短信息ID字符串
* @param iUserID 用户ID
*/
public static void delMsgByIDs(String strMsgIDs, int iUserID)
{
String strSQLString = "Update " + TableName + " Set IsRecieverDel=1 where ID in(" + strMsgIDs
+ ") and RecieveUserID=" + iUserID;
SQLManager.ExcuteSQL(strSQLString);
strSQLString = "Update " + TableName + " Set IsSenderDel=1 where ID in(" + strMsgIDs + ") and SendUserID="
+ iUserID;
SQLManager.ExcuteSQL(strSQLString);
strSQLString = "Delete from ArticleAttInfo where FartherID in (Select ID from " + TableName
+ " where IsSenderDel=1 and IsRecieverDel=1) and FartherTable='" + TableName + "'";
SQLManager.ExcuteSQL(strSQLString);
strSQLString = "Delete from " + TableName + " where IsSenderDel=1 and IsRecieverDel=1";
SQLManager.ExcuteSQL(strSQLString);
}
/**
* 将ID为iMessageID的短信息设置为已读
* @param iMessageID 短信ID
*/
public static void setReaded(int iMessageID)
{
SQLManager.ExcuteSQL("Update " + TableName + " Set IsReaded=1,IsReminded=1 where ID =" + iMessageID);
}
/**
* 将ID为iMessageID的短信息设置为已提醒
* @param iMessageID 短信ID
*/
public static void setIsReminded(int iMessageID)
{
SQLManager.ExcuteSQL("Update " + TableName + " Set IsReminded=1 where ID =" + iMessageID);
}
/**
* 获取指定ID的记录向量集
* @param iMsgID 短信息ID
* @return 指定ID的记录向量集
*/
public static Vector getRecordByID(int iMsgID)
{
Vector vt = SQLManager.GetResultSet("Select * from " + TableName + " where ID=" + iMsgID + "");
return vt;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -