fix:新增平台库数据源
feat:新增账密登录接口
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package com.cool.store.annotation;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 平台库数据源
|
||||||
|
*/
|
||||||
|
@Target({ElementType.METHOD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface PlatformDB {
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.cool.store.datasource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 数据源上下文
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/4
|
||||||
|
*/
|
||||||
|
public class DataSourceContextHolder {
|
||||||
|
private static final ThreadLocal<String> contextHolder = new ThreadLocal<>();
|
||||||
|
|
||||||
|
public static void setDataSourceType(String dataSourceType) {
|
||||||
|
contextHolder.set(dataSourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getDataSourceType() {
|
||||||
|
return contextHolder.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void clearDataSourceType() {
|
||||||
|
contextHolder.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
package com.cool.store.datasource;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Primary;
|
||||||
|
import org.springframework.jdbc.datasource.AbstractDataSource;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.Connection;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 动态数据源
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/4
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Primary
|
||||||
|
public class DynamicDataSource extends AbstractDataSource {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataSource defaultDataSource;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DataSource platformDataSource;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConnection() throws SQLException {
|
||||||
|
DataSource currentDB = getCurrentDB();
|
||||||
|
return currentDB.getConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Connection getConnection(String username, String password) throws SQLException {
|
||||||
|
DataSource currentDB = getCurrentDB();
|
||||||
|
Connection connection = currentDB.getConnection(username, password);
|
||||||
|
connection.setCatalog(DataSourceContextHolder.getDataSourceType());
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected DataSource getCurrentDB() {
|
||||||
|
String dbName = DataSourceContextHolder.getDataSourceType();
|
||||||
|
if (StringUtils.isBlank(dbName)) {
|
||||||
|
return defaultDataSource;
|
||||||
|
}
|
||||||
|
return platformDataSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -62,6 +62,11 @@ public enum ErrorCodeEnum {
|
|||||||
DATA_CONVERT_ERROR(400002, "日期转换异常!", null),
|
DATA_CONVERT_ERROR(400002, "日期转换异常!", null),
|
||||||
PARENT_NODE_NOT_EXIST(400002, "父节点不存在", null),
|
PARENT_NODE_NOT_EXIST(400002, "父节点不存在", null),
|
||||||
LOGIN_ERROR_MOBILE_ERROR(418, "登录失败 获取手机号失败!!", null),
|
LOGIN_ERROR_MOBILE_ERROR(418, "登录失败 获取手机号失败!!", null),
|
||||||
|
PASSWORD_ERROR_MAX_COUNT(1021084, "密码错误{0}次,今日账号已锁定",null),
|
||||||
|
PASSWORD_MISSING(1021085, "密码不能为空!",null),
|
||||||
|
IMPROVE_USER_INFO(1021086,"请联系管理员,完善用户信息!",null),
|
||||||
|
PASSWORD_ERROR(1021087, "密码输入错误",null),
|
||||||
|
PASSWORD_ERROR_MULTI(1021088, "密码错误{0}次,请使用验证码登录",null),
|
||||||
//红圈通
|
//红圈通
|
||||||
HQT_SHOP_DECORATION_ATTRIBUTES(1022000, "获取红圈通装修属性错误", null),
|
HQT_SHOP_DECORATION_ATTRIBUTES(1022000, "获取红圈通装修属性错误", null),
|
||||||
HQT_PARAMS_ERROR(1022001, "构建红圈通请求参数错误", null),
|
HQT_PARAMS_ERROR(1022001, "构建红圈通请求参数错误", null),
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.cool.store.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 登录类型 枚举类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/4
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum LoginTypeEnum {
|
||||||
|
|
||||||
|
PASSWORD("账号密码", "passwordLoginServiceImpl"),
|
||||||
|
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String message;
|
||||||
|
|
||||||
|
private final String clazzName;
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.cool.store.utils;
|
||||||
|
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* bean转换工具
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/3/6
|
||||||
|
*/
|
||||||
|
public class BeanUtil extends cn.hutool.core.bean.BeanUtil {
|
||||||
|
|
||||||
|
public static <T, R> List<R> toList(List<T> list, Class<R> clazz) {
|
||||||
|
if (list == null || list.isEmpty()) {
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
List<R> result = new ArrayList<>(list.size());
|
||||||
|
for (T t : list) {
|
||||||
|
R r = toBean(t, clazz);
|
||||||
|
result.add(r);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T, R> PageInfo<R> toPage(PageInfo<T> page, Class<R> clazz) {
|
||||||
|
PageInfo<R> newPage = new PageInfo<>();
|
||||||
|
newPage.setPages(page.getPages());
|
||||||
|
newPage.setTotal(page.getTotal());
|
||||||
|
newPage.setPageNum(page.getPageNum());
|
||||||
|
newPage.setPageSize(page.getPageSize());
|
||||||
|
List<R> list = toList(page.getList(), clazz);
|
||||||
|
newPage.setList(list);
|
||||||
|
return newPage;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.cool.store.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* Spring上下文工具
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/4
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
public class SpringContextUtil implements ApplicationContextAware {
|
||||||
|
private static ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
SpringContextUtil.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取bean
|
||||||
|
* @param name beanName
|
||||||
|
* @param clazz bean类型
|
||||||
|
* @return bean
|
||||||
|
*/
|
||||||
|
public static <T> T getBean(String name, Class<T> clazz) {
|
||||||
|
return applicationContext.getBean(name, clazz);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,8 @@ import com.cool.store.constants.CommonConstants;
|
|||||||
import com.cool.store.dto.UserDTO;
|
import com.cool.store.dto.UserDTO;
|
||||||
import com.cool.store.dto.openPreparation.UserNameDTO;
|
import com.cool.store.dto.openPreparation.UserNameDTO;
|
||||||
import com.cool.store.entity.EnterpriseUserDO;
|
import com.cool.store.entity.EnterpriseUserDO;
|
||||||
|
import com.cool.store.entity.login.UserLoginDO;
|
||||||
import com.cool.store.mapper.EnterpriseUserMapper;
|
import com.cool.store.mapper.EnterpriseUserMapper;
|
||||||
import com.cool.store.response.oppty.UserResponse;
|
|
||||||
import com.cool.store.utils.StringUtil;
|
import com.cool.store.utils.StringUtil;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@@ -175,4 +175,13 @@ public class EnterpriseUserDAO {
|
|||||||
}
|
}
|
||||||
return enterpriseUserMapper.searchUserByUserIdsAndKeyword(userIdList, keyword);
|
return enterpriseUserMapper.searchUserByUserIdsAndKeyword(userIdList, keyword);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从平台库根据唯一id获取用户登录信息
|
||||||
|
* @param unionid 唯一id
|
||||||
|
* @return 用户登录信息
|
||||||
|
*/
|
||||||
|
public UserLoginDO getUserLoginByUnionid(String unionid) {
|
||||||
|
return enterpriseUserMapper.getUserLoginByUnionid(unionid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
package com.cool.store.mapper;
|
package com.cool.store.mapper;
|
||||||
|
|
||||||
|
import com.cool.store.annotation.PlatformDB;
|
||||||
import com.cool.store.dto.UserDTO;
|
import com.cool.store.dto.UserDTO;
|
||||||
import com.cool.store.dto.openPreparation.UserNameDTO;
|
import com.cool.store.dto.openPreparation.UserNameDTO;
|
||||||
import com.cool.store.entity.EnterpriseUserDO;
|
import com.cool.store.entity.EnterpriseUserDO;
|
||||||
|
import com.cool.store.entity.login.UserLoginDO;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Param;
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
|
||||||
@@ -103,4 +105,12 @@ public interface EnterpriseUserMapper {
|
|||||||
List<EnterpriseUserDO> searchUserByUserIdsAndKeyword( @Param("userIdList") List<String> userIdList, @Param("keyword") String keyword);
|
List<EnterpriseUserDO> searchUserByUserIdsAndKeyword( @Param("userIdList") List<String> userIdList, @Param("keyword") String keyword);
|
||||||
|
|
||||||
List<String> getUserIdsByRegionIdList( @Param("regionIdList") List<String> regionIdList);
|
List<String> getUserIdsByRegionIdList( @Param("regionIdList") List<String> regionIdList);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从平台库根据唯一id获取用户登录信息
|
||||||
|
* @param unionid 唯一id
|
||||||
|
* @return 用户登录信息
|
||||||
|
*/
|
||||||
|
@PlatformDB
|
||||||
|
UserLoginDO getUserLoginByUnionid(@Param("unionid") String unionid);
|
||||||
}
|
}
|
||||||
@@ -229,4 +229,10 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getUserLoginByUnionid" resultType="com.cool.store.entity.login.UserLoginDO">
|
||||||
|
SELECT user_id, mobile, password
|
||||||
|
FROM enterprise_user
|
||||||
|
WHERE unionid = #{unionid} AND active = true
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.cool.store.dto.login;
|
||||||
|
|
||||||
|
import com.cool.store.enums.LoginTypeEnum;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 登录DTO
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/3
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserLoginDTO {
|
||||||
|
@ApiModelProperty("手机号")
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
@ApiModelProperty("密码")
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
@NotNull(message = "登录类型不能为空")
|
||||||
|
private LoginTypeEnum loginType;
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.cool.store.entity.login;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户登录信息
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/3
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class UserLoginDO {
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private String userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 手机号
|
||||||
|
*/
|
||||||
|
private String mobile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 密码
|
||||||
|
*/
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package com.cool.store.vo.login;
|
||||||
|
|
||||||
|
import com.cool.store.vo.point.UserBaseInfoVO;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 用户登录VO
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/4
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserLoginVO {
|
||||||
|
/**
|
||||||
|
* 登录token
|
||||||
|
*/
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 刷新token
|
||||||
|
*/
|
||||||
|
private String refreshToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否需要完善用户信息
|
||||||
|
*/
|
||||||
|
private Boolean isNeedImproveUserInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户信息
|
||||||
|
*/
|
||||||
|
private UserBaseInfoVO userInfo;
|
||||||
|
}
|
||||||
@@ -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 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";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,4 +40,16 @@ public class PartnerWebApplication {
|
|||||||
return defaultDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
|
return defaultDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("platform.datasource")
|
||||||
|
public DataSourceProperties platformDataSourceProperties() {
|
||||||
|
return new DataSourceProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("spring.datasource.hikari")
|
||||||
|
public DataSource platformDataSource() {
|
||||||
|
return platformDataSourceProperties().initializeDataSourceBuilder().type(HikariDataSource.class).build();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ public class SignValidateFilter implements Filter {
|
|||||||
"/zxjp/mini/program/v1/partnerManage/openArea/areaApplyQuery",
|
"/zxjp/mini/program/v1/partnerManage/openArea/areaApplyQuery",
|
||||||
"/zxjp/**/api/audit/result",
|
"/zxjp/**/api/audit/result",
|
||||||
"/zxjp/**/api/license",
|
"/zxjp/**/api/license",
|
||||||
"/zxjp/mini/line/getRegionPayPic"
|
"/zxjp/mini/line/getRegionPayPic",
|
||||||
|
"/zxjp/v3/login/accountLogin"
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ public class TokenValidateFilter implements Filter {
|
|||||||
"/zxjp/pc/sysRole/**",
|
"/zxjp/pc/sysRole/**",
|
||||||
"/zxjp/**/api/audit/result",
|
"/zxjp/**/api/audit/result",
|
||||||
"/zxjp/pc/video/**",
|
"/zxjp/pc/video/**",
|
||||||
"/zxjp/**/api/license"
|
"/zxjp/**/api/license",
|
||||||
|
"/zxjp/v3/login/accountLogin"
|
||||||
|
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.cool.store.controller.webb;
|
||||||
|
|
||||||
|
import com.cool.store.dto.login.UserLoginDTO;
|
||||||
|
import com.cool.store.response.ResponseResult;
|
||||||
|
import com.cool.store.service.login.LoginStrategy;
|
||||||
|
import com.cool.store.utils.SpringContextUtil;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 登录 前端控制器
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author wangff
|
||||||
|
* @since 2025/9/4
|
||||||
|
*/
|
||||||
|
@Api(tags = "登录")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/v3/login")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class LoginController {
|
||||||
|
|
||||||
|
@ApiOperation("账号密码登录")
|
||||||
|
@PostMapping("/accountLogin")
|
||||||
|
public ResponseResult accountLogin(@RequestBody UserLoginDTO param) {
|
||||||
|
return SpringContextUtil.getBean(param.getLoginType().getClazzName(), LoginStrategy.class).login(param);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,10 @@ default.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3
|
|||||||
default.datasource.username=coolstore
|
default.datasource.username=coolstore
|
||||||
default.datasource.password=CSCErYcXniNYm7bT
|
default.datasource.password=CSCErYcXniNYm7bT
|
||||||
|
|
||||||
|
platform.datasource.url=jdbc:mysql://dingpushcoolcollege.mysql.rds.aliyuncs.com:3306/coolcollege_intelligent_config?useSSL=false&useUnicode=true&characterEncoding=utf8&allowMultiQueries=true&autoReconnect=true
|
||||||
|
platform.datasource.username=coolstore
|
||||||
|
platform.datasource.password=CSCErYcXniNYm7bT
|
||||||
|
|
||||||
#redis
|
#redis
|
||||||
redis.host.uri=http://userInfo:Cx111111@tstore-coolcollege-open.redis.rds.aliyuncs.com:6379/0
|
redis.host.uri=http://userInfo:Cx111111@tstore-coolcollege-open.redis.rds.aliyuncs.com:6379/0
|
||||||
|
|
||||||
@@ -133,3 +137,8 @@ special.user.id=wpayJeDAAAhGIFgUJpJN-zg39JuNbYhg_woayJeDAAA0TC8mkCJeXouw94hYA-D3
|
|||||||
|
|
||||||
ask.bot.url=https://test.auth.wx.askbot.cn
|
ask.bot.url=https://test.auth.wx.askbot.cn
|
||||||
|
|
||||||
|
hqt.token.url=https://tc.cloud.hecom.cn
|
||||||
|
hqt.token.username=18161486722
|
||||||
|
hqt.token.grant_type=client_credentials
|
||||||
|
hqt.token.client.id=WrPffdGpcWkcPsbN
|
||||||
|
hqt.token.client.secret=rYe9Cwug5LwQNIBJAiW0a7weF9CAhYCD
|
||||||
Reference in New Issue
Block a user