xiongzhu пре 3 година
родитељ
комит
5eb607a46b

+ 0 - 4
src/main/java/com/izouma/nineth/TokenHistory.java

@@ -42,8 +42,4 @@ public class TokenHistory extends BaseEntity {
     private Long toUserId;
 
     private String toAvatar;
-
-    private String sFromUser;
-
-    private String sToUser;
 }

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

@@ -200,10 +200,17 @@ public class Asset extends CollectionBaseEntity {
     @JsonView(View.Detail.class)
     private Set<Tag> tags = new HashSet<>();
 
-    private String     hcTxHash;
+    private String hcTxHash;
+
     private BigInteger hcBlockNumber;
+
     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) {
         return Asset.builder()

+ 0 - 1
src/main/java/com/izouma/nineth/event/CreateOrderEvent.java

@@ -26,5 +26,4 @@ public class CreateOrderEvent implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long    invitor;
     private boolean vip;
-    private boolean safeTransfer;
 }

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

@@ -77,4 +77,7 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
     Page<Asset> findByUserIdAndStatusAndNameLike(Long userId, AssetStatus status, String name, Pageable pageable);
 
     List<Asset> findAllByUserIdAndCollectionIdAndStatus(Long userId, Long collectionId, AssetStatus status);
+
+    @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);
 }

+ 18 - 11
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -2,6 +2,7 @@ package com.izouma.nineth.service;
 
 import cn.hutool.core.convert.Convert;
 import com.izouma.nineth.TokenHistory;
+import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.domain.*;
@@ -340,13 +341,23 @@ public class AssetService {
         Objects.requireNonNull(toUser, "转让人不能为空");
         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();
         BeanUtils.copyProperties(asset, newAsset);
         newAsset.setId(null);
         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.setConsignment(false);
         newAsset.setPublicCollectionId(null);
@@ -358,6 +369,7 @@ public class AssetService {
         newAsset.setType(CollectionType.DEFAULT);
         newAsset.setSource(TransferReason.GIFT == reason ? AssetSource.GIFT : AssetSource.TRANSFER);
         newAsset.setTags(new HashSet<>(asset.getTags()));
+        newAsset.setSafeTransfer(safeTransfer);
         assetRepo.save(newAsset);
 
         TokenHistory tokenHistory = TokenHistory.builder()
@@ -370,21 +382,16 @@ public class AssetService {
                 .toAvatar(toUser.getAvatar())
                 .operation(reason.getDescription())
                 .price(TransferReason.GIFT == reason ? null : price)
-                .sFromUser(tokenHistoryRepo.findByTokenIdOrderByCreatedAtDesc(asset.getTokenId())
-                        .stream().findFirst().map(TokenHistory::getSToUser).orElse(null))
                 .build();
-        if (safeTransfer) {
-            tokenHistory.setSToUser("9th_" + RandomStringUtils.randomAlphabetic(8));
-        }
         tokenHistoryRepo.save(tokenHistory);
 
         asset.setPublicShow(false);
         asset.setConsignment(false);
         asset.setPublicCollectionId(null);
         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);
 
         //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) -> {
             Join join = root.join("tags");
             return criteriaBuilder.and(criteriaBuilder.equal(join.get("id"), tagId),
+                    criteriaBuilder.equal(root.get("source"), CollectionSource.TRANSFER),
                     criteriaBuilder.not(root.get("ownerId").in(excludeUserId)));
         }, pageable);
     }

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

@@ -188,9 +188,10 @@ public class OrderService {
         }
 
         Long id = snowflakeIdWorker.nextId();
+        redisTemplate.opsForValue().set("safeTransfer::" + id, "1", 10, TimeUnit.MINUTES);
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
-                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId,
-                        invitor, vip, safeTransfer), 100000);
+                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip),
+                100000);
 
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         return String.valueOf(id);
@@ -666,6 +667,7 @@ public class OrderService {
                     .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) {
                 order.setStatus(OrderStatus.PROCESSING);
                 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) {
-        String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+        String name = "0x" + RandomStringUtils.randomAlphabetic(8);
         Invite invite = null;
         if (StringUtils.isNotBlank(inviteCode)) {
             invite = inviteRepo.findFirstByCode(inviteCode).orElse(null);
@@ -292,7 +292,7 @@ public class UserService {
         User user = userRepo.findByPhoneAndDelFalse(phone).orElse(null);
         smsService.verify(phone, code);
         if (user == null) {
-            String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
             user = create(UserRegister.builder()
                     .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
                     .username(name)
@@ -340,7 +340,7 @@ public class UserService {
         WxMpUser wxMpUser = wxMpService.oauth2getUserInfo(accessToken, null);
         User user = userRepo.findByOpenIdAndDelFalse(wxMpUser.getOpenId()).orElse(null);
         if (user == null) {
-            String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
             user = User.builder()
                     .username(name)
                     .nickname(name)
@@ -374,7 +374,7 @@ public class UserService {
             if (userInfo != null) {
                 return userInfo;
             }
-            String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+            String name = "0x" + RandomStringUtils.randomAlphabetic(8);
             userInfo = User.builder()
                     .username(name)
                     .nickname(name)
@@ -688,7 +688,7 @@ public class UserService {
                     err.add(phone);
                 } else {
                     try {
-                        String name = "9th_" + RandomStringUtils.randomAlphabetic(8);
+                        String name = "0x" + RandomStringUtils.randomAlphabetic(8);
                         User user = create(UserRegister.builder()
                                 .authorities(Collections.singleton(Authority.get(AuthorityName.ROLE_USER)))
                                 .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(),
                 mintActivityId, pageable).toPage();
     }
+
+    @GetMapping("/byTag")
+    public Page<Asset> byTag(@RequestParam Long tagId, Pageable pageable) {
+        return assetRepo.byTag(SecurityUtils.getAuthenticatedUser().getId(), tagId, pageable);
+    }
 }