AllUtils.java
2.0 KB
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
package com.sunyo.energy.location.utils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
public class AllUtils {
// 数字相减 参数1 减去 参数2
public static String nubmerSubtraction(String sacc, String lacc) {
BigDecimal saccBigDecimal = new BigDecimal(sacc);
BigDecimal laccBigDecimal = new BigDecimal(lacc);
String surplus = saccBigDecimal.subtract(laccBigDecimal).toString();
return surplus;
}
// 数字相除 参数1 除以参数2
public static String nubmerDivision(String payFees) {
// 单价
String unitprice = PropertiesLoader.getUnitPrice("unitprice");
BigDecimal payFessDecimal = new BigDecimal(payFees);
BigDecimal unitpriceDecimal = new BigDecimal(unitprice);
String s = payFessDecimal.divide(unitpriceDecimal, 2, RoundingMode.HALF_UP).toString();
return s;
}
//数字相加 参数1加参数2
public static String nubmerAdd(String oneWmSacc, BigDecimal s) {
BigDecimal bigDecimal = new BigDecimal(oneWmSacc);
String s1 = bigDecimal.add(s).toString();
return s1;
}
// 订单号生成 时间加随机数
public static String getOrderIdByTime() {
// 商户码
String merchantId = "105001453995827";
String result = "";
Random random = new Random();
for (int i = 0; i < 3; i++) {
result += random.nextInt(10);
}
return merchantId + result;
}
/**
* 处理水表编号加 '-' 问题
* @param replace 水表编号
* @return
*/
public static String wmIdUtils(String replace) {
if (!replace.contains("-")){
String regex = "(.{2})";
replace = replace.replaceAll(regex, "$1-");
String substring = replace.substring(0, replace.length() - 1);
return substring;
}else {
return replace;
}
}
}