You've already forked FrameTour-BE
- 新增注册接口和相关请求/响应对象 - 实现手机号格式验证、密码非空验证 - 检查手机号是否已注册 - 创建新账号并设置初始状态 - 返回注册结果及提示信息
This commit is contained in:
@@ -5,6 +5,8 @@ import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginOldRespVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginReq;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginRespVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicRegisterReq;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicRegisterRespVO;
|
||||
import com.ycwl.basic.model.mobile.weChat.DTO.WeChatUserInfoDTO;
|
||||
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
@@ -63,6 +65,13 @@ public class AppScenicAccountController {
|
||||
return ApiResponse.success(vo);
|
||||
}
|
||||
|
||||
// 注册
|
||||
@PostMapping("/register")
|
||||
@IgnoreToken
|
||||
public ApiResponse<ScenicRegisterRespVO> register(@RequestBody ScenicRegisterReq scenicRegisterReq) {
|
||||
return scenicService.register(scenicRegisterReq);
|
||||
}
|
||||
|
||||
@GetMapping("/myScenicList")
|
||||
public ApiResponse<List<ScenicRespVO>> myScenicList() {
|
||||
List<ScenicRespVO> list;
|
||||
|
@@ -0,0 +1,14 @@
|
||||
package com.ycwl.basic.model.mobile.scenic.account;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 景区账号注册请求
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/28 10:00
|
||||
*/
|
||||
@Data
|
||||
public class ScenicRegisterReq {
|
||||
private String phone;
|
||||
private String password;
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package com.ycwl.basic.model.mobile.scenic.account;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 景区账号注册响应
|
||||
* @Author:longbinbin
|
||||
* @Date:2024/12/28 10:00
|
||||
*/
|
||||
@Data
|
||||
public class ScenicRegisterRespVO {
|
||||
private Long id;
|
||||
private String account;
|
||||
private String phone;
|
||||
private Integer isActive;
|
||||
private String message;
|
||||
}
|
@@ -6,6 +6,8 @@ import com.ycwl.basic.model.mobile.scenic.ScenicDeviceCountVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.ScenicIndexVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginReq;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginRespVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicRegisterReq;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicRegisterRespVO;
|
||||
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
@@ -26,6 +28,8 @@ public interface AppScenicService {
|
||||
|
||||
ApiResponse<ScenicLoginRespVO> login(ScenicLoginReq scenicLoginReq) throws Exception;
|
||||
|
||||
ApiResponse<ScenicRegisterRespVO> register(ScenicRegisterReq scenicRegisterReq);
|
||||
|
||||
List<ScenicAppVO> scenicListByLnLa(ScenicIndexVO scenicIndexVO);
|
||||
|
||||
ApiResponse<List<DeviceRespVO>> getDevices(Long scenicId);
|
||||
|
@@ -11,6 +11,8 @@ import com.ycwl.basic.model.mobile.scenic.ScenicDeviceCountVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.ScenicIndexVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginReq;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicLoginRespVO;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicRegisterReq;
|
||||
import com.ycwl.basic.model.mobile.scenic.account.ScenicRegisterRespVO;
|
||||
import com.ycwl.basic.model.pc.device.entity.DeviceEntity;
|
||||
import com.ycwl.basic.model.pc.device.resp.DeviceRespVO;
|
||||
import com.ycwl.basic.model.pc.scenic.entity.ScenicAccountEntity;
|
||||
@@ -116,6 +118,57 @@ public class AppScenicServiceImpl implements AppScenicService {
|
||||
return ApiResponse.success(scenicLoginRespVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApiResponse<ScenicRegisterRespVO> register(ScenicRegisterReq scenicRegisterReq) {
|
||||
// 验证手机号格式
|
||||
if (scenicRegisterReq.getPhone() == null || !scenicRegisterReq.getPhone().matches("^1[3-9]\\d{9}$")) {
|
||||
return ApiResponse.fail("手机号格式不正确");
|
||||
}
|
||||
|
||||
// 验证密码不能为空
|
||||
if (scenicRegisterReq.getPassword() == null || scenicRegisterReq.getPassword().trim().isEmpty()) {
|
||||
return ApiResponse.fail("密码不能为空");
|
||||
}
|
||||
|
||||
// 检查手机号是否已存在
|
||||
try {
|
||||
ScenicAccountEntity existingAccount = scenicAccountService.getScenicAccountByAccount(scenicRegisterReq.getPhone());
|
||||
if (existingAccount != null) {
|
||||
return ApiResponse.fail("该手机号已注册");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// 如果抛出异常说明账号不存在,可以继续注册
|
||||
}
|
||||
|
||||
// 创建新账号
|
||||
ScenicAccountEntity newAccount = new ScenicAccountEntity();
|
||||
newAccount.setAccount(scenicRegisterReq.getPhone());
|
||||
newAccount.setPhone(scenicRegisterReq.getPhone());
|
||||
newAccount.setPassword(scenicRegisterReq.getPassword());
|
||||
newAccount.setIsActive(0); // 未激活状态
|
||||
newAccount.setStatus(1); // 正常状态
|
||||
newAccount.setCreateTime(new Date());
|
||||
newAccount.setUpdateTime(new Date());
|
||||
|
||||
try {
|
||||
int result = scenicAccountService.addScenicAccount(newAccount);
|
||||
if (result > 0) {
|
||||
ScenicRegisterRespVO response = new ScenicRegisterRespVO();
|
||||
response.setId(newAccount.getId());
|
||||
response.setAccount(newAccount.getAccount());
|
||||
response.setPhone(newAccount.getPhone());
|
||||
response.setIsActive(newAccount.getIsActive());
|
||||
response.setMessage("注册成功,请等待后台激活");
|
||||
return ApiResponse.success(response);
|
||||
} else {
|
||||
return ApiResponse.fail("注册失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("注册失败", e);
|
||||
return ApiResponse.fail("注册失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ScenicAppVO> scenicListByLnLa(ScenicIndexVO scenicIndexVO) {
|
||||
List<ScenicAppVO> scenicAppVOS = scenicMapper.scenicListByLnLa(scenicIndexVO);
|
||||
|
Reference in New Issue
Block a user