Explorar o código

Merge branch 'dev-meta' of xiongzhu/raex_back into master

sunkean %!s(int64=3) %!d(string=hai) anos
pai
achega
056726d292

+ 30 - 0
src/main/java/com/izouma/nineth/domain/MetaAwardDrop.java

@@ -0,0 +1,30 @@
+package com.izouma.nineth.domain;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.izouma.nineth.enums.MetaAwardTypeEnum;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+@Entity
+@ApiModel("元宇宙奖励空投记录")
+public class MetaAwardDrop extends BaseEntity {
+
+    @ApiModelProperty("奖励类型")
+    @ExcelProperty("奖励类型")
+    @Enumerated(EnumType.STRING)
+    private MetaAwardTypeEnum awardType;
+
+    @ApiModelProperty("文件地址")
+    @ExcelProperty("文件地址")
+    private String fileUrl;
+}

+ 17 - 0
src/main/java/com/izouma/nineth/dto/MetaAwardDropJsonDTO.java

@@ -0,0 +1,17 @@
+package com.izouma.nineth.dto;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class MetaAwardDropJsonDTO {
+
+    private Long userId;
+
+    private int value;
+
+    private Long propId;
+}

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

@@ -10,6 +10,9 @@ import java.util.List;
 
 public interface MetaTaskBindRepo extends JpaRepository<MetaTaskBind, Long>, JpaSpecificationExecutor<MetaTaskBind> {
 
+    @Query(value = "select * from meta_task_bind m where m.task_id = ?1 and type = ?2 and m.del = false and m.atom_task_id not in (select m2.atom_task_id from meta_task_to_user_new m2 where m2.task_id = ?1 and m2.user_id = ?3 and m2.del = false)", nativeQuery = true)
+    List<MetaTaskBind> findUnReceived(Long taskId, String type, Long userId);
+
     List<MetaTaskBind> findByTaskIdAndTypeAndDel(Long taskId, MetaTaskType type, boolean del);
 
     @Query(value = "select m.atom_task_id from meta_task_bind m where m.task_id = ?1 and m.type = ?2 and m.del = false order by m.atom_task_index asc limit 1", nativeQuery = true)

+ 2 - 3
src/main/java/com/izouma/nineth/repo/MetaTaskNewRepo.java

@@ -23,12 +23,11 @@ public interface MetaTaskNewRepo extends JpaRepository<MetaTaskNew, Long>, JpaSp
 
     List<MetaTaskNew> findAllByPublishAndDel(boolean publish, boolean del);
 
+    List<MetaTaskNew> findAllByChannelIdAndPublishAndDel(Long channelId, boolean publish, boolean del);
+
     @Query("select m.id from MetaTaskNew m where m.publish = true and m.del = false")
     List<Long> findIdByPublishAndDel();
 
-    @Query(value = "select * from meta_task_new where del = false and publish = true and channel_id = ?2 and id not in (select task_id from meta_task_to_user where user_id = ?1)", nativeQuery = true)
-    List<MetaTaskNew> canGet(Long userId, Long channelId);
-
     @Query("select m.id from MetaTaskNew m where m.type = ?1 and m.del = false and m.publish = true")
     List<Long> findDailyTaskIds(MetaTaskType type);
 }

+ 0 - 1
src/main/java/com/izouma/nineth/security/WebSecurityConfig.java

@@ -153,7 +153,6 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
                 .antMatchers("/websocket/**").permitAll()
                 .antMatchers("/user/websocket/*").permitAll()
                 .antMatchers("/purchaseLevel/websocket/*").permitAll()
-                .antMatchers("/metaAdvertRecord/metaQuery").permitAll()
                 .antMatchers("/metaTask/**").permitAll()
                 .antMatchers("/asset/destroy").permitAll()
                 .antMatchers("/user/topTen").permitAll()

+ 64 - 3
src/main/java/com/izouma/nineth/service/MetaTaskNewService.java

@@ -17,6 +17,7 @@ import org.apache.commons.collections.CollectionUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
 
