-
Notifications
You must be signed in to change notification settings - Fork 29
/
tes4
183 lines (158 loc) · 5.79 KB
/
tes4
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import java.math.BigDecimal;
public class GxcwCharging {
/**
* 免费时长
*/
private float freeDuration = 0f;
/**
* 起始计费时长
*/
private float startHour = 5f;
/**
* 起始计费费用
*/
private float startCost;
/**
* 封顶费用
*/
private float cappingFee;
/**
* 封顶小时
*/
private float cappingHour = 24f;
/**
* 每小时价格
*/
private float pricePerHour;
/**
* 超时后每小时价格
*/
private float overtimePerHour = 1f;
public double calcFee(float hour,boolean isCalcFree) {
if (hour <= 0.00f) {
return 0d;
}
if (isCalcFree && freeDuration > 0f && hour <= freeDuration) {
return 0d;
}
//在起始计费时间内
if (startHour > 0.00f && hour <= startHour) {
return AmountUtil.get2Double(Double.valueOf(startCost), 2);
}
if (cappingHour > 0f && hour <= cappingHour && hour >= startHour) {
//每小时价格
if (pricePerHour > 0.00f && AmountUtil.compareTo(Double.valueOf(pricePerHour), Double.valueOf(0.00d)) == 1) {
double diffHour = hour - startHour;
double calcPrice = AmountUtil.multiply(diffHour, Double.valueOf(pricePerHour), 2);
double taotalFee = AmountUtil.add(Double.valueOf(startCost), calcPrice, 2);
int compareTo = AmountUtil.compareTo(taotalFee,Double.valueOf(cappingFee));
if (compareTo == 1) {
return AmountUtil.get2Double(Double.valueOf(cappingFee), 2);
}else {
return taotalFee;
}
}else {
return AmountUtil.get2Double(Double.valueOf(cappingFee), 2);
}
}else if (cappingHour > 0f && hour > cappingHour) {
BigDecimal val1 = new BigDecimal(hour);
BigDecimal val2 = new BigDecimal(cappingHour);
BigDecimal[] bigDecimals = val1.divideAndRemainder(val2);
double diffDay = bigDecimals[0].doubleValue();
float diffHour = bigDecimals[1].floatValue();
double totalDayFree = AmountUtil.multiply(diffDay, Double.valueOf(cappingFee), 2);
double diffHourFree = 0d;
if (diffHour > 0.00d) {
diffHourFree = calcFee(diffHour,false);
}
return AmountUtil.add(totalDayFree, diffHourFree, 2);
} else {
if (pricePerHour > 0.00f && AmountUtil.compareTo(Double.valueOf(pricePerHour), Double.valueOf(0.00d)) == 1) {
}
}
return Double.MAX_VALUE;
}
public static void main(String[] args) {
//5小时以内5元,超过5小时1元/每小时 24小时13元封顶,不足1小时按照1小时计费超过24小时,累计计费
// GxcwCharging charging = new GxcwCharging();
// charging.setCappingFee(13f);
// charging.setCappingHour(24f);
// charging.setFreeDuration(0f);
// charging.setPricePerHour(1f);
// charging.setStartCost(5f);
// charging.setStartHour(5f);
//
// for (int i = 1;i < 100;i++) {
// float hour = Float.valueOf(i);
// System.err.println(hour + "小时," + charging.calcFee(hour) + "元");
// }
// System.err.println(48 + "小时," + charging.calcFee(48f) + "元");
//8小时以内5元 超过8小时10元
// GxcwCharging charging = new GxcwCharging();
// charging.setCappingFee(10f);
// charging.setCappingHour(24f);
// charging.setFreeDuration(0f);
// charging.setPricePerHour(0f);
// charging.setStartCost(5f);
// charging.setStartHour(8f);
// for (int i = 1;i < 100;i++) {
// float hour = Float.valueOf(i);
// System.err.println(hour + "小时," + charging.calcFee(hour) + "元");
// }
// System.err.println(9 + "小时," + charging.calcFee(9f) + "元");
GxcwCharging charging = new GxcwCharging();
charging.setCappingFee(10f);
charging.setCappingHour(24f);
charging.setFreeDuration(2f);
charging.setPricePerHour(0f);
charging.setStartCost(5f);
charging.setStartHour(12f);
for (int i = 1; i < 100; i++) {
float hour = Float.valueOf(i);
System.err.println(hour + "小时," + charging.calcFee(hour,true) + "元");
}
// System.err.println(3 + "小时," + charging.calcFee(3f) + "元");
}
public float getFreeDuration() {
return freeDuration;
}
public void setFreeDuration(float freeDuration) {
this.freeDuration = freeDuration;
}
public float getStartHour() {
return startHour;
}
public void setStartHour(float startHour) {
this.startHour = startHour;
}
public float getStartCost() {
return startCost;
}
public void setStartCost(float startCost) {
this.startCost = startCost;
}
public float getCappingFee() {
return cappingFee;
}
public void setCappingFee(float cappingFee) {
this.cappingFee = cappingFee;
}
public float getCappingHour() {
return cappingHour;
}
public void setCappingHour(float cappingHour) {
this.cappingHour = cappingHour;
}
public float getPricePerHour() {
return pricePerHour;
}
public void setPricePerHour(float pricePerHour) {
this.pricePerHour = pricePerHour;
}
public float getOvertimePerHour() {
return overtimePerHour;
}
public void setOvertimePerHour(float overtimePerHour) {
this.overtimePerHour = overtimePerHour;
}
}