diff --git a/src/main/java/cn/fw/freya/dao/AccountDao.java b/src/main/java/cn/fw/freya/dao/AccountDao.java index 9f1c311..2b45c43 100644 --- a/src/main/java/cn/fw/freya/dao/AccountDao.java +++ b/src/main/java/cn/fw/freya/dao/AccountDao.java @@ -15,7 +15,6 @@ import java.util.List; */ @Repository public interface AccountDao extends JpaRepository { - /** * 删除指定账号 * @@ -98,4 +97,12 @@ public interface AccountDao extends JpaRepository { @Modifying @Query("update Account a set a.cookiesStatus = ?3 where a.phoneNo = ?1 and a.type = ?2") void updateAccountCookiesStatus(String phoneNo, Integer type, boolean cookiesStatus); + + /** + * 设置账户状态为未完成 + * @param accountNo + */ + @Modifying + @Query("update Account a set a.done = false where a.phoneNo = ?1") + void setAccountUndone(String accountNo); } diff --git a/src/main/java/cn/fw/freya/service/CrawlBizService.java b/src/main/java/cn/fw/freya/service/CrawlBizService.java index 29e295f..b109fb0 100644 --- a/src/main/java/cn/fw/freya/service/CrawlBizService.java +++ b/src/main/java/cn/fw/freya/service/CrawlBizService.java @@ -249,6 +249,7 @@ public class CrawlBizService { final List yesterdayLiveMsg = crawlStrategy.getYesterdayLiveMsg(accountNo);// 获取昨日直播信息 final boolean reportLive = this.doReportLive(account, yesterdayLiveMsg); if (!reportLive) { + accountService.setAccountUndone(accountNo); log.error(LocalDate.now() + " 上报账户为" + accountNo + "的" + (account.getType() == 1 ? "快手" : "抖音") + "的直播数据失败"); } } diff --git a/src/main/java/cn/fw/freya/service/crawl/impl/DongCheDiCrawl.java b/src/main/java/cn/fw/freya/service/crawl/impl/DongCheDiCrawl.java index d862b7c..943de5d 100644 --- a/src/main/java/cn/fw/freya/service/crawl/impl/DongCheDiCrawl.java +++ b/src/main/java/cn/fw/freya/service/crawl/impl/DongCheDiCrawl.java @@ -256,6 +256,7 @@ public class DongCheDiCrawl implements CrawlStrategy { */ @Override public List getYesterdayLiveMsg(String accountNo) { + List livePoolList = new ArrayList<>(); final List hasFoundLive = common.getHasFoundLive(accountNo, this.getType().getValue(), DateUtil.getThisDayMinTime(new Date())); if (Objects.nonNull(hasFoundLive)) { return hasFoundLive; @@ -277,7 +278,19 @@ public class DongCheDiCrawl implements CrawlStrategy { ); String res = RequestUtil.get(config); log.info(String.format("%s [%s]平台账户号为: %s的直播数据的原始数据为: %s", LocalDateTime.now(), this.getType().getName(), accountNo, res)); - final JSONObject response = JSONObject.parseObject(res); + JSONObject response = new JSONObject(); + try { + response = JSONObject.parseObject(res); + } catch (Exception e) { + log.info(LocalDate.now() + " 暂未找到账户号为:" + accountNo + "的懂车帝直播数据"); + final LivePool nullLive = LivePool.builder() + .type(this.getType().getValue()) + .phoneNo(accountNo) + .reportDate(new Date()) + .build(); + livePoolDao.save(nullLive); + return livePoolList; + } if (this.verifyCookies(response)) { return null; } @@ -287,7 +300,6 @@ public class DongCheDiCrawl implements CrawlStrategy { } JSONArray roomList = response.getJSONObject("data").getJSONObject("data").getJSONArray("Rooms"); JSONArray mctLiveDetails = this.getMCTLiveDetails(accountNo, LocalDateTime.of(LocalDate.now().minusDays(1), LocalTime.MIN).toEpochSecond(ZoneOffset.of("+8"))); - List livePoolList = new ArrayList<>(); final LocalDate yesterday = LocalDate.now().minusDays(1); final long yesterdaySecond = LocalDateTime.of(yesterday, LocalTime.MIN).toInstant(ZoneOffset.of("+8")).toEpochMilli(); roomList.forEach(item -> { diff --git a/src/main/java/cn/fw/freya/service/crawl/impl/KuaiShouCrawl.java b/src/main/java/cn/fw/freya/service/crawl/impl/KuaiShouCrawl.java index 572659f..d5ced51 100644 --- a/src/main/java/cn/fw/freya/service/crawl/impl/KuaiShouCrawl.java +++ b/src/main/java/cn/fw/freya/service/crawl/impl/KuaiShouCrawl.java @@ -466,9 +466,9 @@ public class KuaiShouCrawl implements CrawlStrategy { final double liveStartSub = BigDecimal.valueOf(Math.abs(liveStartTimeStamp - startTimeStamp)).divide(BigDecimal.valueOf(60 * 1000), 1, RoundingMode.HALF_UP).doubleValue(); // (Objects.equals(liveDuration, duration) || (timeSubAbs < 5))->说明时长几乎相等 // (liveStartSub < 2)->说明开播时间几乎一样 - if (!((Objects.equals(liveDuration, duration) || - (timeSubAbs < 5)) && liveStartSub < 10) || - !(startTimeStamp >= liveStartTimeStamp && startTimeStamp <= liveStartTimeStamp + liveDuration * 1000 && duration >= durationThreshold)) { + if ((!((Objects.equals(liveDuration, duration) || + (timeSubAbs < 5)) && liveStartSub < 10)) && + !(startTimeStamp >= liveStartTimeStamp && startTimeStamp <= liveStartTimeStamp + liveDuration * 60 * 1000 && duration >= durationThreshold)) { playbackMsg = null; log.info(String.format("%s [%s]平台账户号为: %s的直播回放数据不匹配!!!", LocalDateTime.now(), this.getType().getName(), accountNo)); } diff --git a/src/main/java/cn/fw/freya/service/data/AccountService.java b/src/main/java/cn/fw/freya/service/data/AccountService.java index 5e60f9f..1781a3d 100644 --- a/src/main/java/cn/fw/freya/service/data/AccountService.java +++ b/src/main/java/cn/fw/freya/service/data/AccountService.java @@ -55,9 +55,17 @@ public interface AccountService { /** * 更新账户cookies状态 * - * @param phoneNo + * @param accountNo * @param type * @param cookiesStatus */ - void updateAccountCookiesStatus(String phoneNo, Integer type, boolean cookiesStatus); + void updateAccountCookiesStatus(String accountNo, Integer type, boolean cookiesStatus); + + /** + * 设置账户为未完成状态 + * + * @param accountNo + */ + void setAccountUndone(String accountNo); + } diff --git a/src/main/java/cn/fw/freya/service/data/impl/AccountServiceImpl.java b/src/main/java/cn/fw/freya/service/data/impl/AccountServiceImpl.java index 6caf9d2..4a15524 100644 --- a/src/main/java/cn/fw/freya/service/data/impl/AccountServiceImpl.java +++ b/src/main/java/cn/fw/freya/service/data/impl/AccountServiceImpl.java @@ -63,12 +63,22 @@ public class AccountServiceImpl implements AccountService { /** * 更新账户cookies状态 * - * @param phoneNo + * @param accountNo * @param type * @param cookiesStatus */ @Override - public void updateAccountCookiesStatus(String phoneNo, Integer type, boolean cookiesStatus) { - accountDao.updateAccountCookiesStatus(phoneNo, type, cookiesStatus); + public void updateAccountCookiesStatus(String accountNo, Integer type, boolean cookiesStatus) { + accountDao.updateAccountCookiesStatus(accountNo, type, cookiesStatus); + } + + /** + * 设置账户为未完成状态 + * + * @param accountNo + */ + @Override + public void setAccountUndone(String accountNo) { + accountDao.setAccountUndone(accountNo); } }