cup 2 years ago
parent
commit
50d27d9a2f

+ 2 - 0
mp-admin/src/main/java/com/qs/mp/web/controller/api/user/UserExchangeController.java

@@ -91,6 +91,7 @@ public class UserExchangeController extends BaseApiController {
     List<GoodsCategory> categoryList = goodsCategoryService.list(
             new LambdaQueryWrapper<GoodsCategory>()
                     .eq(GoodsCategory::getParentId, 0)
+                    .eq(GoodsCategory::getIsShow, 1)
                     .orderByDesc(GoodsCategory::getSort));
     if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isEmpty(categoryList)) {
       return getErrorDataTable("分类信息不存在");
@@ -103,6 +104,7 @@ public class UserExchangeController extends BaseApiController {
       List<GoodsCategory> list = goodsCategoryService.list(
               new LambdaQueryWrapper<GoodsCategory>()
                       .eq(GoodsCategory::getParentId, goodsCategory.getCategoryId())
+                      .eq(GoodsCategory::getIsShow, 1)
                       .orderByDesc(GoodsCategory::getSort));
       goodsCategoryTreeVO.setGoodsCategoryList(list);
       return goodsCategoryTreeVO;

+ 26 - 15
mp-admin/src/main/java/com/qs/mp/web/controller/api/user/UserTicketController.java

@@ -125,24 +125,35 @@ public class UserTicketController extends BaseApiController {
       TicketBox ticketBox = ticketBoxService.getById(param.getBoxId());
       TicketBoxVO ticketBoxVO = mapperFacade.map(ticketBox, TicketBoxVO.class);
       // 设置奖项标签信息
-      List<TicketAwardsLabelVO> ticketAwardsLabelVOS = new ArrayList<>();
-      for (AwardsLabelEnum awardsLabelEnum : AwardsLabelEnum.values()) {
-      TicketAwardsLabelVO ticketAwardsLabelVO = new TicketAwardsLabelVO();
-      ticketAwardsLabelVO.setLabelTitle(awardsLabelEnum.getValue());
-      ticketAwardsLabelVO.setPicUrl(awardsLabelEnum.getPicUrl());
-      Integer quantity = ticketBox.getQuantity();
       QueryWrapper<TicketAwards> queryWrapper = new QueryWrapper<>();
-      queryWrapper.eq("awards_label",awardsLabelEnum.getValue());
       queryWrapper.eq("box_id",ticketBox.getBoxId());
-      Integer num = ticketAwardsService.groupSumQuantityByQueryWrapper(queryWrapper);
-      if (Objects.isNull(num) || num == 0) {
-        continue;
-//        ticketAwardsLabelVO.setHitRate(new BigDecimal(0));
-      }else {
-        ticketAwardsLabelVO.setHitRate(BigDecimal.valueOf(num).divide(BigDecimal.valueOf(quantity), 3, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
+      queryWrapper.groupBy("awards_label");
+      StringBuilder sortField = new StringBuilder("FIELD(awards_label,'");
+      int index = 0;
+      for (AwardsLabelEnum awardsLabelEnum : AwardsLabelEnum.values()) {
+        index++;
+        if (index == AwardsLabelEnum.values().length) {
+          sortField.append(awardsLabelEnum.getValue()).append("'");
+        }else {
+          sortField.append(awardsLabelEnum.getValue()).append("','");
+        }
       }
-      ticketAwardsLabelVOS.add(ticketAwardsLabelVO);
-    }
+      sortField.append(")");
+      queryWrapper.orderByAsc(sortField.toString());
+      List<TicketAwardsLabelVO> ticketAwardsLabelVOS = ticketAwardsService.groupSumQuantityByQueryWrapper(queryWrapper);
+      if (CollectionUtils.isNotEmpty(ticketAwardsLabelVOS)) {
+        for (TicketAwardsLabelVO ticketAwardsLabelVO : ticketAwardsLabelVOS) {
+          AwardsLabelEnum awardsLabelEnum = AwardsLabelEnum.getByValue(ticketAwardsLabelVO.getLabelTitle());
+          if (Objects.isNull(awardsLabelEnum)) {
+            continue;
+          }
+          ticketAwardsLabelVO.setPicUrl(awardsLabelEnum.getPicUrl());
+          Integer quantity = ticketBox.getQuantity();
+          int num = ticketAwardsLabelVO.getQuantity();
+          ticketAwardsLabelVO.setHitRate(BigDecimal.valueOf(num).divide(BigDecimal.valueOf(quantity), 3, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)));
+        }
+      }
+
     if (CollectionUtils.isNotEmpty(ticketAwardsLabelVOS)) {
       // 精度问题处理
       int maxIndex = 0;

+ 4 - 1
mp-service/src/main/java/com/qs/mp/admin/mapper/TicketAwardsMapper.java

@@ -4,8 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.qs.mp.admin.domain.TicketAwards;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.qs.mp.user.domain.vo.TicketAwardsLabelVO;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /**
  * @auther quanshu
  * @create 2022-03-02 12:25:55
@@ -18,5 +21,5 @@ public interface TicketAwardsMapper extends BaseMapper<TicketAwards> {
      * @param queryWrapper
      * @return
      */
-    Integer groupSumQuantityByQueryWrapper(@Param(Constants.WRAPPER) QueryWrapper<TicketAwards> queryWrapper);
+    List<TicketAwardsLabelVO> groupSumQuantityByQueryWrapper(@Param(Constants.WRAPPER) QueryWrapper<TicketAwards> queryWrapper);
 }

+ 4 - 1
mp-service/src/main/java/com/qs/mp/admin/service/ITicketAwardsService.java

@@ -3,6 +3,9 @@ package com.qs.mp.admin.service;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.qs.mp.admin.domain.TicketAwards;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.qs.mp.user.domain.vo.TicketAwardsLabelVO;
+
+import java.util.List;
 
 /**
  * <p>
@@ -19,5 +22,5 @@ public interface ITicketAwardsService extends IService<TicketAwards> {
      * @param queryWrapper
      * @return
      */
-    Integer groupSumQuantityByQueryWrapper(QueryWrapper<TicketAwards> queryWrapper);
+    List<TicketAwardsLabelVO> groupSumQuantityByQueryWrapper(QueryWrapper<TicketAwards> queryWrapper);
 }

+ 4 - 1
mp-service/src/main/java/com/qs/mp/admin/service/impl/TicketAwardsServiceImpl.java

@@ -5,8 +5,11 @@ import com.qs.mp.admin.domain.TicketAwards;
 import com.qs.mp.admin.mapper.TicketAwardsMapper;
 import com.qs.mp.admin.service.ITicketAwardsService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qs.mp.user.domain.vo.TicketAwardsLabelVO;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  * 盲票盒奖项设置 服务实现类
@@ -21,7 +24,7 @@ public class TicketAwardsServiceImpl extends ServiceImpl<TicketAwardsMapper, Tic
 
 
     @Override
-    public Integer groupSumQuantityByQueryWrapper(QueryWrapper<TicketAwards> queryWrapper) {
+    public List<TicketAwardsLabelVO> groupSumQuantityByQueryWrapper(QueryWrapper<TicketAwards> queryWrapper) {
         return this.baseMapper.groupSumQuantityByQueryWrapper(queryWrapper);
     }
 }

+ 3 - 0
mp-service/src/main/java/com/qs/mp/user/domain/vo/TicketAwardsLabelVO.java

@@ -23,4 +23,7 @@ public class TicketAwardsLabelVO {
 
     @ApiModelProperty("中奖概率")
     private BigDecimal hitRate;
+
+    @ApiModelProperty("奖品数")
+    private Integer quantity;
 }

+ 2 - 2
mp-service/src/main/resources/mapper/admin/TicketAwardsMapper.xml

@@ -20,8 +20,8 @@
         awards_id, box_id, name, sort, quantity, memo, cashed_qty, created_time, updated_time
     </sql>
 
-    <select id="groupSumQuantityByQueryWrapper" resultType="int">
-        select sum(quantity)
+    <select id="groupSumQuantityByQueryWrapper" resultType="com.qs.mp.user.domain.vo.TicketAwardsLabelVO">
+        select awards_label labelTitle, SUM(quantity) as quantity
         from mp_ticket_awards
         ${ew.customSqlSegment}
     </select>