|
|
@@ -3,12 +3,13 @@ package com.uas.platform.b2c.advertise.ad.service.impl;
|
|
|
import com.uas.platform.b2c.advertise.ad.service.CarouselService;
|
|
|
import com.uas.platform.b2c.core.config.MicroServicesConf;
|
|
|
import com.uas.platform.b2c.core.utils.JsonUtil;
|
|
|
+import net.sf.json.JSONException;
|
|
|
import net.sf.json.JSONObject;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
-import java.util.List;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* The type Carousels service implementation.
|
|
|
@@ -30,10 +31,29 @@ public class CarouselsServiceImpl implements CarouselService{
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<JSONObject> getCarousels(String usedFor) {
|
|
|
+ public List<LinkedHashMap> getCarousels(String usedFor) {
|
|
|
String url = conf.getRequestUrlForCarousel(20030, "/carousels?usedFor=" + usedFor);
|
|
|
String result = restTemplate.getForEntity(url, String.class).getBody();
|
|
|
- List<JSONObject> r = JsonUtil.parseJsonToObject(result);
|
|
|
- return r;
|
|
|
+ List<LinkedHashMap> jsonValues = JsonUtil.parseJsonToObject(result);
|
|
|
+
|
|
|
+ Collections.sort( jsonValues, new Comparator<LinkedHashMap>() {
|
|
|
+ private static final String KEY_NAME = "orderNumber";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int compare(LinkedHashMap a, LinkedHashMap b) {
|
|
|
+ String valA = new String();
|
|
|
+ String valB = new String();
|
|
|
+
|
|
|
+ try {
|
|
|
+ valA = String.valueOf(a.get(KEY_NAME));
|
|
|
+ valB = String.valueOf(b.get(KEY_NAME));
|
|
|
+ }
|
|
|
+ catch (JSONException e) {
|
|
|
+ }
|
|
|
+ return valA.compareTo(valB);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return jsonValues;
|
|
|
}
|
|
|
}
|