|
@@ -1,5 +1,7 @@
|
|
|
package com.cyksj.web.controller.market;
|
|
package com.cyksj.web.controller.market;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.lang.Validator;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
import com.cyksj.common.constant.TaskTypeEnum;
|
|
@@ -14,6 +16,7 @@ import com.cyksj.model.entity.UserBindPhone;
|
|
|
import com.cyksj.model.request.LoginPhoneReq;
|
|
import com.cyksj.model.request.LoginPhoneReq;
|
|
|
import com.cyksj.model.request.TaskFollowReq;
|
|
import com.cyksj.model.request.TaskFollowReq;
|
|
|
import com.cyksj.model.views.TaskFrontView;
|
|
import com.cyksj.model.views.TaskFrontView;
|
|
|
|
|
+import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
import com.cyksj.service.market.MarketFrontService;
|
|
|
import com.cyksj.service.market.task.TaskService;
|
|
import com.cyksj.service.market.task.TaskService;
|
|
|
import com.cyksj.service.phone.PhoneCodeService;
|
|
import com.cyksj.service.phone.PhoneCodeService;
|
|
@@ -27,6 +30,7 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
*项目名: netflix
|
|
*项目名: netflix
|
|
@@ -53,6 +57,8 @@ public class TaskFrontController {
|
|
|
|
|
|
|
|
private final TaskTypeMapper taskTypeMapper;
|
|
private final TaskTypeMapper taskTypeMapper;
|
|
|
|
|
|
|
|
|
|
+ private final RedisService redisService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 任务列表
|
|
* 任务列表
|
|
|
*/
|
|
*/
|
|
@@ -89,18 +95,21 @@ public class TaskFrontController {
|
|
|
if (other != null) {
|
|
if (other != null) {
|
|
|
throw BusinessRuntimeException.getInstance("该手机号已被绑定");
|
|
throw BusinessRuntimeException.getInstance("该手机号已被绑定");
|
|
|
}
|
|
}
|
|
|
- UserBindPhone bindPhone = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
|
|
|
- .eq(UserBindPhone::getUserId, userId).last("limit 1"));
|
|
|
|
|
- if (bindPhone != null) {
|
|
|
|
|
|
|
+ UserBindPhone bindPhone = Optional.ofNullable(userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
|
|
|
+ .eq(UserBindPhone::getUserId, userId).last("limit 1"))).orElse(new UserBindPhone());
|
|
|
|
|
+ if (StrUtil.isNotBlank(bindPhone.getPhone())) {
|
|
|
throw BusinessRuntimeException.getInstance("您已绑定手机号");
|
|
throw BusinessRuntimeException.getInstance("您已绑定手机号");
|
|
|
}
|
|
}
|
|
|
//校验
|
|
//校验
|
|
|
phoneCodeService.checkPhone(phoneReq.getPhone(), phoneReq.getCode());
|
|
phoneCodeService.checkPhone(phoneReq.getPhone(), phoneReq.getCode());
|
|
|
- UserBindPhone userBindPhone = new UserBindPhone();
|
|
|
|
|
- userBindPhone.setUserId(userId);
|
|
|
|
|
- userBindPhone.setPhone(phoneReq.getPhone());
|
|
|
|
|
|
|
+ bindPhone.setUserId(userId);
|
|
|
|
|
+ bindPhone.setPhone(phoneReq.getPhone());
|
|
|
try {
|
|
try {
|
|
|
- userBindPhoneMapper.insert(userBindPhone);
|
|
|
|
|
|
|
+ if (bindPhone.getId() == null) {
|
|
|
|
|
+ userBindPhoneMapper.insert(bindPhone);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ userBindPhoneMapper.updateById(bindPhone);
|
|
|
|
|
+ }
|
|
|
} catch (DuplicateKeyException e) {
|
|
} catch (DuplicateKeyException e) {
|
|
|
|
|
|
|
|
}
|
|
}
|
|
@@ -111,6 +120,48 @@ public class TaskFrontController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("绑定手机号成功");
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult("绑定手机号成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 绑定邮箱
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/bind/email")
|
|
|
|
|
+ public Result<String> bindEmail(@RequestBody LoginPhoneReq phoneReq) {
|
|
|
|
|
+ Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
|
|
+ if (!Validator.isEmail(phoneReq.getEmail())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("请输入正确的邮箱");
|
|
|
|
|
+ }
|
|
|
|
|
+ UserBindPhone other = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
|
|
|
+ .eq(UserBindPhone::getEmail, phoneReq.getEmail()).ne(UserBindPhone::getUserId, userId).select(UserBindPhone::getId).last("limit 1"));
|
|
|
|
|
+ if (other != null) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("该邮箱已被绑定");
|
|
|
|
|
+ }
|
|
|
|
|
+ UserBindPhone bindPhone = Optional.ofNullable(userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
|
|
|
+ .eq(UserBindPhone::getUserId, userId).last("limit 1"))).orElse(new UserBindPhone());
|
|
|
|
|
+ if (StrUtil.isNotBlank(bindPhone.getEmail())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("您已绑定邮箱");
|
|
|
|
|
+ }
|
|
|
|
|
+ String code = redisService.getStr(RedisService.key.EMAIL_CODE_KEY.getNameFormat(phoneReq.getEmail()));
|
|
|
|
|
+ if (StrUtil.isEmpty(code)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("邮箱验证码已失效,请重新获取");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!StrUtil.equals(phoneReq.getCode(), code)) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("邮箱验证码错误,请重新输入");
|
|
|
|
|
+ }
|
|
|
|
|
+ bindPhone.setEmail(phoneReq.getEmail());
|
|
|
|
|
+ bindPhone.setUserId(userId);
|
|
|
|
|
+ try {
|
|
|
|
|
+ if (bindPhone.getId() == null) {
|
|
|
|
|
+ userBindPhoneMapper.insert(bindPhone);
|
|
|
|
|
+ }else {
|
|
|
|
|
+ userBindPhoneMapper.updateById(bindPhone);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (DuplicateKeyException e) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ redisService.del(RedisService.key.EMAIL_CODE_KEY.getNameFormat(phoneReq.getEmail()));
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult("绑定邮箱成功");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 修改手机号
|
|
* 修改手机号
|
|
|
*/
|
|
*/
|
|
@@ -119,7 +170,7 @@ public class TaskFrontController {
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
UserBindPhone bindPhone = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
UserBindPhone bindPhone = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
|
.eq(UserBindPhone::getUserId, userId).last("limit 1"));
|
|
.eq(UserBindPhone::getUserId, userId).last("limit 1"));
|
|
|
- if (bindPhone == null) {
|
|
|
|
|
|
|
+ if (bindPhone == null || StrUtil.isEmpty(bindPhone.getPhone())) {
|
|
|
throw BusinessRuntimeException.getInstance("您未绑定手机号");
|
|
throw BusinessRuntimeException.getInstance("您未绑定手机号");
|
|
|
}
|
|
}
|
|
|
UserBindPhone other = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|
|
UserBindPhone other = userBindPhoneMapper.selectOne(Wrappers.lambdaQuery(UserBindPhone.class)
|