1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.ylx.massage.utils;
- import com.ylx.common.core.redis.RedisCache;
- import org.apache.commons.lang3.StringUtils;
- import javax.annotation.Resource;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- import java.text.DateFormat;
- import java.text.DecimalFormat;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.List;
- /**
- * @author jianlong
- * @date 2024-04-15 14:38
- */
- public class BillNoUtil {
- @Resource
- private RedisCache redisCache;
- public static final String NIGHT_FRAGRANCE_KEY_PREFIX = "NIGHT:codegenrator:";
- /**
- * 从Redis中获取某种类型的自增值
- * 生成规则 年(两位)+月(两位)+流水码(五位)
- * @param type
- * @return
- */
- // public String getAutoNumber(String type) {
- // String autoKeyFlag = ""; //定义接收用于自增的value
- // String autoKey = type+"tableAutoKey";
- // Boolean exists = redisCache.exists(autoKey);
- // long time = 2505600;//一个月时间
- // if(exists) {
- // autoKeyFlag = String.valueOf(redisCache.incr(autoKey));
- // }else {
- // redisService.set(autoKey, "0", "NX", "EX", time);
- // autoKeyFlag = String.valueOf(redisCache.incr(autoKey));
- // }
- // DecimalFormat df = new DecimalFormat("00000");
- // autoKeyFlag = df.format(Integer.parseInt(autoKeyFlag));
- // autoKeyFlag = String.valueOf(new SimpleDateFormat("yyMM").format(new Date()))+autoKeyFlag;
- // return autoKeyFlag;
- // }
- ////
- //// public List<String> fun() {
- //// return batchGenerateCode("JSIRTP", new SimpleDateFormat("yyMMdd"), 3, 4);
- //// }
- //
- /**
- * 批量获取Code
- *
- * @param prefix:业务场景,比如 PAYEE 表示收款
- * @param sdf: 日期格式化方式,如 yyyyMMdd
- * @param batchNum: 批量生成多少条,如 1000条
- * @param increaseFormatNum: 自增数格式化成多少位,如 5位
- * @return 生成的编码列表, 如[]
- */
- // public List<String> batchGenerateCode(String prefix, DateFormat sdf, int batchNum, int increaseFormatNum) {
- // if (null == prefix || sdf == null || batchNum <= 0) {
- // return null;
- // }
- // //构造key
- // Date date = Calendar.getInstance().getTime();
- // String formatDate = sdf.format(date);
- // String redisKey = new StringBuffer(NIGHT_FRAGRANCE_KEY_PREFIX).append(prefix).append(":").append(formatDate).toString();
- // //批量生成no
- // Long finalNum = redisCache.incr(redisKey, batchNum);
- // //设置过期时间
- // redisCache.expire(redisKey, DateUtils.getCurrent2TodayEndMillisTime() / SysConstant.ONE_THOUSAND);
- // //获取自增位格式化位数
- // DecimalFormat df = new DecimalFormat(StringUtils.repeat("0", increaseFormatNum));
- //
- // //构造结果
- // List<String> result = new ArrayList<>(batchNum);
- // for (long num = finalNum - batchNum + 1; num <= finalNum; num++) {
- // result.add(new StringBuffer(prefix).append(formatDate).append(df.format(num)).toString());
- // }
- // return result;
- // }
- }
|