Compare commits

...

2 Commits

Author SHA1 Message Date
Hoshi 4e0f74e2ed Merge branch 'develop' of http://58.210.154.140:8888/iidi/backend/bocloud.sms into develop 2024-11-12 21:23:43 +08:00
Hoshi 756a4370d4 登录接口增加日志 2024-11-12 21:22:41 +08:00
1 changed files with 57 additions and 52 deletions

View File

@ -63,65 +63,70 @@ public class LoginController {
@PostMapping("/users/login") @PostMapping("/users/login")
public GeneralResult<Map<String, Object>> userLogin(@RequestBody LoginModel loginModel, public GeneralResult<Map<String, Object>> userLogin(@RequestBody LoginModel loginModel,
HttpServletRequest request) { HttpServletRequest request) {
log.info("开始执行登录请求"); try {
long start; log.info("开始执行登录请求");
String account = loginModel.getAccount(); long start;
String password = loginModel.getPassword(); String account = loginModel.getAccount();
log.info("开始调用UserService"); String password = loginModel.getPassword();
GeneralResult<Map<String, Object>> loginResult = userService log.info("开始调用UserService");
.login(account, password, request.getSession().getId(), IpTool.getIP(request), loginModel.getIsManager()); GeneralResult<Map<String, Object>> loginResult = userService
log.info("请求方ip地址trx" + trxService.getRequestIpAddress(request)); .login(account, password, request.getSession().getId(), IpTool.getIP(request), loginModel.getIsManager());
log.info("请求方ip地址" + IpTool.getIP(request)); log.info("请求方ip地址trx" + trxService.getRequestIpAddress(request));
log.info("结束调用UserService"); log.info("请求方ip地址" + IpTool.getIP(request));
if (loginResult.isFailed()) { log.info("结束调用UserService");
if (null == loginResult.getData()) { if (loginResult.isFailed()) {
String path = "Login_" + account; if (null == loginResult.getData()) {
try (com.megatron.framework.lock.AutoCloseLock lock = lockFactory.getACLock(path)) { String path = "Login_" + account;
Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时"); try (com.megatron.framework.lock.AutoCloseLock lock = lockFactory.getACLock(path)) {
start = System.currentTimeMillis(); Assert.isTrue(lock.acquire(10, TimeUnit.SECONDS), "请求超时");
String value = redisTemplate.opsForValue().get(RequestContext.Catalog.User.name() + account);
log.info("查询Redis耗时{}ms", System.currentTimeMillis() - start);
SystemConfig errorNumber = systemConfigRepository.queryByCode("pwdErrorNumber");
int error = Integer.parseInt(errorNumber.getValue());
if (!StringUtils.hasText(value)) {
//密码操作失败
start = System.currentTimeMillis(); start = System.currentTimeMillis();
redisTemplate.opsForValue() String value = redisTemplate.opsForValue().get(RequestContext.Catalog.User.name() + account);
.set(RequestContext.Catalog.User.name() + account, String.valueOf(1), 60, TimeUnit.SECONDS); log.info("查询Redis耗时{}ms", System.currentTimeMillis() - start);
log.info("写入Redis耗时{}ms", System.currentTimeMillis() - start); SystemConfig errorNumber = systemConfigRepository.queryByCode("pwdErrorNumber");
loginResult = new GeneralResult<>(false, loginResult.getMessage() + "已操作【1】次"); int error = Integer.parseInt(errorNumber.getValue());
} else if (Integer.parseInt(value) >= error) { if (!StringUtils.hasText(value)) {
Result lockResult = userService.lockByAccount(account); //密码操作失败
boolean success = lockResult.isSuccess(); start = System.currentTimeMillis();
start = System.currentTimeMillis(); redisTemplate.opsForValue()
redisTemplate.delete(RequestContext.Catalog.User.name() + account); .set(RequestContext.Catalog.User.name() + account, String.valueOf(1), 60, TimeUnit.SECONDS);
log.info("删除Redis耗时{}ms", System.currentTimeMillis() - start); log.info("写入Redis耗时{}ms", System.currentTimeMillis() - start);
if (success) { loginResult = new GeneralResult<>(false, loginResult.getMessage() + "已操作【1】次");
loginResult = new GeneralResult<>(false, "账号或者密码错误已达【" + error + "】次,若用户存在将被冻结,请联系管理员解冻"); } else if (Integer.parseInt(value) >= error) {
Result lockResult = userService.lockByAccount(account);
boolean success = lockResult.isSuccess();
start = System.currentTimeMillis();
redisTemplate.delete(RequestContext.Catalog.User.name() + account);
log.info("删除Redis耗时{}ms", System.currentTimeMillis() - start);
if (success) {
loginResult = new GeneralResult<>(false, "账号或者密码错误已达【" + error + "】次,若用户存在将被冻结,请联系管理员解冻");
} else {
loginResult = new GeneralResult<>(false, "认证服务账号缓存存在问题");
}
} else { } else {
loginResult = new GeneralResult<>(false, "认证服务账号缓存存在问题"); start = System.currentTimeMillis();
redisTemplate.boundValueOps(RequestContext.Catalog.User.name() + account).increment(1L);
log.info("写入Redis耗时{}ms", System.currentTimeMillis() - start);
String num = redisTemplate.opsForValue().get(RequestContext.Catalog.User.name() + account);
loginResult = new GeneralResult<>(false, loginResult.getMessage() + ",已操作【" + num + "】次");
} }
} else { log.info("登录请求处理完成");
start = System.currentTimeMillis(); return loginResult;
redisTemplate.boundValueOps(RequestContext.Catalog.User.name() + account).increment(1L); } catch (Exception e) {
log.info("写入Redis耗时{}ms", System.currentTimeMillis() - start); log.error("Get login error message", e);
String num = redisTemplate.opsForValue().get(RequestContext.Catalog.User.name() + account); log.info("登录请求处理完成");
loginResult = new GeneralResult<>(false, loginResult.getMessage() + ",已操作【" + num + "】次"); return loginResult;
} }
log.info("登录请求处理完成");
return loginResult;
} catch (Exception e) {
log.error("Get login error message", e);
log.info("登录请求处理完成");
return loginResult;
} }
} }
start = System.currentTimeMillis();
redisTemplate.delete(RequestContext.Catalog.User.name() + account);
log.info("删除Redis耗时{}ms", System.currentTimeMillis() - start);
log.info("登录请求处理完成");
return loginResult;
}catch (Exception e){
log.error("登录异常",e);
return new GeneralResult<>(false,"登录异常:" + e.getMessage());
} }
start = System.currentTimeMillis();
redisTemplate.delete(RequestContext.Catalog.User.name() + account);
log.info("删除Redis耗时{}ms", System.currentTimeMillis() - start);
log.info("登录请求处理完成");
return loginResult;
} }
/** /**