添加全局异常处理校验
This commit is contained in:
parent
a308c69968
commit
1dfa644911
@ -45,6 +45,15 @@ public class CommonResult<T> {
|
||||
return new CommonResult<T>(errorCode.getCode(), errorCode.getMessage(), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
* @param errorCode 错误码
|
||||
* @param message 错误信息
|
||||
*/
|
||||
public static <T> CommonResult<T> failed(IErrorCode errorCode,String message) {
|
||||
return new CommonResult<T>(errorCode.getCode(), message, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败返回结果
|
||||
* @param message 提示信息
|
||||
|
@ -0,0 +1,32 @@
|
||||
package com.macro.mall.common.exception;
|
||||
|
||||
import com.macro.mall.common.api.IErrorCode;
|
||||
|
||||
/**
|
||||
* 自定义API异常
|
||||
* Created by macro on 2020/2/27.
|
||||
*/
|
||||
public class ApiException extends RuntimeException {
|
||||
private IErrorCode errorCode;
|
||||
|
||||
public ApiException(IErrorCode errorCode) {
|
||||
super(errorCode.getMessage());
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public ApiException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ApiException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ApiException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public IErrorCode getErrorCode() {
|
||||
return errorCode;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package com.macro.mall.common.exception;
|
||||
|
||||
import com.macro.mall.common.api.IErrorCode;
|
||||
|
||||
/**
|
||||
* 断言处理类,用于抛出各种API异常
|
||||
* Created by macro on 2020/2/27.
|
||||
*/
|
||||
public class Asserts {
|
||||
public static void fail(String message) {
|
||||
throw new ApiException(message);
|
||||
}
|
||||
|
||||
public static void fail(IErrorCode errorCode) {
|
||||
throw new ApiException(errorCode);
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.macro.mall.common.exception;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
* Created by macro on 2020/2/27.
|
||||
*/
|
||||
@ControllerAdvice
|
||||
public class GlobalExceptionHandler {
|
||||
|
||||
@ResponseBody
|
||||
@ExceptionHandler(value = ApiException.class)
|
||||
public CommonResult handle(ApiException e) {
|
||||
if (e.getErrorCode() != null) {
|
||||
return CommonResult.failed(e.getErrorCode());
|
||||
}
|
||||
return CommonResult.failed(e.getMessage());
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package com.macro.mall.portal;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(scanBasePackages = "com.macro.mall")
|
||||
public class MallPortalApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.macro.mall.portal.component;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.portal.service.OmsPortalOrderService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -24,7 +23,7 @@ public class OrderTimeOutCancelTask {
|
||||
*/
|
||||
@Scheduled(cron = "0 0/10 * ? * ?")
|
||||
private void cancelTimeOutOrder(){
|
||||
CommonResult result = portalOrderService.cancelTimeOutOrder();
|
||||
LOGGER.info("取消订单,并根据sku编号释放锁定库存:{}",result);
|
||||
Integer count = portalOrderService.cancelTimeOutOrder();
|
||||
LOGGER.info("取消订单,并根据sku编号释放锁定库存,取消订单数量:{}",count);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,27 @@
|
||||
package com.macro.mall.portal.config;
|
||||
|
||||
import com.macro.mall.portal.service.UmsMemberService;
|
||||
import com.macro.mall.security.component.DynamicSecurityService;
|
||||
import com.macro.mall.security.config.SecurityConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.access.ConfigAttribute;
|
||||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* mall-security模块相关配置
|
||||
* Created by macro on 2019/11/5.
|
||||
*/
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
@EnableGlobalMethodSecurity(prePostEnabled=true)
|
||||
@EnableGlobalMethodSecurity(prePostEnabled = true)
|
||||
public class MallSecurityConfig extends SecurityConfig {
|
||||
|
||||
@Autowired
|
||||
|
@ -10,48 +10,55 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 订单管理Controller
|
||||
* Created by macro on 2018/8/30.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "OmsPortalOrderController",description = "订单管理")
|
||||
@Api(tags = "OmsPortalOrderController", description = "订单管理")
|
||||
@RequestMapping("/order")
|
||||
public class OmsPortalOrderController {
|
||||
@Autowired
|
||||
private OmsPortalOrderService portalOrderService;
|
||||
|
||||
@ApiOperation("根据购物车信息生成确认单信息")
|
||||
@RequestMapping(value = "/generateConfirmOrder",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/generateConfirmOrder", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult<ConfirmOrderResult> generateConfirmOrder(){
|
||||
public CommonResult<ConfirmOrderResult> generateConfirmOrder() {
|
||||
ConfirmOrderResult confirmOrderResult = portalOrderService.generateConfirmOrder();
|
||||
return CommonResult.success(confirmOrderResult);
|
||||
}
|
||||
|
||||
@ApiOperation("根据购物车信息生成订单")
|
||||
@RequestMapping(value = "/generateOrder",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/generateOrder", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object generateOrder(@RequestBody OrderParam orderParam){
|
||||
return portalOrderService.generateOrder(orderParam);
|
||||
public CommonResult generateOrder(@RequestBody OrderParam orderParam) {
|
||||
Map<String, Object> result = portalOrderService.generateOrder(orderParam);
|
||||
return CommonResult.success(result, "下单成功");
|
||||
}
|
||||
|
||||
@ApiOperation("支付成功的回调")
|
||||
@RequestMapping(value = "/paySuccess",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/paySuccess", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object paySuccess(@RequestParam Long orderId){
|
||||
return portalOrderService.paySuccess(orderId);
|
||||
public CommonResult paySuccess(@RequestParam Long orderId) {
|
||||
Integer count = portalOrderService.paySuccess(orderId);
|
||||
return CommonResult.success(count, "支付成功");
|
||||
}
|
||||
|
||||
@ApiOperation("自动取消超时订单")
|
||||
@RequestMapping(value = "/cancelTimeOutOrder",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/cancelTimeOutOrder", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object cancelTimeOutOrder(){
|
||||
return portalOrderService.cancelTimeOutOrder();
|
||||
public CommonResult cancelTimeOutOrder() {
|
||||
portalOrderService.cancelTimeOutOrder();
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
@ApiOperation("取消单个超时订单")
|
||||
@RequestMapping(value = "/cancelOrder",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/cancelOrder", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult cancelOrder(Long orderId){
|
||||
public CommonResult cancelOrder(Long orderId) {
|
||||
portalOrderService.sendDelayMessageCancelOrder(orderId);
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
@ -38,7 +38,8 @@ public class UmsMemberController {
|
||||
@RequestParam String password,
|
||||
@RequestParam String telephone,
|
||||
@RequestParam String authCode) {
|
||||
return memberService.register(username, password, telephone, authCode);
|
||||
memberService.register(username, password, telephone, authCode);
|
||||
return CommonResult.success(null,"注册成功");
|
||||
}
|
||||
|
||||
@ApiOperation("会员登录")
|
||||
@ -60,7 +61,8 @@ public class UmsMemberController {
|
||||
@RequestMapping(value = "/getAuthCode", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult getAuthCode(@RequestParam String telephone) {
|
||||
return memberService.generateAuthCode(telephone);
|
||||
String authCode = memberService.generateAuthCode(telephone);
|
||||
return CommonResult.success(authCode,"获取验证码成功");
|
||||
}
|
||||
|
||||
@ApiOperation("修改密码")
|
||||
@ -69,7 +71,8 @@ public class UmsMemberController {
|
||||
public CommonResult updatePassword(@RequestParam String telephone,
|
||||
@RequestParam String password,
|
||||
@RequestParam String authCode) {
|
||||
return memberService.updatePassword(telephone,password,authCode);
|
||||
memberService.updatePassword(telephone,password,authCode);
|
||||
return CommonResult.success(null,"密码修改成功");
|
||||
}
|
||||
|
||||
|
||||
|
@ -35,7 +35,8 @@ public class UmsMemberCouponController {
|
||||
@RequestMapping(value = "/add/{couponId}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult add(@PathVariable Long couponId) {
|
||||
return memberCouponService.add(couponId);
|
||||
memberCouponService.add(couponId);
|
||||
return CommonResult.success(null,"领取成功");
|
||||
}
|
||||
|
||||
@ApiOperation("获取用户优惠券列表")
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.macro.mall.portal.service;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.portal.domain.ConfirmOrderResult;
|
||||
import com.macro.mall.portal.domain.OrderParam;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 前台订单管理Service
|
||||
* Created by macro on 2018/8/30.
|
||||
@ -19,19 +20,19 @@ public interface OmsPortalOrderService {
|
||||
* 根据提交信息生成订单
|
||||
*/
|
||||
@Transactional
|
||||
CommonResult generateOrder(OrderParam orderParam);
|
||||
Map<String, Object> generateOrder(OrderParam orderParam);
|
||||
|
||||
/**
|
||||
* 支付成功后的回调
|
||||
*/
|
||||
@Transactional
|
||||
CommonResult paySuccess(Long orderId);
|
||||
Integer paySuccess(Long orderId);
|
||||
|
||||
/**
|
||||
* 自动取消超时订单
|
||||
*/
|
||||
@Transactional
|
||||
CommonResult cancelTimeOutOrder();
|
||||
Integer cancelTimeOutOrder();
|
||||
|
||||
/**
|
||||
* 取消单个超时订单
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.macro.mall.portal.service;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.model.SmsCouponHistory;
|
||||
import com.macro.mall.portal.domain.CartPromotionItem;
|
||||
import com.macro.mall.portal.domain.SmsCouponHistoryDetail;
|
||||
@ -17,7 +16,7 @@ public interface UmsMemberCouponService {
|
||||
* 会员添加优惠券
|
||||
*/
|
||||
@Transactional
|
||||
CommonResult add(Long couponId);
|
||||
void add(Long couponId);
|
||||
|
||||
/**
|
||||
* 获取优惠券列表
|
||||
|
@ -24,18 +24,18 @@ public interface UmsMemberService {
|
||||
* 用户注册
|
||||
*/
|
||||
@Transactional
|
||||
CommonResult register(String username, String password, String telephone, String authCode);
|
||||
void register(String username, String password, String telephone, String authCode);
|
||||
|
||||
/**
|
||||
* 生成验证码
|
||||
*/
|
||||
CommonResult generateAuthCode(String telephone);
|
||||
String generateAuthCode(String telephone);
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
*/
|
||||
@Transactional
|
||||
CommonResult updatePassword(String telephone, String password, String authCode);
|
||||
void updatePassword(String telephone, String password, String authCode);
|
||||
|
||||
/**
|
||||
* 获取当前登录会员
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.macro.mall.portal.service.impl;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.common.exception.Asserts;
|
||||
import com.macro.mall.mapper.*;
|
||||
import com.macro.mall.model.*;
|
||||
import com.macro.mall.portal.component.CancelOrderSender;
|
||||
@ -83,7 +83,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult generateOrder(OrderParam orderParam) {
|
||||
public Map<String, Object> generateOrder(OrderParam orderParam) {
|
||||
List<OmsOrderItem> orderItemList = new ArrayList<>();
|
||||
//获取购物车及优惠信息
|
||||
UmsMember currentMember = memberService.getCurrentMember();
|
||||
@ -110,7 +110,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
}
|
||||
//判断购物车中商品是否都有库存
|
||||
if (!hasStock(cartPromotionItemList)) {
|
||||
return CommonResult.failed("库存不足,无法下单");
|
||||
Asserts.fail("库存不足,无法下单");
|
||||
}
|
||||
//判断使用使用了优惠券
|
||||
if (orderParam.getCouponId() == null) {
|
||||
@ -122,7 +122,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
//使用优惠券
|
||||
SmsCouponHistoryDetail couponHistoryDetail = getUseCoupon(cartPromotionItemList, orderParam.getCouponId());
|
||||
if (couponHistoryDetail == null) {
|
||||
return CommonResult.failed("该优惠券不可用");
|
||||
Asserts.fail("该优惠券不可用");
|
||||
}
|
||||
//对下单商品的优惠券进行处理
|
||||
handleCouponAmount(orderItemList, couponHistoryDetail);
|
||||
@ -138,7 +138,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
BigDecimal totalAmount = calcTotalAmount(orderItemList);
|
||||
BigDecimal integrationAmount = getUseIntegrationAmount(orderParam.getUseIntegration(), totalAmount, currentMember, orderParam.getCouponId() != null);
|
||||
if (integrationAmount.compareTo(new BigDecimal(0)) == 0) {
|
||||
return CommonResult.failed("积分不可用");
|
||||
Asserts.fail("积分不可用");
|
||||
} else {
|
||||
//可用情况下分摊到可用商品中
|
||||
for (OmsOrderItem orderItem : orderItemList) {
|
||||
@ -226,11 +226,11 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("order", order);
|
||||
result.put("orderItemList", orderItemList);
|
||||
return CommonResult.success(result, "下单成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult paySuccess(Long orderId) {
|
||||
public Integer paySuccess(Long orderId) {
|
||||
//修改订单支付状态
|
||||
OmsOrder order = new OmsOrder();
|
||||
order.setId(orderId);
|
||||
@ -240,16 +240,17 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
//恢复所有下单商品的锁定库存,扣减真实库存
|
||||
OmsOrderDetail orderDetail = portalOrderDao.getDetail(orderId);
|
||||
int count = portalOrderDao.updateSkuStock(orderDetail.getOrderItemList());
|
||||
return CommonResult.success(count,"支付成功");
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult cancelTimeOutOrder() {
|
||||
public Integer cancelTimeOutOrder() {
|
||||
Integer count=0;
|
||||
OmsOrderSetting orderSetting = orderSettingMapper.selectByPrimaryKey(1L);
|
||||
//查询超时、未支付的订单及订单详情
|
||||
List<OmsOrderDetail> timeOutOrders = portalOrderDao.getTimeOutOrders(orderSetting.getNormalOrderOvertime());
|
||||
if (CollectionUtils.isEmpty(timeOutOrders)) {
|
||||
return CommonResult.failed("暂无超时订单");
|
||||
return count;
|
||||
}
|
||||
//修改订单状态为交易取消
|
||||
List<Long> ids = new ArrayList<>();
|
||||
@ -268,7 +269,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
|
||||
memberService.updateIntegration(timeOutOrder.getMemberId(), member.getIntegration() + timeOutOrder.getUseIntegration());
|
||||
}
|
||||
}
|
||||
return CommonResult.success(null);
|
||||
return timeOutOrders.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.macro.mall.portal.service.impl;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.common.exception.Asserts;
|
||||
import com.macro.mall.mapper.SmsCouponHistoryMapper;
|
||||
import com.macro.mall.mapper.SmsCouponMapper;
|
||||
import com.macro.mall.model.*;
|
||||
@ -13,7 +13,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* 会员优惠券管理Service实现类
|
||||
@ -30,26 +33,26 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
|
||||
@Autowired
|
||||
private SmsCouponHistoryDao couponHistoryDao;
|
||||
@Override
|
||||
public CommonResult add(Long couponId) {
|
||||
public void add(Long couponId) {
|
||||
UmsMember currentMember = memberService.getCurrentMember();
|
||||
//获取优惠券信息,判断数量
|
||||
SmsCoupon coupon = couponMapper.selectByPrimaryKey(couponId);
|
||||
if(coupon==null){
|
||||
return CommonResult.failed("优惠券不存在");
|
||||
Asserts.fail("优惠券不存在");
|
||||
}
|
||||
if(coupon.getCount()<=0){
|
||||
return CommonResult.failed("优惠券已经领完了");
|
||||
Asserts.fail("优惠券已经领完了");
|
||||
}
|
||||
Date now = new Date();
|
||||
if(now.before(coupon.getEnableTime())){
|
||||
return CommonResult.failed("优惠券还没到领取时间");
|
||||
Asserts.fail("优惠券还没到领取时间");
|
||||
}
|
||||
//判断用户领取的优惠券数量是否超过限制
|
||||
SmsCouponHistoryExample couponHistoryExample = new SmsCouponHistoryExample();
|
||||
couponHistoryExample.createCriteria().andCouponIdEqualTo(couponId).andMemberIdEqualTo(currentMember.getId());
|
||||
long count = couponHistoryMapper.countByExample(couponHistoryExample);
|
||||
if(count>=coupon.getPerLimit()){
|
||||
return CommonResult.failed("您已经领取过该优惠券");
|
||||
Asserts.fail("您已经领取过该优惠券");
|
||||
}
|
||||
//生成领取优惠券历史
|
||||
SmsCouponHistory couponHistory = new SmsCouponHistory();
|
||||
@ -67,7 +70,6 @@ public class UmsMemberCouponServiceImpl implements UmsMemberCouponService {
|
||||
coupon.setCount(coupon.getCount()-1);
|
||||
coupon.setReceiveCount(coupon.getReceiveCount()==null?1:coupon.getReceiveCount()+1);
|
||||
couponMapper.updateByPrimaryKey(coupon);
|
||||
return CommonResult.success(null,"领取成功");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
package com.macro.mall.portal.service.impl;
|
||||
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.common.exception.Asserts;
|
||||
import com.macro.mall.mapper.UmsMemberLevelMapper;
|
||||
import com.macro.mall.mapper.UmsMemberMapper;
|
||||
import com.macro.mall.model.UmsMember;
|
||||
@ -71,10 +71,10 @@ public class UmsMemberServiceImpl implements UmsMemberService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult register(String username, String password, String telephone, String authCode) {
|
||||
public void register(String username, String password, String telephone, String authCode) {
|
||||
//验证验证码
|
||||
if(!verifyAuthCode(authCode,telephone)){
|
||||
return CommonResult.failed("验证码错误");
|
||||
Asserts.fail("验证码错误");
|
||||
}
|
||||
//查询是否已有该用户
|
||||
UmsMemberExample example = new UmsMemberExample();
|
||||
@ -82,7 +82,7 @@ public class UmsMemberServiceImpl implements UmsMemberService {
|
||||
example.or(example.createCriteria().andPhoneEqualTo(telephone));
|
||||
List<UmsMember> umsMembers = memberMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(umsMembers)) {
|
||||
return CommonResult.failed("该用户已经存在");
|
||||
Asserts.fail("该用户已经存在");
|
||||
}
|
||||
//没有该用户进行添加操作
|
||||
UmsMember umsMember = new UmsMember();
|
||||
@ -100,11 +100,10 @@ public class UmsMemberServiceImpl implements UmsMemberService {
|
||||
}
|
||||
memberMapper.insert(umsMember);
|
||||
umsMember.setPassword(null);
|
||||
return CommonResult.success(null,"注册成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult generateAuthCode(String telephone) {
|
||||
public String generateAuthCode(String telephone) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for(int i=0;i<6;i++){
|
||||
@ -113,25 +112,24 @@ public class UmsMemberServiceImpl implements UmsMemberService {
|
||||
//验证码绑定手机号并存储到redis
|
||||
redisService.set(REDIS_KEY_PREFIX_AUTH_CODE+telephone,sb.toString());
|
||||
redisService.expire(REDIS_KEY_PREFIX_AUTH_CODE+telephone,AUTH_CODE_EXPIRE_SECONDS);
|
||||
return CommonResult.success(sb.toString(),"获取验证码成功");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult updatePassword(String telephone, String password, String authCode) {
|
||||
public void updatePassword(String telephone, String password, String authCode) {
|
||||
UmsMemberExample example = new UmsMemberExample();
|
||||
example.createCriteria().andPhoneEqualTo(telephone);
|
||||
List<UmsMember> memberList = memberMapper.selectByExample(example);
|
||||
if(CollectionUtils.isEmpty(memberList)){
|
||||
return CommonResult.failed("该账号不存在");
|
||||
Asserts.fail("该账号不存在");
|
||||
}
|
||||
//验证验证码
|
||||
if(!verifyAuthCode(authCode,telephone)){
|
||||
return CommonResult.failed("验证码错误");
|
||||
Asserts.fail("验证码错误");
|
||||
}
|
||||
UmsMember umsMember = memberList.get(0);
|
||||
umsMember.setPassword(passwordEncoder.encode(password));
|
||||
memberMapper.updateByPrimaryKeySelective(umsMember);
|
||||
return CommonResult.success(null,"密码修改成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user