CmsGroupServiceImpl.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. package com.cyksj.service.mange.group;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateField;
  4. import cn.hutool.core.date.DateTime;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.StrUtil;
  7. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  8. import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
  9. import com.cyksj.common.EnvCommonService;
  10. import com.cyksj.common.constant.Constant;
  11. import com.cyksj.common.exception.BusinessRuntimeException;
  12. import com.cyksj.common.task.GlobalThreadPoolTaskExecutor;
  13. import com.cyksj.dto.RedisKey;
  14. import com.cyksj.mapper.*;
  15. import com.cyksj.mapper.manage.GroupsTripsAccountReplaceRecordMapper;
  16. import com.cyksj.mapper.manage.cms.CmsUserMapper;
  17. import com.cyksj.model.entity.*;
  18. import com.cyksj.model.manage.views.AccountView;
  19. import com.cyksj.model.manage.views.GroupsRelationView;
  20. import com.cyksj.model.request.ReplaceTripsAccountReq;
  21. import com.cyksj.model.views.GroupsAccountView;
  22. import com.cyksj.redis.RedisService;
  23. import com.cyksj.service.mange.AccountCommonService;
  24. import com.cyksj.service.mange.CmsGroupService;
  25. import com.cyksj.service.sms.SmsService;
  26. import com.cyksj.service.user.UserSysMsgNotifyService;
  27. import com.ejlchina.searcher.BeanSearcher;
  28. import com.ejlchina.searcher.param.Operator;
  29. import com.ejlchina.searcher.util.MapBuilder;
  30. import com.ejlchina.searcher.util.MapUtils;
  31. import lombok.RequiredArgsConstructor;
  32. import lombok.extern.slf4j.Slf4j;
  33. import org.springframework.stereotype.Service;
  34. import org.springframework.transaction.annotation.Transactional;
  35. import java.util.Arrays;
  36. import java.util.Date;
  37. import java.util.List;
  38. import java.util.Optional;
  39. import java.util.stream.Collectors;
  40. /**
  41. * @author chan
  42. * @date 2022/9/27 6:27 PM
  43. */
  44. @Slf4j
  45. @Service
  46. @RequiredArgsConstructor
  47. public class CmsGroupServiceImpl extends ServiceImpl<GroupsMapper,GroupsTrips> implements CmsGroupService {
  48. private final GoodsDonSkuMapper skuMapper;
  49. private final GroupsRelationMapper relationMapper;
  50. private final OrderDonMapper orderDonMapper;
  51. private final AccountMapper accountMapper;
  52. private final BeanSearcher beanSearcher;
  53. private final GroupsTripsAccountReplaceRecordMapper replaceRecordMapper;
  54. private final CmsUserMapper cmsUserMapper;
  55. private final GoodsDonMapper goodsDonMapper;
  56. private final SmsService smsService;
  57. private final EnvCommonService envCommonService;
  58. private final RedisService redisService;
  59. private final GroupsMapper groupsMapper;
  60. private final AccountCommonService accountCommonService;
  61. private final GroupsRelationAlertMapper alertMapper;
  62. private final UserSysMsgNotifyService userSysMsgNotifyService;
  63. private static final GlobalThreadPoolTaskExecutor TASK_EXECUTOR = GlobalThreadPoolTaskExecutor.getInstance();
  64. @Override
  65. public GroupsTrips issuance(GroupsTrips groups, String verifyCodes) {
  66. GoodsDonSku sku = skuMapper.selectById(groups.getSkuId());
  67. if (sku == null) {
  68. throw new BusinessRuntimeException("该商品规格不存在!");
  69. }
  70. List<String> verifyCodeList = null;
  71. if (StrUtil.isNotBlank(verifyCodes)) {
  72. verifyCodes = verifyCodes.replaceAll("\n", "");
  73. String[] verifyCodeArray = verifyCodes.split("\\*");
  74. verifyCodeList = Arrays.stream(verifyCodeArray).filter(str -> StrUtil.isNotBlank(str)).map(str -> str.trim()).collect(Collectors.toList());
  75. }
  76. groups.setNum(sku.getNum());
  77. groups.setAvailableNum(sku.getNum());
  78. if (groups.getAccountId() == null || accountMapper.selectById(groups.getAccountId()) == null) {
  79. throw new BusinessRuntimeException("该账号不存在");
  80. }
  81. groups.setStatus(GroupsTrips.Status.validity);
  82. this.save(groups);
  83. for (Integer i = 1; i <= groups.getNum(); i++) {
  84. GroupsRelation relation = new GroupsRelation();
  85. relation.setGroupsId(groups.getId());
  86. relation.setStatus(GroupsRelation.Status.none);
  87. relation.setNum(i);
  88. if (verifyCodeList != null && verifyCodeList.size() > 0 && verifyCodeList.size() >= i) {
  89. relation.setVerifyCode(verifyCodeList.get(i - 1));
  90. }
  91. relationMapper.insert(relation);
  92. }
  93. Integer alertCount = alertMapper.selectCount(Wrappers.lambdaQuery(GroupsRelationAlert.class)
  94. .eq(GroupsRelationAlert::getSkuId, sku.getId())
  95. .last("limit 1"));
  96. if (alertCount > 0) {
  97. alertMapper.update(null, Wrappers.lambdaUpdate(GroupsRelationAlert.class)
  98. .set(GroupsRelationAlert::getIsReset, true)
  99. .eq(GroupsRelationAlert::getSkuId, sku.getId())
  100. .eq(GroupsRelationAlert::getIsReset, false));
  101. }
  102. return groups;
  103. }
  104. @Override
  105. public void close(Long groupId) {
  106. GroupsTrips groupsTrips = this.getById(groupId);
  107. if(groupsTrips == null){
  108. throw new BusinessRuntimeException("非法参数.车队不存在");
  109. }
  110. Integer count = relationMapper.selectCount(Wrappers.lambdaQuery(GroupsRelation.class)
  111. .eq(GroupsRelation::getGroupsId, groupId)
  112. .ne(GroupsRelation::getUserId, 0)
  113. .ne(GroupsRelation::getStatus, GroupsRelation.Status.none));
  114. if (count > 0) {
  115. throw BusinessRuntimeException.getInstance("请移除该车队下的用户再进行删掉操作");
  116. }
  117. //可强制删除
  118. //后台记录
  119. // if (count > 0) {
  120. // List<GroupsRelation> groupsRelations = relationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class)
  121. // .eq(GroupsRelation::getGroupsId, groupId)
  122. // .ne(GroupsRelation::getStatus, GroupsRelation.Status.none));
  123. // if (groupsRelations.size() > 0) {
  124. // Account account = accountMapper.selectById(groupsTrips.getAccountId());
  125. // TASK_EXECUTOR.execute(() -> {
  126. // if (redisService.setNx(String.format("%s-%s", groupId, groupsTrips.getAccount()), groupId, 10l)) {
  127. // groupsRelations.forEach(data -> {
  128. // DelGroupsTripsRecord delGroupsTripsRecord = new DelGroupsTripsRecord();
  129. // delGroupsTripsRecord.setGroupsId(groupId);
  130. // delGroupsTripsRecord.setGroupsStatus(groupsTrips.getStatus().name());
  131. // if (account != null) {
  132. // delGroupsTripsRecord.setAccount(account.getAccount());
  133. // delGroupsTripsRecord.setPassword(account.getPassword());
  134. // }
  135. // delGroupsTripsRecord.setRelationId(data.getId());
  136. // delGroupsTripsRecord.setSkuId(groupsTrips.getSkuId());
  137. // delGroupsTripsRecord.setUserId(data.getUserId());
  138. // delGroupsTripsRecord.setStartTime(data.getStartTime());
  139. // delGroupsTripsRecord.setExpiryTime(data.getExpiryTime());
  140. // delGroupsTripsRecord.setRelationStatus(data.getStatus().name());
  141. // delGroupsTripsRecord.setType("delete");
  142. // delGroupsTripsRecordMapper.insert(delGroupsTripsRecord);
  143. // });
  144. // }
  145. // });
  146. // }
  147. // }
  148. relationMapper.delete(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId,groupId));
  149. this.removeById(groupId);
  150. }
  151. @Override
  152. @Transactional(rollbackFor = Throwable.class)
  153. public void setAccount(GroupsTrips groupsTrips) throws Exception {
  154. int count = count(Wrappers.lambdaQuery(GroupsTrips.class).eq(GroupsTrips::getAccountId, groupsTrips.getAccountId()));
  155. if (count > 0) {
  156. throw new BusinessRuntimeException("该账号已发车.请选择未发车账户");
  157. }
  158. Account account = accountMapper.selectById(groupsTrips.getAccountId());
  159. //将预备账号 类型替换掉
  160. if (account.getType() == 2) {
  161. int update = accountMapper.update(null, Wrappers.lambdaUpdate(Account.class)
  162. .set(Account::getType, 1)
  163. .eq(Account::getId, account.getId())
  164. .eq(Account::getType, 2));
  165. if (update == 0) {
  166. throw BusinessRuntimeException.getInstance("该账号已配置车队");
  167. }
  168. }
  169. List<GroupsRelation> groupsRelations = relationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsTrips.getId()).eq(GroupsRelation::getStatus, GroupsRelation.Status.validity));
  170. GroupsTrips trips = beanSearcher.searchFirst(GroupsTrips.class, MapUtils.builder().field(GroupsTrips::getId, groupsTrips.getId()).onlySelect(GroupsTrips::getTitle).build());
  171. String title = "车票";
  172. if (trips != null && StrUtil.isNotBlank(trips.getTitle())) {
  173. title = trips.getTitle();
  174. }
  175. //配置midJourney安全码
  176. String verifyCodes = groupsTrips.getVerifyCodes();
  177. List<String> verifyCodeList = null;
  178. if (StrUtil.isNotBlank(verifyCodes)) {
  179. verifyCodes = verifyCodes.replaceAll("\n", "");
  180. String[] verifyCodesArray = verifyCodes.split("\\*");
  181. verifyCodeList = Arrays.stream(verifyCodesArray).filter(str -> StrUtil.isNotBlank(str)).map(str -> str.trim()).collect(Collectors.toList());
  182. }
  183. Boolean isPrdEnv = envCommonService.isPrdEnv();
  184. for (int i = 0; i < groupsRelations.size(); i++) {
  185. GroupsRelation relation = groupsRelations.get(i);
  186. if (relation.getExpiryTime() == null) {
  187. List<OrderDon> orderDonList = orderDonMapper.selectList(Wrappers.lambdaQuery(OrderDon.class).eq(OrderDon::getUserId, relation.getUserId()).eq(OrderDon::getRelationId, relation.getId()).eq(OrderDon::getStatus, OrderDon.Status.hasPayment));
  188. //加购车票
  189. if (orderDonList.isEmpty()) {
  190. GoodsDonSku donSku = skuMapper.selectById(groupsTrips.getSkuId());
  191. Date expiryTime = Optional.ofNullable(relation.getExpiryTime()).orElse(new Date());
  192. Date newDate;
  193. if (donSku.getDays() != null && donSku.getDays() > 0) {
  194. newDate = DateUtil.offsetDay(expiryTime, donSku.getDays() * 1);
  195. } else {
  196. //奈飞月付 按30天计算
  197. if (donSku.getId() == 4) {
  198. newDate = DateUtil.offsetDay(expiryTime, 30);
  199. } else {
  200. newDate = DateUtil.offset(expiryTime, DateField.MONTH, donSku.getMonths() * 1);
  201. }
  202. }
  203. relation.setExpiryTime(newDate);
  204. relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
  205. relationMapper.updateById(relation);
  206. return;
  207. }
  208. orderDonList.forEach((orderDon) -> {
  209. //如果续费增加时间,如果首次则设置当前时间为初始时间
  210. Date expiryTime = Optional.ofNullable(relation.getExpiryTime()).orElse(new Date());
  211. log.info("设置账号,该用户 {} 初始时间:{} ", orderDon.getUserId(), DateUtil.format(expiryTime, "yyyy-MM-dd HH:mm:ss"));
  212. GoodsDonSku donSku = skuMapper.selectById(orderDon.getSkuId());
  213. Date newDate;
  214. if (donSku.getDays() != null && donSku.getDays() > 0) {
  215. newDate = DateUtil.offsetDay(expiryTime, donSku.getDays() * orderDon.getNum());
  216. } else {
  217. newDate = DateUtil.offset(expiryTime, DateField.MONTH, donSku.getMonths() * orderDon.getNum());
  218. }
  219. relation.setExpiryTime(newDate);
  220. log.info("设置账号,该用户 {} 过期时间:{} ", orderDon.getUserId(), DateUtil.format(newDate, "yyyy-MM-dd HH:mm:ss"));
  221. relation.setStartTime(relation.getStartTime() == null ? new Date() : null);
  222. relationMapper.updateById(relation);
  223. orderDon.setStatus(OrderDon.Status.complete);
  224. orderDonMapper.updateById(orderDon);
  225. });
  226. }
  227. if (relation.getUserId() != 0 && isPrdEnv && relation.getYhsId() == 0) {
  228. //发送短信
  229. smsService.sendSmsToRelationUser(relation.getUserId(), Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
  230. }
  231. if (verifyCodeList != null && verifyCodeList.size() > 0 && i < verifyCodeList.size()) {
  232. relation.setVerifyCode(verifyCodeList.get(i));
  233. relationMapper.updateById(relation);
  234. }
  235. }
  236. if (groupsRelations.isEmpty() && verifyCodeList != null && verifyCodeList.size() > 0) {
  237. groupsRelations = relationMapper.selectList(Wrappers.lambdaQuery(GroupsRelation.class).eq(GroupsRelation::getGroupsId, groupsTrips.getId()));
  238. for (int i = 0; i < groupsRelations.size(); i++) {
  239. GroupsRelation relation = groupsRelations.get(i);
  240. if (i < verifyCodeList.size()) {
  241. relation.setVerifyCode(verifyCodeList.get(i));
  242. relationMapper.updateById(relation);
  243. }
  244. }
  245. }
  246. groupsTrips.setStatus(GroupsTrips.Status.validity);
  247. GoodsDonSku sku = skuMapper.selectById(groupsTrips.getSkuId());
  248. //下架上过车的POE,PS AI账号 || GPT Plus独立规格 下架
  249. if (Constant.DOWN_GOODS_PAY.contains(sku.getGoodsId()) || skuMapper.selectSingleSkuIdsByGoodsId(Constant.AI_goodsIds.get(0)).contains(groupsTrips.getSkuId())) {
  250. Number number = beanSearcher.searchCount(GroupsRelation.class, MapUtils.builder()
  251. .field(GroupsRelation::getGroupsId, groupsTrips.getId())
  252. .field(GroupsRelation::getUserId, 0).op(Operator.NotEqual)
  253. .field(GroupsRelation::getStatus, GroupsRelation.Status.validity.name())
  254. .build());
  255. if (number.intValue() > 0) {
  256. groupsTrips.setStatus(GroupsTrips.Status.down);
  257. }
  258. }
  259. updateById(groupsTrips);
  260. GoodsDon goodsDon = goodsDonMapper.selectById(account.getGoodsId());
  261. userSysMsgNotifyService.recordUserAccountSetSysMsg(account.getGoodsId(), groupsTrips.getSkuId(), groupsRelations, account.getAccount(), goodsDon.getTitle());
  262. Integer alertCount = alertMapper.selectCount(Wrappers.lambdaQuery(GroupsRelationAlert.class)
  263. .eq(GroupsRelationAlert::getSkuId, sku.getId())
  264. .last("limit 1"));
  265. if (alertCount > 0) {
  266. alertMapper.update(null, Wrappers.lambdaUpdate(GroupsRelationAlert.class)
  267. .set(GroupsRelationAlert::getIsReset, true)
  268. .eq(GroupsRelationAlert::getSkuId, sku.getId())
  269. .eq(GroupsRelationAlert::getIsReset, false));
  270. }
  271. }
  272. @Override
  273. @Transactional(rollbackFor = Throwable.class)
  274. public void replaceTripsAccount(ReplaceTripsAccountReq req) {
  275. Long groupsId = req.getGroupsId();
  276. String account = req.getAccount().trim();
  277. String password = req.getPassword().trim();
  278. String remark = req.getRemark();
  279. Date afterStartTime = req.getStartTime();
  280. Date afterExpiryTime = req.getExpiryTime();
  281. GroupsAccountView groupsAccountView = beanSearcher.searchFirst(GroupsAccountView.class, MapUtils.builder()
  282. .field(GroupsAccountView::getGroupsId, groupsId)
  283. .build());
  284. if (groupsId == null) {
  285. throw BusinessRuntimeException.getInstance("车队已不存在");
  286. }
  287. Long accountId = groupsAccountView.getAccountId();
  288. if (accountId == null) {
  289. throw BusinessRuntimeException.getInstance("该车队暂未配置账号");
  290. }
  291. Long goodsId = groupsAccountView.getGoodsId();
  292. if (!account.contains("客服")) {
  293. if (accountCommonService.checkIsDupAccount(goodsId, account)) {
  294. throw BusinessRuntimeException.getInstance("该平台下已生成该账号");
  295. }
  296. }
  297. //Claude3只允许替换一次
  298. if (Constant.CALUDE_GOODS_ID.equals(groupsAccountView.getGoodsId())) {
  299. Integer count = replaceRecordMapper.selectCount(Wrappers.lambdaQuery(GroupsTripsAccountReplaceRecord.class)
  300. .eq(GroupsTripsAccountReplaceRecord::getGroupsId, groupsAccountView.getGroupsId()));
  301. if (count > 0) throw BusinessRuntimeException.getInstance("Claude3账号只允许替换一次");
  302. }
  303. if (afterStartTime == null) {
  304. afterStartTime = groupsAccountView.getStartTime();
  305. }
  306. if (afterExpiryTime == null) {
  307. afterExpiryTime = groupsAccountView.getExpiryTime();
  308. }
  309. log.info("原账号accountId:{}", accountId);
  310. //替换账号
  311. int update = accountMapper.update(null, Wrappers.lambdaUpdate(Account.class)
  312. .set(Account::getAccount, account)
  313. .set(Account::getPassword, password)
  314. .set(Account::getRemark, remark)
  315. .set(Account::getStartTime, afterStartTime)
  316. .set(Account::getExpiryTime, afterExpiryTime)
  317. .set(Account::getGptRefreshToken, StrUtil.EMPTY)
  318. .eq(Account::getId, accountId));
  319. if (update == 0) {
  320. log.info("替换原账号oldAccount:{}至新账号newAccount:{}失败", groupsAccountView.getAccount(), account);
  321. throw BusinessRuntimeException.getInstance("替换账号失败");
  322. }
  323. if (StrUtil.isNotBlank(groupsAccountView.getGptRefreshToken())) {
  324. //清除gpt token
  325. redisService.del(RedisKey.CHATGPT_ACCESS_TOKEN + groupsAccountView.getAccount());
  326. redisService.del(RedisService.key.CHAT_GPT_TOKEN_EXCEPTION_KEY.getName() + groupsAccountView.getAccount());
  327. }
  328. //时间有效
  329. if (afterExpiryTime != null && afterExpiryTime.after(DateTime.now())) {
  330. groupsMapper.update(null, Wrappers.lambdaUpdate(GroupsTrips.class)
  331. .set(GroupsTrips::getStatus, GroupsTrips.Status.validity)
  332. .eq(GroupsTrips::getAccountId, accountId)
  333. .eq(GroupsTrips::getStatus, GroupsTrips.Status.down));
  334. }
  335. //保存替换记录
  336. GroupsTripsAccountReplaceRecord replaceRecord = new GroupsTripsAccountReplaceRecord();
  337. replaceRecord.setGroupsId(groupsId);
  338. replaceRecord.setOldAccountId(accountId);
  339. replaceRecord.setOldAccount(groupsAccountView.getAccount());
  340. replaceRecord.setOldPassword(groupsAccountView.getPassword());
  341. replaceRecord.setOldStartTime(groupsAccountView.getStartTime());
  342. replaceRecord.setOldExpiryTime(groupsAccountView.getExpiryTime());
  343. Long adminId = req.getAdminId();
  344. Optional.ofNullable(cmsUserMapper.selectById(adminId)).ifPresent(admin -> replaceRecord.setOperator(admin.getNickname()));
  345. replaceRecord.setNewAccount(account);
  346. replaceRecord.setNewPassword(password);
  347. replaceRecord.setNewStartTime(afterStartTime);
  348. replaceRecord.setNewExpiryTime(afterExpiryTime);
  349. replaceRecord.setRemark(remark);
  350. replaceRecordMapper.insert(replaceRecord);
  351. TASK_EXECUTOR.execute(() -> sendChangeAccountMsg(groupsId, goodsId, account));;
  352. }
  353. @Override
  354. public Integer getAvailableRelation(Long goodsId, Long skuId) {
  355. //chatGPT
  356. GoodsDonSku sku = skuMapper.selectById(skuId);
  357. goodsId = sku.getGoodsId();
  358. Integer skuNum = sku.getNum();
  359. if (Constant.AI_goodsIds.contains(sku.getGoodsId()) && sku.getNum() > 1) {
  360. Integer extraNum = Constant.AI_EXTRACT_NUM;
  361. //GPT 4个月付
  362. if (skuId == 178l) {
  363. extraNum = 2;
  364. }
  365. Integer maxNum = skuNum + extraNum;
  366. //主账号有效时间
  367. DateTime time = DateUtil.offsetDay(DateUtil.beginOfDay(DateTime.now()), 25);
  368. Integer available = relationMapper.selectAvailableRelation(skuId, skuNum);
  369. //额外硬塞
  370. Integer special_available = relationMapper.selectSpecialGroupsRelationAvailable(skuId, maxNum, skuNum, extraNum, time);
  371. available += special_available;
  372. //GPT Plus 10人月付规格 4人月付
  373. if (Constant.GPT_PLUS_PARKING_SKU_IDS.contains(skuId)) {
  374. //上面已排除限制车队
  375. //限制车队可用车数位
  376. Integer limitAvailable = Optional.ofNullable(relationMapper.selectLimitAvailableNum(skuId, maxNum)).orElse(0);
  377. if (limitAvailable < 0) {
  378. limitAvailable = 0;
  379. }
  380. available += limitAvailable;
  381. //新车队预备上车 最大可用数
  382. if (Constant.GPT_PLUS_PARKING_SKU_IDS.get(0).equals(skuId)) {
  383. maxNum = 10;
  384. }else {
  385. maxNum = 4;
  386. }
  387. }
  388. available = getAvailableAfterPreAccount(available, skuId, maxNum, goodsId);
  389. //待发车已有人员成功上车
  390. Integer waitingNum = relationMapper.selectNumWaitingGroups(skuId);
  391. available -= waitingNum;
  392. return available;
  393. }
  394. Integer available = relationMapper.selectAvailableRelation(skuId, skuNum);
  395. available = getAvailableAfterPreAccount(available, skuId, skuNum, goodsId);
  396. //待发车已有人员成功上车
  397. Integer waitingNum = relationMapper.selectNumWaitingGroups(skuId);
  398. available -= waitingNum;
  399. return available;
  400. }
  401. @Override
  402. public void sendChangeAccountMsg(Long groupsId, Long goodsId, String account) {
  403. GoodsDon goodsDon = goodsDonMapper.selectById(goodsId);
  404. String title = goodsDon != null ? goodsDon.getTitle() : "车票";
  405. DateTime now = DateTime.now();
  406. Boolean isPrd = envCommonService.isPrdEnv();
  407. List<GroupsRelationView> groupsRelations = beanSearcher.searchAll(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getGroupsId, groupsId).build());
  408. if (CollUtil.isEmpty(groupsRelations)) {
  409. return;
  410. }
  411. Long skuId = groupsMapper.selectById(groupsId).getSkuId();
  412. userSysMsgNotifyService.recordUserAccountUpdateSysMsg(goodsId, skuId, groupsRelations, account, goodsDon.getTitle());
  413. groupsRelations.forEach(relation -> {
  414. if (relation.getExpiryTime() == null) {
  415. return;
  416. }
  417. //账号有效期小于5天的人,不发账号替换/改密码短信提醒
  418. if (now.after(DateUtil.offsetDay(relation.getExpiryTime(), -5))) {
  419. return;
  420. }
  421. //去掉GPT过滤平台
  422. if (Constant.CHANGE_ACCOUNT_PWD_FILTER_GIDS.get(1) == goodsId) {
  423. return;
  424. }
  425. if (relation.getUserId() != 0 && isPrd && relation.getYhsId() == 0) {
  426. try {
  427. smsService.sendSmsToRelationUser(relation.getUserId(), Constant.CHANGE_GROUPS_TRIPS_ACCOUNT, title);
  428. } catch (Exception e) {
  429. }
  430. }
  431. });
  432. }
  433. public Integer getAvailableAfterPreAccount(Integer available, Long skuId, Integer maxNum, Long goodsId) {
  434. MapBuilder builder = MapUtils.builder();
  435. if (goodsId == 26) {
  436. //是否在预备规格集合中
  437. String extra_sql = String.format("FIND_IN_SET(%s,a.pre_sku_ids) > 0", skuId);
  438. builder.put("extra_sql", extra_sql);
  439. }
  440. Number preAccount = beanSearcher.searchCount(AccountView.class, builder
  441. .field(AccountView::getGoodsId, goodsId)
  442. .field(AccountView::getAccountType, 2)
  443. .field(AccountView::getGroupsId).op(Operator.IsNull)
  444. .build());
  445. //计算上预发布账号车位数
  446. if (preAccount.intValue() > 0) {
  447. available += preAccount.intValue() * maxNum;
  448. }
  449. return available;
  450. }
  451. }