Kaynağa Gözat

银月:excel导入不同品质装备随机权重数据

tangbin 1 yıl önce
ebeveyn
işleme
d4877fd2e9
15 değiştirilmiş dosya ile 400 ekleme ve 102 silme
  1. 1 1
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/Equip.java
  2. 0 72
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipPropertyElse.java
  3. 15 8
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipQuality.java
  4. 2 2
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipEntryTemplateService.java
  5. 88 0
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipQualityService.java
  6. 0 4
      logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipService.java
  7. 29 10
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/controller/EquipExcelController.java
  8. 35 0
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/dto/EquipQualityExcelDTO.java
  9. 1 1
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/listener/EquipEntryTemplateExcelListener.java
  10. 136 0
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/listener/EquipQualityExcelListener.java
  11. 23 0
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/EquipQualityExcelService.java
  12. 1 1
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/EquipTemplateExcelService.java
  13. 66 0
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/impl/EquipQualityExcelServiceImpl.java
  14. 2 2
      logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/impl/EquipTemplateExcelServiceImpl.java
  15. 1 1
      provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/EquipMessage.java

+ 1 - 1
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/Equip.java

@@ -48,7 +48,7 @@ public class Equip {
     String position;
     /** 要求等级 */
     int level;
-    /** 品质 1白色,2黄色,3绿色,4蓝色,5紫色,6鬼装*/
+    /** 品质 white白色,yellow黄色,green绿色,blue蓝色,red红色,purple紫色,ghost鬼装*/
     String quality;
     /** 耐久度 */
     int durability;

+ 0 - 72
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipPropertyElse.java

@@ -1,72 +0,0 @@
-/*
- * ioGame
- * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
- * # iohao.com . 渔民小镇
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-package com.iohao.mmo.equip.entity;
-
-import lombok.AccessLevel;
-import lombok.Data;
-import lombok.experimental.FieldDefaults;
-import org.springframework.data.mongodb.core.mapping.Document;
-
-import java.math.BigDecimal;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 装备额外属性统计(装备基础属性以外的属性)
- * <pre>
- *     装备的基本属性
- * </pre>
- *
- * @author 唐斌
- * @date 2023-07-24
- */
-@Data
-@Document
-@FieldDefaults(level = AccessLevel.PRIVATE)
-public class EquipPropertyElse {
-    /** 根骨 */
-    int rootBone;
-    /** 精力 */
-    int energy;
-    /** 力量 */
-    int power;
-    /** 智力 */
-    int intelligence;
-    /** 敏捷 */
-    int agile;
-    /** 幸运 */
-    int lucky;
-
-    /** 最小物理攻击百分比 */
-    BigDecimal physicsAttackMinPct;
-    /** 最大物理攻击百分比 */
-    BigDecimal physicsAttackMaxPct;
-    /** 最小法术攻击百分比 */
-    BigDecimal magicAttackMinPct;
-    /** 最大法术攻击百分比 */
-    BigDecimal magicAttackMaxPct;
-    /** 是否不能打孔 */
-    boolean bndkFlag = false;
-    /** 是否不可修复 */
-    boolean bkxfFlag = false;
-
-    /** 技能等级 */
-    Map<String,Integer> skillLevel = new HashMap<>();
-}

+ 15 - 8
logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipPropertyItem.java → logic/equip-logic/src/main/java/com/iohao/mmo/equip/entity/EquipQuality.java

@@ -19,13 +19,16 @@
 package com.iohao.mmo.equip.entity;
 
 import lombok.AccessLevel;
+import lombok.Builder;
 import lombok.Data;
 import lombok.experimental.FieldDefaults;
 import org.springframework.data.annotation.Id;
 import org.springframework.data.mongodb.core.mapping.Document;
 
+import java.util.List;
+
 /**
- * 元素攻击
+ * 装备
  *
  * @author 唐斌
  * @date 2023-07-26
@@ -33,11 +36,15 @@ import org.springframework.data.mongodb.core.mapping.Document;
 @Data
 @Document
 @FieldDefaults(level = AccessLevel.PRIVATE)
-public class EquipPropertyItem {
-    /**对应属性字典 */
-    String itemType;
-    /** 增加数值类型:1增加数字,2增加百分比(小数) */
-    int effectType;
-    /** 增加数值 */
-    int effectValue;
+public class EquipQuality {
+    @Id
+    String id;
+    /** 品质 white白色,yellow黄色,green绿色,blue蓝色,red红色,purple紫色,ghost鬼装*/
+    String quality;
+    /** 最小随机词条数 */
+    int randomNumMin;
+    /** 最大随机词条数 */
+    int randomNumMax;
+    /** 词条数对应随机权重,从少到多 */
+    int[] prizeWeightArr;
 }

+ 2 - 2
logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipEntryTemplateService.java

@@ -88,7 +88,7 @@ public class EquipEntryTemplateService {
     }
 
     /**
-     * 根据装备部位、数量 随机词条模板
+     * 根据装备部位、数量 随机词条
      * @param position 部位
      * @param count 随机数量
      * @return
@@ -142,7 +142,7 @@ public class EquipEntryTemplateService {
     }
 
     /**
-     * 根据装备等级、编号查找词条模板并随机出词条
+     * 根据装备等级、编号查找词条并随机出词条
      * @param level 等级
      * @param code 编号
      * @return

+ 88 - 0
logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipQualityService.java

@@ -0,0 +1,88 @@
+/*
+ * ioGame
+ * Copyright (C) 2021 - 2023  渔民小镇 (262610965@qq.com、luoyizhu@gmail.com) . All Rights Reserved.
+ * # iohao.com . 渔民小镇
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+package com.iohao.mmo.equip.service;
+
+import com.iohao.mmo.common.kit.ConvertKit;
+import com.iohao.mmo.common.kit.RandomKit;
+import com.iohao.mmo.equip.entity.EquipEntry;
+import com.iohao.mmo.equip.entity.EquipEntryProperty;
+import com.iohao.mmo.equip.entity.EquipEntryTemplate;
+import com.iohao.mmo.equip.entity.EquipQuality;
+import com.iohao.mmo.equip.kit.EquipRandomKit;
+import lombok.AllArgsConstructor;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * 装备品质库
+ *
+ * @author 唐斌
+ * @date 2023-07-30
+ * @description: 装备品质库
+ */
+@Service
+@AllArgsConstructor
+public class EquipQualityService {
+
+    final MongoTemplate mongoTemplate;
+
+    /**
+     * 通过id查询装备品质库
+     * @param id 装备品质库id
+     * @return
+     */
+    public EquipQuality findById(String id) {
+        return  mongoTemplate.findById(id, EquipQuality.class);
+    }
+
+    /**
+     * 通过code查询装备品质库
+     * @param quality 装备品质库编码
+     * @return
+     */
+    public EquipQuality findByQuality(String quality) {
+        return  mongoTemplate.findOne(
+                Query.query(new Criteria("quality").is(quality)), EquipQuality.class);
+    }
+
+    /**
+     * 保存装备品质库
+     * @param equipQuality 装备品质库
+     */
+    public void save(EquipQuality equipQuality) {
+        mongoTemplate.save(equipQuality);
+    }
+
+    /**
+     * 根据装备品质库id列表批量删除装备库
+     * @param idList 装备品质库id列表
+     */
+    public void delBatch(List<String> idList) {
+        Query query = new Query(new Criteria("id").in(idList));
+        mongoTemplate.remove(query, EquipQuality.class);
+    }
+
+}

+ 0 - 4
logic/equip-logic/src/main/java/com/iohao/mmo/equip/service/EquipService.java

@@ -20,15 +20,11 @@ package com.iohao.mmo.equip.service;
 
 import com.iohao.mmo.common.config.GameCode;
 import com.iohao.mmo.equip.entity.EquipEntry;
-import com.iohao.mmo.equip.entity.EquipPropertyElse;
 import com.iohao.mmo.equip.entity.Equip;
-import com.iohao.mmo.equip.entity.EquipTemplate;
-import com.iohao.mmo.equip.kit.EquipRandomKit;
 import lombok.AllArgsConstructor;
 import org.springframework.data.mongodb.core.MongoTemplate;
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
-import org.springframework.data.mongodb.core.query.Update;
 import org.springframework.stereotype.Service;
 import java.math.BigDecimal;
 import java.util.List;

+ 29 - 10
logic/excel-logic/src/main/java/com/iohao/mmo/excel/controller/EquipExcelController.java

@@ -3,12 +3,16 @@ package com.iohao.mmo.excel.controller;
 import com.alibaba.excel.EasyExcel;
 import com.iohao.mmo.common.kit.Result;
 import com.iohao.mmo.equip.entity.EquipEntryTemplate;
+import com.iohao.mmo.equip.entity.EquipQuality;
 import com.iohao.mmo.excel.dto.EquipEntryTemplateExcelDTO;
+import com.iohao.mmo.excel.dto.EquipQualityExcelDTO;
 import com.iohao.mmo.excel.dto.EquipTemplateExcelDTO;
 import com.iohao.mmo.excel.kit.ExcelKit;
 import com.iohao.mmo.excel.listener.EquipEntryTemplateExcelListener;
+import com.iohao.mmo.excel.listener.EquipQualityExcelListener;
 import com.iohao.mmo.excel.listener.EquipTemplateExcelListener;
 import com.iohao.mmo.excel.service.EquipEntryTemplateExcelService;
+import com.iohao.mmo.excel.service.EquipQualityExcelService;
 import com.iohao.mmo.excel.service.EquipTemplateExcelService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -31,32 +35,33 @@ import java.util.Map;
 @RequestMapping("/equipexcel")
 @Tag(name = "EquipExcelController", description = "装备excel数据")
 public class EquipExcelController {
+    private final EquipQualityExcelService equipQualityExcelService;
+
     private final EquipTemplateExcelService equipTemplateExcelService;
 
     private final EquipEntryTemplateExcelService equipEntryTemplateExcelService;
 
     /**
-     * 导入装备模板
+     * 导入装备品质库
      * @param file
      * @return
      * @throws Exception
      */
-    @PostMapping(value = "importEquipExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
-    @Operation(summary = "导入装备模板",description = "导入装备模板")
-    public Result importEquipExcel(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
+    @PostMapping(value = "importEquipQualityExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    @Operation(summary = "导入装备品质库",description = "导入装备品质库")
+    public Result importEquipQualityExcel(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
         //自定义读取
-        EasyExcel.read(file.getInputStream(), EquipTemplateExcelDTO.class, new EquipTemplateExcelListener<>(equipTemplateExcelService,2)).sheet(0).doRead();
+        EasyExcel.read(file.getInputStream(), EquipQualityExcelDTO.class, new EquipQualityExcelListener<>(equipQualityExcelService,2)).sheet(0).doRead();
         return new Result().ok("导入成功!");
     }
 
-
     /**
-     * 导出装备词条模板
+     * 导出装备词条
      * @param params
      * @param response
      * @throws Exception
      */
-    @Operation(summary = "导出装备词条模板",description = "导出装备词条模板")
+    @Operation(summary = "导出装备词条库",description = "导出装备词条库")
     @GetMapping("exportEntryExcel")
     public void exportEntryExcel(@RequestParam Map<String, Object> params, HttpServletResponse response) throws Exception{
         List<EquipEntryTemplate> list = equipEntryTemplateExcelService.list(params,EquipEntryTemplate.class);
@@ -64,13 +69,13 @@ public class EquipExcelController {
     }
 
     /**
-     * 导入装备词条模板
+     * 导入装备词条
      * @param file
      * @return
      * @throws Exception
      */
     @PostMapping(value = "importEntryExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
-    @Operation(summary = "导入装备词条模板",description = "导入装备词条模板")
+    @Operation(summary = "导入装备词条库",description = "导入装备词条库")
     public Result importEntryExcel(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
         //自定义读取
         EasyExcel.read(file.getInputStream(), EquipEntryTemplateExcelDTO.class, new EquipEntryTemplateExcelListener<>(equipEntryTemplateExcelService,2)).sheet(0).doRead();
@@ -79,4 +84,18 @@ public class EquipExcelController {
 //        list.forEach(System.out::println);
         return new Result().ok("导入成功!");
     }
+
+    /**
+     * 导入装备库
+     * @param file
+     * @return
+     * @throws Exception
+     */
+    @PostMapping(value = "importEquipExcel", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
+    @Operation(summary = "导入装备库",description = "导入装备库")
+    public Result importEquipExcel(@RequestPart("file") @Parameter(description = "文件")MultipartFile file) throws Exception {
+        //自定义读取
+        EasyExcel.read(file.getInputStream(), EquipTemplateExcelDTO.class, new EquipTemplateExcelListener<>(equipTemplateExcelService,2)).sheet(0).doRead();
+        return new Result().ok("导入成功!");
+    }
 }

+ 35 - 0
logic/excel-logic/src/main/java/com/iohao/mmo/excel/dto/EquipQualityExcelDTO.java

@@ -0,0 +1,35 @@
+package com.iohao.mmo.excel.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import com.iohao.mmo.excel.dto.converter.PositionConverter;
+import com.iohao.mmo.excel.dto.converter.QualityConverter;
+import lombok.Data;
+
+/**
+ * 装备品质Excel
+ *
+ * @author Toby javatangbin@163.com
+ */
+@Data
+@ContentRowHeight(20)
+@HeadRowHeight(20)
+@ColumnWidth(25)
+public class EquipQualityExcelDTO {
+    @ColumnWidth(20)
+    @ExcelProperty(value ="品质",index = 0, converter = QualityConverter.class)
+    private String quality;
+
+    @ExcelProperty(value ="最小随机词条数",index = 1)
+    private int randomNumMin;
+
+    @ColumnWidth(20)
+    @ExcelProperty(value = "最大随机词条数",index = 2)
+    private int randomNumMax;
+
+    @ExcelProperty(value = "词条数对应随机权重",index = 3)
+    private String prizeWeightStr;
+
+}

+ 1 - 1
logic/excel-logic/src/main/java/com/iohao/mmo/excel/listener/EquipEntryTemplateExcelListener.java

@@ -19,7 +19,7 @@ import java.util.Arrays;
 import java.util.List;
 
 /**
- * 装备词条模板excel(公共列未合并)
+ * 装备词条excel(公共列未合并)
  *
  * @author Toby javatangbin@163.com
  */

+ 136 - 0
logic/excel-logic/src/main/java/com/iohao/mmo/excel/listener/EquipQualityExcelListener.java

@@ -0,0 +1,136 @@
+package com.iohao.mmo.excel.listener;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.alibaba.excel.metadata.CellExtra;
+import com.alibaba.fastjson2.JSONObject;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.iohao.mmo.common.kit.ConvertKit;
+import com.iohao.mmo.equip.entity.EquipQuality;
+import com.iohao.mmo.excel.dto.EquipQualityExcelDTO;
+import com.iohao.mmo.excel.service.EquipQualityExcelService;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * 装备品质库excel(公共列未合并)
+ *
+ * @author Toby javatangbin@163.com
+ */
+public class EquipQualityExcelListener<E, T> extends AnalysisEventListener<T> {
+    private static final Logger LOGGER = LoggerFactory.getLogger(EquipQualityExcelListener.class);
+    /**
+     * 每隔2000条存储数据库,然后清理list,方便内存回收
+     */
+    private static final int BATCH_COUNT = 2000;
+    private final List<EquipQuality> equipQualityList = new ArrayList<>();
+
+    /**
+     * 通过构造器注入Service
+     */
+    private final EquipQualityExcelService equipQualityExcelService;
+    /**
+     * 表头行数
+     */
+    int headRowNumber = 1;
+
+    /**
+     * 构造方法
+     *
+     * @param equipQualityExcelService Service对象
+     */
+    public EquipQualityExcelListener(EquipQualityExcelService equipQualityExcelService, int headRowNumber) {
+        this.equipQualityExcelService = equipQualityExcelService;
+        this.headRowNumber = headRowNumber;
+    }
+
+    /**
+     * 每条数据解析完,都会调用此方法
+     */
+    @Override
+    public void invoke(T data, AnalysisContext context) {
+        //装备属性浮动,最小值为最大值的多少比例
+        double minPct = 0.8;
+        LOGGER.info("解析到一条数据:{}", JSONObject.toJSONString(data));
+        EquipQualityExcelDTO excel = ConvertKit.sourceToTarget(data, EquipQualityExcelDTO.class);
+
+        EquipQuality equipQuality = ConvertKit.sourceToTarget(excel, EquipQuality.class);
+        //随机权重
+        if(StringUtils.isNotBlank(excel.getPrizeWeightStr())) {
+            String[] prizeWeightStrArr = excel.getPrizeWeightStr().split("-");
+            equipQuality.setPrizeWeightArr(Arrays.stream(prizeWeightStrArr).mapToInt(Integer::parseInt).toArray());
+        }
+
+        equipQualityList.add(equipQuality);
+        // 达到BATCH_COUNT了,需要去存储一次数据库,防止数据几万条数据在内存,容易OOM
+        if (equipQualityList.size() >= BATCH_COUNT) {
+            saveData();
+            // 存储完成清理 list
+            equipQualityList.clear();
+        }
+    }
+    @Override
+    public void extra(CellExtra extra, AnalysisContext context) {
+        switch (extra.getType()) {
+            case COMMENT: {
+                LOGGER.info("额外信息是批注,在rowIndex:{},columnIndex;{},内容是:{}", extra.getRowIndex(), extra.getColumnIndex(),
+                        extra.getText());
+                break;
+            }
+            case HYPERLINK: {
+                if ("Sheet1!A1".equals(extra.getText())) {
+                    LOGGER.info("额外信息是超链接,在rowIndex:{},columnIndex;{},内容是:{}", extra.getRowIndex(),
+                            extra.getColumnIndex(), extra.getText());
+                } else if ("Sheet2!A1".equals(extra.getText())) {
+                    LOGGER.info(
+                            "额外信息是超链接,而且覆盖了一个区间,在firstRowIndex:{},firstColumnIndex;{},lastRowIndex:{},lastColumnIndex:{},"
+                                    + "内容是:{}",
+                            extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(),
+                            extra.getLastColumnIndex(), extra.getText());
+                } else {
+                    LOGGER.info("Unknown hyperlink!");
+                }
+                break;
+            }
+            case MERGE: {
+                LOGGER.info(
+                        "额外信息是合并单元格,而且覆盖了一个区间,在firstRowIndex:{},firstColumnIndex;{},lastRowIndex:{},lastColumnIndex:{}",
+                        extra.getFirstRowIndex(), extra.getFirstColumnIndex(), extra.getLastRowIndex(),
+                        extra.getLastColumnIndex());
+                if (extra.getRowIndex() >= headRowNumber) {
+//                    extraMergeInfoList.add(extra);
+                }
+                break;
+            }
+            default: {
+            }
+        }
+    }
+
+    /**
+     * 所有数据解析完成了 都会来调用
+     */
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext context) {
+        // 这里也要保存数据,确保最后遗留的数据也存储到数据库
+        saveData();
+        LOGGER.info("所有数据解析完成!");
+    }
+    /**
+     * 加上存储数据库
+     */
+    private void saveData() {
+        LOGGER.info("{}条数据,开始存储数据库!", equipQualityList.size());
+        try {
+            //根据code批量更新或者插入
+            equipQualityExcelService.updateBatch(equipQualityList);
+        } catch (JsonProcessingException e) {
+            throw new RuntimeException(e);
+        }
+        LOGGER.info("存储数据库成功!");
+    }
+}

+ 23 - 0
logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/EquipQualityExcelService.java

@@ -0,0 +1,23 @@
+package com.iohao.mmo.excel.service;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.iohao.mmo.equip.entity.EquipEntry;
+import com.iohao.mmo.equip.entity.EquipQuality;
+import com.iohao.mmo.equip.entity.EquipTemplate;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+
+/**
+ * 装备库Excel
+ *
+ * @author 唐斌
+ * @date 2023-08-30
+ * @description: 装备词条Excel
+ */
+public interface EquipQualityExcelService extends BaseService<EquipQuality>{
+
+    @Transactional(rollbackFor = Exception.class)
+    void updateBatch(List<EquipQuality> entityList) throws JsonProcessingException;
+}

+ 1 - 1
logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/EquipTemplateExcelService.java

@@ -8,7 +8,7 @@ import java.util.List;
 
 
 /**
- * 装备模板Excel
+ * 装备Excel
  *
  * @author 唐斌
  * @date 2023-08-30

+ 66 - 0
logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/impl/EquipQualityExcelServiceImpl.java

@@ -0,0 +1,66 @@
+package com.iohao.mmo.excel.service.impl;
+
+import com.iohao.mmo.equip.entity.EquipQuality;
+import com.iohao.mmo.equip.service.EquipQualityService;
+import com.iohao.mmo.excel.service.EquipQualityExcelService;
+import com.mongodb.bulk.BulkWriteResult;
+import org.apache.commons.collections4.CollectionUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.mongodb.core.BulkOperations;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.core.query.Update;
+import org.springframework.data.util.Pair;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * 装备词条Excel
+ *
+ * @author 唐斌
+ * @date 2023-08-30
+ * @description: 装备词条Excel
+ */
+@Service
+public class EquipQualityExcelServiceImpl extends BaseServiceImpl<EquipQuality> implements EquipQualityExcelService {
+    final MongoTemplate mongoTemplate;
+
+    @Autowired
+    EquipQualityService equipQualityService;
+
+    public EquipQualityExcelServiceImpl(MongoTemplate mongoTemplate) {
+        super(mongoTemplate);
+        this.mongoTemplate = mongoTemplate;
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateBatch(List<EquipQuality> entityList) {
+        if (CollectionUtils.isEmpty(entityList)) {
+            return;
+        }
+        List<Pair<Query, Update>> updateList = new ArrayList<>(entityList.size());
+        BulkOperations operations = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, "equipQuality");
+        entityList.forEach(data -> {
+            //以code为标识判断新增或者修改
+            Query query = new Query(new Criteria("quality").is(data.getQuality()));
+            Update update = new Update();
+            //如果userId是主键,必须使用setOnInsert()
+            update.set("randomNumMin",data.getRandomNumMin());
+            update.set("randomNumMax",data.getRandomNumMax());
+            update.set("quality",data.getQuality());
+            update.set("prizeWeightArr",data.getPrizeWeightArr());
+
+            Pair<Query, Update> updatePair = Pair.of(query, update);
+            updateList.add(updatePair);
+        });
+        operations.upsert(updateList);
+        BulkWriteResult result = operations.execute();
+        System.out.println(result.getUpserts());
+    }
+
+}

+ 2 - 2
logic/excel-logic/src/main/java/com/iohao/mmo/excel/service/impl/EquipTemplateExcelServiceImpl.java

@@ -74,7 +74,7 @@ public class EquipTemplateExcelServiceImpl extends BaseServiceImpl<EquipTemplate
     }
 
     /**
-     * 根据装备等级、编号查找词条模板并随机出词条
+     * 根据装备等级、编号查找词条并随机出词条
      * @param level 等级
      * @param code 编号
      * @return
@@ -85,7 +85,7 @@ public class EquipTemplateExcelServiceImpl extends BaseServiceImpl<EquipTemplate
     }
 
     /**
-     * 根据装备等级、编号查找词条模板并随机出词条
+     * 根据装备等级、编号查找词条并随机出词条
      * @param level 等级
      * @param position 部位
      * @param count 随机数量

+ 1 - 1
provide/equip-provide/src/main/java/com/iohao/mmo/equip/proto/EquipMessage.java

@@ -42,7 +42,7 @@ public class EquipMessage{
     String position;
     /** 要求等级 */
     int level;
-    /** 品质 1白色,2黄色,3绿色,4蓝色,5紫色,6鬼装*/
+    /** 品质 white白色,yellow黄色,green绿色,blue蓝色,red红色,purple紫色,ghost鬼装*/
     String quality;
     /** 耐久度 */
     int durability;