|
@@ -3,19 +3,18 @@ package com.storlead.sms.service.impl;
|
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import com.storlead.frame.constants.RedisKeySaltConstant;
|
|
|
|
|
-import com.storlead.frame.core.assemble.Result;
|
|
|
|
|
-import com.storlead.frame.enums.ErrorMsgCode;
|
|
|
|
|
-import com.storlead.frame.redis.RedisService;
|
|
|
|
|
|
|
+import com.storlead.framework.common.constant.RedisKeySaltConstant;
|
|
|
|
|
+import com.storlead.framework.common.enums.ErrorMsgCode;
|
|
|
|
|
+import com.storlead.framework.common.result.BizResult;
|
|
|
|
|
+import com.storlead.framework.common.util.RandomCodeUtil;
|
|
|
|
|
+import com.storlead.framework.redis.RedisService;
|
|
|
import com.storlead.sms.constants.SmsTemplateConstants;
|
|
import com.storlead.sms.constants.SmsTemplateConstants;
|
|
|
-import com.storlead.sms.exception.SMSException;
|
|
|
|
|
import com.storlead.sms.mapper.SmsLogMapper;
|
|
import com.storlead.sms.mapper.SmsLogMapper;
|
|
|
import com.storlead.sms.pojo.entity.SmsLogEntity;
|
|
import com.storlead.sms.pojo.entity.SmsLogEntity;
|
|
|
-import com.storlead.sms.service.SmsLogService;
|
|
|
|
|
-import com.storlead.common.util.RandomCodeUtil;
|
|
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
|
+import com.storlead.sms.server.SmsLogService;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
@@ -31,17 +30,15 @@ import java.util.concurrent.TimeUnit;
|
|
|
@Service
|
|
@Service
|
|
|
public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLogEntity> implements SmsLogService {
|
|
public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLogEntity> implements SmsLogService {
|
|
|
|
|
|
|
|
- @Autowired
|
|
|
|
|
|
|
+ @Resource
|
|
|
private RedisService redisService;
|
|
private RedisService redisService;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public Result sendLoginSmsCode(String mobile) throws ClientException, SMSException {
|
|
|
|
|
|
|
+ public BizResult sendLoginSmsCode(String mobile) {
|
|
|
//
|
|
//
|
|
|
int count = this.count(new LambdaQueryWrapper<SmsLogEntity>().eq(SmsLogEntity::getMobile,mobile).eq(SmsLogEntity::getType,Integer.valueOf(10)).apply(" TO_DAYS(send_time) = TO_DAYS(NOW()) "));
|
|
int count = this.count(new LambdaQueryWrapper<SmsLogEntity>().eq(SmsLogEntity::getMobile,mobile).eq(SmsLogEntity::getType,Integer.valueOf(10)).apply(" TO_DAYS(send_time) = TO_DAYS(NOW()) "));
|
|
|
if (count >= SmsTemplateConstants.SEND_MAXIMIZE) {
|
|
if (count >= SmsTemplateConstants.SEND_MAXIMIZE) {
|
|
|
- return Result.error(ErrorMsgCode.D_400001);
|
|
|
|
|
|
|
+ return BizResult.error(ErrorMsgCode.D_400001);
|
|
|
}
|
|
}
|
|
|
Object var1 = redisService.getCacheObject(RedisKeySaltConstant.REDIS_LOGIN_VALID_CODE_KEY+mobile);
|
|
Object var1 = redisService.getCacheObject(RedisKeySaltConstant.REDIS_LOGIN_VALID_CODE_KEY+mobile);
|
|
|
if (Objects.nonNull(var1)) {
|
|
if (Objects.nonNull(var1)) {
|
|
@@ -49,7 +46,7 @@ public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLogEntity> i
|
|
|
Long currentTime = System.currentTimeMillis();
|
|
Long currentTime = System.currentTimeMillis();
|
|
|
Long sendTime = smsLog.getSendTime().getTime();
|
|
Long sendTime = smsLog.getSendTime().getTime();
|
|
|
if ((currentTime - sendTime) / 1000 < smsLog.getValidTime()) {
|
|
if ((currentTime - sendTime) / 1000 < smsLog.getValidTime()) {
|
|
|
- return Result.error(ErrorMsgCode.D_400002);
|
|
|
|
|
|
|
+ return BizResult.error(ErrorMsgCode.D_400002);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
int checkCode = RandomCodeUtil.RandomCheckCode();
|
|
int checkCode = RandomCodeUtil.RandomCheckCode();
|
|
@@ -57,7 +54,7 @@ public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLogEntity> i
|
|
|
try {
|
|
try {
|
|
|
boolean res = sendMobileVerifyCode(mobile, checkCode);
|
|
boolean res = sendMobileVerifyCode(mobile, checkCode);
|
|
|
if (!res) {
|
|
if (!res) {
|
|
|
- return Result.error(ErrorMsgCode.D_400003);
|
|
|
|
|
|
|
+ return BizResult.error(ErrorMsgCode.D_400003);
|
|
|
}
|
|
}
|
|
|
log.error("SmsLog ---- = "+checkCode);
|
|
log.error("SmsLog ---- = "+checkCode);
|
|
|
SmsLogEntity smsLog = new SmsLogEntity();
|
|
SmsLogEntity smsLog = new SmsLogEntity();
|
|
@@ -71,10 +68,10 @@ public class SmsLogServiceImpl extends ServiceImpl<SmsLogMapper, SmsLogEntity> i
|
|
|
smsLog.setStatus(1);
|
|
smsLog.setStatus(1);
|
|
|
this.baseMapper.insert(smsLog);
|
|
this.baseMapper.insert(smsLog);
|
|
|
redisService.setCacheObject(RedisKeySaltConstant.REDIS_LOGIN_VALID_CODE_KEY+mobile,smsLog,120L, TimeUnit.MINUTES);
|
|
redisService.setCacheObject(RedisKeySaltConstant.REDIS_LOGIN_VALID_CODE_KEY+mobile,smsLog,120L, TimeUnit.MINUTES);
|
|
|
- } catch (ClientException e) {
|
|
|
|
|
- return Result.error(e.getMessage());
|
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return BizResult.error(e.getMessage());
|
|
|
}
|
|
}
|
|
|
- return Result.ok();
|
|
|
|
|
|
|
+ return BizResult.ok();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|