1.调整 controller 位置
2.添加日志拦截
This commit is contained in:
4
pom.xml
4
pom.xml
@@ -61,6 +61,10 @@
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-aop</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ResponseData<T> implements Serializable {
|
||||
|
||||
// 返回错误的方法
|
||||
public static ResponseData<Object> error(int code,String message) {
|
||||
return new ResponseData<>(code, message);
|
||||
return new ResponseData<>(code, null,message);
|
||||
}
|
||||
|
||||
public static ResponseData<Object> error(ErrorCode errorCode) {
|
||||
|
||||
@@ -127,7 +127,6 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserModel> implements
|
||||
|
||||
@Override
|
||||
public UserModelVO addUserWithMail(UserModelDTO userModelDTO) {
|
||||
|
||||
LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
lambdaQueryWrapper.eq(UserModel::getEmail,userModelDTO.getEmail());
|
||||
UserModel userModel = userDao.selectOne(lambdaQueryWrapper);
|
||||
@@ -156,9 +155,12 @@ public class UserServiceImpl extends ServiceImpl<UserDao, UserModel> implements
|
||||
userDao.updateById(oldUser);
|
||||
}
|
||||
UserModelVO userModelVO = BeanUtil.copyProperties(userModelEntity, UserModelVO.class);
|
||||
StpUtil.login(userModelVO.getId());
|
||||
userModelVO.setToken(StpUtil.getTokenValue());
|
||||
userModelVO.setHavaPassword(true);
|
||||
userModelVO.setNewAccount(true);
|
||||
userModelVO.setChatInfo(wxChatParam);
|
||||
log.info("用户{}注册,邮箱{},手机号{}",userModelVO.getId(),userModelVO.getEmail(),userModelVO.getPhoneNumber());
|
||||
return userModelVO;
|
||||
}
|
||||
|
||||
|
||||
55
src/main/java/vvpkassistant/aop/LogInterceptor.java
Normal file
55
src/main/java/vvpkassistant/aop/LogInterceptor.java
Normal file
@@ -0,0 +1,55 @@
|
||||
package vvpkassistant.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.context.request.RequestAttributes;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.UUID;
|
||||
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
public class LogInterceptor {
|
||||
|
||||
/**
|
||||
* 执行拦截
|
||||
*/
|
||||
@Around("execution(* vvpkassistant.controller.*.*(..))")
|
||||
public Object doInterceptor(ProceedingJoinPoint point) throws Throwable {
|
||||
// 计时
|
||||
StopWatch stopWatch = new StopWatch();
|
||||
stopWatch.start();
|
||||
// 获取请求路径
|
||||
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
|
||||
HttpServletRequest httpServletRequest = ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||
// 生成请求唯一 id
|
||||
String requestId = UUID.randomUUID().toString();
|
||||
String url = httpServletRequest.getRequestURI();
|
||||
// 获取请求参数
|
||||
Object[] args = point.getArgs();
|
||||
String reqParam = "[" + StringUtils.join(args, ", ") + "]";
|
||||
// 输出请求日志
|
||||
log.info("request start,id: {}, path: {}, ip: {}, params: {}", requestId, url,
|
||||
httpServletRequest.getRemoteHost(), reqParam);
|
||||
// log.info("request start,id: {}, path: {}, ip: {}", requestId, url,
|
||||
// httpServletRequest.getRemoteHost());
|
||||
// 执行原方法
|
||||
Object result = point.proceed();
|
||||
// 输出响应日志
|
||||
stopWatch.stop();
|
||||
long totalTimeMillis = stopWatch.getTotalTimeMillis();
|
||||
log.info("request end, id: {}, cost: {}ms", requestId, totalTimeMillis);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package vvpkassistant.Anchors.controller;
|
||||
package vvpkassistant.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -1,10 +1,9 @@
|
||||
package vvpkassistant.chat.controller;
|
||||
package vvpkassistant.controller;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vvpkassistant.Data.ResponseData;
|
||||
import vvpkassistant.Data.ResponseInfo;
|
||||
import vvpkassistant.chat.mapper.ChatDao;
|
||||
import vvpkassistant.chat.model.ChatModel;
|
||||
import vvpkassistant.common.ErrorCode;
|
||||
@@ -1,4 +1,4 @@
|
||||
package vvpkassistant.file.controller;
|
||||
package vvpkassistant.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -1,8 +1,7 @@
|
||||
package vvpkassistant.FunctionConfig.controller;
|
||||
package vvpkassistant.controller;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vvpkassistant.Data.ResponseData;
|
||||
import vvpkassistant.Data.ResponseInfo;
|
||||
import vvpkassistant.FunctionConfig.mapper.FunctionConfigMapper;
|
||||
import vvpkassistant.FunctionConfig.model.FunctionConfigModel;
|
||||
import vvpkassistant.FunctionConfig.service.FunctionConfigService;
|
||||
@@ -1,14 +1,11 @@
|
||||
package vvpkassistant.pk.controller;
|
||||
package vvpkassistant.controller;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vvpkassistant.CoinRecords.CoinRecords;
|
||||
import vvpkassistant.CoinRecords.CoinRecordsDao;
|
||||
import vvpkassistant.Data.ResponseData;
|
||||
import vvpkassistant.Data.ResponseInfo;
|
||||
import vvpkassistant.config.FunctionConfigHolder;
|
||||
import vvpkassistant.Tools.VVTools;
|
||||
import vvpkassistant.User.mapper.UserDao;
|
||||
import vvpkassistant.User.model.UserModel;
|
||||
import vvpkassistant.pk.mapper.PkInfoDao;
|
||||
import vvpkassistant.pk.mapper.PkRecordDao;
|
||||
import vvpkassistant.pk.mapper.PkRecordDetailDao;
|
||||
@@ -1,4 +1,4 @@
|
||||
package vvpkassistant.SystemMessage.controller;
|
||||
package vvpkassistant.controller;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
@@ -1,7 +1,6 @@
|
||||
package vvpkassistant.User.controller;
|
||||
package vvpkassistant.controller;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.extra.mail.Mail;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import vvpkassistant.CoinRecords.CoinRecords;
|
||||
@@ -10,12 +9,10 @@ import vvpkassistant.Data.ResponseData;
|
||||
import vvpkassistant.Data.ResponseInfo;
|
||||
import vvpkassistant.Data.WxChatParam;
|
||||
import vvpkassistant.User.mapper.UserDao;
|
||||
import vvpkassistant.User.model.DTO.LoginInfoDTO;
|
||||
import vvpkassistant.User.model.DTO.ScanInfoDTO;
|
||||
import vvpkassistant.User.model.DTO.UserModelDTO;
|
||||
import vvpkassistant.User.model.UserModel;
|
||||
import vvpkassistant.User.model.UserModelVO;
|
||||
import vvpkassistant.User.model.enumeration.LoginStatusEnum;
|
||||
import vvpkassistant.User.service.UserService;
|
||||
import vvpkassistant.common.ErrorCode;
|
||||
import vvpkassistant.config.FunctionConfigHolder;
|
||||
@@ -205,8 +202,14 @@ public class UserController {
|
||||
|
||||
// 获取用户信息
|
||||
@PostMapping("getUserInfo")
|
||||
public ResponseData<Object> getUserInfo(@RequestBody Map<String,Integer> map) {
|
||||
UserModel userModel = userDao.selectById(map.get("id"));
|
||||
public ResponseData<Object> getUserInfo(@RequestBody UserModelDTO userModelDTO) {
|
||||
if (userModelDTO.getId() == null){
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
UserModel userModel = userDao.selectById(userModelDTO.getId());
|
||||
if (userModel == null) {
|
||||
throw new BusinessException(ErrorCode.USER_DOES_NOT_EXIST);
|
||||
}
|
||||
UserModelVO userModelVO = BeanUtil.copyProperties(userModel, UserModelVO.class);
|
||||
userModelVO.setHavaPassword(userModel.getPassword() != null);
|
||||
return ResponseData.success(userModelVO);
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.extra.mail.MailUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.ibm.j9ddr.tools.ddrinteractive.IFieldFormatter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
@@ -379,17 +380,25 @@ public class MailServiceImpl implements MailService {
|
||||
|
||||
@Override
|
||||
public Boolean resendMail(MailModel mailModel) {
|
||||
Object ifPresent = emailSendCache.getIfPresent(mailModel.getMailAddress());
|
||||
if (mailModel.getMailAddress() == null && mailModel.getType() == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR);
|
||||
}
|
||||
LambdaQueryWrapper<UserModel> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
UserModel userModel = userDao.selectOne(lambdaQueryWrapper.eq(UserModel::getEmail, mailModel.getMailAddress()));
|
||||
if (userModel == null) {
|
||||
throw new BusinessException(ErrorCode.USER_DOES_NOT_EXIST);
|
||||
}
|
||||
Object ifPresent = emailSendCache.getIfPresent(mailModel.getMailAddress());
|
||||
if (ifPresent == null) {
|
||||
switch (mailModel.getType()) {
|
||||
case 1:
|
||||
sendMail(mailModel.getMailAddress(), mailModel.getUserId());
|
||||
sendMail(mailModel.getMailAddress(), userModel.getId());
|
||||
break;
|
||||
case 2:
|
||||
sendVerificationMail(mailModel.getMailAddress(), mailModel.getUserId());
|
||||
sendVerificationMail(mailModel.getMailAddress(), userModel.getId());
|
||||
break;
|
||||
case 3:
|
||||
sendForgetPassWordMail(mailModel.getMailAddress(), mailModel.getUserId());
|
||||
sendForgetPassWordMail(mailModel.getMailAddress(), userModel.getId());
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user