소스 검색

Merge branch 'test'

yumeng 5 년 전
부모
커밋
75f30e68ce

+ 128 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/controller/KuaiShouReportController.java

@@ -0,0 +1,128 @@
+package cn.com.ctop.kuaishou.modules.batch.controller;
+
+import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.UserAllocation;
+import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
+import cn.com.ctop.common.module.mapper.UserAllocationMapper;
+import cn.com.ctop.common.module.utils.Check;
+import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import lombok.extern.slf4j.Slf4j;
+import org.jeecg.common.util.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.text.ParseException;
+import java.util.List;
+
+/**
+ * @Description: 快手-本地图片保存
+ * @Author: jeecg-boot
+ * @Date: 2019-08-14
+ * @Version: V1.0
+ */
+@Slf4j
+
+@RestController
+@RequestMapping("/kuaishou/getReport")
+public class KuaiShouReportController {
+    @Autowired
+    private UserAllocationMapper userAllocationMapper;
+    @Autowired
+    private CtopOauthTokenMapper ctopOauthTokenMapper;
+    @Autowired
+    private IKuaishouInterfaceService kuaishouInterfaceService;
+
+
+    @RequestMapping(value = "/historyData")
+    public String queryPageList() throws ParseException {
+
+        QueryWrapper<UserAllocation> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("media_id", 2);
+        queryWrapper.groupBy("account_id");
+        List<UserAllocation> userAllocations = userAllocationMapper.selectList(queryWrapper);
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        if (!Check.isNull(userAllocations)) {
+            for (UserAllocation allocation : userAllocations) {
+                String beginDate = null;
+                String hourDate = null;
+                Long accountId = allocation.getAccountId();
+                if (!Check.isNull(accountId)) {
+                    QueryWrapper<CtopOauthToken> tokenQueryWrapper = new QueryWrapper<>();
+                    tokenQueryWrapper.eq("account_id", accountId);
+                    tokenQueryWrapper.eq("media_id", 2);
+                    tokenQueryWrapper.orderByDesc("create_time");
+                    tokenQueryWrapper.last("limit 1");
+                    CtopOauthToken ctopOauthToken = ctopOauthTokenMapper.selectOne(tokenQueryWrapper);
+                    if (!Check.isNull(ctopOauthToken)) {
+                        //   String accessToken, Long advertiserId, String startDate, String endDate, int pageSize, int pageNum
+                        String accessToken = ctopOauthToken.getAccessToken();
+                        Long advertiserId = ctopOauthToken.getAccountId();
+                        for (int i = 0; i < 6; i++) {
+                            if (i == 0) {
+                                String monthBefore = DateUtils.getMonthBefore("yyyy-MM-dd", nowDate, -1);
+                                System.err.println("开始时间:" + anotherDay);
+                                System.err.println("结束时间:" + monthBefore);
+                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, anotherDay, 500, 1);
+                                beginDate = monthBefore;
+
+
+                            } else if (i > 0) {
+                                String startDate = DateUtils.getAnotherDay("yyyy-MM-dd", beginDate, -1);
+                                String monthBefore = DateUtils.getMonthBefore("yyyy-MM-dd", beginDate, -1);
+                                System.err.println("开始时间:" + startDate);
+
+                                if (i == 5) {
+                                    monthBefore = DateUtils.getAnotherDay("yyyy-MM-dd", monthBefore, 4);
+                                }
+                                System.err.println("结束时间:" + monthBefore);
+                                kuaishouInterfaceService.getAccountDailyReport(accessToken, advertiserId, monthBefore, startDate, 1, 500);
+                                beginDate = monthBefore;
+
+                                //
+
+                            }
+
+                        }
+
+                        for (int i = 0; i < 7; i++) {
+                            if (i == 0) {
+                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, nowDate, nowDate, 1, 500);
+                                hourDate = nowDate;
+                                System.err.println(nowDate);
+                            } else if (i > 0) {
+                                String hourAnotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", hourDate, -1);
+                                kuaishouInterfaceService.getAccountHourlyReport(accessToken, advertiserId, hourAnotherDay, hourAnotherDay, 1, 500);
+                                System.err.println(hourAnotherDay);
+                                hourDate = hourAnotherDay;
+                            }
+
+                        }
+
+
+                        //     kuaishouInterfaceService.getAccountDailyReport();
+
+                    }
+
+                }
+
+            }
+        }
+
+
+        return null;
+
+
+    }
+
+
+    public static void main(String[] args) throws ParseException {
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String anotherDay1 = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay1, -180);
+
+        System.err.println(anotherDay);
+    }
+}

+ 54 - 13
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/batch/service/impl/KuaishouInterfaceServiceImpl.java

