|
@@ -15,6 +15,7 @@ import com.reptileclient.jlifeapp.service.DyLaikeService;
|
|
|
import com.reptileclient.jlifeapp.util.OkHttpUtil;
|
|
|
import com.reptileclient.jlifeapp.util.ThreadPoolManager;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -47,15 +48,16 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
|
|
|
private String token;
|
|
|
|
|
|
- private String accountId;
|
|
|
+ private String accountId = "7161316264890075172";
|
|
|
|
|
|
private Integer batchId = 0;
|
|
|
private Integer batchId2 = 0;
|
|
|
private Integer shopEvaltionCount = 0;
|
|
|
|
|
|
- private final Integer pageSize = 200;
|
|
|
+ private final Integer pageSize = 2000;
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
public void syncShopAndPoi() {
|
|
|
shopMapInfoMapper.clear();
|
|
|
DyLaikeToken dyLaikeToken = dyLaikeTokenMapper.selectByPrimaryKey(1);
|
|
@@ -63,9 +65,21 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
accountId = dyLaikeToken.getAccountId();
|
|
|
String requestUrl = DyLifeConstants.shopList.replace("{root_life_account_id}", accountId);
|
|
|
Map<String, Object> requestMap = new HashMap<>();
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("claim_status", 1);
|
|
|
+ jsonObject.put("open_status", 1);
|
|
|
+ jsonObject.put("req_source", 1);
|
|
|
+ jsonObject.put("role_list", "1");
|
|
|
+ jsonObject.put("template_type", "open_multi_account");
|
|
|
+ JSONObject jsonObject1 = new JSONObject();
|
|
|
+ jsonObject1.put("page", 1);
|
|
|
+ jsonObject1.put("page_size", 2000);
|
|
|
+ jsonObject.put("page", jsonObject1);
|
|
|
+ requestMap.put("param", jsonObject);
|
|
|
+
|
|
|
String response = OkHttpUtil.post2Dy(requestUrl, requestMap, token);
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(response);
|
|
|
- Integer code = jsonObject.getInteger("status_code");
|
|
|
+ JSONObject x = JSONObject.parseObject(response);
|
|
|
+ Integer code = x.getInteger("status_code");
|
|
|
if (code != 0) {
|
|
|
//休息2秒,准备重试
|
|
|
try {
|
|
@@ -98,7 +112,7 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
realStart(requestUrl, secondJsonObject);
|
|
|
}
|
|
|
}
|
|
|
- realStart(requestUrl, jsonObject);
|
|
|
+ realStart(requestUrl, x);
|
|
|
}
|
|
|
|
|
|
private void realStart(String requestUrl, JSONObject thirdJsonObject) {
|
|
@@ -106,6 +120,43 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
Integer count = pageInfo.getInteger("total_count");
|
|
|
//计算需要请求的次数
|
|
|
int requestTimes = count / pageSize;
|
|
|
+ if (requestTimes == 0) {
|
|
|
+ //只有一页,直接处理本次返回的数据
|
|
|
+ JSONArray jsonArray = thirdJsonObject.getJSONObject("data").getJSONArray("claim_pois");
|
|
|
+ String relationUrl = DyLifeConstants.relationList.replace("{root_life_account_id}", accountId);
|
|
|
+
|
|
|
+ String json = "{\"search_params\":{\"parent_life_account_ids\":[\"10000\"],\"relation_types\":[1,6]},\"page_index\":1,\"page_size\":200}";
|
|
|
+ String s = OkHttpUtil.post2Dy(relationUrl, json, token);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(s);
|
|
|
+ JSONArray array = jsonObject.getJSONObject("data").getJSONArray("list");
|
|
|
+
|
|
|
+
|
|
|
+ for (int i = 0; i <= 6; i++) {
|
|
|
+ json = "{\"search_params\":{\"parent_life_account_ids\":[\"10000\"],\"relation_types\":[1,6]},\"page_index\":" + (i + 1) + ",\"page_size\":200}";
|
|
|
+ String s1 = OkHttpUtil.post2Dy(relationUrl, json, token);
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(s1);
|
|
|
+ JSONArray array1 = jsonObject1.getJSONObject("data").getJSONArray("list");
|
|
|
+ array.addAll(array1);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (Object o : jsonArray) {
|
|
|
+ JSONObject js = (JSONObject) o;
|
|
|
+ DyLaikeAccountShopMapInfo dyLaikeAccountShopMapInfo = new DyLaikeAccountShopMapInfo();
|
|
|
+ array.forEach(a -> {
|
|
|
+ JSONObject j = (JSONObject) a;
|
|
|
+ if (j.getString("poi_id").equals(js.getString("poi_id"))) {
|
|
|
+ dyLaikeAccountShopMapInfo.setShopAccountId(j.getString("poi_life_account_id"));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ dyLaikeAccountShopMapInfo.setDeleted(0);
|
|
|
+ dyLaikeAccountShopMapInfo.setShopName(js.getString("poi_name"));
|
|
|
+ dyLaikeAccountShopMapInfo.setShopPoiId(js.getString("poi_id"));
|
|
|
+ shopMapInfoMapper.insertSelective(dyLaikeAccountShopMapInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (count % pageSize != 0) {
|
|
|
requestTimes++;
|
|
|
}
|
|
@@ -150,13 +201,17 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
|
|
|
@Override
|
|
|
public void getReviewData() {
|
|
|
- syncShopAndPoi();
|
|
|
-
|
|
|
+// syncShopAndPoi();
|
|
|
+ DyLaikeToken dyLaikeToken = dyLaikeTokenMapper.selectByPrimaryKey(1);
|
|
|
+ token = dyLaikeToken.getToken();
|
|
|
List<DyLaikeAccountShopMapInfo> shops = shopMapInfoMapper.selectAll();
|
|
|
|
|
|
batchId = shopEvaltionMapper.getLastBatch();
|
|
|
List<DyLaikeAccountShopMapInfo> failShopMaps = new ArrayList<>();
|
|
|
for (DyLaikeAccountShopMapInfo shop : shops) {
|
|
|
+ if (shop.getShopAccountId() == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
String requestUrl = DyLifeConstants.reviewApi.replace("{shop_account_id}", shop.getShopAccountId())
|
|
|
.replace("{poi_id}", shop.getShopPoiId())
|
|
|
.replace("{root_life_account_id}", accountId);
|
|
@@ -199,15 +254,19 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
@Override
|
|
|
public void getThreeRate() {
|
|
|
syncShopAndPoi();
|
|
|
+ DyLaikeToken dyLaikeToken = dyLaikeTokenMapper.selectByPrimaryKey(1);
|
|
|
+ token = dyLaikeToken.getToken();
|
|
|
List<DyLaikeAccountShopMapInfo> shops = shopMapInfoMapper.selectAll();
|
|
|
|
|
|
batchId2 = shopEvaltionMapper.getLastBatch();
|
|
|
- // 上周三
|
|
|
- String start_date = LocalDateTime.now().minusDays(7).withHour(0).withMinute(0).withSecond(0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
- //本周二
|
|
|
+ // 30天
|
|
|
+ String start_date = LocalDateTime.now().minusDays(30).withHour(0).withMinute(0).withSecond(0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
String end_date = LocalDateTime.now().minusDays(1).withHour(0).withMinute(0).withSecond(0).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
|
|
List<DyLaikeAccountShopMapInfo> failShopMaps = new ArrayList<>();
|
|
|
for (DyLaikeAccountShopMapInfo shop : shops) {
|
|
|
+ if (StringUtils.isEmpty(shop.getShopAccountId())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
String requestUrl = DyLifeConstants.threeRateApi.replace("{this_shop_id}", shop.getShopAccountId())
|
|
|
.replace("{root_life_account_id}", accountId)
|
|
|
.replace("{start_date}", start_date)
|
|
@@ -253,9 +312,6 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
ThreadPoolManager.execute(() -> {
|
|
|
try {
|
|
|
saveThreeRate(requestUrl, shopPoiId, shopName, start_date, end_date);
|
|
|
- } catch (Exception e) {
|
|
|
- //把对应门店更新为已deleted
|
|
|
- shopMapInfoMapper.updateDeleted(shopPoiId);
|
|
|
} finally {
|
|
|
shopEvaltionCount++;
|
|
|
}
|
|
@@ -289,9 +345,6 @@ public class DyLaikeServiceImpl implements DyLaikeService {
|
|
|
ThreadPoolManager.execute(() -> {
|
|
|
try {
|
|
|
saveData(requestUrl, shopPoiId, shopName);
|
|
|
- } catch (Exception e) {
|
|
|
- //把对应门店更新为已deleted
|
|
|
- shopMapInfoMapper.updateDeleted(shopPoiId);
|
|
|
} finally {
|
|
|
shopEvaltionCount++;
|
|
|
}
|