From 292a4634d9c52ce193eca9de356d65960bdc35f4 Mon Sep 17 00:00:00 2001 From: xiaoyong931011 <15274802129@163.com> Date: Fri, 15 Jan 2021 18:20:37 +0800 Subject: [PATCH] 20210115 --- src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java | 40 +++++++++++++++++++++++++++++++++++++++- 1 files changed, 39 insertions(+), 1 deletions(-) diff --git a/src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java b/src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java index aad0d55..f812194 100644 --- a/src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java +++ b/src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java @@ -1,13 +1,17 @@ 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.configurations.properties.ApplicationProperties; 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 @@ -20,13 +24,47 @@ @Resource private RedisUtils redisUtils; + @Resource + private ApplicationProperties properties; + @Override public boolean verifyCode(String account, String code) { +// if (properties.isDebug()) { +// return true; +// } 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; + } + } - return code.equals(cacheCode); + @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(); } } -- Gitblit v1.9.1