package com.xcong.excoin.common.system.service.impl;
|
|
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.StrUtil;
|
import com.xcong.excoin.common.contants.AppContants;
|
import com.xcong.excoin.common.system.service.CommonService;
|
import com.xcong.excoin.utils.RedisUtils;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.Date;
|
|
/**
|
* @author wzy
|
* @date 2020-05-29
|
**/
|
@Slf4j
|
@Service
|
public class CommonServiceImpl implements CommonService {
|
|
@Resource
|
private RedisUtils redisUtils;
|
|
@Override
|
public boolean verifyCode(String account, String code) {
|
if(StrUtil.isBlank(code)){
|
return false;
|
}
|
String cacheCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + account);
|
if (StrUtil.isBlank(cacheCode)) {
|
return false;
|
}
|
if (code.equals(cacheCode)) {
|
redisUtils.del(AppContants.VERIFY_CODE_PREFIX + account);
|
return true;
|
} else {
|
return false;
|
}
|
}
|
|
@Override
|
public boolean mutiVerifyCode(String email, String emailCode, String phone, String phoneCode) {
|
if (StrUtil.isBlank(emailCode) || StrUtil.isBlank(phoneCode)) {
|
return false;
|
}
|
|
String cacheEmailCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + email);
|
String cachePhoneCode = redisUtils.getString(AppContants.VERIFY_CODE_PREFIX + phone);
|
if (StrUtil.isBlank(cacheEmailCode) || StrUtil.isBlank(cachePhoneCode)) {
|
return false;
|
}
|
|
if (emailCode.equals(cacheEmailCode) && phoneCode.equals(cachePhoneCode)) {
|
redisUtils.del(AppContants.VERIFY_CODE_PREFIX + email);
|
redisUtils.del(AppContants.VERIFY_CODE_PREFIX + phone);
|
return true;
|
}
|
return false;
|
}
|
|
@Override
|
public String generateOrderNo(Long mid) {
|
StringBuilder orderNo = new StringBuilder();
|
String date = DateUtil.format(new Date(), "yyyyMMdd");
|
orderNo.append(date);
|
orderNo.append(mid);
|
orderNo.append(RandomUtil.randomNumbers(2));
|
|
Object countObj = redisUtils.get(date);
|
if (countObj == null) {
|
countObj = 0;
|
}
|
int count = (int) countObj;
|
count++;
|
redisUtils.set(date, count, 24 * 60 * 60);
|
|
int size = 4;
|
for (int i = 0; i < size - String.valueOf(count).length(); i++) {
|
orderNo.append("0");
|
}
|
orderNo.append(count);
|
return orderNo.toString();
|
}
|
}
|