|
|
|
package com.qs.serve.common.util;
|
|
|
|
|
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author YenHex
|
|
|
|
* @since 2022/2/28
|
|
|
|
*/
|
|
|
|
@UtilityClass
|
|
|
|
public class StringUtils extends org.springframework.util.StringUtils {
|
|
|
|
|
|
|
|
/** 订单号生成(NEW) **/
|
|
|
|
private static final AtomicInteger SEQ = new AtomicInteger(1000);
|
|
|
|
private static final DateTimeFormatter DF_FMT_PREFIX = DateTimeFormatter.ofPattern("yyMMddHHmmssSS");
|
|
|
|
private static ZoneId ZONE_ID = ZoneId.of("Asia/Shanghai");
|
|
|
|
public static String generateOrderNo(){
|
|
|
|
LocalDateTime dataTime = LocalDateTime.now(ZONE_ID);
|
|
|
|
if(SEQ.intValue()>9990){
|
|
|
|
SEQ.getAndSet(1000);
|
|
|
|
}
|
|
|
|
return dataTime.format(DF_FMT_PREFIX)+SEQ.getAndIncrement();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 非空 */
|
|
|
|
public static boolean isNotEmpty(String str){
|
|
|
|
return !isEmpty(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 含有空对象 */
|
|
|
|
public static boolean hasEmpty(Object... strings){
|
|
|
|
for (Object str : strings) {
|
|
|
|
if(isEmpty(str)){return true;}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 格式化
|
|
|
|
* @param exp 含{}的表达式
|
|
|
|
* @param params 参数(注意跳过空值)
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static String format(String exp,String... params){
|
|
|
|
StringBuilder builder = new StringBuilder(exp);
|
|
|
|
int idx_p = 0;
|
|
|
|
while (hasText(builder,"{}")){
|
|
|
|
int idx = builder.indexOf("{}");
|
|
|
|
if(idx_p<params.length&¶ms[idx_p]!=null){
|
|
|
|
builder.replace(idx,idx+2,params[idx_p]);
|
|
|
|
idx_p++;
|
|
|
|
}else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static boolean hasText(StringBuilder a,String text){
|
|
|
|
return a.toString().contains(text);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<String> splitIdString(String ids){
|
|
|
|
if(ids==null){
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if(ids.contains(",")){
|
|
|
|
String[] idsA= ids.split(",");
|
|
|
|
return Arrays.asList(idsA);
|
|
|
|
}
|
|
|
|
return Arrays.asList(ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<Long> splitIdLong(String ids){
|
|
|
|
List<String> strs = splitIdString(ids);
|
|
|
|
if(strs!=null){
|
|
|
|
return strs.stream().map(a->Long.parseLong(a)).collect(Collectors.toList());
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|