zhangfufeng hai 1 semana
pai
achega
073920c638

+ 2 - 1
src/main/java/com/reptileclient/jlifeapp/constant/DyLifeConstants.java

@@ -2,7 +2,8 @@ package com.reptileclient.jlifeapp.constant;
 
 public class DyLifeConstants {
 
-    public static String shopList = "https://life.douyin.com/life/account/v1/poi/relation/search?root_life_account_id={root_life_account_id}";
+    public static String shopList = "https://life.douyin.com/life/merchant/v1/account/claim/list?root_life_account_id={root_life_account_id}";
+    public static String relationList = "https://life.douyin.com/life/account/v1/poi/relation/search?root_life_account_id={root_life_account_id}";
 
     public static String reviewApi = "https://life.douyin.com/life/infra/v1/review/get_douyin_review/?life_account_ids={shop_account_id}&poi_id={poi_id}&account_id={shop_account_id}&root_life_account_id={root_life_account_id}";
 

+ 2 - 10
src/main/java/com/reptileclient/jlifeapp/schedule/DouyinLaikeTask.java

@@ -48,22 +48,14 @@ public class DouyinLaikeTask {
     @Scheduled(cron = "0 30 8 * * ?")
     public void runTask() {
         log.info("开始获取抖音来客门店评价信息");
-        if ("pro".equals(env)) {
-            dyLaikeService.getReviewData();
-        } else {
-            log.info("非生产环境,不进行同步!");
-        }
+        dyLaikeService.getReviewData();
         log.info("结束获取抖音来客门店评价信息");
     }
 
     @Scheduled(cron = "0 10 9 ? * WED")
     public void queryThreeRate() {
         log.info("开始获取抖音来客门店违规三率信息");
-        if ("pro".equals(env)) {
-            dyLaikeService.getThreeRate();
-        } else {
-            log.info("非生产环境,不进行同步!");
-        }
+        dyLaikeService.getThreeRate();
         log.info("结束获取抖音来客门店违规三率信息");
     }
 }

+ 2 - 0
src/main/java/com/reptileclient/jlifeapp/service/DyLaikeService.java

@@ -1,6 +1,8 @@
 package com.reptileclient.jlifeapp.service;
 
 public interface DyLaikeService {
+    void syncShopAndPoi();
+
     void getReviewData();
 
     void getThreeRate();

+ 69 - 16
src/main/java/com/reptileclient/jlifeapp/service/impl/DyLaikeServiceImpl.java

@@ -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++;
             }

+ 14 - 0
src/main/java/com/reptileclient/jlifeapp/util/OkHttpUtil.java

@@ -93,6 +93,20 @@ public class OkHttpUtil extends EventListener {
         }
     }
 
