📄 userlog.java
字号:
/**
* 用户日志管理
*/
package com.NCL;
import java.sql.*;
import java.util.*;
import com.sinosoft.common.*;
public class UserLog{
protected IndexMap propList;
protected HashSet Property;
private List strList = new ArrayList();
protected String fMessageTime = "";
protected String tMessageTime = "";
private boolean EOF = false;
private int COUNT;
public Connection conn = null;
public PreparedStatement pstmt = null;
/**
* 构造函数
*
*/
public UserLog(){
propList = new IndexMap();
Property = new HashSet();
Property.add("ID"); //ID
Property.add("UserID"); //操作者
Property.add("OperationType"); //操作类型
Property.add("OperationObject"); //操作对象
Property.add("OperationContent"); //操作内容
Property.add("MakeDate"); //创建日期
}
/**
* 获取fMessageTime
* @return String
*/
public String getfMessageTime() {
return fMessageTime;
}
/**
* 设置fMessageTime
* @param str 日期
*/
public void setfMessageTime(String str) {
fMessageTime = str;
}
/**
* 获取tMessageTime
* @return String
*/
public String gettMessageTime() {
return tMessageTime;
}
/**
* 设置tMessageTime
* @param str 日期
*/
public void settMessageTime(String str) {
tMessageTime = str;
}
/**
* 在此映射中关联指定值与指定键
* @param name 指定键
* @param value 指定值
*/
public void setUpdateValue(String name,Object value){
if(this.set(name,value)){
Object[] uValue = new Object[2];
uValue[0] = name;
uValue[1] = value;
strList.add(uValue);
}
}
/**
* 在此映射中关联指定值与指定键
* @param name 指定键
* @param value 指定值
*/
public boolean set(String name, Object value){
if(Property.contains(name)){
propList.put(name,value);
return true;
}else
return false;
}
/**
* 返回指定键在此映射中所映射的值
* @param name 指定键
* @return
*/
public String get(String name){
if (Property.contains(name)){
String value = (String)propList.get(name);
if(value != null && !value.equals(""))
return value;
else
return "";
}else
return "";
}
/**
* 返回COUNT
* @return int
*/
public int getCOUNT() {
return COUNT;
}
/**
* 设置COUNT
* @param count
*/
public void setCOUNT(int count) {
COUNT = count;
}
/**
* 返回EOF
* @return boolean
*/
public boolean isEOF() {
return EOF;
}
/**
* 设置EOF
* @param eof
*/
public void setEOF(boolean eof) {
EOF = eof;
}
/**
* 清空propList
*
*/
public void clear(){
propList.clear();
}
/**
* 初始化
* @param id ID
*/
public void init(String id){
DBAccess d = new DBAccess();
String sql = "SELECT * from UserLog where id=?";
this.propList = d.init(sql,id,this.Property);
}
/**
* 创建
* @param UserID 操作者
* @param OperationType 操作类型
* @param OperationObject 操作对象
* @param OperationContent 操作内容
* @return boolean
*/
public boolean create(String UserID,String OperationType,String OperationObject,String OperationContent){
if(!Data.hasValue(UserID) || !Data.hasValue(OperationType) || !Data.hasValue(OperationObject) || !Data.hasValue(OperationContent))return false;
try {
conn = DataConPool.getConnection();
} catch (Exception e) {
System.out.println("UserLog:create() error!" + e.toString());
return false;
}
CallableStatement proc = null;
try {
proc = conn.prepareCall("{?=call GET_USERLOG_ID(?,?,?,?)}");
proc.registerOutParameter(1, Types.INTEGER);
proc.setString(2,UserID);
proc.setString(3,OperationType);
proc.setString(4,OperationObject);
proc.setString(5,OperationContent);
proc.execute();
COUNT = proc.getInt(1);
}catch(Exception ex){
System.out.println(ex.getMessage());
return false;
}finally {
try{
if(proc!=null)proc.close();
if(conn!=null)conn.close();
} catch(SQLException e){
System.out.println(e.getMessage());
return false;
}
}
return true;
}
/**
* 根据条件查询
* @param cm 对象
* @param pageSize 分页大小
* @param pageIndex 分页页码
* @return String
*/
public String find(UserLog cm,int pageSize,int pageIndex){
String UserID = cm.get("UserID");
String OperationType = cm.get("OperationType");
String OperationObject = cm.get("OperationObject");
String fMessageTime = cm.getfMessageTime();
String tMessageTime = cm.gettMessageTime();
if(Data.hasValue(fMessageTime) && fMessageTime.length()!=10)return "";
if(Data.hasValue(tMessageTime) && tMessageTime.length()!=10)return "";
StringBuffer SQL = new StringBuffer("SELECT id from UserLog where 1=1");
//顺序 和 cm.set()的顺序应该对应
if(Data.hasValue(UserID))
SQL.append(" and UserID=?");
if("代理人".equals(OperationType)){
cm.set("OperationType","代理人%");
SQL.append(" and OperationType like ?");
}else if(Data.hasValue(OperationType))
SQL.append(" and OperationType=?");
else SQL.append(" and OperationType in ('注册','登录','查询','保全','咨询留言','找回密码')");
if(Data.hasValue(OperationObject))
SQL.append(" and OperationObject=?");
if(Data.hasValue(fMessageTime))
SQL.append(" and MakeDate>=to_date('" + fMessageTime + "','yyyy-MM-dd')");
if(Data.hasValue(tMessageTime))
SQL.append(" and makeDate<=to_date('" + tMessageTime + " 23:59:59','yyyy-MM-dd hh24:mi:ss')");
SQL.append(" order by MakeDate desc");
String result = "";
DBAccess d = new DBAccess();
result = d.executeQuery(SQL.toString(),cm.propList,pageSize,pageIndex);
setCOUNT(d.COUNT);
setEOF(d.EOF);
return result;
}
/**
* 获取日志报文
* @param ID ID
* @return String
*/
public String getBLOB(String ID){
if(!Data.hasValue(ID))return "";
BlobInfo bb = new BlobInfo();
bb.set("TableID",ID);
bb.set("TableName","UserLog");
String tmp = bb.find(bb, 1, 1);
if(!Data.hasValue(tmp))return "";
WriteAndReadBLOB wb = new WriteAndReadBLOB();
String[] str = wb.readString("BlobInfo", "Content", "ID", tmp);
if(str.length==0)return "";
else return str[0];
}
/**
* 获取报文中pk字段的内容
* @param content 报文
* @param pk 字段
* @return String
*/
public static String getSubstring(String content,String pk){
String result = "";
String tmp1 = "<" + pk + ">";
String tmp2 = "</" + pk + ">";
int first = -1;
int end = -1;
first = content.indexOf(tmp1);
first += tmp1.length();
end = content.indexOf(tmp2);
if(first>-1 && end>-1 && end>first)result = content.substring(first,end);
return result.trim();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -