fix:新增平台库数据源
feat:新增账密登录接口
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.cool.store.aspect;
|
||||
|
||||
import com.cool.store.annotation.PlatformDB;
|
||||
import com.cool.store.datasource.DataSourceContextHolder;
|
||||
import org.aspectj.lang.annotation.After;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 数据源切换 切面
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/4
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class DataSourceAspect {
|
||||
|
||||
@Before("@annotation(platformDB)")
|
||||
public void before(PlatformDB platformDB) {
|
||||
DataSourceContextHolder.setDataSourceType("platform");
|
||||
}
|
||||
|
||||
@After("@annotation(platformDB)")
|
||||
public void after(PlatformDB platformDB) {
|
||||
DataSourceContextHolder.clearDataSourceType();
|
||||
}
|
||||
|
||||
@AfterThrowing("@annotation(platformDB)")
|
||||
public void afterThrowing(PlatformDB platformDB) {
|
||||
DataSourceContextHolder.clearDataSourceType();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.cool.store.service.login;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cool.store.constants.RedisConstant;
|
||||
import com.cool.store.dao.EnterpriseUserDAO;
|
||||
import com.cool.store.dto.login.UserLoginDTO;
|
||||
import com.cool.store.entity.EnterpriseUserDO;
|
||||
import com.cool.store.entity.login.UserLoginDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.EnterpriseService;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.utils.poi.constant.Constants;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录基础服务类
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/3
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class LoginBaseService implements LoginStrategy {
|
||||
@Resource
|
||||
private RedisUtilPool redisUtilPool;
|
||||
@Resource
|
||||
private EnterpriseUserDAO enterpriseUserDAO;
|
||||
@Resource
|
||||
private EnterpriseService enterpriseService;
|
||||
|
||||
/**
|
||||
* 策略登录实现方法
|
||||
*/
|
||||
public abstract ResponseResult userLogin(UserLoginDTO param, UserLoginDO userLoginDO);
|
||||
|
||||
@Override
|
||||
public ResponseResult login(UserLoginDTO param) {
|
||||
log.info("login:{}", JSONObject.toJSONString(param));
|
||||
String errorPasswordCountKey = MessageFormat.format(RedisConstant.ERROR_PASSWORD_COUNT_KEY, LocalDate.now(), param.getMobile());
|
||||
String errorCount = redisUtilPool.getString(errorPasswordCountKey);
|
||||
//判断密码错误次数
|
||||
if (StringUtils.isNotBlank(errorCount)) {
|
||||
if (Integer.parseInt(errorCount) >= Constants.MAX_ERROR_PASSWORD_COUNT) {
|
||||
return ResponseResult.fail(ErrorCodeEnum.PASSWORD_ERROR_MAX_COUNT, errorCount);
|
||||
}
|
||||
}
|
||||
EnterpriseUserDO enterpriseUserDO = enterpriseUserDAO.selectByMobile(param.getMobile());
|
||||
UserLoginDO userLoginDO = enterpriseUserDAO.getUserLoginByUnionid(enterpriseUserDO.getUnionid());
|
||||
return userLogin(param, userLoginDO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取登录accessToken
|
||||
*
|
||||
* @param userLoginDO 用户登录信息
|
||||
* @return accessToken
|
||||
*/
|
||||
public String getAccessToken(UserLoginDO userLoginDO) {
|
||||
return enterpriseService.getAccessToken(userLoginDO.getMobile());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.cool.store.service.login;
|
||||
|
||||
import com.cool.store.dto.login.UserLoginDTO;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 登录策略
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/3
|
||||
*/
|
||||
public interface LoginStrategy {
|
||||
/**
|
||||
* 登录基础方法
|
||||
* @param param
|
||||
* @return
|
||||
*/
|
||||
ResponseResult login(UserLoginDTO param);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.cool.store.service.login.impl;
|
||||
|
||||
import com.aliyun.core.utils.StringUtils;
|
||||
import com.cool.store.constants.RedisConstant;
|
||||
import com.cool.store.dto.login.UserLoginDTO;
|
||||
import com.cool.store.entity.login.UserLoginDO;
|
||||
import com.cool.store.enums.ErrorCodeEnum;
|
||||
import com.cool.store.response.ResponseResult;
|
||||
import com.cool.store.service.login.LoginBaseService;
|
||||
import com.cool.store.utils.Md5Utils;
|
||||
import com.cool.store.utils.RedisUtilPool;
|
||||
import com.cool.store.utils.poi.constant.Constants;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 密码登录服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author wangff
|
||||
* @since 2025/9/4
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class PasswordLoginServiceImpl extends LoginBaseService {
|
||||
private final RedisUtilPool redisUtilPool;
|
||||
|
||||
@Override
|
||||
public ResponseResult userLogin(UserLoginDTO param, UserLoginDO userLoginDO) {
|
||||
if (StringUtils.isBlank(param.getPassword())) {
|
||||
return ResponseResult.fail(ErrorCodeEnum.PASSWORD_MISSING);
|
||||
}
|
||||
if (StringUtils.isBlank(userLoginDO.getPassword())) {
|
||||
return ResponseResult.fail(ErrorCodeEnum.IMPROVE_USER_INFO);
|
||||
}
|
||||
String password = Md5Utils.md5(param.getPassword() + Constants.USER_AUTH_KEY);
|
||||
if (!password.equals(userLoginDO.getPassword())) {
|
||||
String errorPasswordCountKey = MessageFormat.format(RedisConstant.ERROR_PASSWORD_COUNT_KEY, LocalDate.now(), param.getMobile());
|
||||
Long errorNum = redisUtilPool.incrby(errorPasswordCountKey, 1);
|
||||
redisUtilPool.expire(errorPasswordCountKey, 24 * 60 * 60);
|
||||
if(errorNum == 1){
|
||||
return ResponseResult.fail(ErrorCodeEnum.PASSWORD_ERROR);
|
||||
}
|
||||
return ResponseResult.fail(ErrorCodeEnum.PASSWORD_ERROR_MULTI, errorNum.toString());
|
||||
}
|
||||
return ResponseResult.success(getAccessToken(userLoginDO));
|
||||
}
|
||||
}
|
||||
@@ -220,6 +220,13 @@ public class Constants
|
||||
|
||||
public static final String WANG_LEI_JOB_NUMBER = "19060164";
|
||||
|
||||
/**
|
||||
* 密码最大错误次数
|
||||
*/
|
||||
public static final int MAX_ERROR_PASSWORD_COUNT = 5;
|
||||
|
||||
|
||||
/**
|
||||
* 用户密码
|
||||
*/
|
||||
public static final String USER_AUTH_KEY = "user_auth_key";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user