• 规则:H+年+月+日+时+分+卡券类型+000000(最后六位为自然数增长加1)


    public class xxxGenerator {

    @Autowired
    private IRedisService redisService;

    /**
    * @desc : xxx规则:H+年+月+日+时+分+类型+000000(最后六位为自然数增长加1)
    **/
    public String generator(TypeEnum type){
    LocalDateTime nowTime = LocalDateTime.now();
    StringBuffer sb = new StringBuffer();
    sb.append("H");
    sb.append(String.valueOf(nowTime.getYear()).substring(2,4));
    sb.append(String.format("%02d",nowTime.getMonthValue()));
    sb.append(String.format("%02d",nowTime.getDayOfMonth()));
    sb.append(String.format("%02d",nowTime.getHour()));
    sb.append(String.format("%02d",nowTime.getMinute()));
    sb.append(couponType.getValue());

    StringBuffer redisKey = new StringBuffer();
    redisKey.append("H");
    redisKey.append(nowTime.getYear());
    redisKey.append(nowTime.getMonthValue());
    redisKey.append(nowTime.getDayOfMonth());

    LocalDateTime midnight = nowTime.plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
    long seconds = ChronoUnit.SECONDS.between(nowTime, midnight);
    sb.append(String.format("%06d",redisService.incr(redisKey.toString(),seconds)));
    log.info("xxx号:{}",sb.toString());
    return sb.toString();
    }

    public String next(TypeEnum type) {
    // return UuidUtil.nextAsTextWithoutHyphen();
    return generator(type);
    }
    }
  • 相关阅读:
    打印一个0到1之间的数的二进制表示
    bzoj-3223 文艺平衡树
    Linux下使用fstatfs/statfs查询系统相关信息
    Pku3664
    hdu-2544 最短路
    java同步包种ArrayBlockingQueue类的分析与理解
    【剑指offer】不用加减乘除做加法
    PA模块经常使用表
    网络编程
    // 插入排序 源代码
  • 原文地址:https://www.cnblogs.com/maohuidong/p/14005902.html
Copyright © 2020-2023  润新知