修复了注册和登录时的验证码异常

This commit is contained in:
chen-xin-zhi 2025-05-19 00:16:02 +08:00
parent 69f31ede73
commit 9cb208f5a0
16 changed files with 169 additions and 43 deletions

View File

@ -155,7 +155,8 @@ public class ProjectController {
// 更新项目价格
projectAllDetailVO.setProjectPrice(projectPrice);
// 获取用户申请的推广码列表
List<PromoCodeApply> promoCodeApplyList = commonService.findByFieldEqTargetField(PromoCodeApply::getUserId, userId, promoCodeApplyService);
Map<SFunction<PromoCodeApply, ?>, Object> promoConditions = Map.of(PromoCodeApply::getUserId, userId, PromoCodeApply::getProjectId, id);
List<PromoCodeApply> promoCodeApplyList = commonService.findByFieldEqTargetFields(promoConditions, promoCodeApplyService);
List<PromoCodeApplyVO> promoCodeApplyVOList = commonService.convertList(promoCodeApplyList, PromoCodeApplyVO.class);
// 填充项目详情VO
projectAllDetailVO.setProjectNotificationVOList(projectNotificationVOS);

View File

@ -52,6 +52,24 @@ public class ProjectNotificationController {
@Resource
private ProjectService projectService;
/**
* 小程序端用户根据id查询项目通知详情
* @param commonRequest 项目通知添加请求体
* @return 项目通知详情
*/
@PostMapping("mini/query/id")
@Operation(summary = "小程序端用户根据id查询项目通知详情", description = "参数项目通知id权限小程序用户方法名miniQueryProjectNotificationById")
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
// @SysLog(title = "项目通知管理", content = "小程序端用户根据id查询项目通知详情")
public BaseResponse<ProjectNotificationVO> miniQueryProjectNotificationById(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
ProjectNotification projectNotification = projectNotificationService.getById(id);
ProjectNotificationVO projectNotificationVO = commonService.copyProperties(projectNotification, ProjectNotificationVO.class);
return ResultUtils.success(projectNotificationVO);
}
/**
* web端管理员添加项目通知
* @param projectNotificationAddRequest 项目通知添加请求体

View File

@ -2,6 +2,7 @@ package com.greenorange.promotion.controller.project;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.greenorange.promotion.annotation.RequiresPermission;
import com.greenorange.promotion.annotation.SysLog;
import com.greenorange.promotion.common.BaseResponse;
@ -38,6 +39,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
/**
@ -76,12 +78,18 @@ public class PromoCodeApplyController {
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
// @SysLog(title = "项目管理", content = "小程序用户申请推广码")
public BaseResponse<Boolean> applyPromoCode(@Valid @RequestBody PromoCodeApplyRequest promoCodeApplyRequest, HttpServletRequest request) {
// 获取用户id
Long userId = (Long) request.getAttribute("userId");
// 取出当前项目的推广码
Long projectId = promoCodeApplyRequest.getProjectId();
LambdaQueryWrapper<PromoCode> promoCodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
promoCodeLambdaQueryWrapper.eq(PromoCode::getProjectId, projectId);
promoCodeLambdaQueryWrapper.eq(PromoCode::getPromoCodeStatus, false);
List<PromoCode> promoCodeList = promoCodeService.list(promoCodeLambdaQueryWrapper);
String phoneNumber = promoCodeApplyRequest.getSalespersonPhone();
// 判断是否重复绑定了手机号
Map<SFunction<PromoCodeApply, ?>, Object> applyConditions = Map.of(PromoCodeApply::getUserId, userId, PromoCodeApply::getProjectId, projectId, PromoCodeApply::getSalespersonPhone, phoneNumber);
List<PromoCodeApply> promoCodeApplyList = commonService.findByFieldEqTargetFields(applyConditions, promoCodeApplyService);
ThrowUtils.throwIf(!promoCodeApplyList.isEmpty(), ErrorCode.OPERATION_ERROR, "不能重复绑定手机号");
Map<SFunction<PromoCode, ?>, Object> fieldConditions = Map.of(PromoCode::getProjectId, projectId, PromoCode::getPromoCodeStatus, false);
List<PromoCode> promoCodeList = commonService.findByFieldEqTargetFields(fieldConditions, promoCodeService);
ThrowUtils.throwIf(promoCodeList.size() == 0, ErrorCode.OPERATION_ERROR, "当前项目没有推广码");
PromoCode promoCode = promoCodeList.get(0);
promoCode.setPromoCodeStatus(true);
@ -89,6 +97,7 @@ public class PromoCodeApplyController {
// 获取推广码参数信息
String promoCodeInfoKey = promoCode.getPromoCodeInfoKey();
String promoCodeLink = promoCode.getPromoCodeLink();
String promoCodeImage = promoCode.getPromoCodeImage();
// 获取项目的参数信息
Project project = projectService.getById(projectId);
// 更新项目的推广人数
@ -100,14 +109,14 @@ public class PromoCodeApplyController {
// 获取业务员信息
String salespersonName = promoCodeApplyRequest.getSalespersonName();
String salespersonPhone = promoCodeApplyRequest.getSalespersonPhone();
// 获取用户id
Long userId = (Long) request.getAttribute("userId");
// 添加推广码申请记录
PromoCodeApply promoCodeApply = PromoCodeApply.builder()
.salespersonName(salespersonName)
.salespersonPhone(salespersonPhone)
.promoCodeInfoKey(promoCodeInfoKey)
.promoCodeLink(promoCodeLink)
.promoCodeImage(promoCodeImage)
.projectId(projectId)
.projectName(projectName)
.projectImage(projectImage)
.userId(userId)

View File

@ -66,16 +66,31 @@ public class UserInfoController {
/**
* 小程序端用户获取验证码
* 小程序端用户获取验证码用于注册
* @param commonStringRequest 手机号
* @return 验证码
*/
@PostMapping("code")
@Operation(summary = "小程序端用户获取验证码", description = "参数手机号权限管理员boss, admin)方法名getVerificationCode")
@SysLog(title = "用户管理", content = "小程序端用户获取验证码")
@Operation(summary = "小程序端用户获取验证码(用于注册)", description = "参数手机号权限管理员boss, admin)方法名getVerificationCodeForRegister")
// @SysLog(title = "用户管理", content = "小程序端用户获取验证码")
public BaseResponse<String> getVerificationCodeForRegister(@Valid @RequestBody CommonStringRequest commonStringRequest) {
String phoneNumber = commonStringRequest.getTemplateString();
String verificationCode = userInfoService.getVerificationCodeForRegister(phoneNumber);
return ResultUtils.success(verificationCode);
}
/**
* 小程序端用户获取验证码用于密码登录和忘记密码
* @param commonStringRequest 手机号
* @return 验证码
*/
@PostMapping("code")
@Operation(summary = "小程序端用户获取验证码(用于密码登录和忘记密码)", description = "参数手机号权限管理员boss, admin)方法名getVerificationCode")
// @SysLog(title = "用户管理", content = "小程序端用户获取验证码")
public BaseResponse<String> getVerificationCode(@Valid @RequestBody CommonStringRequest commonStringRequest) {
String phoneNumber = commonStringRequest.getTemplateString();
String verificationCode = userInfoService.getVerificationCode(phoneNumber);
String verificationCode = userInfoService.getVerificationCodeForPwdLogin(phoneNumber);
return ResultUtils.success(verificationCode);
}
@ -87,7 +102,7 @@ public class UserInfoController {
*/
@PostMapping("inviteCode")
@Operation(summary = "小程序端用户根据id获取上级邀请码", description = "参数用户id权限管理员boss, admin)方法名getParentUserInviteCode")
@SysLog(title = "用户管理", content = "小程序端用户根据id获取上级邀请码")
// @SysLog(title = "用户管理", content = "小程序端用户根据id获取上级邀请码")
public BaseResponse<String> getParentUserInviteCode(@Valid @RequestBody CommonRequest commonRequest) {
Long id = commonRequest.getId();
UserInfo userInfo = userInfoService.getById(id);
@ -103,7 +118,7 @@ public class UserInfoController {
*/
@PostMapping("register")
@Operation(summary = "小程序端用户注册", description = "参数小程序用户注册请求体权限管理员boss, admin)方法名userInfoMiniRegister")
@SysLog(title = "用户管理", content = "小程序端用户注册")
// @SysLog(title = "用户管理", content = "小程序端用户注册")
public BaseResponse<Boolean> userInfoMiniRegister(@Valid @RequestBody UserInfoRegisterRequest userInfoRegisterRequest) {
userInfoService.userInfoMiniRegister(userInfoRegisterRequest);
return ResultUtils.success(true);
@ -118,7 +133,7 @@ public class UserInfoController {
*/
@PostMapping("mini/pwd/login")
@Operation(summary = "小程序端用户密码登录", description = "参数小程序用户密码登录请求体权限管理员boss, admin)方法名userInfoMiniLogin")
@SysLog(title = "用户管理", content = "小程序端用户密码登录")
// @SysLog(title = "用户管理", content = "小程序端用户密码登录")
public BaseResponse<String> userInfoMiniLoginByPwd(@Valid @RequestBody UserInfoMiniPasswordLoginRequest userInfoMiniPasswordLoginRequest) {
String token = userInfoService.userInfoMiniLoginByPwd(userInfoMiniPasswordLoginRequest);
return ResultUtils.success(token);
@ -132,7 +147,7 @@ public class UserInfoController {
*/
@PostMapping("mini/vcd/login")
@Operation(summary = "小程序端用户验证码登录", description = "参数小程序用户验证码登录请求体权限管理员boss, admin)方法名userInfoMiniLoginByVcd")
@SysLog(title = "用户管理", content = "小程序端用户验证码登录")
// @SysLog(title = "用户管理", content = "小程序端用户验证码登录")
public BaseResponse<String> userInfoMiniLoginByVcd(@Valid @RequestBody UserInfoMiniVerifyCodeLoginRequest userInfoMiniVerifyCodeLoginRequest) {
String token = userInfoService.userInfoMiniLoginByVcd(userInfoMiniVerifyCodeLoginRequest);
return ResultUtils.success(token);
@ -146,7 +161,7 @@ public class UserInfoController {
*/
@PostMapping("mini/out/reset/pwd")
@Operation(summary = "小程序用户重置密码(外部)", description = "参数小程序用户密码重置请求体权限管理员boss, admin)方法名userInfoMiniOuterResetPwd")
@SysLog(title = "用户管理", content = "小程序用户重置密码(外部)")
// @SysLog(title = "用户管理", content = "小程序用户重置密码(外部)")
public BaseResponse<Boolean> userInfoMiniOuterResetPwd(@Valid @RequestBody UserInfoResetRequest userInfoResetRequest) {
userInfoService.userInfoMiniResetPwd(userInfoResetRequest);
return ResultUtils.success(true);
@ -175,7 +190,7 @@ public class UserInfoController {
@GetMapping("get/jwt/web")
@Operation(summary = "web端用户根据jwt获取用户信息", description = "参数权限管理员boss, admin)方法名getWebUserInfoByJWT")
@RequiresPermission(mustRole = UserConstant.ADMIN_ROLE)
@SysLog(title = "用户管理", content = "web端用户根据jwt获取用户信息")
// @SysLog(title = "用户管理", content = "web端用户根据jwt获取用户信息")
public BaseResponse<UserInfoVO> getWebUserInfoByJWT(HttpServletRequest request) {
Long userId = (Long) request.getAttribute("userId");
UserInfo userInfo = userInfoService.getById(userId);
@ -390,20 +405,20 @@ public class UserInfoController {
}
/**
* (小程序端)查询当前用户到根节点的userId路径
* @param commonRequest 用户id
* @return 用户表列表
*/
@PostMapping("query/path")
@Operation(summary = "查询当前用户到根节点的userId路径", description = "参数用户id权限管理员boss, admin),方法名:findPathToRootUserIdList")
@RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
@SysLog(title = "用户管理", content = "查询当前用户到根节点的userId路径")
public BaseResponse<List<Long>> findPathToRootUserIdList(@Valid @RequestBody CommonRequest commonRequest) {
Long userId = commonRequest.getId();
List<Long> pathToRoot = userInfoService.findPathToRoot(userId);
return ResultUtils.success(pathToRoot);
}
// /**
// * (小程序端)查询当前用户到根节点的userId路径
// * @param commonRequest 用户id
// * @return 用户表列表
// */
// @PostMapping("query/path")
// @Operation(summary = "查询当前用户到根节点的userId路径", description = "参数用户id权限管理员boss, admin),方法名:findPathToRootUserIdList")
// @RequiresPermission(mustRole = UserConstant.DEFAULT_ROLE)
// @SysLog(title = "用户管理", content = "查询当前用户到根节点的userId路径")
// public BaseResponse<List<Long>> findPathToRootUserIdList(@Valid @RequestBody CommonRequest commonRequest) {
// Long userId = commonRequest.getId();
// List<Long> pathToRoot = userInfoService.findPathToRoot(userId);
// return ResultUtils.success(pathToRoot);
// }

View File

@ -18,6 +18,7 @@ import java.io.Serializable;
"salespersonPhone",
"promoCodeInfoKey",
"promoCodeLink",
"projectId",
"projectName",
"projectImage",
"userId",
@ -60,6 +61,13 @@ public class PromoCodeApplyAddRequest implements Serializable {
@Schema(description = "推广码图片", example = "http://xxx.png")
private String promoCodeImage;
/**
* 绑定的项目ID
*/
@Min(value = 1L, message = "用户ID ID不能小于1")
@Schema(description = "绑定的项目ID", example = "1")
private Long projectId;
/**
* 绑定的项目名称
*/

View File

@ -19,6 +19,7 @@ import java.io.Serializable;
"salespersonPhone",
"promoCodeInfoKey",
"promoCodeLink",
"projectId",
"projectName",
"projectImage",
"userId",
@ -68,6 +69,13 @@ public class PromoCodeApplyUpdateRequest implements Serializable {
@Schema(description = "推广码图片", example = "http://xxx.png")
private String promoCodeImage;
/**
* 绑定的项目ID
*/
@Min(value = 1L, message = "用户ID ID不能小于1")
@Schema(description = "绑定的项目ID", example = "1")
private Long projectId;
/**
* 绑定的项目名称
*/

View File

@ -54,6 +54,11 @@ public class PromoCodeApply implements Serializable {
*/
private String promoCodeImage;
/**
* 项目id
*/
private Long projectId;
/**
* 绑定的项目名称
*/

View File

@ -70,6 +70,11 @@ public class ProjectAllDetailVO implements Serializable {
@Schema(description = "项目流程(富文本)", example = "富文本")
private String projectFlow;
/**
* 申请推广码说明富文本
*/
private String applyPromoCodeDesc;
/**
* 项目通知列表
*/

View File

@ -6,6 +6,7 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 项目通知 视图对象
@ -38,6 +39,12 @@ public class ProjectNotificationVO implements Serializable {
@Schema(description = "项目ID", example = "1")
private Long projectId;
/**
* 创建时间
*/
@Schema(description = "创建时间", example = "2023-04-01 12:00:00")
private Date createTime;
@Serial
private static final long serialVersionUID = 1L;

View File

@ -6,6 +6,7 @@ import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
/**
* 推广码申请记录 视图对象
@ -50,6 +51,12 @@ public class PromoCodeApplyVO implements Serializable {
@Schema(description = "推广码图片", example = "http://xxx.png")
private String promoCodeImage;
/**
* 绑定的项目ID
*/
@Schema(description = "绑定的项目ID", example = "1")
private Long projectId;
/**
* 绑定的项目名称
*/
@ -68,6 +75,12 @@ public class PromoCodeApplyVO implements Serializable {
@Schema(description = "用户ID", example = "1")
private Long userId;
/**
* 创建时间
*/
@Schema(description = "创建时间", example = "2025-07-01 12:00:00")
private Date createTime;
@Serial
private static final long serialVersionUID = 1L;

View File

@ -52,9 +52,15 @@ public interface UserInfoService extends IService<UserInfo> {
/**
* 小程序用户获取验证码
* 小程序用户获取验证码用于密码登录和忘记密码
*/
String getVerificationCode(String phoneNumber);
String getVerificationCodeForPwdLogin(String phoneNumber);
/**
* 小程序用户获取验证码用于注册
*/
String getVerificationCodeForRegister(String phoneNumber);
/**

View File

@ -271,21 +271,21 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
/**
* 小程序用户获取验证码
* 小程序用户获取验证码用于密码登录和忘记密码
*/
@Override
public String getVerificationCode(String phoneNumber) {
public String getVerificationCodeForPwdLogin(String phoneNumber) {
ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phoneNumber), ErrorCode.PARAMS_ERROR, "手机号格式错误");
// // 判断手机号是否已注册
// LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
// lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
// UserInfo userInfo = this.getOne(lambdaQueryWrapper);
// ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
// 判断手机号是否已注册
LambdaQueryWrapper<UserInfo> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(UserInfo::getPhoneNumber, phoneNumber);
UserInfo userInfo = this.getOne(lambdaQueryWrapper);
ThrowUtils.throwIf(userInfo == null, ErrorCode.OPERATION_ERROR, "手机号未注册");
String verificationCode = SendSmsUtil.getVerificationCode(phoneNumber);
ThrowUtils.throwIf(verificationCode == null, ErrorCode.OPERATION_ERROR, "验证码获取失败");
redisTemplate.opsForValue().set(SystemConstant.VERIFICATION_CODE + ":" + verificationCode, verificationCode, 5, TimeUnit.MINUTES);
redisTemplate.opsForValue().set(SystemConstant.VERIFICATION_CODE + ":" + verificationCode, verificationCode, 1, TimeUnit.MINUTES);
return verificationCode;
}
@ -299,6 +299,20 @@ public class UserInfoServiceImpl extends ServiceImpl<UserInfoMapper, UserInfo>
}
/**
* 小程序用户获取验证码用于注册
*/
@Override
public String getVerificationCodeForRegister(String phoneNumber) {
ThrowUtils.throwIf(RegexUtils.isPhoneInvalid(phoneNumber), ErrorCode.PARAMS_ERROR, "手机号格式错误");
String verificationCode = SendSmsUtil.getVerificationCode(phoneNumber);
ThrowUtils.throwIf(verificationCode == null, ErrorCode.OPERATION_ERROR, "验证码获取失败");
redisTemplate.opsForValue().set(SystemConstant.VERIFICATION_CODE + ":" + verificationCode, verificationCode, 1, TimeUnit.MINUTES);
return verificationCode;
}
}

View File

@ -17,13 +17,17 @@ spring:
database: 9
password: Cksys6509
servlet:
multipart:
max-file-size: 20MB
max-request-size: 20MB
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
springdoc:
default-flat-param-object: true
@ -39,7 +43,6 @@ server:
port: 3456
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
configuration:

View File

@ -24,6 +24,11 @@ spring:
max-request-size: 20MB
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
springdoc:
default-flat-param-object: true

View File

@ -24,6 +24,11 @@ spring:
max-request-size: 20MB
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
springdoc:
default-flat-param-object: true

View File

@ -24,6 +24,10 @@ spring:
max-request-size: 20MB
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
springdoc:
default-flat-param-object: true