//package com.pcloud.common.shadow;
//
//import com.pcloud.common.permission.PermissionException;
//import com.pcloud.common.utils.SessionUtil;
//import com.pcloud.common.utils.cache.redis.JedisClusterUtils;
//import com.pcloud.common.utils.nginx.NginxUtils;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.ws.rs.container.ContainerRequestContext;
//import javax.ws.rs.core.Context;
//import javax.ws.rs.core.MultivaluedMap;
//import javax.ws.rs.core.UriInfo;
//import java.io.IOException;
//import java.util.Map;
//
//
///**
// *@author tianchao
// *@desc 统计过滤器
// *@date 2017/10/27
// **/
//public class ShadowFilter implements javax.ws.rs.container.ContainerRequestFilter {
//
//	private static final Logger logger= LoggerFactory.getLogger(ShadowFilter.class);
//	private static final String TOKEN="token";
//	private static final String key = "SHADOW_INSERT_RECORD";
//	@Context
//	private HttpServletRequest servletRequest;
//
//	@Override
//	public void filter(ContainerRequestContext requestContext) throws IOException {
//		logger.info("开始记录请求信息");
//		long startTime = System.currentTimeMillis();
//		final MultivaluedMap<String, String> headers = requestContext.getHeaders();
//		UriInfo uriInfo = requestContext.getUriInfo();
//		String token = headers.getFirst(TOKEN);
//		try {
//			Map<String, Object> map = SessionUtil.getToken4Redis(token);
//			RecordDto operationRecordDto = new RecordDto();
//			operationRecordDto.setPermissionId(0L);
//			operationRecordDto.setRecordType(1);
//			operationRecordDto.setIpAddress(NginxUtils.getClientIp(servletRequest));
//			operationRecordDto.setPath(uriInfo.getPath());
//			operationRecordDto.setPartyId((Long) map.get(SessionUtil.PARTY_ID));
//			operationRecordDto.setPartyRole((String) map.get(SessionUtil.ROLE_CODE));
//			operationRecordDto.setDuration(0L);
//			operationRecordDto.setUserId((Long) map.get(SessionUtil.USER_ID));
//			try {
//				JedisClusterUtils.rpushJson(key, operationRecordDto);
//			} catch (Exception e) {
//				logger.error("记录出错" + e, e.getMessage());
//			}
//			long endTime = System.currentTimeMillis();
//			logger.info("记录完毕，耗时" + (endTime - startTime) + "ms");
//		}catch (PermissionException e){
//			logger.info("无token接口");
//		}
//	}
//}
