|
|
@@ -1,11 +1,13 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
+import com.fasterxml.jackson.annotation.JsonView;
|
|
|
import com.izouma.nineth.TokenHistory;
|
|
|
import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
+import com.izouma.nineth.dto.PageWrapper;
|
|
|
import com.izouma.nineth.dto.UserHistory;
|
|
|
import com.izouma.nineth.enums.AssetStatus;
|
|
|
import com.izouma.nineth.enums.CollectionSource;
|
|
|
@@ -19,6 +21,7 @@ import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import com.izouma.nineth.utils.TokenUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
|
|
@@ -26,13 +29,18 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.security.crypto.password.PasswordEncoder;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.persistence.criteria.CriteriaBuilder;
|
|
|
+import javax.persistence.criteria.CriteriaQuery;
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
@@ -59,7 +67,7 @@ public class AssetService {
|
|
|
private ShowCollectionRepo showCollectionRepo;
|
|
|
private CollectionPrivilegeRepo collectionPrivilegeRepo;
|
|
|
private PasswordEncoder passwordEncoder;
|
|
|
-
|
|
|
+ private MintActivityRepo mintActivityRepo;
|
|
|
|
|
|
public Page<Asset> all(PageQuery pageQuery) {
|
|
|
Page<Asset> all = assetRepo
|
|
|
@@ -103,8 +111,10 @@ public class AssetService {
|
|
|
|
|
|
public Asset createAsset(BlindBoxItem winItem, User user, Long orderId, BigDecimal price, String type,
|
|
|
Integer number, Integer holdDays) {
|
|
|
- Collection blindBox = collectionRepo.findById(winItem.getBlindBoxId()).orElseThrow(new BusinessException("盲盒不存在"));
|
|
|
- Collection collection = collectionRepo.findById(winItem.getCollectionId()).orElseThrow(new BusinessException("藏品不存在"));
|
|
|
+ Collection blindBox = collectionRepo.findById(winItem.getBlindBoxId())
|
|
|
+ .orElseThrow(new BusinessException("盲盒不存在"));
|
|
|
+ Collection collection = collectionRepo.findById(winItem.getCollectionId())
|
|
|
+ .orElseThrow(new BusinessException("藏品不存在"));
|
|
|
Asset asset = Asset.create(winItem, user, holdDays);
|
|
|
asset.setTokenId(TokenUtils.genTokenId());
|
|
|
asset.setNumber(number);
|
|
|
@@ -571,4 +581,27 @@ public class AssetService {
|
|
|
asset.setConsignment(false);
|
|
|
assetRepo.save(asset);
|
|
|
}
|
|
|
+
|
|
|
+ @Cacheable(cacheNames = "fmaa", key = "#userId+'#'+#mintActivityId+'#'+#pageable.hashCode()")
|
|
|
+ public PageWrapper<Asset> findMintActivityAssetsWrap(Long userId, Long mintActivityId, Pageable pageable) {
|
|
|
+ return PageWrapper.of(findMintActivityAssets(userId, mintActivityId, pageable));
|
|
|
+ }
|
|
|
+
|
|
|
+ public Page<Asset> findMintActivityAssets(Long userId, Long mintActivityId, Pageable pageable) {
|
|
|
+ MintActivity mintActivity = mintActivityRepo.findById(mintActivityId).orElse(null);
|
|
|
+ if (mintActivity == null) return new PageImpl<>(Collections.emptyList());
|
|
|
+
|
|
|
+ if (!mintActivity.isAudit()) {
|
|
|
+ Set<Tag> tags = mintActivity.getRule().getTags();
|
|
|
+ if (tags.isEmpty()) return new PageImpl<>(Collections.emptyList());
|
|
|
+ return assetRepo.findAll((Specification<Asset>) (root, query, criteriaBuilder) ->
|
|
|
+ query.distinct(true).where(criteriaBuilder.equal(root.get("userId"), userId),
|
|
|
+ criteriaBuilder.equal(root.get("status"), AssetStatus.NORMAL),
|
|
|
+ root.join("tags").get("id").in(tags.stream().map(Tag::getId).toArray()))
|
|
|
+ .getRestriction(), pageable);
|
|
|
+ } else {
|
|
|
+ return assetRepo.findByUserIdAndStatusAndNameLike(userId, AssetStatus.NORMAL,
|
|
|
+ "%" + mintActivity.getCollectionName() + "%", pageable);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|