Browse Source

game box point 添加zombie类型

sunkean 3 years ago
parent
commit
9f0541b664

+ 8 - 0
src/main/java/com/izouma/nineth/domain/MetaAccessories.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.domain;
 
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.izouma.nineth.enums.EntryModeType;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
@@ -8,6 +9,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.Transient;
 
 @Data
@@ -18,15 +21,20 @@ import javax.persistence.Transient;
 public class MetaAccessories extends BaseEntity {
 
     @ApiModelProperty("配饰名称")
+    @ExcelProperty("配饰名称")
     private String name;
 
     @ApiModelProperty("购买方式")
+    @ExcelProperty("购买方式")
+    @Enumerated(EnumType.STRING)
     private EntryModeType purchaseMethod;
 
     @ApiModelProperty("价格/金币数量")
+    @ExcelProperty("价格/金币数量")
     private int price;
 
     @ApiModelProperty("NFT名称")
+    @ExcelProperty("NFT名称")
     private String collectionName;
 
     @Transient

+ 15 - 0
src/main/java/com/izouma/nineth/domain/MetaGameBoxPoints.java

@@ -1,6 +1,9 @@
 package com.izouma.nineth.domain;
 
+import com.alibaba.excel.annotation.ExcelIgnore;
+import com.alibaba.excel.annotation.ExcelProperty;
 import com.izouma.nineth.annotations.Searchable;
+import com.izouma.nineth.enums.MetaPointTypeEnum;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.AllArgsConstructor;
@@ -8,6 +11,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 
 import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
 import javax.persistence.Transient;
 
 @Data
@@ -18,21 +23,31 @@ import javax.persistence.Transient;
 public class MetaGameBoxPoints extends BaseEntity {
 
     @ApiModelProperty("用户ID")
+    @ExcelProperty("用户ID")
     @Searchable
     private Long userId;
 
+    @ApiModelProperty("类型")
+    @ExcelProperty("类型")
+    @Enumerated(EnumType.STRING)
+    private MetaPointTypeEnum type;
+
     @ApiModelProperty("昵称")
+    @ExcelIgnore
     @Transient
     private String nickname;
 
     @ApiModelProperty("头像")
+    @ExcelIgnore
     @Transient
     private String head;
 
     @ApiModelProperty("当前最高积分")
+    @ExcelProperty("当前最高积分")
     private int score;
 
     @ApiModelProperty("当前排名")
+    @ExcelIgnore
     @Transient
     private int scoreRank;
 }

+ 20 - 0
src/main/java/com/izouma/nineth/enums/MetaPointTypeEnum.java

@@ -0,0 +1,20 @@
+package com.izouma.nineth.enums;
+
+
+public enum MetaPointTypeEnum {
+
+    GAME_BOX("GAME_BOX"),
+
+    ZOMBIE("ZOMBIE");
+
+    private final String description;
+
+    MetaPointTypeEnum(String description) {
+        this.description = description;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+}
+

+ 6 - 5
src/main/java/com/izouma/nineth/repo/MetaGameBoxPointsRepo.java

@@ -1,6 +1,7 @@
 package com.izouma.nineth.repo;
 
 import com.izouma.nineth.domain.MetaGameBoxPoints;
+import com.izouma.nineth.enums.MetaPointTypeEnum;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
@@ -10,12 +11,12 @@ import java.util.Map;
 
 public interface MetaGameBoxPointsRepo extends JpaRepository<MetaGameBoxPoints, Long>, JpaSpecificationExecutor<MetaGameBoxPoints> {
 
-    @Query(value = "SELECT m.user_id userId, m.score score, u.nickname nickname, u.avatar head, RANK() OVER(ORDER BY m.score DESC) scoreRank FROM meta_game_box_points m LEFT JOIN user u ON m.user_id = u.id LIMIT 50", nativeQuery = true)
-    List<Map<String, Object>> findTopFifty();
+    @Query(value = "SELECT m.user_id userId, m.score score, m.type type, u.nickname nickname, u.avatar head, RANK() OVER(ORDER BY m.score DESC) scoreRank FROM meta_game_box_points m LEFT JOIN user u ON m.user_id = u.id where m.type = ?1 LIMIT 50", nativeQuery = true)
+    List<Map<String, Object>> findTopFiftyByType(String type);
 
-    @Query(value = "SELECT m.score score, a.scoreRank scoreRank FROM meta_game_box_points m LEFT JOIN ( SELECT user_id userId, RANK() OVER ( ORDER BY score DESC ) scoreRank FROM meta_game_box_points ) a ON m.user_id = a.userId  WHERE m.user_id = ?1", nativeQuery = true)
-    Map<String, Object> findInfoByUserId(Long userId);
+    @Query(value = "SELECT m.score score, a.scoreRank scoreRank FROM meta_game_box_points m LEFT JOIN ( SELECT user_id userId, RANK() OVER ( ORDER BY score DESC ) scoreRank FROM meta_game_box_points where type = ?2 ) a ON m.user_id = a.userId  WHERE m.user_id = ?1 and m.type = ?2", nativeQuery = true)
+    Map<String, Object> findInfoByUserIdAndType(Long userId, String type);
 
-    MetaGameBoxPoints findByUserId(Long userId);
+    MetaGameBoxPoints findByUserIdAndType(Long userId, MetaPointTypeEnum type);
 
 }

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

@@ -6,6 +6,7 @@ import com.izouma.nineth.domain.MetaGameBoxPoints;
 import com.izouma.nineth.dto.MetaGameBoxPointsDTO;
 import com.izouma.nineth.dto.MetaRestResult;
 import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.enums.MetaPointTypeEnum;
 import com.izouma.nineth.repo.MetaGameBoxPointsRepo;
 import com.izouma.nineth.utils.JpaUtils;
 import lombok.AllArgsConstructor;
@@ -26,21 +27,22 @@ public class MetaGameBoxPointsService {
         return metaGameBoxPointsRepo.findAll(JpaUtils.toSpecification(pageQuery, MetaGameBoxPoints.class), JpaUtils.toPageRequest(pageQuery));
     }
 
-    public MetaRestResult<MetaGameBoxPointsDTO> get(Long userId) {
+    public MetaRestResult<MetaGameBoxPointsDTO> get(Long userId, MetaPointTypeEnum type) {
         MetaGameBoxPointsDTO metaGameBoxPointsDTO = new MetaGameBoxPointsDTO();
-        MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserId(userId);
+        MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserIdAndType(userId, type);
         if (Objects.isNull(metaGameBoxPoints)) {
             metaGameBoxPoints = new MetaGameBoxPoints();
             metaGameBoxPoints.setUserId(userId);
+            metaGameBoxPoints.setType(type);
             metaGameBoxPoints.setScore(0);
             metaGameBoxPointsRepo.save(metaGameBoxPoints);
         }
-        Map<String, Object> metaGameBoxPointsMap = metaGameBoxPointsRepo.findInfoByUserId(userId);
+        Map<String, Object> metaGameBoxPointsMap = metaGameBoxPointsRepo.findInfoByUserIdAndType(userId, type.toString());
         String jsonStr = JSONObject.toJSONString(metaGameBoxPointsMap);
         metaGameBoxPoints = JSONObject.parseObject(jsonStr, MetaGameBoxPoints.class);
         metaGameBoxPointsDTO.setSelfHiScore(metaGameBoxPoints.getScore());
         metaGameBoxPointsDTO.setSelfRank(metaGameBoxPoints.getScoreRank());
-        List<Map<String, Object>> map = metaGameBoxPointsRepo.findTopFifty();
+        List<Map<String, Object>> map = metaGameBoxPointsRepo.findTopFiftyByType(type.toString());
         JSONArray jsonArray = new JSONArray();
         jsonArray.addAll(map);
         List<MetaGameBoxPoints> data = jsonArray.toJavaList(MetaGameBoxPoints.class);
@@ -55,9 +57,13 @@ public class MetaGameBoxPointsService {
         if (Objects.isNull(record.getUserId())) {
             return MetaRestResult.returnError("Illegal parameter : userId can not be null");
         }
-        MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserId(record.getUserId());
+        if (Objects.isNull(record.getType())) {
+            return MetaRestResult.returnError("Illegal parameter : type can not be null");
+        }
+        MetaGameBoxPoints metaGameBoxPoints = metaGameBoxPointsRepo.findByUserIdAndType(record.getUserId(), record.getType());
         if (Objects.isNull(metaGameBoxPoints)) {
             metaGameBoxPoints = new MetaGameBoxPoints();
+            metaGameBoxPoints.setType(record.getType());
             metaGameBoxPoints.setUserId(record.getUserId());
             metaGameBoxPoints.setScore(record.getScore());
             metaGameBoxPointsRepo.save(metaGameBoxPoints);

+ 1 - 0
src/main/java/com/izouma/nineth/utils/excel/ExcelUtils.java

@@ -37,6 +37,7 @@ public class ExcelUtils<T> {
                 .registerConverter(new ListConverter())
                 .registerConverter(new OperationSourceConverter())
                 .registerConverter(new RecordTypeConverter())
+                .registerConverter(new MetaPointTypeEnumConverter())
                 .doWrite(data);
     }
 }

+ 42 - 0
src/main/java/com/izouma/nineth/utils/excel/MetaPointTypeEnumConverter.java

@@ -0,0 +1,42 @@
+package com.izouma.nineth.utils.excel;
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.CellData;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import com.izouma.nineth.enums.MetaPointTypeEnum;
+
+public class MetaPointTypeEnumConverter implements Converter<MetaPointTypeEnum> {
+
+    @Override
+    public Class supportJavaTypeKey() {
+        return MetaPointTypeEnum.class;
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return null;
+    }
+
+    @Override
+    public MetaPointTypeEnum convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+        try {
+            for (MetaPointTypeEnum value : MetaPointTypeEnum.values()) {
+                if (value.getDescription().equals(cellData.getStringValue())) {
+                    return value;
+                }
+            }
+        } catch (Exception ignored) {
+        }
+        return null;
+    }
+
+    @Override
+    public CellData convertToExcelData(MetaPointTypeEnum value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+        if (value != null) {
+            return new CellData(value.getDescription());
+        }
+        return null;
+    }
+}

+ 4 - 3
src/main/java/com/izouma/nineth/web/MetaGameBoxPointsController.java

@@ -4,6 +4,7 @@ import com.izouma.nineth.domain.MetaGameBoxPoints;
 import com.izouma.nineth.dto.MetaGameBoxPointsDTO;
 import com.izouma.nineth.dto.MetaRestResult;
 import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.enums.MetaPointTypeEnum;
 import com.izouma.nineth.service.MetaGameBoxPointsService;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
@@ -25,9 +26,9 @@ public class MetaGameBoxPointsController extends BaseController {
         return metaGameBoxPointsService.all(pageQuery);
     }
 
-    @GetMapping("/{userId}/get")
-    public MetaRestResult<MetaGameBoxPointsDTO> get(@PathVariable Long userId) {
-        return metaGameBoxPointsService.get(userId);
+    @GetMapping("/{userId}/{type}/get")
+    public MetaRestResult<MetaGameBoxPointsDTO> get(@PathVariable Long userId, @PathVariable MetaPointTypeEnum type) {
+        return metaGameBoxPointsService.get(userId, type);
     }
 
     @PostMapping("/update")