CmsAccountServiceImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. package com.cyksj.service.mange.account;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.lang.Validator;
  4. import cn.hutool.core.util.RandomUtil;
  5. import cn.hutool.core.util.StrUtil;
  6. import com.baomidou.mybatisplus.core.metadata.IPage;
  7. import com.baomidou.mybatisplus.core.toolkit.Assert;
  8. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  9. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  10. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  11. import com.cyksj.common.constant.Constant;
  12. import com.cyksj.common.exception.BusinessRuntimeException;
  13. import com.cyksj.common.util.Jsons;
  14. import com.cyksj.common.util.StringUtil;
  15. import com.cyksj.mapper.*;
  16. import com.cyksj.mapper.manage.AutoUpdateAccountPwdLogMapper;
  17. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  18. import com.cyksj.mapper.sys.SysEmailMapper;
  19. import com.cyksj.model.entity.*;
  20. import com.cyksj.model.excel.ExcelAccountData;
  21. import com.cyksj.model.manage.views.AccountView;
  22. import com.cyksj.model.request.DelAccountTripsReq;
  23. import com.cyksj.model.views.CmsUserVO;
  24. import com.cyksj.model.views.ExpiredAccountDataView;
  25. import com.cyksj.redis.RedisService;
  26. import com.cyksj.service.mail.CommonMailService;
  27. import com.cyksj.service.mange.AccountCommonService;
  28. import com.cyksj.service.mange.CmsAccountService;
  29. import com.cyksj.service.mange.CmsGroupService;
  30. import com.cyksj.service.sys.SysConfigService;
  31. import com.ejlchina.searcher.BeanSearcher;
  32. import com.ejlchina.searcher.param.Operator;
  33. import com.ejlchina.searcher.util.MapUtils;
  34. import com.google.common.collect.Lists;
  35. import lombok.RequiredArgsConstructor;
  36. import lombok.extern.slf4j.Slf4j;
  37. import org.springframework.stereotype.Service;
  38. import org.springframework.transaction.annotation.Transactional;
  39. import org.springframework.web.multipart.MultipartFile;
  40. import java.io.BufferedReader;
  41. import java.io.InputStream;
  42. import java.io.InputStreamReader;
  43. import java.util.*;
  44. import java.util.regex.Matcher;
  45. import java.util.regex.Pattern;
  46. /**
  47. * @author chan
  48. * @date 2022/9/27 6:23 PM
  49. */
  50. @Slf4j
  51. @Service("cms")
  52. @RequiredArgsConstructor
  53. public class CmsAccountServiceImpl extends ServiceImpl<AccountMapper, Account> implements CmsAccountService {
  54. private final AccountMapper accountMapper;
  55. private final AccountUpdatePasswordRecordMapper accountUpdatePasswordRecordMapper;
  56. private final CmsUserMapper cmsUserMapper;
  57. private final AutoUpdateAccountPwdLogMapper autoUpdateAccountPwdLogMapper;
  58. private final BeanSearcher beanSearcher;
  59. private final CmsGroupService cmsGroupService;
  60. private final RedisService redisService;
  61. private final AccountCommonService accountCommonService;
  62. private final SysConfigService sysConfigService;
  63. private final SysEmailMapper sysEmailMapper;
  64. private final GoodsDonMapper goodsDonMapper;
  65. private final AccountBlockedReplaceRecordMapper accountBlockedReplaceRecordMapper;
  66. private final CommonMailService commonMailService;
  67. private final DelAccountRecordMapper delAccountRecordMapper;
  68. private final GroupsMapper groupsMapper;
  69. private final GroupsRelationMapper relationMapper;
  70. @Override
  71. public IPage<ExpiredAccountDataView> getExpiredAccountView(Boolean isCorpWx, String customerService, Long goodsId, Long skuId, String account, Boolean renewStatus, Boolean handleStatus, String cnAccount, String usAccount, Integer userId, String startTime, String endTime, String now, Long offset, Long limit) {
  72. return accountMapper.getExpiredAccountView(isCorpWx, customerService, goodsId, skuId, account, renewStatus, handleStatus, cnAccount, usAccount, userId, startTime, endTime, now, new Page<>(offset, limit));
  73. }
  74. @Override
  75. public List<ExcelAccountData> getExpiredAccountViewNoPage(Boolean isCorpWx, String customerService, Long goodsId, Long skuId, String account, Boolean renewStatus, Boolean handleStatus, String cnAccount, String usAccount, Integer userId, String startTime, String endTime, String now) {
  76. return accountMapper.getExpiredAccountViewNoPage(isCorpWx, customerService, goodsId, skuId, account, renewStatus, handleStatus, cnAccount, usAccount, userId, startTime, endTime, now);
  77. }
  78. @Override
  79. public List<OrderDon> getNoAppleOneOrderDon(List<Long> skuIds, Date yesZeroDate, Date thisZeroDate, List<String> noOrderStatus) {
  80. return accountMapper.getNoAppleOneOrderDon(skuIds, yesZeroDate, thisZeroDate, noOrderStatus);
  81. }
  82. @Override
  83. public List<AccountView> getExpiredAllAccount() {
  84. return accountMapper.getExpiredAllAccount();
  85. }
  86. @Override
  87. public void saveRecord(Long operateUserId, Long accountId, String oldPassword, String newPassword, String type) {
  88. AccountUpdatePasswordRecord record = new AccountUpdatePasswordRecord();
  89. record.setAccountId(accountId);
  90. record.setOperateUserId(operateUserId);
  91. Optional.ofNullable(cmsUserMapper.selectById(operateUserId))
  92. .ifPresent(admin -> record.setOperator(admin.getNickname()));
  93. record.setOldPassword(oldPassword);
  94. record.setNewPassword(newPassword);
  95. record.setType(type);
  96. accountUpdatePasswordRecordMapper.insert(record);
  97. }
  98. @Override
  99. public void recordAutoUpdatePwd(Long accountId, String account, String oldPwd, String newPwd, String operateIp) {
  100. AutoUpdateAccountPwdLog log = new AutoUpdateAccountPwdLog();
  101. log.setAccountId(accountId);
  102. log.setAccount(account);
  103. log.setOldPwd(oldPwd);
  104. log.setNewPwd(newPwd);
  105. log.setOperateLocation(StringUtil.getRealAddressByIP(operateIp));
  106. log.setOperateIp(operateIp);
  107. autoUpdateAccountPwdLogMapper.insert(log);
  108. }
  109. @Override
  110. public void assignDeleteCustomerAccount(Long customerServiceId) {
  111. List<AccountView> accountViews = beanSearcher.searchAll(AccountView.class, MapUtils.builder()
  112. .field(AccountView::getCustomerServiceId, customerServiceId)
  113. .build());
  114. if (accountViews.size() > 0) {
  115. List<CmsUserVO> customers = beanSearcher.searchAll(CmsUserVO.class, MapUtils.builder()
  116. .field(CmsUserVO::getId, customerServiceId).op(Operator.NotEqual)
  117. .field(CmsUserVO::getRoleNames, "客服").op(Operator.Contain)
  118. .build());
  119. if (customers.size() > 0) {
  120. log.info("删除客服id:{},分配其未修改的过期账号,账号数量:{}", customerServiceId, accountViews.size());
  121. assignCustomerAccount(customers, accountViews);
  122. }
  123. }
  124. }
  125. @Override
  126. public void assignCustomerAccount(List<CmsUserVO> customers, List<AccountView> accountViews) {
  127. int customerSize = customers.size();
  128. int accountSize = accountViews.size();
  129. if (accountSize < customerSize) {
  130. accountViews.forEach(account -> {
  131. int randomIndex = RandomUtil.randomInt(customerSize);
  132. CmsUserVO customer = customers.get(randomIndex);
  133. accountMapper.update(null, Wrappers.lambdaUpdate(Account.class)
  134. .set(Account::getCustomerServiceId, customer.getId())
  135. .eq(Account::getId, account.getId()));
  136. });
  137. return;
  138. }
  139. int num = accountSize / customerSize;
  140. int remain = accountSize % customerSize;
  141. List<List<AccountView>> partition = Lists.partition(accountViews, num);
  142. for (int i = 0; i < customerSize; i++) {
  143. List<AccountView> expiredAccounts = partition.get(i);
  144. CmsUserVO customer = customers.get(i);
  145. expiredAccounts.forEach(ea -> {
  146. Long accountId = ea.getId();
  147. accountMapper.update(null, Wrappers.lambdaUpdate(Account.class)
  148. .set(Account::getCustomerServiceId, customer.getId())
  149. .eq(Account::getId, accountId));
  150. });
  151. }
  152. if (remain > 0) {
  153. log.info("分配多余的过期账号给客服");
  154. List<AccountView> remainExpiredAccount = partition.get(customerSize);
  155. remainExpiredAccount.forEach(remainAccount -> {
  156. int randomIndex = RandomUtil.randomInt(customerSize);
  157. log.info("获取的随机下标:{}", randomIndex);
  158. CmsUserVO customer = customers.get(randomIndex);
  159. log.info("随机分配的客服是:{}", customer.getNickname());
  160. Long accountId = remainAccount.getId();
  161. accountMapper.update(null, Wrappers.lambdaUpdate(Account.class)
  162. .set(Account::getCustomerServiceId, customer.getId())
  163. .eq(Account::getId, accountId));
  164. });
  165. }
  166. }
  167. @Override
  168. @Transactional(rollbackFor = Throwable.class)
  169. public void analysisChatGPTAccount(Long goodsId, Long skuId, List<Object> accountList) {
  170. insertAccount(goodsId, skuId, accountList);
  171. }
  172. @Override
  173. public void analysisAmericaAppidAccount(Long goodsId, Long skuId, List<Object> accountList) {
  174. insertAccount(goodsId, skuId, accountList);
  175. }
  176. @Override
  177. public void readFileAndImportEmail(MultipartFile file) throws Exception {
  178. InputStream in = null;
  179. BufferedReader br = null;
  180. String regex = "----";
  181. List<SysEmail> sysEmails = new ArrayList<>();
  182. List<String> error = new ArrayList<>();
  183. try {
  184. in = file.getInputStream();
  185. br = new BufferedReader(new InputStreamReader(file.getInputStream()));
  186. String content = null;
  187. while ((content = br.readLine()) != null) {
  188. String[] split = content.split(regex);
  189. if (split.length > 1) {
  190. String email = split[0];
  191. String password = split[1];
  192. if (!StrUtil.hasEmpty(email, password)) {
  193. SysEmail sysEmail = new SysEmail();
  194. sysEmail.setEmail(email);
  195. sysEmail.setPassword(password);
  196. sysEmails.add(sysEmail);
  197. }
  198. }else {
  199. error.add(split[0]);
  200. }
  201. }
  202. if (CollUtil.isNotEmpty(sysEmails)) {
  203. Lists.partition(sysEmails, 1000).forEach(data -> {
  204. sysEmailMapper.batchInsert(data);
  205. });
  206. }
  207. } finally {
  208. if (br != null) {
  209. br.close();
  210. }
  211. if (in != null) {
  212. in.close();
  213. }
  214. }
  215. System.out.println(Jsons.toJson(error));
  216. }
  217. /**
  218. *
  219. * @param goodsId
  220. * @param skuId
  221. * @param accountList
  222. */
  223. public void insertAccount(Long goodsId, Long skuId, List<Object> accountList) {
  224. if (CollUtil.isEmpty(accountList)) {
  225. throw BusinessRuntimeException.getInstance("文件数据为空");
  226. }
  227. String cache = RedisService.key.IMPORT_ACCOUNT_CACHE_KEY.getNameFormat(goodsId);
  228. if (!redisService.setNx(cache, goodsId, RedisService.key.IMPORT_ACCOUNT_CACHE_KEY.getTimeout())) {
  229. throw BusinessRuntimeException.getInstance("后台程序正在导入账号中...");
  230. }
  231. List<Long> special_email_goods_ids = new ArrayList<>();
  232. SysConfig sysConfig = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
  233. .eq(SysConfig::getSysKey, Constant.SPECIAL_GOODS_ACCOUNT_IMPORT_KEY).last("limit 1"));
  234. if (sysConfig != null) {
  235. try {
  236. special_email_goods_ids.addAll(Jsons.parseList(sysConfig.getSysValue(), Long.class));
  237. } catch (Exception e) {
  238. }
  239. }
  240. String regex;
  241. String regex2 = "---";
  242. if (goodsId == 29l) {
  243. regex = "\\|";
  244. } else {
  245. regex = "----";
  246. }
  247. try {
  248. accountList.forEach(accountData -> {
  249. Map<String, Object> map = Jsons.toMap(accountData);
  250. Account insert = new Account();
  251. insert.setGoodsId(goodsId);
  252. //Gemini pro批量导入特殊格式
  253. if (goodsId == Constant.GEMINI_GOODS_ID) {
  254. String info = map.get("0").toString();
  255. if (info.contains("2FA验证")) {
  256. saveAccount(insert, info);
  257. }
  258. } else {
  259. if (map.keySet().size() >= 5) {
  260. String account = map.get("0").toString();
  261. String password = map.get("1").toString();
  262. String friend = map.get("2").toString();
  263. String work = map.get("3").toString();
  264. String parents = map.get("4").toString();
  265. String secret;
  266. if (map.keySet().size() == 6) {
  267. String country = map.get("5").toString();
  268. secret = String.format(Constant.NEW_APPID_SECRET, friend, work, parents, country);
  269. } else {
  270. secret = String.format(Constant.NEW_APPID_NO_COUNTRY_SECRET, friend, work, parents);
  271. }
  272. insert.setAccount(account);
  273. insert.setPassword(password);
  274. insert.setSecret(secret);
  275. } else {
  276. String params = map.get("0").toString();
  277. String[] part;
  278. //兼容
  279. if (params.contains(regex2) && !params.contains(regex)) {
  280. part = params.split(regex2);
  281. } else {
  282. part = params.split(regex);
  283. }
  284. if (part.length >= 2) {
  285. String account = part[0];
  286. String password = part[1];
  287. insert.setAccount(account);
  288. insert.setPassword(password);
  289. if (part.length > 2 && part.length < 9) {
  290. //google36、辅助邮箱
  291. //46 Google Bard
  292. if (special_email_goods_ids.contains(goodsId)) {
  293. String email = part[2];
  294. insert.setEmail(email);
  295. if (part.length > 3) {
  296. String googleAuth = part[3];
  297. insert.setGoogleAuth(googleAuth);
  298. //google双重认证密钥
  299. insert.setApiSecret(googleAuth);
  300. }
  301. } else {
  302. //chatGPT 邮箱密码
  303. String gptEmailPwd = part[2];
  304. insert.setGptEmailPwd(gptEmailPwd);
  305. if (gptEmailPwd.contains("http")) {
  306. insert.setSecret(gptEmailPwd);
  307. }
  308. }
  309. }
  310. if (goodsId.equals(31l)) {
  311. if (part.length >= 9) {
  312. StringBuilder sb = new StringBuilder();
  313. String country = part[part.length - 1];
  314. if (country.contains("国")) {
  315. sb.append(part[part.length - 1]);
  316. sb.append(Constant.ONE_EMPTY);
  317. sb.append(part[part.length - 2]);
  318. sb.append(Constant.ONE_EMPTY);
  319. }
  320. for (int i = 2; i < part.length; i++) {
  321. if (part[i].contains("朋友")) {
  322. sb.append("朋友");
  323. sb.append(Constant.ONE_EMPTY);
  324. sb.append(part[i + 1]);
  325. i++;
  326. }
  327. if (part[i].contains("工作")) {
  328. sb.append("工作");
  329. sb.append(Constant.ONE_EMPTY);
  330. sb.append(part[i + 1]);
  331. i++;
  332. }
  333. if (part[i].contains("父母")) {
  334. sb.append("父母");
  335. sb.append(Constant.ONE_EMPTY);
  336. sb.append(part[i + 1]);
  337. i++;
  338. }
  339. if (part[i].contains("菜")) {
  340. sb.append("一道菜");
  341. sb.append(Constant.ONE_EMPTY);
  342. sb.append(part[i + 1]);
  343. i++;
  344. }
  345. if (part[i].contains("书")) {
  346. sb.append("一本书");
  347. sb.append(Constant.ONE_EMPTY);
  348. sb.append(part[i + 1]);
  349. i++;
  350. }
  351. if (part[i].contains("专辑")) {
  352. sb.append("一张专辑");
  353. sb.append(Constant.ONE_EMPTY);
  354. sb.append(part[i + 1]);
  355. i++;
  356. }
  357. }
  358. String string = sb.toString();
  359. if (string.contains("菜")) {
  360. StringBuilder builder = new StringBuilder();
  361. string = builder.append("生日").append(Constant.ONE_EMPTY).append(part[2]).append(Constant.ONE_EMPTY).append(string).toString();
  362. }
  363. insert.setSecret(string);
  364. } else {
  365. //密保
  366. if (part.length > 5) {
  367. String friends = part[2];
  368. String works = part[3];
  369. String parents = part[4];
  370. String birthday = part[5];
  371. String secret = String.format(Constant.NEW_APPID_NO_COUNTRY_SECRET_DATE, birthday, friends, works, parents);
  372. insert.setSecret(secret);
  373. }
  374. }
  375. }
  376. }
  377. }
  378. }
  379. String account = insert.getAccount();
  380. if (StrUtil.isEmpty(account)) {
  381. return;
  382. }
  383. //重复不再重新插入
  384. if (accountCommonService.checkIsDupAccount(goodsId, account)) {
  385. return;
  386. }
  387. this.save(insert);
  388. //是否存在未发车的车队
  389. GroupsTrips waiting = cmsGroupService.getOne(Wrappers.lambdaQuery(GroupsTrips.class)
  390. .eq(GroupsTrips::getSkuId, skuId)
  391. .eq(GroupsTrips::getStatus, GroupsTrips.Status.waiting).last("limit 1"));
  392. if (waiting != null) {
  393. waiting.setAccountId(insert.getId());
  394. try {
  395. cmsGroupService.setAccount(waiting);
  396. } catch (Exception e) {
  397. //自动配置车队
  398. setGroupsTrips(skuId, insert.getId());
  399. }
  400. } else {
  401. //自动配置车队
  402. setGroupsTrips(skuId, insert.getId());
  403. }
  404. });
  405. } catch (Exception e) {
  406. log.error(StringUtil.getErrorText(e));
  407. }
  408. redisService.del(cache);
  409. }
  410. private void saveAccount(Account insert, String info) {
  411. // 定义各项对应的正则表达式
  412. String accountRegex = "账号(.*?)密码";
  413. String passwordRegex = "密码(.*?)登录二次验证码";
  414. String login2faUrlRegex = "登录二次验证码(.*?)\\s*2FA验证"; // \s* 用于处理可能存在的空格
  415. String twoFaCodeRegex = "2FA验证(.*?)美国手机号";
  416. // 获取“美国手机号:”后面的所有字符串(匹配到行尾)
  417. String usPhoneAndRestRegex = "美国手机号(.*)";
  418. // 提取数据
  419. String account = extractValue(info, accountRegex);
  420. String password = extractValue(info, passwordRegex);
  421. String login2faUrl = extractValue(info, login2faUrlRegex);
  422. String twoFaCode = extractValue(info, twoFaCodeRegex);
  423. String phoneInfos = extractValue(info, usPhoneAndRestRegex);
  424. insert.setAccount(account);
  425. insert.setPassword(password);
  426. insert.setApiSecret(twoFaCode);
  427. insert.setEmail("登录二次验证码:" + login2faUrl + " 美国手机号:" + phoneInfos);
  428. }
  429. public void setGroupsTrips(Long skuId, Long accountId) {
  430. //自动配置车队
  431. GroupsTrips groupsTrips = new GroupsTrips();
  432. groupsTrips.setSkuId(skuId);
  433. groupsTrips.setAccountId(accountId);
  434. cmsGroupService.issuance(groupsTrips, null, false);
  435. }
  436. @Override
  437. public void batchImportBlockedAccount(Long goodsId, List<Object> accountBlockedList) {
  438. GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
  439. Assert.notNull(goodsDon, "平台不存在");
  440. List<AccountBlockedReplaceRecord> list = new ArrayList<>();
  441. accountBlockedList.forEach(accountBlocked->{
  442. Map<String, Object> map = Jsons.toMap(accountBlocked);
  443. String blockedAccount = map.get("0").toString();
  444. if (!Validator.isEmail(blockedAccount)) {
  445. return;
  446. }
  447. AccountBlockedReplaceRecord accountBlockedReplaceRecord = new AccountBlockedReplaceRecord();
  448. accountBlockedReplaceRecord.setGoodsId(goodsId);
  449. accountBlockedReplaceRecord.setAccount(blockedAccount);
  450. list.add(accountBlockedReplaceRecord);
  451. if (list.size() == 400) {
  452. accountBlockedReplaceRecordMapper.batchInsert(list);
  453. list.clear();
  454. }
  455. });
  456. if (list.size() > 0) {
  457. accountBlockedReplaceRecordMapper.batchInsert(list);
  458. }
  459. }
  460. @Override
  461. public String nfUpgradeDevice(Long accountId) throws Exception {
  462. Account at = accountMapper.selectById(accountId);
  463. if (at == null || at.getGoodsId() != 1l) {
  464. throw BusinessRuntimeException.getInstance("只支持奈飞账号");
  465. }
  466. String account = at.getAccount();
  467. String password = at.getPassword();
  468. if (StrUtil.hasEmpty(account, password)) {
  469. throw BusinessRuntimeException.getInstance("账户异常");
  470. }
  471. String code = commonMailService.getTicketMailCode(at.getGoodsId(), at.getAccount(), at.getRelateEmail(), at.getGptEmailPwd(), at.getCreatedTime(), null, 1, false);
  472. return code;
  473. }
  474. @Override
  475. public String getAccountEmailCode(Long accountId) throws Exception {
  476. Account at = accountMapper.selectById(accountId);
  477. String account = at.getAccount();
  478. String password = at.getPassword();
  479. if (StrUtil.hasEmpty(account, password)) {
  480. throw BusinessRuntimeException.getInstance("账户异常");
  481. }
  482. String code = commonMailService.getTicketMailCode(at.getGoodsId(), at.getAccount(), at.getRelateEmail(), at.getGptEmailPwd(), at.getCreatedTime(), null, null, false);
  483. return code;
  484. }
  485. @Override
  486. @Transactional(rollbackFor = Throwable.class)
  487. public void batchDeleteAccountTrips(DelAccountTripsReq delAccountTripsReq, long adminId) throws Exception {
  488. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  489. List<Long> accountIds = delAccountTripsReq.getAccountIds();
  490. DelAccountRecord delAccountRecord = null;
  491. if (CollUtil.isNotEmpty(accountIds)) {
  492. for (Long accountId : accountIds) {
  493. Account account = accountMapper.selectById(accountId);
  494. if (account == null) {
  495. continue;
  496. }
  497. GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  498. .eq(GroupsTrips::getAccountId, accountId)
  499. .last("limit 1"));
  500. if (groupsTrips != null) {
  501. Integer selectCount = relationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  502. .eq(GroupsRelation::getGroupsId, groupsTrips.getId())
  503. .ne(GroupsRelation::getUserId, 0));
  504. //车队上存在用户不删除 下个循环
  505. if (selectCount > 0) {
  506. continue;
  507. }
  508. groupsMapper.deleteById(groupsTrips.getId());
  509. relationMapper.delete(Wrappers.lambdaQuery(GroupsRelation.class)
  510. .eq(GroupsRelation::getGroupsId, groupsTrips.getId()));
  511. }
  512. delAccountRecord = new DelAccountRecord();
  513. if (cmsUser != null) {
  514. delAccountRecord.setOperator(cmsUser.getNickname());
  515. }
  516. delAccountRecord.setAccountInfo(Jsons.toJson(account));
  517. delAccountRecordMapper.insert(delAccountRecord);
  518. accountMapper.deleteById(accountId);
  519. }
  520. }
  521. //通过车队批量删除
  522. List<Long> groupsIds = delAccountTripsReq.getGroupsIds();
  523. if (CollUtil.isNotEmpty(groupsIds)) {
  524. for (Long groupsId : groupsIds) {
  525. GroupsTrips groupsTrips = groupsMapper.selectById(groupsId);
  526. if (groupsTrips == null) {
  527. continue;
  528. }
  529. Integer selectCount = relationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  530. .eq(GroupsRelation::getGroupsId, groupsTrips.getId())
  531. .ne(GroupsRelation::getUserId, 0));
  532. //车队上存在用户不删除 下个循环
  533. if (selectCount > 0) {
  534. continue;
  535. }
  536. groupsMapper.deleteById(groupsTrips.getId());
  537. relationMapper.delete(Wrappers.lambdaQuery(GroupsRelation.class)
  538. .eq(GroupsRelation::getGroupsId, groupsTrips.getId()));
  539. Long accountId = groupsTrips.getAccountId();
  540. if (accountId != null) {
  541. Account account = accountMapper.selectById(accountId);
  542. if (account != null) {
  543. delAccountRecord = new DelAccountRecord();
  544. if (cmsUser != null) {
  545. delAccountRecord.setOperator(cmsUser.getNickname());
  546. }
  547. delAccountRecord.setAccountInfo(Jsons.toJson(account));
  548. delAccountRecordMapper.insert(delAccountRecord);
  549. accountMapper.deleteById(accountId);
  550. }
  551. }
  552. }
  553. }
  554. }
  555. @Override
  556. public List<String> batchDelAccountTripsByGoodsAccount(DelAccountTripsReq delAccountTripsReq, long adminId) throws Exception {
  557. CmsUser cmsUser = cmsUserMapper.selectById(adminId);
  558. Integer goodsId = delAccountTripsReq.getGoodsId();
  559. List<String> accounts = delAccountTripsReq.getAccounts();
  560. GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
  561. Assert.notNull(goodsDon,"平台不存在");
  562. List<String> fails = new ArrayList<>();
  563. if (CollUtil.isNotEmpty(accounts)) {
  564. DelAccountRecord delAccountRecord = null;
  565. for (String account : accounts) {
  566. Account dbAccount = accountMapper.selectOne(Wrappers.lambdaQuery(Account.class).eq(Account::getAccount, account.trim()).eq(Account::getGoodsId, goodsId).last("limit 1"));
  567. if (dbAccount == null) {
  568. fails.add(account);
  569. continue;
  570. }
  571. GroupsTrips groupsTrips = groupsMapper.selectOne(Wrappers.lambdaQuery(GroupsTrips.class)
  572. .eq(GroupsTrips::getAccountId, dbAccount.getId())
  573. .last("limit 1"));
  574. if (groupsTrips != null) {
  575. Integer selectCount = relationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  576. .eq(GroupsRelation::getGroupsId, groupsTrips.getId())
  577. .ne(GroupsRelation::getUserId, 0));
  578. //车队上存在用户不删除 下个循环
  579. if (selectCount > 0) {
  580. fails.add(account);
  581. continue;
  582. }
  583. groupsMapper.deleteById(groupsTrips.getId());
  584. relationMapper.delete(Wrappers.lambdaQuery(GroupsRelation.class)
  585. .eq(GroupsRelation::getGroupsId, groupsTrips.getId()));
  586. }
  587. delAccountRecord = new DelAccountRecord();
  588. if (cmsUser != null) {
  589. delAccountRecord.setOperator(cmsUser.getNickname());
  590. }
  591. delAccountRecord.setAccountInfo(Jsons.toJson(account));
  592. delAccountRecordMapper.insert(delAccountRecord);
  593. accountMapper.deleteById(dbAccount.getId());
  594. }
  595. }
  596. return fails;
  597. }
  598. private String extractValue(String text, String regex) {
  599. Pattern pattern = Pattern.compile(regex);
  600. Matcher matcher = pattern.matcher(text);
  601. if (matcher.find()) {
  602. // group(1) 返回第一个括号内匹配的内容,trim() 用于去除首尾多余的空格
  603. return matcher.group(1).trim().replaceAll(":", "").trim();
  604. }
  605. return "";
  606. }
  607. }