Procházet zdrojové kódy

Merge branch 'trading' into dev

# Conflicts:
#	src/main/java/com/izouma/nineth/repo/AssetRepo.java
#	src/main/java/com/izouma/nineth/service/AssetService.java
xiongzhu před 4 roky
rodič
revize
a915658f91

+ 9 - 2
src/main/java/com/izouma/nineth/domain/Asset.java

@@ -203,10 +203,17 @@ public class Asset extends CollectionBaseEntity {
     @JsonView(View.Detail.class)
     @JsonView(View.Detail.class)
     private Set<Tag> tags = new HashSet<>();
     private Set<Tag> tags = new HashSet<>();
 
 
-    private String     hcTxHash;
+    private String hcTxHash;
+
     private BigInteger hcBlockNumber;
     private BigInteger hcBlockNumber;
+
     private BigInteger hcGasUsed;
     private BigInteger hcGasUsed;
-    private String     hcTokenId;
+
+    private String hcTokenId;
+
+    @Column(columnDefinition = "bit(1) default 0")
+    private boolean safeTransfer;
+
 
 
     public static Asset create(Collection collection, User user) {
     public static Asset create(Collection collection, User user) {
         return Asset.builder()
         return Asset.builder()

+ 3 - 0
src/main/java/com/izouma/nineth/domain/Order.java

@@ -213,4 +213,7 @@ public class Order extends BaseEntityNoID {
     private String     hcTxHash;
     private String     hcTxHash;
     private BigInteger hcBlockNumber;
     private BigInteger hcBlockNumber;
     private BigInteger hcGasUsed;
     private BigInteger hcGasUsed;
+
+    @Column(columnDefinition = "bit(1) default 0")
+    private boolean safeTransfer;
 }
 }

+ 3 - 0
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -82,4 +82,7 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
     @Transactional
     @Transactional
     @Query(value = "update Asset a set a.holdDays = ?2 where a.id = ?1")
     @Query(value = "update Asset a set a.holdDays = ?2 where a.id = ?1")
     void updateHoldDays(Long id, Integer holdDays);
     void updateHoldDays(Long id, Integer holdDays);
+
+    @Query("select a from Asset a join a.tags t on t.id = ?2 where a.userId = ?1")
+    Page<Asset> byTag(Long userId, Long tagId, Pageable pageable);
 }
 }

+ 26 - 16
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -1,8 +1,8 @@
 package com.izouma.nineth.service;
 package com.izouma.nineth.service;
 
 
 import cn.hutool.core.convert.Convert;
 import cn.hutool.core.convert.Convert;
-import com.fasterxml.jackson.annotation.JsonView;
 import com.izouma.nineth.TokenHistory;
 import com.izouma.nineth.TokenHistory;
+import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.domain.*;
 import com.izouma.nineth.domain.*;
@@ -10,7 +10,6 @@ import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.dto.PageWrapper;
 import com.izouma.nineth.dto.PageWrapper;
 import com.izouma.nineth.dto.UserHistory;
 import com.izouma.nineth.dto.UserHistory;
 import com.izouma.nineth.enums.*;
 import com.izouma.nineth.enums.*;
-import com.izouma.nineth.event.TransferAssetEvent;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.utils.JpaUtils;
 import com.izouma.nineth.utils.JpaUtils;
@@ -18,9 +17,8 @@ import com.izouma.nineth.utils.SecurityUtils;
 import com.izouma.nineth.utils.TokenUtils;
 import com.izouma.nineth.utils.TokenUtils;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.ObjectUtils;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.cache.annotation.Cacheable;
@@ -29,15 +27,11 @@ import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.PageImpl;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.jpa.domain.Specification;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.security.crypto.password.PasswordEncoder;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
-import javax.persistence.criteria.CriteriaBuilder;
-import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
 import java.math.BigDecimal;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.ChronoUnit;
