Commit b937cef6 by weisong

add log

parent 693c0e52
package com.cnooc.expert.auth.service; package com.cnooc.expert.auth.service;
import com.cnooc.expert.system.entity.pojo.ZhuanJiaUser;
import com.cnooc.expert.system.entity.vo.LoginVO; import com.cnooc.expert.system.entity.vo.LoginVO;
import com.cnooc.expert.system.entity.vo.VerifyCodeVO; import com.cnooc.expert.system.entity.vo.VerifyCodeVO;
public interface LoginService { public interface LoginService {
/**
* 登录,兼容短信登录和密码登录
* @param loginVO
* @return
*/
String login(LoginVO loginVO); String login(LoginVO loginVO);
/**
* 发送短信验证码
* @param vo
* @return
*/
String sendPhoneCode(LoginVO vo); String sendPhoneCode(LoginVO vo);
/**
* 修改密码
* @param loginVO
* @return
*/
String changePass(LoginVO loginVO); String changePass(LoginVO loginVO);
/**
* 验证码验证接口
* @param codeVO
* @return
*/
String verifyCode(VerifyCodeVO codeVO); String verifyCode(VerifyCodeVO codeVO);
/**
* 根据token查询专家基础信息
* @param token
* @return
*/
ZhuanJiaUser getZhuanJiaUserByToken(String token);
} }
...@@ -21,12 +21,11 @@ import com.cnooc.expert.auth.service.SysCaptchaService; ...@@ -21,12 +21,11 @@ import com.cnooc.expert.auth.service.SysCaptchaService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.Duration; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -234,17 +233,6 @@ public class LoginServiceImpl implements LoginService { ...@@ -234,17 +233,6 @@ public class LoginServiceImpl implements LoginService {
return token; return token;
} }
// /**
// * 缓存存入token
// * @param token token
// * @param uuidKey uuidKey
// */
// private void tokenSetRedis(String token, String uuidKey) {
// String redisTokenKey = TokenConstants.TOKEN_KEY_ + uuidKey;
// redisTemplate.opsForValue().set(redisTokenKey, token, Duration.ofHours(24));
// }
private ZhuanJiaUser convert2ZhuanjiaUser(ExpertInfoResp expertInfoResp){ private ZhuanJiaUser convert2ZhuanjiaUser(ExpertInfoResp expertInfoResp){
if( expertInfoResp == null ){ if( expertInfoResp == null ){
return null; return null;
...@@ -260,7 +248,24 @@ public class LoginServiceImpl implements LoginService { ...@@ -260,7 +248,24 @@ public class LoginServiceImpl implements LoginService {
zhuanJiaUser.setZhuanJiaName(expertInfoResp.getZhuanJiaName()); zhuanJiaUser.setZhuanJiaName(expertInfoResp.getZhuanJiaName());
zhuanJiaUser.setZhuanJiaShiXiangGuid(expertInfoResp.getZhuanJiaShiXiangGuid()); zhuanJiaUser.setZhuanJiaShiXiangGuid(expertInfoResp.getZhuanJiaShiXiangGuid());
zhuanJiaUser.setZhuanJiaZhuangTai(expertInfoResp.getZhuanJiaZhuangTai()); zhuanJiaUser.setZhuanJiaZhuangTai(expertInfoResp.getZhuanJiaZhuangTai());
zhuanJiaUser.setAdAccount(expertInfoResp.getAdAccount());
return zhuanJiaUser; return zhuanJiaUser;
} }
@Override
public ZhuanJiaUser getZhuanJiaUserByToken(String token){
try {
Map<String, String> userMap = JwtUtils.getTokenInfo(token);
String userId = userMap.get(TokenConstants.USER_ID);
ZhuanJiaUser zhuanjiaUser = (ZhuanJiaUser)redisTemplate.opsForValue().get(TokenConstants.LOGIN_USER_KEY_ + userId);
if(zhuanjiaUser!=null) {
UserUtils.setUserId(zhuanjiaUser);
}
return zhuanjiaUser;
} catch (Exception e) {
log.info("token解析异常 {}",e.getMessage(),e);
return null;
}
}
} }
...@@ -35,6 +35,8 @@ public class ZhuanJiaUser { ...@@ -35,6 +35,8 @@ public class ZhuanJiaUser {
private String suoShuBuMeng;//所在部门 private String suoShuBuMeng;//所在部门
private String adAccount;
} }
package com.cnooc.expert.system.operatelog.aspect; package com.cnooc.expert.system.operatelog.aspect;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.cnooc.expert.common.utils.KafkaProducerUtil;
import com.cnooc.expert.common.utils.UserUtils;
import com.cnooc.expert.system.entity.pojo.ZhuanJiaUser;
import com.cnooc.expert.system.operatelog.dto.LogBody; import com.cnooc.expert.system.operatelog.dto.LogBody;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint; import org.aspectj.lang.JoinPoint;
...@@ -8,6 +11,8 @@ import org.aspectj.lang.annotation.AfterReturning; ...@@ -8,6 +11,8 @@ import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order; import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestAttributes;
...@@ -25,6 +30,14 @@ public class LogAspectj { ...@@ -25,6 +30,14 @@ public class LogAspectj {
private static final String EXCEPTION_CODE = "500"; private static final String EXCEPTION_CODE = "500";
private String host=""; private String host="";
@Value("app.info.appId")
private String appId;
@Value("app.info.appName")
private String appName;
@Autowired
private KafkaProducerUtil kafkaProducerUtil;
@Pointcut("execution(* com.cnooc.expert.controller.auth.*.*(..)) ||"+ @Pointcut("execution(* com.cnooc.expert.controller.auth.*.*(..)) ||"+
"execution(* com.cnooc.expert.controller.expert.*.*(..)) || " + "execution(* com.cnooc.expert.controller.expert.*.*(..)) || " +
"execution(* com.cnooc.expert.controller.portal.*.*(..)) || " + "execution(* com.cnooc.expert.controller.portal.*.*(..)) || " +
...@@ -90,9 +103,11 @@ public class LogAspectj { ...@@ -90,9 +103,11 @@ public class LogAspectj {
HttpServletRequest request = sra.getRequest(); HttpServletRequest request = sra.getRequest();
return request; return request;
} }
private String getCurrentUser() { private ZhuanJiaUser getCurrentUser() {
//这里需要添加代码 //这里需要添加代码
return ""; ZhuanJiaUser zhuanJiaUser = UserUtils.getUserId();
System.out.println(zhuanJiaUser);
return zhuanJiaUser;
} }
/** /**
* mysql * mysql
...@@ -105,7 +120,7 @@ public class LogAspectj { ...@@ -105,7 +120,7 @@ public class LogAspectj {
System.out.println("进入sendLog方法========"); System.out.println("进入sendLog方法========");
HttpServletRequest httpServletRequest = getHttpServletRequest(); HttpServletRequest httpServletRequest = getHttpServletRequest();
String method = httpServletRequest.getMethod(); String method = httpServletRequest.getMethod();
String account = getCurrentUser(); ZhuanJiaUser zhuanJiaUser = getCurrentUser();
LogBody logBody = new LogBody(); LogBody logBody = new LogBody();
Enumeration<String> headers = httpServletRequest.getHeaderNames(); Enumeration<String> headers = httpServletRequest.getHeaderNames();
...@@ -125,9 +140,28 @@ public class LogAspectj { ...@@ -125,9 +140,28 @@ public class LogAspectj {
}else { }else {
logBody.setResponseContent(JSON.toJSONString(returnValue)); logBody.setResponseContent(JSON.toJSONString(returnValue));
} }
logBody.setAppId(appId);
logBody.setAppName(appName);
// 用户id
logBody.setUserId(zhuanJiaUser.getZhuanJiaGuid());
// 用户account
logBody.setAccount(zhuanJiaUser.getAdAccount());
// 部门id
// logBody.setDomainId();
// 部门名称
logBody.setDomainName(zhuanJiaUser.getSuoShuBuMeng());
// logBody.setRole();
logBody.setRequestPath(httpServletRequest.getRequestURI());
String uuidKey = UUID.randomUUID().toString();
logBody.setOperateRecordId(uuidKey);
System.out.println("logBody对象信息如下========="); System.out.println("logBody对象信息如下=========");
System.out.println(logBody); System.out.println(logBody);
//将数据发送到kafka,这里需要加代码逻辑 //将数据发送到kafka,这里需要加代码逻辑
// Kafka默认异步发送(Topic、key需要提供,如果有key的话这样写:kafkaProducerUtil.sendMessage("test-topic(topic值)", "key的值",logBody); )
kafkaProducerUtil.sendMessage("test-topic", logBody);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -38,10 +38,10 @@ spring: ...@@ -38,10 +38,10 @@ spring:
linger-ms: 1 linger-ms: 1
buffer-memory: 33554432 buffer-memory: 33554432
app:
info:
appId: 10000
appName: 海油小程序
server: server:
port: 9090 port: 9090
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment