فهرست منبع

同步excel奈飞账号状态

zoujiajian 1 سال پیش
والد
کامیت
cf690f6cc8

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

@@ -30,4 +30,6 @@ public interface AccountMapper extends BaseMapper<Account> {
 	Account selectNetflixTempAccount();
 
 	Integer isNormal(String account);
+
+	List<Account> selectNetflixAccountLimit(int limit);
 }

+ 13 - 0
netflix-dao/src/main/java/com/cyksj/mapper/AccountNetflixStateMapper.java

@@ -0,0 +1,13 @@
+package com.cyksj.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.cyksj.model.entity.AccountNetflixState;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: AccountNetflixStateMapper
+ * 创建者: JavaZou
+ * 创建时间:2024/10/28 15:35
+ */
+public interface AccountNetflixStateMapper extends BaseMapper<AccountNetflixState> {
+}

+ 23 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/AccountNetflixState.java

@@ -0,0 +1,23 @@
+package com.cyksj.model.entity;
+
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: AccountNetflixState
+ * 创建者: JavaZou
+ * 创建时间:2024/11/8 10:48
+ */
+@Getter
+@Setter
+public class AccountNetflixState extends BaseEntity{
+	private String account;
+
+	private String password;
+
+	private String taskId;
+
+	//0正在执行中 1是账号正常 2是登录失败 3是被封号
+	private Integer state;
+}

+ 22 - 0
netflix-dao/src/main/java/com/cyksj/model/excel/ExcelAccountStateData.java

@@ -0,0 +1,22 @@
+package com.cyksj.model.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * 项目名: yhlxj2
+ * 文件名: ExcelAccountStateData
+ * 创建者: JavaZou
+ * 创建时间:2024/11/8 10:51
+ */
+@Getter
+@Setter
+public class ExcelAccountStateData {
+
+	@ExcelProperty("账号")
+	private String account;
+
+	@ExcelProperty("密码")
+	private String password;
+}

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

@@ -203,4 +203,8 @@
     <select id="isNormal" resultType="java.lang.Integer">
         select `state` from account_netflix_state where account = #{account} limit 1
     </select>
+
+    <select id="selectNetflixAccountLimit" resultType="com.cyksj.model.entity.Account">
+        select * from account_netflix_state where state = 0 limit #{limit}
+    </select>
 </mapper>

+ 4 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupRelationFrontService.java

@@ -73,4 +73,8 @@ public interface GroupRelationFrontService {
 	void changeTicket(long userId, Long relationId);
 
 	AccountView getTempAccount(long userId, Long relationId);
+
+	void syncNfAccountState();
+
+	void syncExcelAccountState(String account, String password);
 }

+ 8 - 0
netflix-service/src/main/java/com/cyksj/service/relation/GroupsRelationNetflixService.java

@@ -1,6 +1,8 @@
 package com.cyksj.service.relation;
 
 import cn.hutool.json.JSONObject;
+import com.cyksj.model.entity.Account;
+import com.cyksj.model.entity.AccountNetflixState;
 import com.cyksj.model.request.NfDeviceReq;
 
 import java.util.Date;
@@ -29,4 +31,10 @@ public interface GroupsRelationNetflixService {
 	JSONObject nfKickOut(long userId, Long relationId);
 
 	void clickNfHouseholdDevice(NfDeviceReq nfDeviceReq);
+
+	String createNetflixAccountStatusTask(Account account) throws Exception;
+
+	Integer checkNetflixAccountState(AccountNetflixState state) throws Exception;
+
+	String createNetflixAccountStatusTask(String account, String password) throws Exception;
 }

+ 84 - 40
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupRelationFrontServiceImpl.java

@@ -161,7 +161,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 
 	private final GroupsRelationChangeService changeTickerRelation;
 
