ab
2024-11-04 22e95203d1e0c285fb6b9a61f05be9438ef3b992
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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;
    }
}