|

楼主 |
发表于 2018-12-19 13:51:06
|
显示全部楼层
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import java.util.Iterator;
import javax.lang.model.type.IntersectionType;
import com.justep.model.Action;
import com.justep.system.action.Interceptor;
import com.justep.system.context.ActionContext;
import com.justep.system.context.ContextHelper;
import com.justep.system.data.KSQL;
import com.justep.system.data.Row;
import com.justep.system.data.SQL;
import com.justep.system.data.Table;
import com.justep.system.interceptor.LogAfter;
import com.justep.system.interceptor.LogBefore;
import com.justep.util.JustepConfig;
import com.justep.util.Utils;
public class LogAfter2 implements Interceptor {
public void execute() {
try {
System.out.println("进入到日志修改器+LogAfter2");
// 获取当作之前的action
ActionContext context = ContextHelper.getActionContext();
Action action = context.getAction();
/* String serverIp= getServerIp();*/
String serverName= java.net.InetAddress.getLocalHost().getHostName();
String serverIp=java.net.InetAddress.getLocalHost().getHostAddress();
System.out.println("服务器ip是"+serverIp+" 服务器名字:"+serverName);
System.out.println(JustepConfig.getHome());
/* //通过用户名查询用户id
String personSql="select P.* from SA_OPPerson P where scode='system2'";
Table table=SQL.select(personSql, null, "/system/data", null);
Iterator<Row> iterator = table.iterator();
Row row1 = null;
String sid=null;
while (iterator.hasNext()){
row1 = iterator.next();
sid=row1.getString("SID");
System.out.println("sid的值:"+sid);
}
*/
//判断是否具有启用日志的标识
if(action.isLogEnabled()){
System.out.println("具有启用日志的标识");
String id=(String)context.get(LogBefore.ACTION_LOG_SID);
System.out.println("id的值:"+id);
if(Utils.isNotEmptyString(id)){
/* String sql = "update SA_Log log set log.sESField01 = '自己的日志数据' where log='" + id + "'";
KSQL.executeUpdate(sql, null, "/system/data", null);*/
}
}
// 判断action是否有启用日志的标识
/* if (action.isLogEnabled()) {
// 获取平台的默认生成的日志记录的id
String id = (String) context.get(LogBefore.ACTION_LOG_SID);
if (Utils.isNotEmptyString(id)) {
// 通过平台的日志id修改这条记录中扩展自己的值,如果是自己的表,可以写自己对应的insert语句等
String sql = "update SA_Log log set log.sESField01 = '自己的日志数据' where log='" + id + "'";
KSQL.executeUpdate(sql, null, "/system/data", null);
}
}
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取服务器IP地址
* @return
*/
@SuppressWarnings("unchecked")
public static String getServerIp(){
String SERVER_IP = null;
try {
Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
InetAddress ip = null;
while (netInterfaces.hasMoreElements()) {
NetworkInterface ni = (NetworkInterface) netInterfaces.nextElement();
ip = (InetAddress) ni.getInetAddresses().nextElement();
SERVER_IP = ip.getHostAddress();
if (!ip.isSiteLocalAddress() && !ip.isLoopbackAddress()
&& ip.getHostAddress().indexOf(":") == -1) {
SERVER_IP = ip.getHostAddress();
break;
} else {
ip = null;
}
}
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SERVER_IP;
}
}
//这是我定义的一个拦截器,一般拿服务器ip和名字需要request对象的吧,reques对象怎么拿呢
我写的那两个应该获取的是本机ip和名字 |
|