-	private final NetflixTempAccountUserMapper netflixTempAccountUserMapper;
+	private final AccountNetflixStateMapper accountNetflixStateMapper;
 
 	@Override
 	public SearchResult<RenewalView> getMyTicket(long userId, Boolean isLoginPopularize, String customId, String account, String orderNo) {
@@ -1030,7 +1030,7 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 		}
 		//若无移至空车队
 		if (newRelation == null) {
-			newRelation = changeTickerRelation.getEmptyGroupsRelation(renewalView.getUserId(), renewalView.getRelationId(), renewalView.getSkuId());
+			newRelation = changeTickerRelation.getEmptyGroupsRelation(renewalView.getRelationId(), renewalView.getUserId(), renewalView.getSkuId());
 		}
 		if (newRelation == null) {
 			throw BusinessRuntimeException.getInstance("更换异常,请重新提交");
@@ -1039,48 +1039,92 @@ public class GroupRelationFrontServiceImpl implements GroupRelationFrontService
 
 	@Override
 	public AccountView getTempAccount(long userId, Long relationId) {
-		List<Long> userIdList = userBindRelationService.getRelationUserIdList(userId, null);
-		RenewalView renewalView = beanSearcher.searchFirst(RenewalView.class, MapUtils.builder()
-				.field(RenewalView::getRelationId, relationId)
-				.field(RenewalView::getUserId, userIdList).op(Operator.InList)
-				.field(RenewalView::getGroupsStatus, GroupsTrips.Status.waiting.name())
-				.field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
-				.build());
-		if (renewalView == null) {
-			throw BusinessRuntimeException.getInstance("车票不存在");
-		}
-		AccountView accountView = new AccountView();
-		//奈飞超过3帐车票不给看
-		Number number = beanSearcher.searchCount(RenewalView.class, MapUtils.builder()
-				.field(RenewalView::getUserId, userIdList).op(Operator.InList)
-				.field(RenewalView::getGoodsId, 1)
-				.field(RenewalView::getExpiryTime, DateTime.now()).op(Operator.GreaterThan)
-				.build());
-		if (number.intValue() > 2) {
-			return accountView;
+		return null;
+	}
+
+	@Override
+	public void syncNfAccountState() {
+		List<Account> accounts = accountMapper.selectNetflixAccountLimit(5);
+		if (CollUtil.isEmpty(accounts)) {
+			throw BusinessRuntimeException.getInstance("已同步完成");
 		}
-		NetflixTempAccountUser netflixTempAccountUser = netflixTempAccountUserMapper.selectOne(Wrappers.lambdaQuery(NetflixTempAccountUser.class)
-				.eq(NetflixTempAccountUser::getRelationId, relationId)
-				.in(NetflixTempAccountUser::getUserId, userIdList)
-				.last("limit 1"));
-		Account account;
-		if (netflixTempAccountUser == null) {
-			account = accountMapper.selectNetflixTempAccount();
-			if (account != null) {
-				netflixTempAccountUser = new NetflixTempAccountUser();
-				netflixTempAccountUser.setAccountId(account.getId());
-				netflixTempAccountUser.setRelationId(relationId);
-				netflixTempAccountUser.setUserId(renewalView.getUserId());
-				netflixTempAccountUserMapper.insert(netflixTempAccountUser);
+		accounts.forEach(account -> {
+			try {
+				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);
+			} catch (Exception e) {
+				log.error("创建检测奈飞账号状态任务失败:{}", StringUtil.getErrorText(e));
 			}
-		} else {
-			account = accountMapper.selectById(netflixTempAccountUser.getAccountId());
+		});
+
+		//同步奈飞账号状态
+		List<AccountNetflixState> accountNetflixStates = accountNetflixStateMapper.selectList(Wrappers.lambdaQuery(AccountNetflixState.class)
+				.eq(AccountNetflixState::getState, 0));
+		accountNetflixStates.forEach(accountNetflixState -> {
+			try {
+				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));
+			}
+		});
+		syncNfAccountState();
+	}
+
+	@Override
+	public void syncExcelAccountState(String account, String password) {
+		Integer selectCount = accountNetflixStateMapper.selectCount(Wrappers.lambdaQuery(AccountNetflixState.class)
+				.eq(AccountNetflixState::getAccount, account));
+		if (selectCount > 0) {
+			log.info("该账号:{}已经同步", account);
+			return;
 		}
-		if (account != null) {
-			accountView.setAccount(account.getAccount());
-			accountView.setPassword(account.getPassword());
+
+
+		try {
+			String taskId = groupsRelationNetflixService.createNetflixAccountStatusTask(account, password);
+			log.info("任务taskId:{}", taskId);
+			AccountNetflixState accountNetflixState = new AccountNetflixState();
+			accountNetflixState.setAccount(account);
+			accountNetflixState.setPassword(password);
+			accountNetflixState.setState(0);
+			accountNetflixState.setTaskId(taskId);
+			accountNetflixStateMapper.insert(accountNetflixState);
+
+			try {
+				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));
+			}
+
+		} catch (Exception e) {
+			log.error("创建奈飞账号状态任务失败:{}", StringUtil.getErrorText(e));
 		}
-		return accountView;
 	}
 
 	private DistributePosterGoodsDetailView setGoodsPoster(RenewalView ticket, User user, List<Long> userIds) {

+ 64 - 4
netflix-service/src/main/java/com/cyksj/service/relation/impl/GroupsRelationNetflixServiceImpl.java

@@ -14,10 +14,7 @@ import com.cyksj.mapper.AccountMapper;
 import com.cyksj.mapper.GroupsMapper;
 import com.cyksj.mapper.GroupsRelationMapper;
 import com.cyksj.mapper.UserMapper;
-import com.cyksj.model.entity.Account;
-import com.cyksj.model.entity.GroupsRelation;
-import com.cyksj.model.entity.GroupsTrips;
-import com.cyksj.model.entity.User;
+import com.cyksj.model.entity.*;
 import com.cyksj.model.request.NfDeviceReq;
 import com.cyksj.redis.RedisService;
 import com.cyksj.service.relation.GroupsRelationNetflixService;
@@ -208,6 +205,69 @@ public class GroupsRelationNetflixServiceImpl implements GroupsRelationNetflixSe
 		}
 	}
 
