Răsfoiți Sursa

添加日志

chunping 3 ani în urmă
părinte
comite
a36162cf62

+ 5 - 6
mp-service/src/main/java/com/qs/mp/admin/service/impl/TicketBoxServiceImpl.java

@@ -144,17 +144,18 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
     if (ticketBox.getType() == TicketTypeEnum.OFFLINE) {
       int pkgNum = ticketBox.getPkgQty();
       int pkgUnit = ticketBox.getPkgUnit();
+
       // 1.把各奖级的中奖数量分摊到每包上
       Map<Integer, List<PkgAwards>> pkgAwardsMap = new HashMap<>();
+      for (int m = 1; m < pkgNum; m++) {
+        pkgAwardsMap.put(m, new ArrayList<PkgAwards>());
+      }
       for (int k = 0; k < ticketAwardsList.size(); k++) {
         TicketAwards ticketAwards = ticketAwardsList.get(k);
         if (ticketAwards.getQuantity() < pkgNum) {
           // 奖级数量少于包数的,随机不重复分配,随机数从1开始
           List<Integer> randomList = getRandomList(ticketAwards.getQuantity(), pkgNum);
           for (Integer pkgId : randomList) {
-            if (null == pkgAwardsMap.get(pkgId)) {
-              pkgAwardsMap.put(pkgId, new ArrayList<PkgAwards>());
-            }
             pkgAwardsMap.get(pkgId).add(
                 new PkgAwards(ticketAwards.getAwardsId(), ticketAwards.getName(),
                     ticketAwards.getSort(), ticketAwards.getQuantity()));
@@ -164,9 +165,6 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
           int remainQty = ticketAwards.getQuantity();
           for (int i = 1; i <= pkgNum; i++) {
             int quantity;
-            if (null == pkgAwardsMap.get(i)) {
-              pkgAwardsMap.put(i, new ArrayList<PkgAwards>());
-            }
             if (k == ticketAwardsList.size() - 1) {
               // 最后一个奖项直接分配奖级数量差额即可
               int hasQty = pkgAwardsMap.get(i).stream().mapToInt(PkgAwards::getQuantity).sum();
@@ -186,6 +184,7 @@ public class TicketBoxServiceImpl extends ServiceImpl<TicketBoxMapper, TicketBox
                     ticketAwards.getSort(), quantity));
           }
         }
+        LogUtil.debug(logger, "奖级{0}分包结果:{1}", new Object[]{k, JSONObject.toJSONString(pkgAwardsMap)});
       }
 
       // 生成票包记录和盲票记录