+    public static String post2Dy(String relationUrl, String json, String token) {
+        RequestBody requestBody = RequestBody.create(json, ACCEPT_JSON);
+        Request request = new Request.Builder().url(relationUrl).post(requestBody)
+                .addHeader("cookie", token)
+                .addHeader("referer", "https://life.douyin.com/p/merchantpoi/comment_management?groupid=1754694907787275")
+                .addHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36")
+                .build();
+        try (Response response = client.newCall(request).execute()) {
+            return Objects.requireNonNull(response.body()).string();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
 
     @Autowired
     private void setBookOrderMapper(HmBookOrderMapper bookOrderMapper) {

+ 1 - 1
src/main/resources/mybatis/mapper/jz/DyLaikeShopThreeRateMapper.xml

@@ -34,7 +34,7 @@
   </select>
   <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.reptileclient.jlifeapp.entity.jz.DyLaikeShopThreeRate" useGeneratedKeys="true">
     <!--@mbg.generated-->
-    insert into dy_laike_shop_three_rate
+    insert into jlife_reports.dy_laike_shop_three_rate
     <trim prefix="(" suffix=")" suffixOverrides=",">
       <if test="batchId != null">
         batch_id,

+ 8 - 85
src/test/java/jlifereptileserver/DyLifeTest.java

@@ -68,92 +68,7 @@ public class DyLifeTest {
     }
 
 
-    @Test
-    public void syncShopAndPoi() {
-        String requestUrl = DyLifeConstants.shopList.replace("{root_life_account_id}", accountId);
-        Map<String, Object> requestMap = new HashMap<>();
-        String response = OkHttpUtil.post2Dy(requestUrl, requestMap, token);
-        JSONObject jsonObject = JSONObject.parseObject(response);
-        Integer code = jsonObject.getInteger("status_code");
-        if (code != 0) {
-            //休息2秒,准备重试
-            try {
-                Thread.sleep(2000);
-            } catch (InterruptedException e) {
-                e.printStackTrace();
-            }
-            String secondResponse = OkHttpUtil.post2Dy(requestUrl, requestMap, token);
-            JSONObject secondJsonObject = JSONObject.parseObject(secondResponse);
-            Integer secondCode = secondJsonObject.getInteger("status_code");
-            if (secondCode != 0) {
-                //休息2秒,准备重试
-                try {
-                    Thread.sleep(2000);
-                } catch (InterruptedException e) {
-                    e.printStackTrace();
-                }
-                String thirdResponse = OkHttpUtil.post2Dy(requestUrl, requestMap, token);
-                JSONObject thirdJsonObject = JSONObject.parseObject(thirdResponse);
-                Integer thirdCode = thirdJsonObject.getInteger("status_code");
-                if (thirdCode != 0) {
-                    System.out.println("三次请求都失败了,不再重试");
-                    return;
-                } else {
-                    System.out.println("第三次请求成功了");
-                    realStart(requestUrl, thirdJsonObject);
-                }
-            } else {
-                System.out.println("第二次请求成功了");
-                realStart(requestUrl, secondJsonObject);
-            }
-        }
-        realStart(requestUrl, jsonObject);
-    }
-
-    private void realStart(String requestUrl, JSONObject thirdJsonObject) {
-        JSONObject pageInfo = thirdJsonObject.getJSONObject("data").getJSONObject("pagination");
-        Integer count = pageInfo.getInteger("total_count");
-        //计算需要请求的次数
-        int requestTimes = count / pageSize;
-        if (count % pageSize != 0) {
-            requestTimes++;
-        }
-        //开启多个线程一起请求
-
-        JSONArray jsonArray = new JSONArray();
-        for (int i = 0; i < requestTimes; i++) {
-            int finalI = i;
-            ThreadPoolManager.execute(() -> {
-                Map<String, Object> requestMap = new HashMap<>();
-                requestMap.put("page_size", pageSize);
-                requestMap.put("page_index", finalI + 1);
-                String response = OkHttpUtil.post2Dy(requestUrl, requestMap, token);
-                JSONObject jsonObject = JSONObject.parseObject(response);
-                JSONArray array = jsonObject.getJSONObject("data").getJSONArray("list");
-                jsonArray.addAll(array);
-            });
-        }
-
-        //等待所有线程执行完毕
-        while (true) {
-            if (jsonArray.size() == count) {
-                break;
-            }
-        }
 
-        //开始处理数据
-        for (Object o : jsonArray) {
-            JSONObject js = (JSONObject) o;
-            DyLaikeAccountShopMapInfo dyLaikeAccountShopMapInfo = new DyLaikeAccountShopMapInfo();
-            dyLaikeAccountShopMapInfo.setShopAccountId(js.getString("poi_life_account_id"));
-            dyLaikeAccountShopMapInfo.setDeleted(0);
-            dyLaikeAccountShopMapInfo.setShopName(js.getString("poi_name"));
-            dyLaikeAccountShopMapInfo.setShopPoiId(js.getString("poi_id"));
-            shopMapInfoMapper.insertSelective(dyLaikeAccountShopMapInfo);
-        }
-
-
-    }
 
 
     @Test
@@ -271,4 +186,12 @@ public class DyLifeTest {
     public void testThreeRate() {
         dyLaikeService.getThreeRate();
     }
+
+    @Test
+    public void syncShopAndPoi() {
+        dyLaikeService.syncShopAndPoi();
+    }
+
+
+
 }