package com.vci.web.service.impl;
|
|
import com.vci.corba.common.data.UserEntityInfo;
|
import com.vci.starter.web.pagemodel.SessionInfo;
|
import com.vci.starter.web.util.WebThreadLocalUtil;
|
import com.vci.web.bo.VciLogObjectBO;
|
import com.vci.web.service.WebLogServiceI;
|
import com.vci.web.util.PlatformClientUtil;
|
import com.vci.web.util.WebUtil;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.concurrent.ConcurrentHashMap;
|
|
/**
|
* 日志服务
|
* @author weidy
|
*
|
*/
|
@Service
|
public class WebLogServiceImpl implements WebLogServiceI {
|
|
/**
|
* 日志
|
*/
|
private Logger logger = LoggerFactory.getLogger(getClass());
|
|
private LogThread logThread = null;
|
|
/**
|
* 平台客户端代理类
|
*/
|
@Autowired
|
private PlatformClientUtil platformClientUtil;
|
|
@Override
|
public void addOperateLog(VciLogObjectBO logObject) {
|
//VCIInvocationInfo vcii = WebThreadLocalUtil.getCurrentUserInvocationInfoInThread().get();
|
SessionInfo si = WebThreadLocalUtil.getCurrentUserSessionInfoInThread().get();
|
if(si!=null){
|
logObject.setUserId(si.getUserId());
|
logObject.setUserName(si.getUserName());
|
logObject.setUserOid(si.getUserOid());
|
logObject.setIp(si.getIp());
|
initThread(logObject,si);
|
}else{
|
//说明还没登录,不记录
|
}
|
}
|
|
private void initThread(VciLogObjectBO logObject,SessionInfo si){
|
if(logThread == null){
|
logThread = new LogThread(platformClientUtil);
|
logThread.isOnService=true;
|
logThread.add(logObject,si);
|
logThread.start();
|
}else{
|
logThread.add(logObject,si);
|
}
|
}
|
}
|
|
class LogThread extends Thread{
|
public boolean isOnService = false;
|
private PlatformClientUtil platformClientUtil = null;
|
public LogThread(PlatformClientUtil platformClientUtil){
|
this.platformClientUtil = platformClientUtil;
|
}
|
|
public List<VciLogObjectBO> allLogs = new ArrayList<VciLogObjectBO>();
|
|
public Map<String,SessionInfo> log_userMap = new ConcurrentHashMap<String, SessionInfo>();
|
|
|
public void add(VciLogObjectBO log,SessionInfo si){
|
log.setOid(WebUtil.getPk());
|
allLogs.add(log);
|
log_userMap.put(log.getOid(),si);
|
}
|
@Override
|
public void run() {
|
while(isOnService){
|
while(allLogs.size() >0){
|
VciLogObjectBO log = allLogs.get(0);
|
SessionInfo si = log_userMap.get(log.getOid());
|
UserEntityInfo ue = new UserEntityInfo();
|
ue.modules = log.getModelName();
|
ue.userName = log.getUserId();
|
WebThreadLocalUtil.getCurrentUserSessionInfoInThread().set(si);
|
if(log.isDebug()){
|
log.setDescription(log.getDescription() + "," + log.getController() + "/" + log.getMethod());
|
}
|
// try {
|
// platformClientUtil.getLogonFactoryService().getFrameworkService().savelogGeneralOperation("操作完成",log.getDescription(), ue, "00000000000000000000000000000000000",log.getOperateName());
|
// } catch (VCIError e) {
|
// System.out.println(e.error_code);
|
// }
|
allLogs.remove(log);
|
}
|
try {
|
Thread.sleep(1000);
|
} catch (InterruptedException e) {
|
e.printStackTrace();
|
}
|
}
|
System.out.println("关闭线程了");
|
}
|
}
|