@@ -79,13 +80,73 @@ public class MetaTaskNewService {
     }
 
     public MetaRestResult<List<MetaTaskNew>> canGet(Long userId, Long channelId) {
-        List<MetaTaskNew> metaTaskNews = metaTaskNewRepo.canGet(userId, channelId);
+        List<MetaTaskNew> metaTaskNews = metaTaskNewRepo.findAllByChannelIdAndPublishAndDel(channelId, true, false);
+        List<MetaTaskNew> newMetaTaskNews = new ArrayList<>();
         try {
-            metaTaskNews.forEach(this::buildAtomTask);
+            metaTaskNews.forEach(metaTaskNew -> {
+                buildAtomTaskUnReceived(metaTaskNew, userId);
+            });
+            metaTaskNews.forEach(metaTaskNew -> {
+                removeMetaTaskNew(metaTaskNew, newMetaTaskNews);
+            });
         } catch (Exception e) {
             return MetaRestResult.returnError(e.getMessage());
         }
-        return MetaRestResult.returnSuccess(metaTaskNews);
+        return MetaRestResult.returnSuccess(newMetaTaskNews);
+    }
+
+    private void removeMetaTaskNew(MetaTaskNew metaTaskNew, List<MetaTaskNew> newMetaTaskNews) {
+        if (MetaTaskType.MAIN_LINE.equals(metaTaskNew.getType())) {
+            if (CollectionUtils.isEmpty(metaTaskNew.getMetaNodeTask()) && CollectionUtils.isEmpty(metaTaskNew.getMetaBranchLineTask())) {
+                return;
+            }
+            newMetaTaskNews.add(metaTaskNew);
+            return;
+        }
+        if (MetaTaskType.BRANCH_LINE.equals(metaTaskNew.getType())) {
+            if (CollectionUtils.isEmpty(metaTaskNew.getMetaBranchLineTask())) {
+                return;
+            }
+            newMetaTaskNews.add(metaTaskNew);
+            return;
+        }
+        if (MetaTaskType.DAILY.equals(metaTaskNew.getType())) {
+            if (CollectionUtils.isEmpty(metaTaskNew.getMetaDailyTask())) {
+                return;
+            }
+            newMetaTaskNews.add(metaTaskNew);
+        }
+    }
+
+    private void buildAtomTaskUnReceived(MetaTaskNew metaTaskNew, Long userId) {
+        if (MetaTaskType.MAIN_LINE.equals(metaTaskNew.getType())) {
+            List<MetaTaskBind> metaNodeTask = metaTaskBindRepo.findUnReceived(metaTaskNew.getId(), MetaTaskType.NODE.toString(), userId);
+            if (CollectionUtils.isNotEmpty(metaNodeTask)) {
+                buildMetaAtomTask(metaNodeTask);
+                metaTaskNew.setMetaNodeTask(metaNodeTask);
+            }
+            List<MetaTaskBind> metaBranchLineTask = metaTaskBindRepo.findUnReceived(metaTaskNew.getId(), MetaTaskType.BRANCH_LINE.toString(), userId);
+            if (CollectionUtils.isNotEmpty(metaBranchLineTask)) {
+                buildMetaAtomTask(metaBranchLineTask);
+                metaTaskNew.setMetaBranchLineTask(metaBranchLineTask);
+            }
+            return;
+        }
+        if (MetaTaskType.BRANCH_LINE.equals(metaTaskNew.getType())) {
+            List<MetaTaskBind> metaBranchLineTask = metaTaskBindRepo.findUnReceived(metaTaskNew.getId(), MetaTaskType.BRANCH_LINE.toString(), userId);
+            if (CollectionUtils.isNotEmpty(metaBranchLineTask)) {
+                buildMetaAtomTask(metaBranchLineTask);
+                metaTaskNew.setMetaBranchLineTask(metaBranchLineTask);
+            }
+            return;
+        }
+        if (MetaTaskType.DAILY.equals(metaTaskNew.getType())) {
+            List<MetaTaskBind> metaDailyTask = metaTaskBindRepo.findUnReceived(metaTaskNew.getId(), MetaTaskType.DAILY.toString(), userId);
+            if (CollectionUtils.isNotEmpty(metaDailyTask)) {
+                buildMetaAtomTask(metaDailyTask);
+                metaTaskNew.setMetaDailyTask(metaDailyTask);
+            }
+        }
     }
 
     private void buildAtomTask(MetaTaskNew metaTaskNew) {

+ 48 - 0
src/test/java/com/izouma/nineth/service/MetaTest.java

@@ -0,0 +1,48 @@
+package com.izouma.nineth.service;
+
+import com.aliyun.oss.OSSClient;
+import com.aliyun.oss.model.OSSObject;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.config.AliyunProperties;
+import com.izouma.nineth.dto.MetaAwardDropJsonDTO;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+@Slf4j
+@ConditionalOnProperty(name = "storage.provider", havingValue = "aliyun")
+class MetaTest extends ApplicationTests {
+
+    @Autowired
+    private AliyunProperties aliyunProperties;
+
+    @Test
+    void createAsset() {
+        String endpoint = aliyunProperties.getOssEndPoint();
+        String accessKeyId = aliyunProperties.getAccessKeyId();
+        String accessKeySecret = aliyunProperties.getAccessKeySecret();
+        String bucketName = aliyunProperties.getOssBucketName();
+        String objectKey = "application/2023-04-18-17-37-58RpoTXHMq.json";
+        OSSClient client = new OSSClient(endpoint, accessKeyId,
+                accessKeySecret);
+        List<MetaAwardDropJsonDTO> objects = new ArrayList<>();
+        OSSObject ossObject = client.getObject(bucketName, objectKey);
+        InputStream inputStream = ossObject.getObjectContent();
+        ObjectMapper objectMapper = new ObjectMapper();
+        try {
+            objects = objectMapper.readValue(inputStream, objects.getClass());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        client.shutdown();
+    }
+
+
+}