Browse Source

快照调整

sunkean 3 years ago
parent
commit
9e60129c76

+ 1 - 1
src/main/java/com/izouma/nineth/config/MetaConstants.java

@@ -4,5 +4,5 @@ import java.util.List;
 
 public interface MetaConstants {
 
-    List<Long> GAME_COPY_IDS = List.of(8746067L, 8734418L, 8734417L);
+    List<Long> GAME_COPY_IDS = List.of(2822644L, 8746067L, 8734418L, 8734417L);
 }

+ 3 - 1
src/main/java/com/izouma/nineth/dto/SnapshotDTO.java

@@ -1,6 +1,7 @@
 package com.izouma.nineth.dto;
 
 import com.alibaba.excel.annotation.ExcelProperty;
+import io.swagger.annotations.ApiModel;
 import lombok.AllArgsConstructor;
 import lombok.Data;
 import lombok.NoArgsConstructor;
@@ -8,6 +9,7 @@ import lombok.NoArgsConstructor;
 @Data
 @NoArgsConstructor
 @AllArgsConstructor
+@ApiModel("元宇宙快照")
 public class SnapshotDTO {
 
     @ExcelProperty("用户id")
@@ -20,5 +22,5 @@ public class SnapshotDTO {
     private String phone;
 
     @ExcelProperty("持有数量")
-    private int count;
+    private int countNum;
 }

+ 11 - 19
src/main/java/com/izouma/nineth/repo/MetaGameProcessRepo.java

@@ -1,13 +1,13 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.MetaGameProcess;
-import com.izouma.nineth.dto.SnapshotDTO;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 
 import java.time.LocalDateTime;
 import java.util.List;
+import java.util.Map;
 
 public interface MetaGameProcessRepo extends JpaRepository<MetaGameProcess, Long>, JpaSpecificationExecutor<MetaGameProcess> {
 
@@ -20,24 +20,16 @@ public interface MetaGameProcessRepo extends JpaRepository<MetaGameProcess, Long
     @Query(value = "select sum(m.point) from MetaGameProcess m where m.userId = ?1 and m.metaGameCopyId in ?2 and m.del = false")
     Long sumPoint(Long userId, List<Long> metaGameCopyIds);
 
-    @Query(value = " SELECT  new com.izouma.nineth.dto.SnapshotDTO(" +
-            "m.userId," +
-            "u.nickname," +
-            "u.phone," +
-            "0 )" +
+    @Query(value = " SELECT m.userId as userId," +
+            "u.nickname as nickName," +
+            "u.phone as phone," +
+            "0 as countNum " +
             "FROM" +
-            "( SELECT user_id userId, sum( point ) point FROM meta_game_process WHERE meta_game_copy_id IN ?2 AND created_at <= ?3 GROUP BY user_id ) m" +
-            "LEFT JOIN USER u ON m.userId = u.id " +
-            "WHERE" +
-            "m.point > ?1 " +
-            "AND m.userId NOT IN (" +
-            "SELECT" +
-            "m.userId userId " +
+            "( SELECT user_id userId, sum( point ) point FROM meta_game_process WHERE meta_game_copy_id IN ?2 AND created_at <= ?3 GROUP BY user_id ) m LEFT JOIN USER u ON m.userId = u.id WHERE m.point > ?1 " +
+            "AND m.userId NOT IN ( SELECT m.userId userId " +
             "FROM" +
-            "( SELECT user_id userId, sum( point ) point FROM meta_game_process WHERE meta_game_copy_id IN ?2 AND created_at <= ?3 GROUP BY user_id ) m" +
-            "LEFT JOIN USER u ON m.userId = u.id " +
-            "WHERE" +
-            "m.point > ?1 " +
-            ")", nativeQuery = true)
-    List<SnapshotDTO> snapshot(int point, List<Long> metaGameCopyIds, LocalDateTime createdAt, LocalDateTime lastCreatedAt);
+            "( SELECT user_id userId, sum( point ) point FROM meta_game_process WHERE meta_game_copy_id IN ?2 AND created_at <= ?4 GROUP BY user_id ) m LEFT JOIN USER u ON m.userId = u.id " +
+            "WHERE m.point > ?1 )"
+            , nativeQuery = true)
+    List<Map<String, Object>> snapshot(int point, List<Long> metaGameCopyIds, LocalDateTime createdAt, LocalDateTime lastCreatedAt);
 }

+ 15 - 3
src/main/java/com/izouma/nineth/web/SnapshotController.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.web;
 
+import com.alibaba.fastjson.JSONArray;
 import com.izouma.nineth.config.MetaConstants;
 import com.izouma.nineth.domain.Snapshot;
 import com.izouma.nineth.dto.PageQuery;
@@ -11,6 +12,7 @@ import com.izouma.nineth.service.SnapshotService;
 import com.izouma.nineth.service.SysConfigService;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
+import org.apache.commons.collections.CollectionUtils;
 import org.springframework.data.domain.Page;
 import org.springframework.web.bind.annotation.*;
 
@@ -18,8 +20,10 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
+import java.time.LocalTime;
 import java.time.format.DateTimeFormatter;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/snapshot")
@@ -49,12 +53,20 @@ public class SnapshotController extends BaseController {
         if (1L == id) {
             int point = sysConfigService.getInt("zombie_point");
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-            LocalDateTime endTime = LocalDate.parse(sqlParams, formatter).atStartOfDay();
+            LocalDateTime endTime = LocalDate.parse(sqlParams, formatter).atTime(LocalTime.MAX);
             LocalDateTime lastEndTime = endTime.plusDays(-1);
-            List<SnapshotDTO> snapshot = metaGameProcessRepo.snapshot(point, MetaConstants.GAME_COPY_IDS, endTime, lastEndTime);
-            ExcelUtils.export(response, snapshot);
+            List<Map<String, Object>> map = metaGameProcessRepo.snapshot(point, MetaConstants.GAME_COPY_IDS, endTime, lastEndTime);
+            if (CollectionUtils.isEmpty(map)) {
+                throw new BusinessException("无数据");
+            }
+            JSONArray jsonArray = new JSONArray();
+            jsonArray.addAll(map);
+            List<SnapshotDTO> snapshotDTOS = jsonArray.toJavaList(SnapshotDTO.class);
+            ExcelUtils.export(response, snapshotDTOS);
         }
+        if (2L == id) {
 
+        }
     }
 }