+	@Override
+	public String createNetflixAccountStatusTask(Account account) throws Exception {
+		String at = account.getAccount();
+		String pd = account.getPassword();
+
+		JSONObject params = new JSONObject();
+		params.putOpt("username", at);
+		params.putOpt("password", pd);
+		String url = "http://netflix.galaxydvd.com/frpnetflix_check_account";
+		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);
+		String taskId = data.getStr("transId");
+		return taskId;
+	}
+
+	@Override
+	public Integer checkNetflixAccountState(AccountNetflixState state) throws Exception {
+		JSONObject params = new JSONObject();
+		params.putOpt("transId", state.getTaskId());
+		//查询任务状态
+		String url = "http://netflix.galaxydvd.com/frp/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");
+		return status;
+	}
+
+	@Override
+	public String createNetflixAccountStatusTask(String account, String password) throws Exception {
+		JSONObject params = new JSONObject();
+		params.putOpt("username", account);
+		params.putOpt("password", password);
+		String url = "http://netflix.galaxydvd.com/frpnetflix_check_account";
+		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);
+		String taskId = data.getStr("transId");
+		return taskId;
+	}
+
 	/**
 	 * 踢出奈飞设备
 	 */

+ 47 - 0
netflix-web/src/main/java/com/cyksj/web/controller/group/GroupRelationController.java

@@ -9,6 +9,9 @@ import cn.hutool.core.thread.ThreadUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.extra.servlet.ServletUtil;
 import cn.hutool.json.JSONObject;
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -28,6 +31,7 @@ import com.cyksj.mapper.manage.form.QuestionnairePromotionMapper;
 import com.cyksj.model.dto.DoubleVerifyDto;
 import com.cyksj.model.dto.QuestionnaireView;
 import com.cyksj.model.entity.*;
+import com.cyksj.model.excel.ExcelAccountStateData;
 import com.cyksj.model.manage.views.AccountView;
 import com.cyksj.model.manage.views.GroupsRelationView;
 import com.cyksj.model.request.*;
@@ -55,10 +59,12 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.constraints.NotEmpty;
 import javax.validation.constraints.NotNull;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.util.*;
@@ -1113,4 +1119,45 @@ public class GroupRelationController {
         AccountView accountView = groupRelationFrontService.getTempAccount(userId, relationId);
         return GatewayResponse.SUCCESS.newBuilder().toResult(accountView);
     }
+
+    /**
+     * 同步奈飞账号可用状态
+     */
+    @PutMapping("/sync/nf/account/state")
+    public Result<String> syncNfAccountState() {
+        groupRelationFrontService.syncNfAccountState();
+        return GatewayResponse.SUCCESS.newBuilder().toResult();
+    }
+
+    /**
+     * excel校验校验账号是否封禁
+     */
+    @PostMapping("/sync/excel/account/state")
+    public Result<String> syncExcelAccountState(MultipartFile file) throws IOException {
+        EasyExcel.read(file.getInputStream(), ExcelAccountStateData.class, new AnalysisEventListener<ExcelAccountStateData>() {
+            @Override
+            public void invoke(ExcelAccountStateData data, AnalysisContext analysisContext) {
+                String account = data.getAccount();
+                String password = data.getPassword();
+
+                if (StrUtil.isEmpty(account) || StrUtil.isEmpty(password)) {
+                    log.info("账号或密码为空");
+                    return;
+                }
+                if (account.contains("yinhe.ac.cn")) {
+                    log.info("yinhe.ac.cn后缀账号不检测");
+                    return;
+                }
+                groupRelationFrontService.syncExcelAccountState(account, password);
+            }
+
+            @Override
+            public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+            }
+        }).sheet().doRead();
+        return GatewayResponse.SUCCESS.newBuilder().toResult("成功");
+    }
+
+
 }