AccountCommonServiceImpl.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.cyksj.service.mange.account;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateUtil;
  4. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  5. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6. import com.cyksj.common.constant.Constant;
  7. import com.cyksj.common.exception.BusinessRuntimeException;
  8. import com.cyksj.common.util.StringUtil;
  9. import com.cyksj.mapper.AccountMapper;
  10. import com.cyksj.mapper.AccountNetflixStateMapper;
  11. import com.cyksj.model.entity.Account;
  12. import com.cyksj.model.entity.AccountNetflixState;
  13. import com.cyksj.service.mange.AccountCommonService;
  14. import com.cyksj.service.relation.GroupsRelationNetflixService;
  15. import lombok.RequiredArgsConstructor;
  16. import lombok.extern.slf4j.Slf4j;
  17. import org.springframework.stereotype.Service;
  18. import java.util.List;
  19. /*
  20. *项目名: netflix
  21. *文件名: AccountCommonServiceImpl
  22. *创建者: JavaZou
  23. *创建时间:2023/8/16 17:12
  24. */
  25. @Service
  26. @RequiredArgsConstructor
  27. @Slf4j
  28. public class AccountCommonServiceImpl implements AccountCommonService {
  29. private final AccountMapper accountMapper;
  30. private final AccountNetflixStateMapper accountNetflixStateMapper;
  31. private final GroupsRelationNetflixService groupsRelationNetflixService;
  32. @Override
  33. public Boolean checkIsDupAccount(Long goodsId, String account) {
  34. LambdaQueryWrapper<Account> wrapper = Wrappers.lambdaQuery(Account.class)
  35. .eq(Account::getAccount, account);
  36. if (Constant.GPT_GOODS_IDS.contains(goodsId)) {
  37. wrapper.in(Account::getGoodsId, Constant.GPT_GOODS_IDS);
  38. } else {
  39. wrapper.eq(Account::getGoodsId, goodsId);
  40. }
  41. int count = accountMapper.selectCount(wrapper);
  42. if (count > 0) return true;
  43. return false;
  44. }
  45. @Override
  46. public void syncDonwNF() {
  47. List<Account> accounts = accountMapper.selectAccountDonw();
  48. if (CollUtil.isEmpty(accounts)) {
  49. throw BusinessRuntimeException.getInstance("已同步完成");
  50. }
  51. accounts.forEach(account -> {
  52. try {
  53. AccountNetflixState exist = accountNetflixStateMapper.selectOne(Wrappers.lambdaQuery(AccountNetflixState.class)
  54. .eq(AccountNetflixState::getAccount, account.getAccount())
  55. .lt(AccountNetflixState::getCreatedTime, DateUtil.parse("2024-11-26"))
  56. .last("limit 1"));
  57. if (exist != null) {
  58. accountNetflixStateMapper.deleteById(exist.getId());
  59. }
  60. String taskId = groupsRelationNetflixService.createNetflixAccountStatusTask(account);
  61. log.info("任务taskId:{}", taskId);
  62. AccountNetflixState accountNetflixState = new AccountNetflixState();
  63. accountNetflixState.setAccount(account.getAccount());
  64. accountNetflixState.setPassword(account.getPassword());
  65. accountNetflixState.setState(0);
  66. accountNetflixState.setTaskId(taskId);
  67. accountNetflixStateMapper.insert(accountNetflixState);
  68. Integer status = groupsRelationNetflixService.checkNetflixAccountState(accountNetflixState);
  69. while (status == 0) {
  70. Thread.sleep(2000);
  71. try {
  72. status = groupsRelationNetflixService.checkNetflixAccountState(accountNetflixState);
  73. } catch (Exception e) {
  74. break;
  75. }
  76. }
  77. accountNetflixState.setState(status);
  78. accountNetflixStateMapper.updateById(accountNetflixState);
  79. } catch (Exception e) {
  80. log.error("创建检测奈飞账号状态任务失败:{}", StringUtil.getErrorText(e));
  81. }
  82. });
  83. }
  84. }