@@ -126,7 +126,35 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("page", pageNum);
         KuaishouResult<KuaishouReportHourlyAccount> kuaishouResult = null;
         try {
+
             String result = HttpUtils.httpPostRequest(url, param, headers);
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                if (resultJson.getInteger("code") == 0) {
+                    JSONObject dataJson = resultJson.getJSONObject("data");
+                    if (!Check.isNull(dataJson)) {
+                        JSONArray details = dataJson.getJSONArray("details");
+                        for (int i = 0; i < details.size(); i++) {
+                            JSONObject detailJson = details.getJSONObject(i);
+                            Long show = detailJson.getLong("show");
+                            detailJson.put("photo_show", show);
+                            Long like = detailJson.getLong("like");
+                            detailJson.put("photo_like", like);
+                            KuaishouReportHourlyAccount kuaishouReportHourlyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportHourlyAccount.class);
+                            System.err.println(kuaishouReportHourlyAccount);
+                            kuaishouReportHourlyAccount.setAccountId(advertiserId);
+                            kuaishouReportHourlyAccount.setId("" + advertiserId + kuaishouReportHourlyAccount.getStatDate() + kuaishouReportHourlyAccount.getStatHour());
+                            hourlyAccountService.saveOrUpdate(kuaishouReportHourlyAccount);
+                        }
+
+                    }
+
+                }
+
+            }
+
+
+            /*String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject resultJson = JSONArray.parseObject(result);
             if (!Check.isNull(resultJson)) {
 
@@ -140,7 +168,7 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
                 hourlyAccount.setAccountId(advertiserId);
                 hourlyAccount.setId("" + hourlyAccount.getAccountId() + hourlyAccount.getStatDate() + hourlyAccount.getStatHour());
                 hourlyAccountService.saveOrUpdate(hourlyAccount);
-            });
+            });*/
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -160,23 +188,36 @@ public class KuaishouInterfaceServiceImpl implements IKuaishouInterfaceService {
         param.put("temporal_granularity", "DAILY");
         param.put("page_size", pageSize);
         param.put("page", pageNum);
-        KuaishouResult<KuaishouReportDailyAccount> kuaishouResult = null;
         try {
             String result = HttpUtils.httpPostRequest(url, param, headers);
-            ObjectMapper mapper = new ObjectMapper();
-            mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
-            kuaishouResult = mapper.readValue(result, new TypeReference<KuaishouResult<KuaishouReportDailyAccount>>() {
-            });
-            List<KuaishouReportDailyAccount> dailyAccounts = kuaishouResult.getData().getDetails();
-            dailyAccounts.forEach((hourlyAccount -> {
-                hourlyAccount.setAccountId(advertiserId);
-                hourlyAccount.setId("" + hourlyAccount.getAccountId() + hourlyAccount.getStatDate());
-                dailyAccountService.saveOrUpdate(hourlyAccount);
-            }));
+
+            JSONObject resultJson = JSONObject.parseObject(result);
+            if (!Check.isNull(resultJson)) {
+                if (resultJson.getInteger("code") == 0) {
+                    JSONObject dataJson = resultJson.getJSONObject("data");
+                    if (!Check.isNull(dataJson)) {
+                        JSONArray details = dataJson.getJSONArray("details");
+                        for (int i = 0; i < details.size(); i++) {
+                            JSONObject detailJson = details.getJSONObject(i);
+                            Long show = detailJson.getLong("show");
+                            detailJson.put("photo_show", show);
+                            Long like = detailJson.getLong("like");
+                            detailJson.put("photo_like", like);
+                            KuaishouReportDailyAccount kuaishouReportDailyAccount = JSONObject.toJavaObject(detailJson, KuaishouReportDailyAccount.class);
+                            kuaishouReportDailyAccount.setAccountId(advertiserId);
+                            kuaishouReportDailyAccount.setId("" + advertiserId + kuaishouReportDailyAccount.getStatDate());
+                            dailyAccountService.saveOrUpdate(kuaishouReportDailyAccount);
+                        }
+
+                    }
+
+                }
+
+            }
         } catch (Exception e) {
             e.printStackTrace();
         }
-        return kuaishouResult;
+        return null;
     }
 
     @Override

+ 10 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/controller/KuaishouWebController.java