@@ -339,17 +333,31 @@ public class AssetService {
     }
     }
 
 
     public void transfer(Asset asset, BigDecimal price, User toUser, TransferReason reason, Long orderId) {
     public void transfer(Asset asset, BigDecimal price, User toUser, TransferReason reason, Long orderId) {
+        transfer(asset, price, toUser, reason, orderId, false);
+    }
+
+    public void transfer(Asset asset, BigDecimal price, User toUser, TransferReason reason, Long orderId, boolean safeTransfer) {
         Objects.requireNonNull(asset, "原藏品不能为空");
         Objects.requireNonNull(asset, "原藏品不能为空");
         Objects.requireNonNull(toUser, "转让人不能为空");
         Objects.requireNonNull(toUser, "转让人不能为空");
         Objects.requireNonNull(reason, "转让原因不能为空");
         Objects.requireNonNull(reason, "转让原因不能为空");
 
 
+        User newOwner = toUser;
+        if (safeTransfer) {
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
+            newOwner = userRepo.save(User.builder()
+                    .username(name)
+                    .nickname(name)
+                    .avatar(Constants.DEFAULT_AVATAR)
+                    .build());
+        }
+
         Asset newAsset = new Asset();
         Asset newAsset = new Asset();
         BeanUtils.copyProperties(asset, newAsset);
         BeanUtils.copyProperties(asset, newAsset);
         newAsset.setId(null);
         newAsset.setId(null);
         newAsset.setUserId(toUser.getId());
         newAsset.setUserId(toUser.getId());
-        newAsset.setOwner(toUser.getNickname());
-        newAsset.setOwnerId(toUser.getId());
-        newAsset.setOwnerAvatar(toUser.getAvatar());
+        newAsset.setOwner(newOwner.getNickname());
+        newAsset.setOwnerId(newOwner.getId());
+        newAsset.setOwnerAvatar(newOwner.getAvatar());
         newAsset.setPublicShow(false);
         newAsset.setPublicShow(false);
         newAsset.setConsignment(false);
         newAsset.setConsignment(false);
         newAsset.setPublicCollectionId(null);
         newAsset.setPublicCollectionId(null);
@@ -361,10 +369,11 @@ public class AssetService {
         newAsset.setType(CollectionType.DEFAULT);
         newAsset.setType(CollectionType.DEFAULT);
         newAsset.setSource(TransferReason.GIFT == reason ? AssetSource.GIFT : AssetSource.TRANSFER);
         newAsset.setSource(TransferReason.GIFT == reason ? AssetSource.GIFT : AssetSource.TRANSFER);
         newAsset.setTags(new HashSet<>(asset.getTags()));
         newAsset.setTags(new HashSet<>(asset.getTags()));
+        newAsset.setSafeTransfer(safeTransfer);
         newAsset.setHoldDays(asset.getOldHoldDays());
         newAsset.setHoldDays(asset.getOldHoldDays());
         assetRepo.save(newAsset);
         assetRepo.save(newAsset);
 
 
-        tokenHistoryRepo.save(TokenHistory.builder()
+        TokenHistory tokenHistory = TokenHistory.builder()
                 .tokenId(asset.getTokenId())
                 .tokenId(asset.getTokenId())
                 .fromUser(asset.getOwner())
                 .fromUser(asset.getOwner())
                 .fromUserId(asset.getOwnerId())
                 .fromUserId(asset.getOwnerId())
@@ -374,15 +383,16 @@ public class AssetService {
                 .toAvatar(toUser.getAvatar())
                 .toAvatar(toUser.getAvatar())
                 .operation(reason.getDescription())
                 .operation(reason.getDescription())
                 .price(TransferReason.GIFT == reason ? null : price)
                 .price(TransferReason.GIFT == reason ? null : price)
-                .build());
+                .build();
+        tokenHistoryRepo.save(tokenHistory);
 
 
         asset.setPublicShow(false);
         asset.setPublicShow(false);
         asset.setConsignment(false);
         asset.setConsignment(false);
         asset.setPublicCollectionId(null);
         asset.setPublicCollectionId(null);
         asset.setStatus(TransferReason.GIFT == reason ? AssetStatus.GIFTED : AssetStatus.TRANSFERRED);
         asset.setStatus(TransferReason.GIFT == reason ? AssetStatus.GIFTED : AssetStatus.TRANSFERRED);
-        asset.setOwner(toUser.getNickname());
-        asset.setOwnerId(toUser.getId());
-        asset.setOwnerAvatar(toUser.getAvatar());
+        asset.setOwner(newOwner.getNickname());
+        asset.setOwnerId(newOwner.getId());
+        asset.setOwnerAvatar(newOwner.getAvatar());
         assetRepo.save(asset);
         assetRepo.save(asset);
 
 
         //vip权限转让
         //vip权限转让

+ 1 - 0
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -623,6 +623,7 @@ public class CollectionService {
         return collectionRepo.findAll((Specification<Collection>) (root, query, criteriaBuilder) -> {
         return collectionRepo.findAll((Specification<Collection>) (root, query, criteriaBuilder) -> {
             Join join = root.join("tags");
             Join join = root.join("tags");
             return criteriaBuilder.and(criteriaBuilder.equal(join.get("id"), tagId),
             return criteriaBuilder.and(criteriaBuilder.equal(join.get("id"), tagId),
+                    criteriaBuilder.equal(root.get("source"), CollectionSource.TRANSFER),
                     criteriaBuilder.not(root.get("ownerId").in(excludeUserId)));
                     criteriaBuilder.not(root.get("ownerId").in(excludeUserId)));
         }, pageable);
         }, pageable);
     }
     }

+ 5 - 2
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -155,7 +155,7 @@ public class OrderService {
     }
     }
 
 
     public String mqCreate(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
     public String mqCreate(Long userId, Long collectionId, int qty, Long addressId, Long userCouponId, Long invitor,
-                           String sign, boolean vip, int vipPurchase, int vipPoint) {
+                           String sign, boolean vip, int vipPurchase, int vipPoint, boolean safeTransfer) {
         String qs = null;
         String qs = null;
         try {
         try {
             qs = AESEncryptUtil.decrypt(sign);
             qs = AESEncryptUtil.decrypt(sign);
@@ -188,8 +188,10 @@ public class OrderService {
         }
         }
 
 
         Long id = snowflakeIdWorker.nextId();
         Long id = snowflakeIdWorker.nextId();
+        redisTemplate.opsForValue().set("safeTransfer::" + id, "1", 10, TimeUnit.MINUTES);
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
-                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip), 100000);
+                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip),
+                100000);
 
 
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         return String.valueOf(id);
         return String.valueOf(id);
@@ -665,6 +667,7 @@ public class OrderService {
                     .orElseThrow(new BusinessException("藏品不存在"));
                     .orElseThrow(new BusinessException("藏品不存在"));
 
 
             User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("用户不存在"));
             User user = userRepo.findById(order.getUserId()).orElseThrow(new BusinessException("用户不存在"));
+            boolean safeTransfer = Objects.equals("1", redisTemplate.opsForValue().get("safeTransfer::" + orderId));
             if (order.getStatus() == OrderStatus.NOT_PAID) {
             if (order.getStatus() == OrderStatus.NOT_PAID) {
                 order.setStatus(OrderStatus.PROCESSING);
                 order.setStatus(OrderStatus.PROCESSING);
                 order.setPayTime(LocalDateTime.now());
                 order.setPayTime(LocalDateTime.now());

+ 5 - 5
src/main/java/com/izouma/nineth/service/UserService.java

@@ -225,7 +225,7 @@ public class UserService {
     }
     }
 
 
     public User phoneRegister(String phone, String code, String password, String inviteCode, Long invitor, Long collectionId) {
     public User phoneRegister(String phone, String code, String password, String inviteCode, Long invitor, Long collectionId) {
-        String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+        String name = "0x" + RandomStringUtils.randomAlphabetic(8);
         Invite invite = null;
         Invite invite = null;
         if (StringUtils.isNotBlank(inviteCode)) {
         if (StringUtils.isNotBlank(inviteCode)) {
             invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
             invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
@@ -292,7 +292,7 @@ public class UserService {
         User user = userRepo.findByPhoneAndDelFalse(phone).orElse(null);
         User user = userRepo.findByPhoneAndDelFalse(phone).orElse(null);
         smsService.verify(phone, code);
         smsService.verify(phone, code);
         if (user == null) {
         if (user == null) {
-            String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
             user = create(UserRegister.builder()
             user = create(UserRegister.builder()
                     .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
                     .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
                     .username(name)
                     .username(name)
@@ -340,7 +340,7 @@ public class UserService {
         WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken, null);
         WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken, null);
         User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId()).orElse(null);
         User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId()).orElse(null);
         if (user == null) {
         if (user == null) {
-            String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
             user = User.builder()
             user = User.builder()
                     .username(name)
                     .username(name)
                     .nickname(name)
                     .nickname(name)
@@ -374,7 +374,7 @@ public class UserService {
             if (userInfo != null) {
             if (userInfo != null) {
                 return userInfo;
                 return userInfo;
             }
             }
-            String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
             userInfo = User.builder()
             userInfo = User.builder()
                     .username(name)
                     .username(name)
                     .nickname(name)
                     .nickname(name)
@@ -688,7 +688,7 @@ public class UserService {
                     err.add(phone);
                     err.add(phone);
                 } else {
                 } else {
                     try {
                     try {
-                        String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+                        String name = "0x" + RandomStringUtils.randomAlphabetic(8);
                         User user = create(UserRegister.builder()
                         User user = create(UserRegister.builder()
                                 .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
                                 .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
                                 .username(name)
                                 .username(name)

+ 5 - 0
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -169,6 +169,11 @@ public class AssetController extends BaseController {
         return assetService.findMintActivityAssetsWrap(SecurityUtils.getAuthenticatedUser().getId(),
         return assetService.findMintActivityAssetsWrap(SecurityUtils.getAuthenticatedUser().getId(),
                 mintActivityId, pageable).toPage();
                 mintActivityId, pageable).toPage();
     }
     }
+
+    @GetMapping("/byTag")
+    public Page<Asset> byTag(@RequestParam Long tagId, Pageable pageable) {
+        return assetRepo.byTag(SecurityUtils.getAuthenticatedUser().getId(), tagId, pageable);
+    }
 }
 }
 
 
 
 

+ 3 - 2
src/main/java/com/izouma/nineth/web/OrderController.java

@@ -114,11 +114,12 @@ public class OrderController extends BaseController {
                                             @RequestParam(required = false) Long couponId,
                                             @RequestParam(required = false) Long couponId,
                                             @RequestParam(required = false) Long invitor,
                                             @RequestParam(required = false) Long invitor,
                                             @RequestParam String sign,
                                             @RequestParam String sign,
-                                            @RequestParam(defaultValue = "false") boolean vip) {
+                                            @RequestParam(defaultValue = "false") boolean vip,
+                                            @RequestParam(defaultValue = "false") boolean safeTransfer) {
         final User user = SecurityUtils.getAuthenticatedUser();
         final User user = SecurityUtils.getAuthenticatedUser();
         return new HashMap<>() {{
         return new HashMap<>() {{
             put("id", orderService.mqCreate(user.getId(), collectionId, qty, addressId, couponId, invitor, sign,
             put("id", orderService.mqCreate(user.getId(), collectionId, qty, addressId, couponId, invitor, sign,
-                    vip, user.getVipPurchase(), user.getVipPoint()));
+                    vip, user.getVipPurchase(), user.getVipPoint(), safeTransfer));
         }};
         }};
     }
     }
 
 

+ 10 - 4
src/test/java/com/izouma/nineth/PayEaseTest.java

@@ -7,10 +7,7 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
 import com.upay.sdk.CipherWrapper;
 import com.upay.sdk.CipherWrapper;
 import com.upay.sdk.ConfigurationUtils;
 import com.upay.sdk.ConfigurationUtils;
 import com.upay.sdk.HttpClientUtils;
 import com.upay.sdk.HttpClientUtils;
-import com.upay.sdk.cashier.bindcard.builder.BindCardBuilder;
-import com.upay.sdk.cashier.bindcard.builder.BindCardConfirmBuilder;
-import com.upay.sdk.cashier.bindcard.builder.BindCardKaptchaBuilder;
-import com.upay.sdk.cashier.bindcard.builder.UnBindCardBuilder;
+import com.upay.sdk.cashier.bindcard.builder.*;
 import com.upay.sdk.cashier.order.builder.ReceiptPaymentBuilder;
 import com.upay.sdk.cashier.order.builder.ReceiptPaymentBuilder;
 import com.upay.sdk.entity.Payer;
 import com.upay.sdk.entity.Payer;
 import com.upay.sdk.entity.ProductDetail;
 import com.upay.sdk.entity.ProductDetail;
@@ -105,6 +102,15 @@ public class PayEaseTest {
         JSONObject response = request(ConfigurationUtils.getCashierUnBindCardUrl(), builder.bothEncryptBuild());
         JSONObject response = request(ConfigurationUtils.getCashierUnBindCardUrl(), builder.bothEncryptBuild());
     }
     }
 
 
+    @Test
+    public void queryBind() {
+        String bindCardId = "20220520100053712312330427711488";
+        BindCardQueryBuilder builder = new BindCardQueryBuilder(merchantId);
+        builder.setBindCardId(bindCardId)
+                .setMerchantUserId("12234");
+        JSONObject response = request(ConfigurationUtils.getCashierBindCardQueryUrl(), builder.bothEncryptBuild());
+    }
+
     @Test
     @Test
     public void pay() {
     public void pay() {
         String subject = "充值";
         String subject = "充值";