zoukankan      html  css  js  c++  java
  • 规则: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);
    }
    }
  • 相关阅读:
    51nod 1117 聪明的木匠:哈夫曼树
    51nod 1010 只包含因子2 3 5的数
    51nod 2636 卡车加油
    51nod 2989 组合数
    51nod 2652 阶乘0的数量 V2
    51nod 1103 N的倍数
    51nod 2489 小b和灯泡
    51nod 1003 阶乘后面0的数量
    51nod 2122 分解质因数
    javascript中的setter和getter
  • 原文地址:https://www.cnblogs.com/maohuidong/p/14005902.html
Copyright © 2011-2022 走看看