Jelajahi Sumber

Merge branch 'import_special_goods'

zoujiajian 3 tahun lalu
induk
melakukan
aa9e24ccb9

+ 41 - 31
netflix-service/src/main/java/com/cyksj/service/mange/account/CmsAccountServiceImpl.java

@@ -200,38 +200,48 @@ public class CmsAccountServiceImpl extends ServiceImpl<AccountMapper, Account> i
 		if (!redisService.setNx(cache, goodsId, RedisService.key.IMPORT_ACCOUNT_CACHE_KEY.getTimeout())) {
 			throw BusinessRuntimeException.getInstance("后台程序正在导入账号中...");
 		}
-		accountList.forEach(accountData -> {
-			Map<String, Object> map = Jsons.toMap(accountData);
-			String[] part = map.get("0").toString().split("----");
-			if (part.length >= 2) {
-				String account = part[0];
-				String password = part[1];
-				int count = this.count(Wrappers.lambdaQuery(Account.class)
-						.eq(Account::getAccount, account)
-						.eq(Account::getGoodsId, goodsId));
-				if (count > 0) {
-					return;
-				}
-				Account insert = new Account();
-				insert.setAccount(account);
-				insert.setPassword(password);
-				if (part.length > 2) {
-					String apiKey = part[2];
-					insert.setApiKey(apiKey);
-				}
-				insert.setGoodsId(goodsId);
-				if (goodsId.equals(31l)) {
-					insert.setSecret(Constant.AMERICA_APPID_SECRET);
+		String regex;
+		if (goodsId == 29l) {
+			regex = "\\|";
+		} else {
+			regex = "----";
+		}
+		try {
+			accountList.forEach(accountData -> {
+				Map<String, Object> map = Jsons.toMap(accountData);
+				String[] part = map.get("0").toString().split(regex);
+				if (part.length >= 2) {
+					String account = part[0];
+					String password = part[1];
+					int count = this.count(Wrappers.lambdaQuery(Account.class)
+							.eq(Account::getAccount, account)
+							.eq(Account::getGoodsId, goodsId));
+					if (count > 0) {
+						return;
+					}
+					Account insert = new Account();
+					insert.setAccount(account);
+					insert.setPassword(password);
+					if (part.length > 2) {
+						String apiKey = part[2];
+						insert.setApiKey(apiKey);
+					}
+					insert.setGoodsId(goodsId);
+					if (goodsId.equals(31l)) {
+						insert.setSecret(Constant.AMERICA_APPID_SECRET);
+					}
+					this.save(insert);
+
+					//自动配置车队
+					GroupsTrips groupsTrips = new GroupsTrips();
+					groupsTrips.setSkuId(skuId);
+					groupsTrips.setAccountId(insert.getId());
+					cmsGroupService.issuance(groupsTrips, null);
 				}
-				this.save(insert);
-
-				//自动配置车队
-				GroupsTrips groupsTrips = new GroupsTrips();
-				groupsTrips.setSkuId(skuId);
-				groupsTrips.setAccountId(insert.getId());
-				cmsGroupService.issuance(groupsTrips, null);
-			}
-		});
+			});
+		} catch (Exception e) {
+			log.error(StringUtil.getErrorText(e));
+		}
 		redisService.del(cache);
 	}
 }

+ 13 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/account/CmsAccountController.java

@@ -314,6 +314,19 @@ public class CmsAccountController {
 		return GatewayResponse.SUCCESS.newBuilder().toResult();
 	}
 
+	/**
+	 * 批量导入特殊格式excel平台账号
+	 */
+	@PostMapping("/import/special/goods/account")
+	public Result<String> analysisChatGptAccount(@RequestParam(required = true) Long goodsId, @RequestParam(required = true) Long skuId, MultipartFile file) throws IOException {
+		if (!file.getOriginalFilename().contains(".xls")) {
+			throw BusinessRuntimeException.getInstance("请导入excel文件");
+		}
+		List<Object> accountList = EasyExcel.read(file.getInputStream()).sheet().headRowNumber(0).doReadSync();
+		accountService.analysisChatGPTAccount(goodsId, skuId, accountList);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
     @PostMapping("/post")
     @NoSubmit
     @Transactional(rollbackFor = Throwable.class)