Helius
2020-05-29 8e64d903658a8df9eebc873c1c72c68f9b9bda32
src/main/java/com/xcong/excoin/common/system/service/impl/CommonServiceImpl.java
@@ -1,5 +1,7 @@
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;
@@ -8,6 +10,7 @@
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
/**
 * @author wzy
@@ -29,4 +32,28 @@
        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();
    }
}