|
@@ -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;
|