|
|
@@ -1,15 +1,21 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
import com.google.zxing.WriterException;
|
|
|
+import com.izouma.nineth.config.RedisKeys;
|
|
|
+import com.izouma.nineth.domain.Asset;
|
|
|
import com.izouma.nineth.domain.DomainOrder;
|
|
|
import com.izouma.nineth.domain.FileObject;
|
|
|
import com.izouma.nineth.domain.User;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.CollectionStatus;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
import com.izouma.nineth.enums.PayMethod;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.AssetRepo;
|
|
|
import com.izouma.nineth.repo.DomainOrderRepo;
|
|
|
import com.izouma.nineth.repo.UserRepo;
|
|
|
import com.izouma.nineth.service.storage.StorageService;
|
|
|
@@ -17,12 +23,15 @@ import com.izouma.nineth.utils.ImageUtils;
|
|
|
import com.izouma.nineth.utils.JpaUtils;
|
|
|
import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.springframework.data.annotation.Transient;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.redis.core.BoundValueOperations;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
@@ -37,19 +46,25 @@ import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.List;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
+@Slf4j
|
|
|
public class DomainOrderService {
|
|
|
|
|
|
- private DomainOrderRepo domainOrderRepo;
|
|
|
- private ContentAuditService contentAuditService;
|
|
|
- private UserRepo userRepo;
|
|
|
- private AssetService assetService;
|
|
|
- private SysConfigService sysConfigService;
|
|
|
- private StorageService storageService;
|
|
|
+ private DomainOrderRepo domainOrderRepo;
|
|
|
+ private ContentAuditService contentAuditService;
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private AssetService assetService;
|
|
|
+ private SysConfigService sysConfigService;
|
|
|
+ private StorageService storageService;
|
|
|
+ private RockRecordService rockRecordService;
|
|
|
+ private AssetRepo assetRepo;
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
|
|
|
public Page<DomainOrder> all(PageQuery pageQuery) {
|
|
|
return domainOrderRepo
|
|
|
@@ -70,6 +85,7 @@ public class DomainOrderService {
|
|
|
}
|
|
|
|
|
|
public DomainOrder create(Long userId, String domain, BigDecimal price, Long year) {
|
|
|
+ AtomicBoolean checkPoint = checkPoint(userId);
|
|
|
List<DomainOrder> notPaidOrders = domainOrderRepo.findAllByUserIdAndOrderStatus(userId, OrderStatus.NOT_PAID);
|
|
|
Long superUserId = Long.valueOf(sysConfigService.getString("domain_superUserId"));
|
|
|
if (notPaidOrders.size() > 0) {
|
|
|
@@ -82,8 +98,14 @@ public class DomainOrderService {
|
|
|
if (isContainChinese(domain)) {
|
|
|
throw new BusinessException("禁止注册中文域名");
|
|
|
}
|
|
|
- if (domain.length() < 9) {
|
|
|
- throw new BusinessException("四位及以下域名只能官方创建。");
|
|
|
+ if (!checkPoint.get()) {
|
|
|
+ if (domain.length() < 9 || domain.length() > 20) {
|
|
|
+ throw new BusinessException("四位及以下域名只能官方创建。");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (domain.length() < 8 || domain.length() > 20) {
|
|
|
+ throw new BusinessException("四位及以下域名只能官方创建。");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
String realName;
|
|
|
@@ -121,10 +143,57 @@ public class DomainOrderService {
|
|
|
domainOrder.setUserId(user.getId());
|
|
|
domainOrder.setUserAvatar(user.getAvatar());
|
|
|
domainOrder.setUserName(user.getNickname());
|
|
|
+ if (checkPoint.get()) {
|
|
|
+ if (realName.length() < 5) {
|
|
|
+ increaseCount(userId, 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
return domainOrderRepo.save(domainOrder);
|
|
|
}
|
|
|
|
|
|
+ public void increaseCount(Long userId, Integer count) {
|
|
|
+ BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.DOMAIN_COUNT + userId);
|
|
|
+ if (ops.get() == null) {
|
|
|
+ Boolean success = ops.setIfAbsent(0);
|
|
|
+ log.info("创建redis域名统计:{}", success);
|
|
|
+ }
|
|
|
+ ops.increment(count);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void decreaseCount(Long userId) {
|
|
|
+ increaseCount(userId, -1);
|
|
|
+ }
|
|
|
+
|
|
|
+ public AtomicBoolean checkPoint(Long userId) {
|
|
|
+ Map<Long, Long> collections = JSONObject.parseObject(sysConfigService
|
|
|
+ .getString("domain_collection"), new TypeReference<HashMap<Long, Long>>() {
|
|
|
+ });
|
|
|
+ if (collections.size() == 0) {
|
|
|
+ return new AtomicBoolean(false);
|
|
|
+ }
|
|
|
+ List<AssetStatus> statuses = new ArrayList<>();
|
|
|
+ statuses.add(AssetStatus.NORMAL);
|
|
|
+ statuses.add(AssetStatus.AUCTIONING);
|
|
|
+ AtomicBoolean vipPoint = new AtomicBoolean(false);
|
|
|
+ collections.forEach((k, v) -> {
|
|
|
+ List<Asset> assets = assetRepo.findAllByCollectionIdAndStatusInAndUserId(k, statuses, userId);
|
|
|
+ if (assets.size() > 0) {
|
|
|
+ BoundValueOperations<String, Object> ops = redisTemplate.boundValueOps(RedisKeys.DOMAIN_COUNT + userId);
|
|
|
+ Integer count = (Integer) ops.get();
|
|
|
+ if (count != null) {
|
|
|
+ if (count < v) {
|
|
|
+ vipPoint.set(true);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ vipPoint.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return vipPoint;
|
|
|
+ }
|
|
|
+
|
|
|
public Map<String, Object> check(String domain) {
|
|
|
+ AtomicBoolean checkPoint = checkPoint(SecurityUtils.getAuthenticatedUser().getId());
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
Long superUserId = Long.valueOf(sysConfigService.getString("domain_superUserId"));
|
|
|
String visibleDomain = domain;
|
|
|
@@ -143,10 +212,18 @@ public class DomainOrderService {
|
|
|
result.put("reason", "包含敏感关键字");
|
|
|
return result;
|
|
|
}
|
|
|
- if (visibleDomain.length() < 9 || visibleDomain.length() > 20) {
|
|
|
- result.put("result", false);
|
|
|
- result.put("reason", "域名长度不合规");
|
|
|
- return result;
|
|
|
+ if (!checkPoint.get()) {
|
|
|
+ if (visibleDomain.length() < 9 || visibleDomain.length() > 20) {
|
|
|
+ result.put("result", false);
|
|
|
+ result.put("reason", "域名长度不合规");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (visibleDomain.length() < 8 || visibleDomain.length() > 20) {
|
|
|
+ result.put("result", false);
|
|
|
+ result.put("reason", "域名长度不合规");
|
|
|
+ return result;
|
|
|
+ }
|
|
|
}
|
|
|
if (!contentAuditService.auditText(domain)) {
|
|
|
result.put("result", false);
|
|
|
@@ -172,7 +249,8 @@ public class DomainOrderService {
|
|
|
domain = domain.substring(0, dotIndex);
|
|
|
}
|
|
|
Pageable pageable = PageRequest.of(0, 10, Sort.by("createdAt").descending());
|
|
|
- List<DomainOrder> used = domainOrderRepo.searchUsedDomain("%" + domain + "%", OrderStatus.CANCELLED,pageable).getContent();
|
|
|
+ List<DomainOrder> used = domainOrderRepo.searchUsedDomain("%" + domain + "%", OrderStatus.CANCELLED, pageable)
|
|
|
+ .getContent();
|
|
|
|
|
|
String n = domain.substring(domain.length() - 1);
|
|
|
List<Map<String, Object>> recommend = new ArrayList<>();
|
|
|
@@ -198,12 +276,10 @@ public class DomainOrderService {
|
|
|
Map<String, Object> sold = new HashMap<>();
|
|
|
if (!domainOrder.getDomainName().contains(".uni")) {
|
|
|
sold.put("domain", domainOrder.getDomainName().toLowerCase());
|
|
|
+ sold.put("endTime", domainOrder.getEndTime());
|
|
|
sold.put("sold", true);
|
|
|
result.add(sold);
|
|
|
}
|
|
|
- if (result.size() > 9) {
|
|
|
-
|
|
|
- }
|
|
|
});
|
|
|
return result;
|
|
|
}
|
|
|
@@ -233,17 +309,22 @@ public class DomainOrderService {
|
|
|
domainOrder.setCreateAssetId(createAsset(domainOrder));
|
|
|
domainOrder.setEndTime(LocalDateTime.now().plusYears(domainOrder.getYears()));
|
|
|
domainOrderRepo.save(domainOrder);
|
|
|
+
|
|
|
+ rockRecordService.addRock(domainOrder.getUserId(), domainOrder.getPrice(), "购买");
|
|
|
}
|
|
|
|
|
|
public void cancel(DomainOrder domainOrder) {
|
|
|
domainOrder.setOrderStatus(OrderStatus.CANCELLED);
|
|
|
domainOrder.setStatus(CollectionStatus.FAIL);
|
|
|
+ if (domainOrder.getPicName().length() < 5) {
|
|
|
+ decreaseCount(domainOrder.getUserId());
|
|
|
+ }
|
|
|
domainOrderRepo.save(domainOrder);
|
|
|
}
|
|
|
|
|
|
public Long createAsset(DomainOrder domainOrder) {
|
|
|
return assetService.createAsset(domainOrder, userRepo.findById(domainOrder.getUserId())
|
|
|
- .orElseThrow(new BusinessException("无用户记录")), null, BigDecimal.ZERO, "域名", null, false).getId();
|
|
|
+ .orElseThrow(new BusinessException("无用户记录")), null, domainOrder.getPrice(), "域名", null, false).getId();
|
|
|
}
|
|
|
|
|
|
public BufferedImage domainImg(String domain) throws IOException, FontFormatException, WriterException {
|