jiangqs
2023-08-06 beeda8df0023376dbb2021148a021731dc4aedb0
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/utils/CodeFactoryUtil.java
@@ -5,7 +5,6 @@
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.security.SecureRandom;
import java.util.Date;
import java.util.Random;
@@ -21,14 +20,13 @@
@Component
public class CodeFactoryUtil {
    private static RedisService redisService = null;
    //静态住入到自己的类中
    private static RedisService redisService;
    //将静态属性以入参(形参)的方式传入一个方法中,然后将此方法通过 @Resource 注入到Spring容器中
    @Resource
    public void setService(RedisService redisService) {
        CodeFactoryUtil.redisService = redisService;
    private static RedisService getRedisService() {
        if (redisService == null) {
            redisService = ApplicationContextUtil.getBean(RedisService.class);
        }
        return redisService;
    }
    /**
@@ -123,7 +121,7 @@
     */
    public static void main(String[] args) {
        System.out.printf("getShopNo()"+getShopNo());
    }
    /**
@@ -167,13 +165,13 @@
    private static String getNoSuffixNumber(String prefix){
        Integer suffixNumberInt;
        String suffixNumber = "00001";
        if(redisService.hasKey(prefix)){
            suffixNumberInt = redisService.getCacheObject(prefix);
        if(getRedisService().hasKey(prefix)){
            suffixNumberInt = getRedisService().getCacheObject(prefix);
            suffixNumber = toFillZeroSuffixNumber(suffixNumberInt,SHOP_LENGTH);
            suffixNumberInt = suffixNumberInt + 1;
            redisService.setCacheObject(prefix, suffixNumberInt);
            getRedisService().setCacheObject(prefix, suffixNumberInt);
        }else{
            redisService.setCacheObject(prefix, 1);
            getRedisService().setCacheObject(prefix, 1);
        }
        return suffixNumber;
    }
@@ -200,13 +198,13 @@
    private static String getOrderSuffixNumber(String prefix){
        Integer suffixNumberInt;
        String suffixNumber = "0001";
        if(redisService.hasKey(prefix)){
            suffixNumberInt = redisService.getCacheObject(prefix);
        if(getRedisService().hasKey(prefix)){
            suffixNumberInt = getRedisService().getCacheObject(prefix);
            suffixNumber = toFillZeroSuffixNumber(suffixNumberInt,ORDER_LENGTH);
            suffixNumberInt = suffixNumberInt + 1;
            redisService.setCacheObject(prefix, suffixNumberInt, 24L, TimeUnit.HOURS);
            getRedisService().setCacheObject(prefix, suffixNumberInt, 24L, TimeUnit.HOURS);
        }else{
            redisService.setCacheObject(prefix, 1, 24L, TimeUnit.HOURS);
            getRedisService().setCacheObject(prefix, 1, 24L, TimeUnit.HOURS);
        }
        return suffixNumber;
    }