package com.cyksj.service.mange.account; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.cyksj.common.constant.Constant; import com.cyksj.common.exception.BusinessRuntimeException; import com.cyksj.common.util.StringUtil; import com.cyksj.mapper.AccountMapper; import com.cyksj.mapper.AccountNetflixStateMapper; import com.cyksj.model.entity.Account; import com.cyksj.model.entity.AccountNetflixState; import com.cyksj.service.mange.AccountCommonService; import com.cyksj.service.relation.GroupsRelationNetflixService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; /* *项目名: netflix *文件名: AccountCommonServiceImpl *创建者: JavaZou *创建时间:2023/8/16 17:12 */ @Service @RequiredArgsConstructor @Slf4j public class AccountCommonServiceImpl implements AccountCommonService { private final AccountMapper accountMapper; private final AccountNetflixStateMapper accountNetflixStateMapper; private final GroupsRelationNetflixService groupsRelationNetflixService; @Override public Boolean checkIsDupAccount(Long goodsId, String account) { LambdaQueryWrapper wrapper = Wrappers.lambdaQuery(Account.class) .eq(Account::getAccount, account); if (Constant.GPT_GOODS_IDS.contains(goodsId)) { wrapper.in(Account::getGoodsId, Constant.GPT_GOODS_IDS); } else { wrapper.eq(Account::getGoodsId, goodsId); } int count = accountMapper.selectCount(wrapper); if (count > 0) return true; return false; } @Override public void syncDonwNF() { List accounts = accountMapper.selectAccountDonw(); if (CollUtil.isEmpty(accounts)) { throw BusinessRuntimeException.getInstance("已同步完成"); } accounts.forEach(account -> { try { AccountNetflixState exist = accountNetflixStateMapper.selectOne(Wrappers.lambdaQuery(AccountNetflixState.class) .eq(AccountNetflixState::getAccount, account.getAccount()) .lt(AccountNetflixState::getCreatedTime, DateUtil.parse("2024-11-26")) .last("limit 1")); if (exist != null) { accountNetflixStateMapper.deleteById(exist.getId()); } String taskId = groupsRelationNetflixService.createNetflixAccountStatusTask(account); log.info("任务taskId:{}", taskId); AccountNetflixState accountNetflixState = new AccountNetflixState(); accountNetflixState.setAccount(account.getAccount()); accountNetflixState.setPassword(account.getPassword()); accountNetflixState.setState(0); accountNetflixState.setTaskId(taskId); accountNetflixStateMapper.insert(accountNetflixState); Integer status = groupsRelationNetflixService.checkNetflixAccountState(accountNetflixState); while (status == 0) { Thread.sleep(2000); try { status = groupsRelationNetflixService.checkNetflixAccountState(accountNetflixState); } catch (Exception e) { break; } } accountNetflixState.setState(status); accountNetflixStateMapper.updateById(accountNetflixState); } catch (Exception e) { log.error("创建检测奈飞账号状态任务失败:{}", StringUtil.getErrorText(e)); } }); } }