BillNoUtil.java 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. package com.ylx.massage.utils;
  2. import com.ylx.common.core.redis.RedisCache;
  3. import org.apache.commons.lang3.StringUtils;
  4. import javax.annotation.Resource;
  5. import java.math.BigDecimal;
  6. import java.math.RoundingMode;
  7. import java.text.DateFormat;
  8. import java.text.DecimalFormat;
  9. import java.text.SimpleDateFormat;
  10. import java.util.ArrayList;
  11. import java.util.Calendar;
  12. import java.util.Date;
  13. import java.util.List;
  14. /**
  15. * @author jianlong
  16. * @date 2024-04-15 14:38
  17. */
  18. public class BillNoUtil {
  19. @Resource
  20. private RedisCache redisCache;
  21. public static final String NIGHT_FRAGRANCE_KEY_PREFIX = "NIGHT:codegenrator:";
  22. /**
  23. * 从Redis中获取某种类型的自增值
  24. * 生成规则 年(两位)+月(两位)+流水码(五位)
  25. * @param type
  26. * @return
  27. */
  28. // public String getAutoNumber(String type) {
  29. // String autoKeyFlag = ""; //定义接收用于自增的value
  30. // String autoKey = type+"tableAutoKey";
  31. // Boolean exists = redisCache.exists(autoKey);
  32. // long time = 2505600;//一个月时间
  33. // if(exists) {
  34. // autoKeyFlag = String.valueOf(redisCache.incr(autoKey));
  35. // }else {
  36. // redisService.set(autoKey, "0", "NX", "EX", time);
  37. // autoKeyFlag = String.valueOf(redisCache.incr(autoKey));
  38. // }
  39. // DecimalFormat df = new DecimalFormat("00000");
  40. // autoKeyFlag = df.format(Integer.parseInt(autoKeyFlag));
  41. // autoKeyFlag = String.valueOf(new SimpleDateFormat("yyMM").format(new Date()))+autoKeyFlag;
  42. // return autoKeyFlag;
  43. // }
  44. ////
  45. //// public List<String> fun() {
  46. //// return batchGenerateCode("JSIRTP", new SimpleDateFormat("yyMMdd"), 3, 4);
  47. //// }
  48. //
  49. /**
  50. * 批量获取Code
  51. *
  52. * @param prefix:业务场景,比如 PAYEE 表示收款
  53. * @param sdf: 日期格式化方式,如 yyyyMMdd
  54. * @param batchNum: 批量生成多少条,如 1000条
  55. * @param increaseFormatNum: 自增数格式化成多少位,如 5位
  56. * @return 生成的编码列表, 如[]
  57. */
  58. // public List<String> batchGenerateCode(String prefix, DateFormat sdf, int batchNum, int increaseFormatNum) {
  59. // if (null == prefix || sdf == null || batchNum <= 0) {
  60. // return null;
  61. // }
  62. // //构造key
  63. // Date date = Calendar.getInstance().getTime();
  64. // String formatDate = sdf.format(date);
  65. // String redisKey = new StringBuffer(NIGHT_FRAGRANCE_KEY_PREFIX).append(prefix).append(":").append(formatDate).toString();
  66. // //批量生成no
  67. // Long finalNum = redisCache.incr(redisKey, batchNum);
  68. // //设置过期时间
  69. // redisCache.expire(redisKey, DateUtils.getCurrent2TodayEndMillisTime() / SysConstant.ONE_THOUSAND);
  70. // //获取自增位格式化位数
  71. // DecimalFormat df = new DecimalFormat(StringUtils.repeat("0", increaseFormatNum));
  72. //
  73. // //构造结果
  74. // List<String> result = new ArrayList<>(batchNum);
  75. // for (long num = finalNum - batchNum + 1; num <= finalNum; num++) {
  76. // result.add(new StringBuffer(prefix).append(formatDate).append(df.format(num)).toString());
  77. // }
  78. // return result;
  79. // }
  80. }