Bläddra i källkod

同步已下架的奈飞车队账号

zoujiajian 1 år sedan
förälder
incheckning
0c40c4e5d3

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/AccountMapper.java

@@ -34,4 +34,6 @@ public interface AccountMapper extends BaseMapper<Account> {
 	List<Account> selectNetflixAccountLimit(int limit);
 
 	List<Account> selectYinhelxComAccount();
+
+	List<Account> selectAccountDonw();
 }

+ 9 - 0
netflix-dao/src/main/resources/mapper/AccountMapper.xml

@@ -218,4 +218,13 @@
                          where ans.account = a.account and ans.created_time > '2024-11-11 17:02:00')
             limit 5
     </select>
+
+    <select id="selectAccountDonw" resultType="com.cyksj.model.entity.Account">
+        select a.*
+        from groups_trips gt
+                 inner join account a on a.id = gt.account_id
+        where a.goods_id = 1
+          and gt.status = 'down'
+          and not exists(select 1 from account_netflix_state ans where ans.account = a.account and ans.state = 3)
+    </select>
 </mapper>

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/mange/AccountCommonService.java

@@ -8,4 +8,6 @@ package com.cyksj.service.mange;
  */
 public interface AccountCommonService {
 	Boolean checkIsDupAccount(Long goodsId, String account);
+
+	void syncDonwNF();
 }

+ 56 - 0
netflix-service/src/main/java/com/cyksj/service/mange/account/AccountCommonServiceImpl.java

@@ -1,14 +1,24 @@
 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
@@ -17,10 +27,15 @@ import org.springframework.stereotype.Service;
  */
 @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<Account> wrapper = Wrappers.lambdaQuery(Account.class)
@@ -34,4 +49,45 @@ public class AccountCommonServiceImpl implements AccountCommonService {
 		if (count > 0) return true;
 		return false;
 	}
+
+	@Override
+	public void syncDonwNF() {
+		List<Account> 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));
+			}
+		});
+	}
 }

+ 19 - 0
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupsRelationNetflixServiceImpl.java

@@ -248,6 +248,25 @@ public class GroupsRelationNetflixServiceImpl implements GroupsRelationNetflixSe
 		return status;
 	}
 
+	public static void main(String[] args) throws Exception {
+		JSONObject params = new JSONObject();
+		params.putOpt("transId", "onesrjhl6n@yinhelx.com1732600477753");
+		//查询任务状态
+		String url = "http://124.220.3.236:8089/netflix_task_status";
+		HttpResponse<String> res =
+				J11HttpC.custom()
+						.ofPost()
+						.url(url)
+						.headers(J11HttpC.ReqType.raw_json)
+						.body(HttpRequest.BodyPublishers.ofString(Jsons.toJson(params), IoKit.Charsets.UTF_8.getCharset()))
+						.send(HttpResponse.BodyHandlers.ofString());
+		String body = res.body();
+		JSONObject jsonObject = Jsons.parseObject(body, JSONObject.class);
+		JSONObject data = Jsons.parseObject(jsonObject.get("data"), JSONObject.class);
+		Integer status = data.getInt("status");
+		System.out.println(status);
+	}
+
 	@Override
 	public String createNetflixAccountStatusTask(String account, String password) throws Exception {
 		JSONObject params = new JSONObject();

+ 9 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/AccountTempController.java

@@ -584,4 +584,13 @@ public class AccountTempController {
 			orderCommonService.delRelation(groupsRelation);
 		}
 	}
+
+	/**
+	 * 同步已下架的账号 除去之前明确封号的  再跑
+	 */
+	@GetMapping("/sync/down/nf")
+	public Result<String> syncDonwNF() {
+		accountCommonService.syncDonwNF();
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }