xiongzhu 4 лет назад
Родитель
Сommit
3d1b1688de

BIN
src/main/comos/src/assets/gift.png


+ 5 - 0
src/main/comos/src/views/Mine.vue

@@ -155,6 +155,11 @@
                     <van-icon :name="require('@assets/icon-anquan.png')" class="search-icon" />
                     <van-icon :name="require('@assets/icon-anquan.png')" class="search-icon" />
                 </template>
                 </template>
             </van-grid-item>
             </van-grid-item>
+            <van-grid-item text="邀请有礼" :to="{ path: '/share' }">
+                <template #icon>
+                    <van-icon :name="require('@assets/gift.png')" class="search-icon" />
+                </template>
+            </van-grid-item>
         </van-grid>
         </van-grid>
 
 
         <div class="tabbar-placeholder"></div>
         <div class="tabbar-placeholder"></div>

+ 5 - 0
src/main/java/com/izouma/nineth/config/EventNames.java

@@ -0,0 +1,5 @@
+package com.izouma.nineth.config;
+
+public class EventNames {
+    public final static String SWITCH_ACCOUNT = "switchAccount";
+}

+ 2 - 2
src/main/java/com/izouma/nineth/config/GeneralProperties.java

@@ -23,8 +23,8 @@ public class GeneralProperties {
     private String  mintTopic;
     private String  mintTopic;
     private String  updateActivityStockGroup;
     private String  updateActivityStockGroup;
     private String  updateActivityStockTopic;
     private String  updateActivityStockTopic;
-    private String  commonEventGroup;
-    private String  switchAccountTopic;
+    private String  broadcastEventGroup;
+    private String  broadcastEventTopic;
     private boolean notifyServer;
     private boolean notifyServer;
     private int     dataCenterId;
     private int     dataCenterId;
     private int     workerId;
     private int     workerId;

+ 43 - 0
src/main/java/com/izouma/nineth/listener/BroadcastEventListener.java

@@ -0,0 +1,43 @@
+package com.izouma.nineth.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.alibaba.fastjson.serializer.SerializerFeature;
+import com.izouma.nineth.config.EventNames;
+import com.izouma.nineth.service.AdapayMerchantService;
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.rocketmq.spring.annotation.ConsumeMode;
+import org.apache.rocketmq.spring.annotation.MessageModel;
+import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
+import org.apache.rocketmq.spring.core.RocketMQListener;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+@AllArgsConstructor
+@RocketMQMessageListener(
+        messageModel = MessageModel.BROADCASTING,
+        consumerGroup = "${general.broadcast-event-group}",
+        topic = "${general.broadcast-event-topic}",
+        consumeMode = ConsumeMode.CONCURRENTLY)
+public class BroadcastEventListener implements RocketMQListener<JSONObject> {
+    private AdapayMerchantService adapayMerchantService;
+
+    @Override
+    public void onMessage(JSONObject message) {
+        log.info("接收到广播事件 {}", JSONObject.toJSONString(message, SerializerFeature.PrettyFormat));
+        String name = message.getString("name");
+        if (name != null) {
+            switch (name) {
+                case EventNames.SWITCH_ACCOUNT:
+                    try {
+                        Long id = message.getLong("data");
+                        adapayMerchantService.select(id);
+                    } catch (Exception e) {
+                        log.error("event error", e);
+                    }
+                    break;
+            }
+        }
+    }
+}

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

@@ -62,4 +62,14 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
             "order by modified_at")
             "order by modified_at")
     List<Asset> findColdAsset(String name, int number);
     List<Asset> findColdAsset(String name, int number);
 
 
+    @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from asset c", nativeQuery = true)
+    List<List<String>> selectResource();
+
+    @Modifying
+    @Transactional
+    @Query(value = "update asset c set c.pic = ?2, c.model3d = ?3, c.minter_avatar = ?4, " +
+            "c.owner_avatar = ?5, c.detail = ?6 where c.id = ?1", nativeQuery = true)
+    int updateCDN(Long id, String pic, String model3d, String minterAvatar,
+                  String ownerAvatar, String detail);
+
 }
 }

+ 13 - 0
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -130,4 +130,17 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @Transactional
     @Transactional
     @Modifying
     @Modifying
     int deleteByAssetId(Long assetId);
     int deleteByAssetId(Long assetId);
+
+    @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from collection_info c", nativeQuery = true)
+    List<List<String>> selectResource();
+
+    @Query(value = "select c.id, c.pic, c.model3d, c.minter_avatar, c.owner_avatar, c.detail from collection_info c where c.id = ?1", nativeQuery = true)
+    List<List<String>> selectResource(Long id);
+
+    @Modifying
+    @Transactional
+    @Query(value = "update collection_info c set c.pic = ?2, c.model3d = ?3, c.minter_avatar = ?4, " +
+            "c.owner_avatar = ?5, c.detail = ?6 where c.id = ?1", nativeQuery = true)
+    int updateCDN(Long id, String pic, String model3d, String minterAvatar,
+                  String ownerAvatar, String detail);
 }
 }

+ 21 - 1
src/main/java/com/izouma/nineth/service/AdapayMerchantService.java

@@ -1,11 +1,14 @@
 package com.izouma.nineth.service;
 package com.izouma.nineth.service;
 
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.huifu.adapay.Adapay;
 import com.huifu.adapay.Adapay;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.huifu.adapay.core.exception.BaseAdaPayException;
 import com.huifu.adapay.model.*;
 import com.huifu.adapay.model.*;
 import com.izouma.nineth.config.AdapayProperties;
 import com.izouma.nineth.config.AdapayProperties;
+import com.izouma.nineth.config.EventNames;
+import com.izouma.nineth.config.GeneralProperties;
 import com.izouma.nineth.domain.AdapayMerchant;
 import com.izouma.nineth.domain.AdapayMerchant;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.dto.PageQuery;
 import com.izouma.nineth.dto.adapay.MemberInfo;
 import com.izouma.nineth.dto.adapay.MemberInfo;
@@ -18,6 +21,7 @@ import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections.MapUtils;
 import org.apache.commons.collections.MapUtils;