@@ -101,7 +101,8 @@ public class KuaishouWebController {
     public Result<Map<String, Object>> videoList(String ksid, String pcursor) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();
         try {
-            Map<String, Object> statusMap = kuaishouWebInterfaceService.videoList(ksid, pcursor);
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            Map<String, Object> statusMap = kuaishouWebInterfaceService.videoList(user.getId(), ksid, pcursor);
             result.setSuccess(true);
             result.setResult(statusMap);
         } catch (Exception e) {
@@ -115,7 +116,8 @@ public class KuaishouWebController {
     public Result<Map<String, Object>> commentList(String ksid, String photoId, String pcursor) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();
         try {
-            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentList(ksid, photoId, pcursor);
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentList(user.getId(), ksid, photoId, pcursor);
             result.setSuccess(true);
             result.setResult(statusMap);
         } catch (Exception e) {
@@ -129,7 +131,8 @@ public class KuaishouWebController {
     public Result<Map<String, Object>> commentDelete(String ksid, String photoId, Long commentId) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();
         try {
-            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentDelete(ksid, photoId, commentId);
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentDelete(user.getId(), ksid, photoId, commentId);
             result.setSuccess(true);
             result.setResult(statusMap);
         } catch (Exception e) {
@@ -143,7 +146,8 @@ public class KuaishouWebController {
     public Result<Map<String, Object>> commentAdd(String ksid, String photoId, String content, Long replyToCommentId, Long repltTo) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();
         try {
-            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentAdd(ksid, photoId, content, replyToCommentId, repltTo);
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            Map<String, Object> statusMap = kuaishouWebInterfaceService.commentAdd(user.getId(), ksid, photoId, content, replyToCommentId, repltTo);
             result.setSuccess(true);
             result.setResult(statusMap);
         } catch (Exception e) {
@@ -157,7 +161,8 @@ public class KuaishouWebController {
     public Result<Map<String, Object>> subCommentList(String ksid, String photoId, Long rootCommentId, String pcursor) {
         Result<Map<String, Object>> result = new Result<Map<String, Object>>();
         try {
-            Map<String, Object> statusMap = kuaishouWebInterfaceService.subCommentList(ksid, photoId, rootCommentId, pcursor);
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            Map<String, Object> statusMap = kuaishouWebInterfaceService.subCommentList(user.getId(), ksid, photoId, rootCommentId, pcursor);
             result.setSuccess(true);
             result.setResult(statusMap);
         } catch (Exception e) {

+ 1 - 1
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/entity/KuaishouCommentConfig.java

@@ -10,7 +10,7 @@ import lombok.Data;
 public class KuaishouCommentConfig {
     @TableId(value = "ksid", type = IdType.INPUT)
     private String ksid;
-    private Boolean autoDelete;
+    private Integer autoDelete;
     private String strategy;
     private String cycle;
 }

+ 20 - 7
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/job/KuaishouCommentDayJob.java

@@ -1,6 +1,7 @@
 package cn.com.ctop.kuaishou.modules.graphql.job;
 
 import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentStat;
 import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouUserCookie;
 import cn.com.ctop.kuaishou.modules.graphql.service.*;
 import com.alibaba.fastjson.JSONArray;
@@ -31,7 +32,7 @@ public class KuaishouCommentDayJob implements Job {
     @Override
     public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
         QueryWrapper<KuaishouCommentConfig> queryWrapper = new QueryWrapper<>();
-        queryWrapper.eq("auto_delete", true);
+        queryWrapper.eq("auto_delete", 1);
         queryWrapper.eq("cycle", "DAY");
         List<KuaishouCommentConfig> kuaishouCommentConfigList = kuaishouCommentConfigService.list(queryWrapper);
         if (kuaishouCommentConfigList != null && kuaishouCommentConfigList.size() > 0) {
@@ -43,7 +44,7 @@ public class KuaishouCommentDayJob implements Job {
                 try {
                     String pcursor = "";
                     do {
-                        Map<String, Object> videoMap = kuaishouWebInterfaceService.videoList(config.getKsid(), pcursor);
+                        Map<String, Object> videoMap = kuaishouWebInterfaceService.videoList(kuaishouUserCookie.getUserId(), config.getKsid(), pcursor);
                         JsonNode videoNode = mapToJson(videoMap);
                         pcursor = videoNode.get("data").get("publicFeeds").get("pcursor").asText();
                         Iterator<JsonNode> list = videoNode.get("data").get("publicFeeds").get("list").iterator();
@@ -54,20 +55,32 @@ public class KuaishouCommentDayJob implements Job {
                                 String photoId = node.get("photoId").asText();
                                 String commentPcursor = "";
                                 do {
-                                    Map<String, Object> commentMap = kuaishouWebInterfaceService.commentList(config.getKsid(), photoId, commentPcursor);
+                                    Map<String, Object> commentMap = kuaishouWebInterfaceService.commentList(kuaishouUserCookie.getUserId(), config.getKsid(), photoId, commentPcursor);
                                     JsonNode commentNode = mapToJson(commentMap);
                                     commentPcursor = commentNode.get("data").get("shortVideoCommentList").get("pcursor").asText();
                                     Iterator<JsonNode> commentList = commentNode.get("data").get("shortVideoCommentList").get("commentList").iterator();
                                     while (commentList.hasNext()) {
                                         JsonNode commentListNode = commentList.next();
                                         Long commentId = commentListNode.get("commentId").asLong();
-                                        Map<String, Object> deleteMap = kuaishouWebInterfaceService.commentDelete(config.getKsid(), photoId, commentId);
-
+                                        Map<String, Object> deleteMap = kuaishouWebInterfaceService.commentDelete(kuaishouUserCookie.getUserId(), config.getKsid(), photoId, commentId);
+                                        if ((int) deleteMap.get("result") == 1) {
+                                            KuaishouCommentStat kuaishouCommentStat = kuaishouCommentStatService.getById(commentId);
+                                            if (kuaishouCommentStat == null) {
+                                                kuaishouCommentStat = new KuaishouCommentStat();
+                                                kuaishouCommentStat.setCommentId(commentId);
+                                                kuaishouCommentStat.setDeleteCount(1);
+                                                kuaishouCommentStat.setKsid(config.getKsid());
+                                                kuaishouCommentStatService.save(kuaishouCommentStat);
+                                            } else {
+                                                kuaishouCommentStat.setDeleteCount(kuaishouCommentStat.getDeleteCount() + 1);
+                                                kuaishouCommentStatService.updateById(kuaishouCommentStat);
+                                            }
+                                        }
                                     }
-                                } while (!commentPcursor.equals("no_more"));
+                                } while (commentPcursor != null && !commentPcursor.equals("no_more"));
                             }
                         }
-                    } while (!pcursor.equals("no_more"));
+                    } while (pcursor != null && !pcursor.equals("no_more"));
 
                 } catch (Exception e) {
                     e.printStackTrace();

+ 96 - 0
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/job/KuaishouCommentHourJob.java

@@ -0,0 +1,96 @@
+package cn.com.ctop.kuaishou.modules.graphql.job;
+
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentConfig;
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouCommentStat;
+import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouUserCookie;
+import cn.com.ctop.kuaishou.modules.graphql.service.*;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.quartz.Job;
+import org.quartz.JobExecutionContext;
+import org.quartz.JobExecutionException;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class KuaishouCommentHourJob implements Job {
+    @Autowired
+    private IKuaishouCommentConfigService kuaishouCommentConfigService;
+    @Autowired
+    private IKuaishouCommentKeywordService kuaishouCommentKeywordService;
+    @Autowired
+    private IKuaishouCommentStatService kuaishouCommentStatService;
+    @Autowired
+    private IKuaishouUserCookieService kuaishouUserCookieService;
+    @Autowired
+    private IKuaishouWebInterfaceService kuaishouWebInterfaceService;
+
+    @Override
+    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
+        QueryWrapper<KuaishouCommentConfig> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("auto_delete", 1);
+        queryWrapper.eq("cycle", "HOUR");
+        List<KuaishouCommentConfig> kuaishouCommentConfigList = kuaishouCommentConfigService.list(queryWrapper);
+        if (kuaishouCommentConfigList != null && kuaishouCommentConfigList.size() > 0) {
+            for (KuaishouCommentConfig config : kuaishouCommentConfigList) {
+                QueryWrapper<KuaishouUserCookie> queryWrapper1 = new QueryWrapper<>();
+                queryWrapper1.eq("ksid", config.getKsid());
+                KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper1);
+
+                try {
+                    String pcursor = "";
+                    do {
+                        Map<String, Object> videoMap = kuaishouWebInterfaceService.videoList(kuaishouUserCookie.getUserId(), config.getKsid(), pcursor);
+                        JsonNode videoNode = mapToJson(videoMap);
+                        pcursor = videoNode.get("data").get("publicFeeds").get("pcursor").asText();
+                        Iterator<JsonNode> list = videoNode.get("data").get("publicFeeds").get("list").iterator();
+                        while (list.hasNext()) {
+                            JsonNode node = list.next();
+                            Integer commentCount = node.get("commentCount").asInt();
+                            if (commentCount > 0) {
+                                String photoId = node.get("photoId").asText();
+                                String commentPcursor = "";
+                                do {
+                                    Map<String, Object> commentMap = kuaishouWebInterfaceService.commentList(kuaishouUserCookie.getUserId(), config.getKsid(), photoId, commentPcursor);
+                                    JsonNode commentNode = mapToJson(commentMap);
+                                    commentPcursor = commentNode.get("data").get("shortVideoCommentList").get("pcursor").asText();
+                                    Iterator<JsonNode> commentList = commentNode.get("data").get("shortVideoCommentList").get("commentList").iterator();
+                                    while (commentList.hasNext()) {
+                                        JsonNode commentListNode = commentList.next();
+                                        Long commentId = commentListNode.get("commentId").asLong();
+                                        Map<String, Object> deleteMap = kuaishouWebInterfaceService.commentDelete(kuaishouUserCookie.getUserId(), config.getKsid(), photoId, commentId);
+                                        if ((int) deleteMap.get("result") == 1) {
+                                            KuaishouCommentStat kuaishouCommentStat = kuaishouCommentStatService.getById(commentId);
+                                            if (kuaishouCommentStat == null) {
+                                                kuaishouCommentStat = new KuaishouCommentStat();
+                                                kuaishouCommentStat.setCommentId(commentId);
+                                                kuaishouCommentStat.setDeleteCount(1);
+                                                kuaishouCommentStat.setKsid(config.getKsid());
+                                                kuaishouCommentStatService.save(kuaishouCommentStat);
+                                            } else {
+                                                kuaishouCommentStat.setDeleteCount(kuaishouCommentStat.getDeleteCount() + 1);
+                                                kuaishouCommentStatService.updateById(kuaishouCommentStat);
+                                            }
+                                        }
+                                    }
+                                } while (commentPcursor != null && !commentPcursor.equals("no_more"));
+                            }
+                        }
+                    } while (pcursor != null && !pcursor.equals("no_more"));
+
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    public JsonNode mapToJson(Map<String, Object> map) throws Exception {
+        ObjectMapper mapper = new ObjectMapper();
+        String json = mapper.writeValueAsString(map);
+        return mapper.readTree(json);
+    }
+}

+ 5 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouWebInterfaceService.java

@@ -22,13 +22,13 @@ public interface IKuaishouWebInterfaceService {
 
     public Map<String, Object> loginStatus(String taskId);
 
-    public Map<String, Object> commentDelete(String ksid, String photoId, Long commentId);
+    public Map<String, Object> commentDelete(String userId, String ksid, String photoId, Long commentId);
 
-    public Map<String, Object> videoList(String ksid, String pcursor);
+    public Map<String, Object> videoList(String userId, String ksid, String pcursor);
 
-    public Map<String, Object> commentList(String ksid, String photoId, String pcursor);
+    public Map<String, Object> commentList(String userId, String ksid, String photoId, String pcursor);
 
-    public Map<String, Object> commentAdd(String ksid, String photoId, String content, Long replyToCommentId, Long replyTo);
+    public Map<String, Object> commentAdd(String userId, String ksid, String photoId, String content, Long replyToCommentId, Long replyTo);
 
-    public Map<String, Object> subCommentList(String ksid, String photoId, Long rootCommentId, String pcursor);
+    public Map<String, Object> subCommentList(String userId, String ksid, String photoId, Long rootCommentId, String pcursor);
 }

+ 64 - 33
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouWebInterfaceServiceImpl.java

@@ -107,11 +107,10 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         return queryStr;
     }
 
-    public Map<String, Object> subCommentList(String ksid, String photoId, Long rootCommentId, String pcursor) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+    public Map<String, Object> subCommentList(String userId, String ksid, String photoId, Long rootCommentId, String pcursor) {
         QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<KuaishouUserCookie>();
         Map<String, Object> resultMap = new HashMap<>();
-        queryWrapper.eq("user_id", user.getId());
+        queryWrapper.eq("user_id", userId);
         queryWrapper.eq("ksid", ksid);
         KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper);
         if (kuaishouUserCookie != null) {
@@ -138,7 +137,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 if (resultNode.get("subCommentList").isNull() || resultNode.get("subCommentList").get("pcursor").isNull()) {
                     ipPool.setStatus(2);
                     iIpPoolService.updateById(ipPool);
-                    return subCommentList(ksid, photoId, rootCommentId, pcursor);
+                    return subCommentList(userId, ksid, photoId, rootCommentId, pcursor);
                 }
             } catch (Exception e) {
                 e.printStackTrace();
@@ -146,17 +145,16 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                     ipPool.setStatus(2);
                     iIpPoolService.updateById(ipPool);
                 }
-                return subCommentList(ksid, photoId, rootCommentId, pcursor);
+                return subCommentList(userId, ksid, photoId, rootCommentId, pcursor);
             }
         }
         return resultMap;
     }
 
-    public Map<String, Object> commentList(String ksid, String photoId, String pcursor) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+    public Map<String, Object> commentList(String userId, String ksid, String photoId, String pcursor) {
         QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<KuaishouUserCookie>();
         Map<String, Object> resultMap = new HashMap<>();
-        queryWrapper.eq("user_id", user.getId());
+        queryWrapper.eq("user_id", userId);
         queryWrapper.eq("ksid", ksid);
         KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper);
         if (kuaishouUserCookie != null) {
@@ -193,7 +191,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 if (httpClientEntity.getResult() == null) {
                     ipPool.setStatus(2);
                     iIpPoolService.updateById(ipPool);
-                    return commentList(ksid, photoId, pcursor);
+                    return commentList(userId, ksid, photoId, pcursor);
                 }
                 resultMap = mapper.readValue(httpClientEntity.getResult(), new TypeReference<Map<String, Object>>() {
                 });
@@ -201,7 +199,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 if (resultNode.get("shortVideoCommentList").isNull() || resultNode.get("shortVideoCommentList").get("pcursor").isNull()) {
                     ipPool.setStatus(2);
                     iIpPoolService.updateById(ipPool);
-                    return commentList(ksid, photoId, pcursor);
+                    return commentList(userId, ksid, photoId, pcursor);
                 }
             } catch (Exception e) {
                 if (ipPool != null) {
@@ -209,7 +207,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                     iIpPoolService.updateById(ipPool);
                 }
                 e.printStackTrace();
-                return commentList(ksid, photoId, pcursor);
+                return commentList(userId, ksid, photoId, pcursor);
             }
         }
         return resultMap;
@@ -239,11 +237,11 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         return map;
     }
 
-    public Map<String, Object> videoList(String ksid, String pcursor) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+    public Map<String, Object> videoList(String userId, String ksid, String pcursor) {
+
         QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<KuaishouUserCookie>();
         Map<String, Object> resultMap = new HashMap<>();
-        queryWrapper.eq("user_id", user.getId());
+        queryWrapper.eq("user_id", userId);
         queryWrapper.eq("ksid", ksid);
         KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper);
         if (kuaishouUserCookie != null) {
@@ -266,7 +264,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 if (httpClientEntity.getResult() == null) {
                     ipPool.setStatus(2);
                     iIpPoolService.updateById(ipPool);
-                    return videoList(ksid, pcursor);
+                    return videoList(userId, ksid, pcursor);
                 }
                 Map<String, String> map = getTTfNumber(kuaishouUserCookie);
                 for (String key : map.keySet()) {
@@ -280,7 +278,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 if (resultNode.get("publicFeeds").isNull() || resultNode.get("publicFeeds").get("pcursor").isNull()) {
                     ipPool.setStatus(2);
                     iIpPoolService.updateById(ipPool);
-                    return videoList(ksid, pcursor);
+                    return videoList(userId, ksid, pcursor);
                 }
             } catch (Exception e) {
                 if (ipPool != null) {
@@ -288,7 +286,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                     iIpPoolService.updateById(ipPool);
                 }
                 e.printStackTrace();
-                return videoList(ksid, pcursor);
+                return videoList(userId, ksid, pcursor);
             }
         }
         return resultMap;
@@ -337,11 +335,10 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         return kuaishouNumberMap.get(key);
     }
 
-    public Map<String, Object> commentDelete(String ksid, String photoId, Long commentId) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+    public Map<String, Object> commentDelete(String userId, String ksid, String photoId, Long commentId) {
         QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<KuaishouUserCookie>();
         Map<String, Object> resultMap = new HashMap<>();
-        queryWrapper.eq("user_id", user.getId());
+        queryWrapper.eq("user_id", userId);
         queryWrapper.eq("ksid", ksid);
         KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper);
         if (kuaishouUserCookie != null) {
@@ -375,11 +372,18 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 ObjectMapper mapper = new ObjectMapper();
                 resultMap = mapper.readValue(httpClientEntity.getResult(), new TypeReference<Map<String, Object>>() {
                 });
-                if (((Integer) resultMap.get("result")) == 109) {
-                    ipPool.setStatus(2);
-                    iIpPoolService.updateById(ipPool);
-                    return commentDelete(ksid, photoId, commentId);
-                }
+                Integer code = ((Integer) resultMap.get("result"));
+//                if(code == 109){
+//
+//                }
+//                if (((Integer) resultMap.get("result")) == 109) {
+//                    reLogin(httpClientEntity,kuaishouUserCookie);
+//                    if(ipPool != null){
+//                        ipPool.setStatus(2);
+//                        iIpPoolService.updateById(ipPool);
+//                    }
+//                    return commentDelete(userId,ksid, photoId, commentId);
+//                }
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -387,11 +391,10 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         return resultMap;
     }
 
-    public Map<String, Object> commentAdd(String ksid, String photoId, String content, Long replyToCommentId, Long replyTo) {
-        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+    public Map<String, Object> commentAdd(String userId, String ksid, String photoId, String content, Long replyToCommentId, Long replyTo) {
         QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<KuaishouUserCookie>();
         Map<String, Object> resultMap = new HashMap<>();
-        queryWrapper.eq("user_id", user.getId());
+        queryWrapper.eq("user_id", userId);
         queryWrapper.eq("ksid", ksid);
         KuaishouUserCookie kuaishouUserCookie = kuaishouUserCookieService.getOne(queryWrapper);
         if (kuaishouUserCookie != null) {
@@ -427,11 +430,12 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
                 ObjectMapper mapper = new ObjectMapper();
                 resultMap = mapper.readValue(httpClientEntity.getResult(), new TypeReference<Map<String, Object>>() {
                 });
-                if (((Integer) resultMap.get("result")) == 109) {
-                    ipPool.setStatus(2);
-                    iIpPoolService.updateById(ipPool);
-                    return commentAdd(ksid, photoId, content, replyToCommentId, replyTo);
-                }
+//                if (((Integer) resultMap.get("result")) == 109) {
+//                    reLogin(httpClientEntity,kuaishouUserCookie);
+//                    ipPool.setStatus(2);
+//                    iIpPoolService.updateById(ipPool);
+//                    return commentAdd(userId,ksid, photoId, content, replyToCommentId, replyTo);
+//                }
             } catch (Exception e) {
                 e.printStackTrace();
             }
@@ -985,6 +989,32 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         return httpClientEntity;
     }
 
+    public HttpClientEntity reLogin(HttpClientEntity httpClientEntity, KuaishouUserCookie kuaishouUserCookie) throws Exception {
+        Map<String, Object> params = new HashMap<String, Object>();
+        IpPool ipPool = iIpPoolService.getAvaliableIp();
+        params.put("sid", "kuaishou.live.web");
+        HttpClientUtils httpClientUtils = new HttpClientUtils();
+        httpClientEntity.setCloseableHttpClient(httpClientUtils.createSSLClientDefault(ipPool));
+        httpClientEntity.setUrl("https://id.kuaishou.com/pass/kuaishou/login/passToken");
+        httpClientEntity.setResult("");
+        httpClientEntity.setHeaders(getHeaders());
+        httpClientEntity.setParams(params);
+        httpClientEntity = httpClientUtils.httpPostParamRequest(httpClientEntity);
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode jsonNode = mapper.readTree(httpClientEntity.getResult());
+        String at = jsonNode.get("kuaishou.live.web.at").asText();
+        httpClientEntity.setUrl("https://live.kuaishou.com/graphql");
+        httpClientEntity = httpClientUtils.callingGraph(httpClientEntity, userLogin(at));
+        httpClientEntity = httpClientUtils.callingGraph(httpClientEntity, userInfoQuery());
+        JsonNode userNode = mapper.readTree(httpClientEntity.getResult());
+        QueryWrapper<KuaishouUserCookie> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("user_id", kuaishouUserCookie.getUserId());
+        queryWrapper.eq("ksid", kuaishouUserCookie.getKsid());
+        kuaishouUserCookie.setCookie(new Gson().toJson(httpClientEntity.getCookieStore()));
+        kuaishouUserCookieService.update(kuaishouUserCookie, queryWrapper);
+        return httpClientEntity;
+    }
+
     public Date getCST(String strGMT) throws ParseException {
         if (strGMT == null) {
             return null;
@@ -1008,6 +1038,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         return httpClientEntity;
     }
 
+
     public String qrLogin(String taskId) throws Exception {
         HttpClientEntity httpClientEntity = this.kuaishouIndex();
         httpClientEntity = this.kuaishouQrStart(httpClientEntity);

+ 5 - 5
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportDailyAccount.java

@@ -23,10 +23,11 @@ public class KuaishouReportDailyAccount implements Serializable {
 
     @JsonProperty
     private BigDecimal charge;
-    @TableField("photo_show")
-    private Long show;
+
+    @JsonProperty
+    private Long photoShow;
+
     @JsonProperty("photo_click")
-    @TableField("photo_click")
     private Long photoClick;
 
     @JsonProperty
@@ -38,8 +39,7 @@ public class KuaishouReportDailyAccount implements Serializable {
     @JsonProperty
     private Long comment;
     @JsonProperty
-    @TableField("`like`")
-    private Long like;
+    private Long photoLike;
     @JsonProperty
     private Long follow;
     @JsonProperty("cancel_follow")

+ 5 - 6
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/report/entity/KuaishouReportHourlyAccount.java

@@ -1,6 +1,5 @@
 package cn.com.ctop.kuaishou.modules.report.entity;
 
-import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableName;
 import com.fasterxml.jackson.annotation.JsonProperty;
@@ -8,6 +7,7 @@ import lombok.Data;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+
 @Data
 @TableName("ctop_kuaishou_report_hourly_account")
 public class KuaishouReportHourlyAccount implements Serializable {
@@ -24,10 +24,10 @@ public class KuaishouReportHourlyAccount implements Serializable {
 
     @JsonProperty
     private BigDecimal charge;
-    @TableField("photo_show")
-    private Long show;
+
+    @JsonProperty
+    private Long photoShow;
     @JsonProperty("photo_click")
-    @TableField("photo_click")
     private Long photoClick;
     @JsonProperty
     private Long aclick;
@@ -38,8 +38,7 @@ public class KuaishouReportHourlyAccount implements Serializable {
     @JsonProperty
     private Long comment;
     @JsonProperty
-    @TableField("`like`")
-    private Long like;
+    private Long photoLike;
     @JsonProperty
     private Long follow;
     @JsonProperty("cancel_follow")

+ 5 - 4
module-report/src/main/java/cn/com/ctop/bytedance/mapper/xml/BytedanceReportMapper.xml

@@ -69,15 +69,16 @@
 
     <select id="selectDayDetailByDate" resultType="com.alibaba.fastjson.JSONObject">
       select
-       charge cost,
-       photo_show photoShow,
-       photo_click photoClick,
-       aclick aclick,
+       sum(charge) cost,
+       sum(photo_show) photoShow,
+       sum(photo_click) photoClick,
+       sum(aclick) aclick,
        stat_date statDate
      from
       ctop_kuaishou_report_daily_account
       where stat_date &lt;= #{startDate}
       and  stat_date &gt;= #{endDate}
+      group by stat_date
       order by stat_date desc
     </select>
 

+ 24 - 17
module-report/src/main/java/cn/com/ctop/bytedance/service/impl/BytedanceReportServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
+import java.text.ParseException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -137,7 +138,7 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                         kuaishouDetailJson.put("click", click);
                         kuaishouClick += click;
 
-                        Long show = reportDailyAccount.getShow();
+                        Long show = reportDailyAccount.getPhotoShow();
                         kuaishouDetailJson.put("show", show);
                         kuaishouShow += show;
 
@@ -209,8 +210,8 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     if (!Check.isNull(yesterdayJson)) {
                         BigDecimal cost = accountJson.getBigDecimal("cost"); // 今日消耗
                         BigDecimal yesterdayCost = yesterdayJson.getBigDecimal("cost");// 昨日消耗
-                        BigDecimal compareBigDecima = new BigDecimal(0);
-                        if (yesterdayCost.compareTo(compareBigDecima) != 0) {
+                        BigDecimal compareBigDecimal = new BigDecimal(0);
+                        if (yesterdayCost.compareTo(compareBigDecimal) != 0) {
                             BigDecimal costProportion = (cost.subtract(yesterdayCost)).divide(yesterdayCost, BigDecimal.ROUND_HALF_UP);
                             accountJson.put("costProportion", costProportion); // 较昨日增加比例
                         } else {
@@ -320,16 +321,17 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                     } else {
                         comparedJson.put("comparedAclick", 0);
                     }
+                    Long comparedPhotoShow = beComparedJson.getLong("photoShow");
+                    Long photoShow = comparedJson.getLong("photoShow");
+                    if (comparedPhotoShow != 0L) {
+                        double showProportion = (photoShow.doubleValue() - comparedPhotoShow.doubleValue()) / comparedPhotoShow.doubleValue();
+                        comparedJson.put("showProportion", showProportion);
+                    } else {
+                        comparedJson.put("showProportion", 0);
+                    }
                 }
 
-                Long comparedPhotoShow = beComparedJson.getLong("photoShow");
-                Long photoShow = comparedJson.getLong("photoShow");
-                if (comparedPhotoShow != 0L) {
-                    double showProportion = (photoShow.doubleValue() - comparedPhotoShow.doubleValue()) / comparedPhotoShow.doubleValue();
-                    comparedJson.put("showProportion", showProportion);
-                } else {
-                    comparedJson.put("showProportion", 0);
-                }
+
                 accountJson.put("beCompared", beComparedJson);
                 accountJson.put("compared", comparedJson);
 
@@ -567,7 +569,6 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
                 reportList = reportMapper.selectReportDetail(anotherDay);
 
             } else if (type == 3) {// 近七天分天列表
-
                 String endDate = DateUtils.getAnotherDay("yyyy-MM-dd", anotherDay, -7);
                 reportList = reportMapper.selectDayDetailByDate(anotherDay, endDate);
 
@@ -618,11 +619,11 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
 
                 } else if ("day".equals(sign)) {
                     List<JSONObject> comparedArr = reportMapper.selectHourlyDetailsByDate(comparedDate);// 除数数据
-                    detailJson.put("beStatDate", beComparedDate);
-                    detailJson.put("beComparedDetail", comparedArr);
-                    List<JSONObject> beComparedArr = reportMapper.selectHourlyDetailsByDate(beComparedDate);// 被除数数据
                     detailJson.put("statDate", comparedDate);
-                    detailJson.put("comparedDetail", beComparedArr);
+                    detailJson.put("comparedDetail", comparedArr);
+                    List<JSONObject> beComparedArr = reportMapper.selectHourlyDetailsByDate(beComparedDate);// 被除数数据
+                    detailJson.put("beStatDate", beComparedDate);
+                    detailJson.put("beComparedDetail", beComparedArr);
 
                 }
                 reportList.add(detailJson);
@@ -631,8 +632,14 @@ public class BytedanceReportServiceImpl implements IBytedanceReportService {
             e.printStackTrace();
         }
 
-
         System.err.println(reportList);
         return reportList;
     }
+
+    public static void main(String[] args) throws ParseException {
+        String nowDate = DateUtils.getNowDate("yyyy-MM-dd");
+        String anotherDay = DateUtils.getAnotherDay("yyyy-MM-dd", nowDate, -1);
+        String endDate = DateUtils.getMonthBefore("yyyy-MM-dd", anotherDay, -3);
+        System.err.println(endDate);
+    }
 }