|
|
@@ -1,5 +1,6 @@
|
|
|
package top.lvzhiqiang.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -9,6 +10,7 @@ import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
|
|
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
|
|
import org.jsoup.Connection;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
@@ -50,6 +52,9 @@ public class CoinServiceImpl implements CoinService {
|
|
|
// 私钥,由系统随机生成,用于签名的生成。
|
|
|
private static final String secretKey = "1fdd0fc2976bea80189ba13710e12825ca3ef6c5e25a0d76fd03f8f6cd4a61d9";
|
|
|
|
|
|
+ @Value("${spring.profiles.active}")
|
|
|
+ private String env;
|
|
|
+
|
|
|
@Resource
|
|
|
private CoinMapper coinMapper;
|
|
|
|
|
|
@@ -60,6 +65,8 @@ public class CoinServiceImpl implements CoinService {
|
|
|
|
|
|
private final Map<String, String> orderMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
+ Proxy proxy = null;
|
|
|
+
|
|
|
static {
|
|
|
// API KEY作为一个字符串。
|
|
|
basicHeaderMap.put("ACCESS-KEY", "bg_433d37306df0e8901c6d107c6d9e9111");
|
|
|
@@ -75,6 +82,16 @@ public class CoinServiceImpl implements CoinService {
|
|
|
basicHeaderMap.put("locale", "zh-CN");
|
|
|
}
|
|
|
|
|
|
+ public void beforeProxy() {
|
|
|
+ if (null == proxy) {
|
|
|
+ if ("dev".equals(env)) {
|
|
|
+ proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
|
|
|
+ } else {
|
|
|
+ proxy = Proxy.NO_PROXY;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
|
|
public void syncData(String startTime, String endTime, String pageSize) {
|
|
|
@@ -90,7 +107,9 @@ public class CoinServiceImpl implements CoinService {
|
|
|
JSONObject response = requestApi4Common("/api/mix/v1/order/historyProductType", signQueryString, null, JsoupUtil.HTTP_GET, paramMap);
|
|
|
|
|
|
JSONArray orderList = response.getJSONObject("data").getJSONArray("orderList");
|
|
|
- coinMapper.insertHistoryOrderList(JSONArray.parseArray(orderList.toJSONString(), CoinHistoryOrder.class));
|
|
|
+ if (orderList.size() > 0) {
|
|
|
+ coinMapper.insertHistoryOrderList(JSONArray.parseArray(orderList.toJSONString(), CoinHistoryOrder.class));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -172,9 +191,9 @@ public class CoinServiceImpl implements CoinService {
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
+ beforeProxy();
|
|
|
+
|
|
|
String requestUrl = mainUrl + requestPath;
|
|
|
- //Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 1080));
|
|
|
- Proxy proxy = Proxy.NO_PROXY;
|
|
|
Connection.Response response = JsoupUtil.requestBody(requestUrl, httpMethod, proxy, headerMap, paramMap);
|
|
|
|
|
|
return JSONObject.parseObject(response.body());
|
|
|
@@ -209,11 +228,23 @@ public class CoinServiceImpl implements CoinService {
|
|
|
result = response.getJSONArray("data");
|
|
|
|
|
|
renderMainSearch4OrderMarginCoinCurrent(result);
|
|
|
+ } else if (params.getString("nameEn").equals("orderHistoryProductType")) {
|
|
|
+ List<CoinHistoryOrder> historyOrderList = coinMapper.findByParams();
|
|
|
+
|
|
|
+ renderMainSearch4OrderHistoryProductType(historyOrderList);
|
|
|
+ result = (JSONArray) JSON.toJSON(historyOrderList);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ private void renderMainSearch4OrderHistoryProductType(List<CoinHistoryOrder> historyOrderList) {
|
|
|
+ for (CoinHistoryOrder coinHistoryOrder : historyOrderList) {
|
|
|
+ coinHistoryOrder.setCTime(DateUtils.longToString(Long.valueOf(coinHistoryOrder.getCTime())));
|
|
|
+ coinHistoryOrder.setUTime(DateUtils.longToString(Long.valueOf(coinHistoryOrder.getUTime())));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void renderMainSearch4OrderMarginCoinCurrent(JSONArray result) {
|
|
|
for (int i = 0; i < result.size(); i++) {
|
|
|
JSONObject jsonObject = result.getJSONObject(i);
|