|
|
@@ -1,16 +1,13 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import com.alibaba.excel.util.StringUtils;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
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.dto.excel.DomainCountDTO;
|
|
|
import com.izouma.nineth.enums.CollectionStatus;
|
|
|
import com.izouma.nineth.enums.OrderStatus;
|
|
|
import com.izouma.nineth.enums.PayMethod;
|
|
|
@@ -25,12 +22,12 @@ import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
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;
|
|
|
|
|
|
@@ -46,7 +43,6 @@ 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;
|
|
|
@@ -65,14 +61,20 @@ public class DomainOrderService {
|
|
|
private RockRecordService rockRecordService;
|
|
|
private AssetRepo assetRepo;
|
|
|
private RedisTemplate<String, Object> redisTemplate;
|
|
|
+ private CacheService cacheService;
|
|
|
|
|
|
public Page<DomainOrder> all(PageQuery pageQuery) {
|
|
|
return domainOrderRepo
|
|
|
.findAll(JpaUtils.toSpecification(pageQuery, DomainOrder.class), JpaUtils.toPageRequest(pageQuery));
|
|
|
}
|
|
|
|
|
|
- public boolean isContainChinese(String str) {
|
|
|
+ @Cacheable(value = "newestDomain")
|
|
|
+ public List<DomainOrder> newest() {
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 50);
|
|
|
+ return domainOrderRepo.findAllByOrderStatusOrderByCreatedAtDesc(OrderStatus.FINISH, pageRequest).getContent();
|
|
|
+ }
|
|
|
|
|
|
+ public boolean isContainChinese(String str) {
|
|
|
if (StringUtils.isEmpty(str)) {
|
|
|
throw new BusinessException("sms context is empty!");
|
|
|
}
|
|
|
@@ -88,6 +90,8 @@ public class DomainOrderService {
|
|
|
AtomicBoolean checkPoint = checkPoint(userId);
|
|
|
List<DomainOrder> notPaidOrders = domainOrderRepo.findAllByUserIdAndOrderStatus(userId, OrderStatus.NOT_PAID);
|
|
|
Long superUserId = Long.valueOf(sysConfigService.getString("domain_superUserId"));
|
|
|
+ int min = sysConfigService.getInt("domain_minimum");
|
|
|
+ min = min + 4;
|
|
|
if (notPaidOrders.size() > 0) {
|
|
|
throw new BusinessException("已存在未支付订单,不可继续下单");
|
|
|
}
|
|
|
@@ -99,12 +103,12 @@ public class DomainOrderService {
|
|
|
throw new BusinessException("禁止注册中文域名");
|
|
|
}
|
|
|
if (!checkPoint.get()) {
|
|
|
- if (domain.length() < 9 || domain.length() > 20) {
|
|
|
+ if (domain.length() < min || domain.length() > 20) {
|
|
|
throw new BusinessException("四位及以下域名只能官方创建。");
|
|
|
}
|
|
|
} else {
|
|
|
if (domain.length() < 8 || domain.length() > 20) {
|
|
|
- throw new BusinessException("四位及以下域名只能官方创建。");
|
|
|
+ throw new BusinessException("四位以下域名只能官方创建。");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -151,48 +155,57 @@ public class DomainOrderService {
|
|
|
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);
|
|
|
+ public void increaseCount(Long userId, Integer usePoint) {
|
|
|
+ if (usePoint > 0) {
|
|
|
+ // 扣除积分
|
|
|
+ userRepo.addVipPoint(userId, -usePoint);
|
|
|
+ cacheService.clearUserMy(userId);
|
|
|
}
|
|
|
- ops.increment(count);
|
|
|
}
|
|
|
|
|
|
- public void decreaseCount(Long userId) {
|
|
|
- increaseCount(userId, -1);
|
|
|
+ public void decreaseCount(DomainOrder order) {
|
|
|
+ userRepo.addVipPoint(order.getUserId(), 1);
|
|
|
+ cacheService.clearUserMy(order.getUserId());
|
|
|
+ log.info("取消加积分用户ID:{},订单ID:{},积分:{}", order.getUserId(), order.getId(), 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);
|
|
|
+ AtomicBoolean atomicBoolean = new AtomicBoolean(false);
|
|
|
+ User user = userRepo.findById(userId).orElseThrow(new BusinessException("用户不存在"));
|
|
|
+ if (user.getVipPoint() > 0) {
|
|
|
+ atomicBoolean.set(true);
|
|
|
}
|
|
|
- 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;
|
|
|
+ return atomicBoolean;
|
|
|
+// 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 > 0) {
|
|
|
+// vipPoint.set(true);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// vipPoint.set(false);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// });
|
|
|
+// return vipPoint;
|
|
|
}
|
|
|
|
|
|
public Map<String, Object> check(String domain) {
|
|
|
+ int min = sysConfigService.getInt("domain_minimum");
|
|
|
+ min = min + 4;
|
|
|
AtomicBoolean checkPoint = checkPoint(SecurityUtils.getAuthenticatedUser().getId());
|
|
|
Map<String, Object> result = new HashMap<>();
|
|
|
Long superUserId = Long.valueOf(sysConfigService.getString("domain_superUserId"));
|
|
|
@@ -213,7 +226,7 @@ public class DomainOrderService {
|
|
|
return result;
|
|
|
}
|
|
|
if (!checkPoint.get()) {
|
|
|
- if (visibleDomain.length() < 9 || visibleDomain.length() > 20) {
|
|
|
+ if (visibleDomain.length() < min || visibleDomain.length() > 20) {
|
|
|
result.put("result", false);
|
|
|
result.put("reason", "域名长度不合规");
|
|
|
return result;
|
|
|
@@ -317,7 +330,7 @@ public class DomainOrderService {
|
|
|
domainOrder.setOrderStatus(OrderStatus.CANCELLED);
|
|
|
domainOrder.setStatus(CollectionStatus.FAIL);
|
|
|
if (domainOrder.getPicName().length() < 5) {
|
|
|
- decreaseCount(domainOrder.getUserId());
|
|
|
+ decreaseCount(domainOrder);
|
|
|
}
|
|
|
domainOrderRepo.save(domainOrder);
|
|
|
}
|
|
|
@@ -345,14 +358,22 @@ public class DomainOrderService {
|
|
|
is2.close();
|
|
|
int length = domainName.length();
|
|
|
BufferedImage shareImg;
|
|
|
- if (length <= 2) {
|
|
|
+ if (length == 1) {
|
|
|
InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_jing.png");
|
|
|
shareImg = ImageIO.read(is3);
|
|
|
is3.close();
|
|
|
- } else if (length <= 4) {
|
|
|
+ } else if (length == 2) {
|
|
|
InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_lv.png");
|
|
|
shareImg = ImageIO.read(is3);
|
|
|
is3.close();
|
|
|
+ } else if (length == 3) {
|
|
|
+ InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_b.png");
|
|
|
+ shareImg = ImageIO.read(is3);
|
|
|
+ is3.close();
|
|
|
+ } else if (length == 4) {
|
|
|
+ InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_h.png");
|
|
|
+ shareImg = ImageIO.read(is3);
|
|
|
+ is3.close();
|
|
|
} else {
|
|
|
InputStream is3 = this.getClass().getResourceAsStream("/static/img/png_zi.png");
|
|
|
shareImg = ImageIO.read(is3);
|
|
|
@@ -437,4 +458,11 @@ public class DomainOrderService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ public List<DomainCountDTO> top20() {
|
|
|
+ List<Map<String, Object>> map = assetRepo.domainTop20();
|
|
|
+ JSONArray jsonArray = new JSONArray();
|
|
|
+ jsonArray.addAll(map);
|
|
|
+ return jsonArray.toJavaList(DomainCountDTO.class);
|
|
|
+ }
|
|
|
+
|
|
|
}
|