+import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
@@ -33,7 +37,9 @@ import java.util.concurrent.atomic.AtomicReference;
 public class AdapayMerchantService {
 public class AdapayMerchantService {
 
 
     private final AdapayMerchantRepo adapayMerchantRepo;
     private final AdapayMerchantRepo adapayMerchantRepo;
-    private final AdapayProperties   adapayProperties;
+    private final AdapayProperties  adapayProperties;
+    private final RocketMQTemplate  rocketMQTemplate;
+    private final GeneralProperties generalProperties;
 
 
     @PostConstruct
     @PostConstruct
     public void init() {
     public void init() {
@@ -72,6 +78,20 @@ public class AdapayMerchantService {
         return record;
         return record;
     }
     }
 
 
+
+    public void sendSelectEvent(Long id) {
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("name", EventNames.SWITCH_ACCOUNT);
+        jsonObject.put("data", id);
+        rocketMQTemplate.convertAndSend(generalProperties.getBroadcastEventTopic(), jsonObject);
+
+        try {
+            Thread.sleep(500);
+        } catch (InterruptedException e) {
+            e.printStackTrace();
+        }
+    }
+
     public void select(Long id) throws Exception {
     public void select(Long id) throws Exception {
         AdapayMerchant merchant = adapayMerchantRepo.findById(id).orElseThrow(new BusinessException("商户不存在"));
         AdapayMerchant merchant = adapayMerchantRepo.findById(id).orElseThrow(new BusinessException("商户不存在"));
 
 

+ 13 - 1
src/main/java/com/izouma/nineth/service/AssetMintService.java

@@ -17,10 +17,12 @@ import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContext;
+import org.springframework.core.env.Environment;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
 import java.io.File;
 import java.io.File;
+import java.util.Arrays;
 
 
 @Service
 @Service
 @Slf4j
 @Slf4j
@@ -30,6 +32,7 @@ public class AssetMintService {
     private UserRepo           userRepo;
     private UserRepo           userRepo;
     private NFTService         nftService;
     private NFTService         nftService;
     private ApplicationContext applicationContext;
     private ApplicationContext applicationContext;
+    private Environment        env;
 
 
     @Async
     @Async
     public void mint(Long assetId) {
     public void mint(Long assetId) {
@@ -92,7 +95,15 @@ public class AssetMintService {
 
 
     public String ipfsUpload(String url) {
     public String ipfsUpload(String url) {
         try {
         try {
-            IPFS ipfs = new IPFS("112.74.34.84", 5001);
+            url = url.replace("9space-2021.oss-cn-shenzhen.aliyuncs.com",
+                            "9space-2021.oss-cn-shenzhen-internal.aliyuncs.com")
+                    .replace("cosmoscdn.9space.vip",
+                            "9space-2021.oss-cn-shenzhen-internal.aliyuncs.com");
+            String host = "112.74.34.84";
+            if (Arrays.asList(env.getActiveProfiles()).contains("prod")) {
+                host = "172.31.167.5";
+            }
+            IPFS ipfs = new IPFS(host, 5001);
             HttpRequest request = HttpRequest.get(url);
             HttpRequest request = HttpRequest.get(url);
             File file = File.createTempFile("ipfs", ".tmp");
             File file = File.createTempFile("ipfs", ".tmp");
             request.receive(file);
             request.receive(file);
@@ -100,6 +111,7 @@ public class AssetMintService {
             MerkleNode put = ipfs.add(file1).get(0);
             MerkleNode put = ipfs.add(file1).get(0);
             Multihash multihash = ipfs.pin.add(put.hash).get(0);
             Multihash multihash = ipfs.pin.add(put.hash).get(0);
             log.info("上传ipfs成功 {}", multihash.toBase58());
             log.info("上传ipfs成功 {}", multihash.toBase58());
+            file.delete();
             return multihash.toBase58();
             return multihash.toBase58();
         } catch (Exception e) {
         } catch (Exception e) {
         }
         }

+ 37 - 0
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -32,6 +32,8 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.time.temporal.ChronoUnit;
 import java.time.temporal.ChronoUnit;
 import java.util.*;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ForkJoinPool;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 @Service
 @Service
@@ -454,4 +456,39 @@ public class AssetService {
         });
         });
         return result;
         return result;
     }
     }
+
+    public void transferCDN() throws ExecutionException, InterruptedException {
+        ForkJoinPool customThreadPool = new ForkJoinPool(100);
+        customThreadPool.submit(() -> {
+            collectionRepo.selectResource().parallelStream().forEach(list -> {
+                for (int i = 0; i < list.size(); i++) {
+                    list.set(i, replaceCDN(list.get(i)));
+                }
+                collectionRepo.updateCDN(Long.parseLong(list.get(0)),
+                        list.get(1),
+                        list.get(2),
+                        list.get(3),
+                        list.get(4),
+                        list.get(5));
+            });
+
+            assetRepo.selectResource().parallelStream().forEach(list -> {
+                for (int i = 0; i < list.size(); i++) {
+                    list.set(i, replaceCDN(list.get(i)));
+                }
+                assetRepo.updateCDN(Long.parseLong(list.get(0)),
+                        list.get(1),
+                        list.get(2),
+                        list.get(3),
+                        list.get(4),
+                        list.get(5));
+            });
+        }).get();
+    }
+
+    public String replaceCDN(String url) {
+        if (url == null) return null;
+        return url.replaceAll("https://9space-2021\\.oss-cn-shenzhen\\.aliyuncs\\.com",
+                "https://cosmoscdn.9space.vip");
+    }
 }
 }

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

@@ -472,7 +472,6 @@ public class UserService {
         if (!bankValidate.isValidated()) {
         if (!bankValidate.isValidated()) {
             throw new BusinessException("暂不支持此卡");
             throw new BusinessException("暂不支持此卡");
         }
         }
-
         smsService.verify(phone, code);
         smsService.verify(phone, code);
 
 
         adapayMerchantService.createMemberForAll(userId.toString(), user.getPhone(), identityAuth.getRealName(), identityAuth.getIdNo());
         adapayMerchantService.createMemberForAll(userId.toString(), user.getPhone(), identityAuth.getRealName(), identityAuth.getIdNo());
@@ -482,7 +481,7 @@ public class UserService {
         String accountId = adapayMerchantService.createSettleAccountForAll
         String accountId = adapayMerchantService.createSettleAccountForAll
                 (user.getMemberId(), identityAuth.getRealName(),
                 (user.getMemberId(), identityAuth.getRealName(),
                         identityAuth.getIdNo(), phone, bankNo);
                         identityAuth.getIdNo(), phone, bankNo);
-        user.setSettleAccountId(accountId);
+        user.setSettleAccountId(Optional.ofNullable(accountId).orElse("1"));
         userRepo.save(user);
         userRepo.save(user);
 
 
         userBankCardRepo.save(UserBankCard.builder()
         userBankCardRepo.save(UserBankCard.builder()

+ 1 - 1
src/main/java/com/izouma/nineth/web/AdapayMerchantController.java

@@ -56,7 +56,7 @@ public class AdapayMerchantController extends BaseController {
 
 
     @PostMapping("/select")
     @PostMapping("/select")
     public void select(@RequestParam Long id) throws Exception {
     public void select(@RequestParam Long id) throws Exception {
-        adapayMerchantService.select(id);
+        adapayMerchantService.sendSelectEvent(id);
     }
     }
 
 
     @PostMapping("/query")
     @PostMapping("/query")

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

@@ -21,6 +21,7 @@ import lombok.AllArgsConstructor;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.apache.rocketmq.spring.core.RocketMQTemplate;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.data.domain.Pageable;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
@@ -29,6 +30,7 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.List;
 import java.util.Map;
 import java.util.Map;
+import java.util.concurrent.ExecutionException;
 
 
 @RestController
 @RestController
 @RequestMapping("/asset")
 @RequestMapping("/asset")
@@ -143,6 +145,19 @@ public class AssetController extends BaseController {
         }
         }
         return "ok";
         return "ok";
     }
     }
+
+    @PostMapping("/cdn")
+    @PreAuthorize("hasRole('ADMIN')")
+    public String cdn() throws ExecutionException, InterruptedException {
+        new Thread(() -> {
+            try {
+                assetService.transferCDN();
+            } catch (ExecutionException | InterruptedException e) {
+                e.printStackTrace();
+            }
+        }).start();
+        return "ok";
+    }
 }
 }
 
 
 
 

+ 6 - 0
src/main/resources/application.yaml

@@ -147,6 +147,8 @@ general:
   mint-topic: mint-topic-dev
   mint-topic: mint-topic-dev
   update-activity-stock-group: update-activity-stock-group-dev
   update-activity-stock-group: update-activity-stock-group-dev
   update-activity-stock-topic: update-activity-stock-topic-dev
   update-activity-stock-topic: update-activity-stock-topic-dev
+  broadcast-event-group: broadcast-event-group-dev
+  broadcast-event-topic: broadcast-event-topic-dev
 mychain:
 mychain:
   rest:
   rest:
     bizid: a00e36c5
     bizid: a00e36c5
@@ -264,6 +266,8 @@ general:
   mint-topic: mint-topic-test
   mint-topic: mint-topic-test
   update-activity-stock-group: update-activity-stock-group-test
   update-activity-stock-group: update-activity-stock-group-test
   update-activity-stock-topic: update-activity-stock-topic-test
   update-activity-stock-topic: update-activity-stock-topic-test
+  broadcast-event-group: broadcast-event-group-test
+  broadcast-event-topic: broadcast-event-topic-test
   notify-server: true
   notify-server: true
 ---
 ---
 
 
@@ -288,6 +292,8 @@ general:
   mint-topic: mint-topic
   mint-topic: mint-topic
   update-activity-stock-group: update-activity-stock-group
   update-activity-stock-group: update-activity-stock-group
   update-activity-stock-topic: update-activity-stock-topic
   update-activity-stock-topic: update-activity-stock-topic
+  broadcast-event-group: broadcast-event-group
+  broadcast-event-topic: broadcast-event-topic
   notify-server: true
   notify-server: true
 wx:
 wx:
   pay:
   pay:

+ 0 - 2
src/test/java/com/izouma/nineth/service/AdapayTest.java

@@ -236,8 +236,6 @@ public class AdapayTest {
             if (paymentItem.getDivMembers() != null && paymentItem.getDivMembers().size() > 1) {
             if (paymentItem.getDivMembers() != null && paymentItem.getDivMembers().size() > 1) {
                 DivMembersItem item = paymentItem.getDivMembers().stream().filter(d -> !d.getMemberId().equals("0"))
                 DivMembersItem item = paymentItem.getDivMembers().stream().filter(d -> !d.getMemberId().equals("0"))
                         .findAny().get();
                         .findAny().get();
-
-
             }
             }
         }
         }
     }
     }