|
|
@@ -1,89 +0,0 @@
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
-
|
|
|
-public class JsonPrice {
|
|
|
-
|
|
|
- public static Double getPriceByQty(String priceJson, Double qty, String priceProperty) {
|
|
|
- List<Map<String, String>> array = JSON.parseArray(priceJson);
|
|
|
- Double start = 0.0d;
|
|
|
- Double end = 0.0d;
|
|
|
- try {
|
|
|
- for (Map<String, String> map : array) {
|
|
|
- start = Double.parseDouble(map.get("start"));
|
|
|
- end = Double.parseDouble(map.get("end"));
|
|
|
- if (Double.compare(start, qty) < 1 && Double.compare(end, qty) > -1) {
|
|
|
- String price = map.get(priceProperty);
|
|
|
- return (null == price || price.length() == 0) ? null : Double.parseDouble(price);
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }catch (Exception e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public static Double getInfoByProperty(String priceJson, Integer index, String property) {
|
|
|
- List<Map<String, String>> array = JSON.parseArray(priceJson);
|
|
|
- if(array.size() <= index) {
|
|
|
- return null;
|
|
|
- }else {
|
|
|
- Map<String, String> map = array.get(index);
|
|
|
- Set<String> properties = map.keySet();
|
|
|
- for (String proper : properties) {
|
|
|
- if(proper.equals(property)) {
|
|
|
- try {
|
|
|
- return Double.parseDouble(map.get(proper));
|
|
|
- }catch (Exception e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static Double getMinPrice(String priceJson, String priceProperty) {
|
|
|
- List<Map<String, String>> array = JSON.parseArray(priceJson);
|
|
|
- Double minPrice = Double.MAX_VALUE;
|
|
|
- for (Map<String, String> map : array) {
|
|
|
- try {
|
|
|
- String price = map.get(priceProperty);
|
|
|
- Double mprice = (null == price || price.length() == 0) ? null : Double.parseDouble(price);
|
|
|
- if (Double.compare(minPrice, mprice) > 0) {
|
|
|
- minPrice = mprice;
|
|
|
- }
|
|
|
- if(Double.compare(Double.MAX_VALUE, minPrice) == 0) {
|
|
|
- return null;
|
|
|
- }else {
|
|
|
- return minPrice;
|
|
|
- }
|
|
|
- }catch (Exception e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public static Double getMaxPrice(String priceJson, String priceProperty) {
|
|
|
- List<Map<String, String>> array = JSON.parseArray(priceJson);
|
|
|
- Double maxPrice = Double.MIN_VALUE;
|
|
|
- try {
|
|
|
- for (Map<String, String> map : array) {
|
|
|
- String price = map.get(priceProperty);
|
|
|
- Double mprice = (null == price || price.length() == 0) ? null : Double.parseDouble(price);
|
|
|
- if (Double.compare(maxPrice, mprice) < 1) {
|
|
|
- maxPrice = mprice;
|
|
|
- }
|
|
|
- }
|
|
|
- if (Double.compare(Double.MIN_VALUE, maxPrice) == 0) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- return maxPrice;
|
|
|
- }
|
|
|
- }catch (Exception e) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|