package com.nova.sankuai.infra.utils;
|
|
import cn.hutool.core.date.DateUtil;
|
import io.swagger.annotations.ApiModel;
|
import org.apache.commons.lang.StringUtils;
|
|
import javax.servlet.http.HttpServletRequest;
|
import java.text.SimpleDateFormat;
|
import java.util.Date;
|
import java.text.DecimalFormat;
|
import java.util.UUID;
|
|
import static com.nova.sankuai.domain.api.yinsheng.SerialGenerator.generateRandomSerial;
|
|
/**
|
* @author weikangdi
|
* @create 2022/6/14
|
*/
|
@ApiModel(value = "通用工具类")
|
public class ConstantsUtil {
|
|
public static String getHostUrl(HttpServletRequest request) {
|
String scheme = request.getScheme();
|
String referer = request.getServerName();
|
String url = scheme + "://" + referer;
|
return url;
|
}
|
|
public static Long parseEndDate(String dateStr) {
|
Date date = DateUtil.parse(dateStr);
|
return DateUtil.endOfDay(date).getTime();
|
}
|
|
public static Double formatPrice(String price) {
|
if (StringUtils.isNotEmpty(price)) {
|
Double d = Double.parseDouble(price);
|
DecimalFormat df = new DecimalFormat("#.00");
|
return Double.valueOf(df.format(d));
|
} else {
|
return 0d;
|
}
|
}
|
|
public static String getOrder() {
|
StringBuilder sb = new StringBuilder();
|
sb.append(dateFormatFactory.get().format(new Date())).append("10")
|
.append(generateRandomSerial(36 - sb.length()));
|
return sb.toString();
|
}
|
|
/**
|
* 日期格式化模板
|
*/
|
public static ThreadLocal<SimpleDateFormat> dateFormatFactory = ThreadLocal.withInitial(() -> new SimpleDateFormat("yyyyMMddHHmmssSSS"));
|
|
/**
|
* 生成creditNo
|
* @return
|
*/
|
public static String getCreditNo() {
|
UUID uuid = UUID.randomUUID();
|
String creditNo = uuid.toString().replace("-", "");
|
return creditNo;
|
}
|
|
/**
|
* 格式化金额(将分转成元)
|
* @param amount
|
* @return
|
*/
|
public static Double parseAmount(Long amount) {
|
if (amount != null) {
|
Double parse = Double.valueOf(amount) / 100;
|
return parse;
|
}
|
return 0.00;
|
}
|
}
|