瀏覽代碼

游戏统计

kk 8 月之前
父節點
當前提交
ab2ed00da5

+ 73 - 4
game-business/src/main/java/com/game/business/controller/AppGameBettingController.java

@@ -3,18 +3,23 @@ package com.game.business.controller;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.game.business.domain.*;
+import com.game.business.dto.AppGameBettingCountDTO;
+import com.game.business.dto.AppGameBettingDetailsCountDTO;
 import com.game.business.service.*;
 import com.game.common.core.controller.BaseController;
 import com.game.common.core.domain.AjaxResult;
+import com.game.common.core.page.TableDataInfo;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
 
 @RestController
 @RequestMapping("/game/betting")
@@ -43,6 +48,7 @@ public class AppGameBettingController extends BaseController{
      * 下注
      */
     @PostMapping(value = "/create")
+    @ApiOperation(value = "游戏下注", notes = "游戏下注")
     public AjaxResult betting(@RequestBody AppGameBetting gameBetting)
     {
 
@@ -169,4 +175,67 @@ public class AppGameBettingController extends BaseController{
 
         return success();
     }
+
+    /**
+     * 游戏输赢统计
+     */
+    @GetMapping(value = "/count")
+    public AjaxResult getCount(@RequestParam(name = "strDate") String strDate)
+    {
+        AppGameBettingCountDTO appGameBettingCountDTO = new AppGameBettingCountDTO();
+        List<AppGame> gameList = appGameService.selectAppGameList(new AppGame());
+
+        if(gameList == null || gameList.isEmpty()){
+            return success(appGameBettingCountDTO);
+        }
+
+        List<AppGameBettingDetailsCountDTO> countList = appGameBettingService.getCount(strDate);
+        if(countList == null){
+            countList = new ArrayList<>();
+        }
+        Map<Long, List<AppGameBettingDetailsCountDTO>> idGameMap = countList.stream().collect(Collectors.groupingBy(AppGameBettingDetailsCountDTO::getGameId));
+
+        List<AppGameBettingDetailsCountDTO> newList = new ArrayList<>();
+        double orderAmount = 0.00;
+        double winAmount = 0.00;
+        double loseAmount = 0.00;
+        for (int i = 0; i < gameList.size(); i++) {
+            AppGame appGame = gameList.get(i);
+            AppGameBettingDetailsCountDTO appGameBettingDetailsCountDTO = new AppGameBettingDetailsCountDTO();
+            appGameBettingDetailsCountDTO.setGameId(appGame.getId());
+            appGameBettingDetailsCountDTO.setGameName(appGame.getName());
+            if(idGameMap.containsKey(appGame.getId())){
+                AppGameBettingDetailsCountDTO dbAppGameBettingDetailsCount = idGameMap.get(appGame.getId()).get(0);
+                appGameBettingDetailsCountDTO.setBettingCount(dbAppGameBettingDetailsCount.getBettingCount());
+                appGameBettingDetailsCountDTO.setOrderAmount(dbAppGameBettingDetailsCount.getOrderAmount());
+                appGameBettingDetailsCountDTO.setWinAmount(dbAppGameBettingDetailsCount.getWinAmount());
+                appGameBettingDetailsCountDTO.setLoseAmount(dbAppGameBettingDetailsCount.getLoseAmount());
+                orderAmount += dbAppGameBettingDetailsCount.getOrderAmount();
+                winAmount += dbAppGameBettingDetailsCount.getWinAmount();
+                loseAmount += dbAppGameBettingDetailsCount.getLoseAmount();
+            }else{
+                appGameBettingDetailsCountDTO.setBettingCount(0);
+                appGameBettingDetailsCountDTO.setOrderAmount(0.00);
+                appGameBettingDetailsCountDTO.setWinAmount(0.00);
+                appGameBettingDetailsCountDTO.setLoseAmount(0.00);
+            }
+            newList.add(appGameBettingDetailsCountDTO);
+        }
+        appGameBettingCountDTO.setOrderAmount(orderAmount);
+        appGameBettingCountDTO.setWinAmount(winAmount);
+        appGameBettingCountDTO.setLoseAmount(loseAmount);
+        appGameBettingCountDTO.setList(newList);
+        return success(appGameBettingCountDTO);
+    }
+
+    /**
+     * 游戏输赢详情列表
+     */
+    @GetMapping(value = "/listByGameId")
+    public TableDataInfo getListByGameId(@RequestParam(name = "gameId") Long gameId)
+    {
+        startPage();
+        List<AppGameBetting> list = appGameBettingService.selectListByGameId(gameId);
+        return getDataTable(list);
+    }
 }

+ 1 - 1
game-business/src/main/java/com/game/business/domain/AppGameBetting.java

@@ -66,7 +66,7 @@ public class AppGameBetting {
 
     @Excel(name = "开奖时间")
     @TableField(value = "update_time")
-    @ApiModelProperty(value = "投注时间")
+    @ApiModelProperty(value = "开奖时间")
     private Date updateTime;
 
 }

+ 24 - 0
game-business/src/main/java/com/game/business/dto/AppGameBettingCountDTO.java

@@ -0,0 +1,24 @@
+package com.game.business.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+@ApiModel(description = "游戏输赢汇总")
+public class AppGameBettingCountDTO {
+
+    @ApiModelProperty(value = "下单金额")
+    private double orderAmount;
+
+    @ApiModelProperty(value = "赢")
+    private double winAmount;
+
+    @ApiModelProperty(value = "输")
+    private double loseAmount;
+
+    @ApiModelProperty(value = "游戏列表统计")
+    private List<AppGameBettingDetailsCountDTO> list;
+}

+ 28 - 0
game-business/src/main/java/com/game/business/dto/AppGameBettingDetailsCountDTO.java

@@ -0,0 +1,28 @@
+package com.game.business.dto;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+@Data
+@ApiModel(description = "游戏输赢详情")
+public class AppGameBettingDetailsCountDTO {
+
+    @ApiModelProperty(value = "游戏ID")
+    private Long gameId;
+
+    @ApiModelProperty(value = "游戏名称")
+    private String gameName;
+
+    @ApiModelProperty(value = "数量")
+    private long bettingCount;
+
+    @ApiModelProperty(value = "下单金额")
+    private double orderAmount;
+
+    @ApiModelProperty(value = "赢")
+    private double winAmount;
+
+    @ApiModelProperty(value = "输")
+    private double loseAmount;
+}

+ 5 - 0
game-business/src/main/java/com/game/business/mapper/AppGameBettingMapper.java

@@ -3,6 +3,11 @@ package com.game.business.mapper;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.AppGameBettingDetailsCountDTO;
+
+import java.util.List;
 
 public interface AppGameBettingMapper extends BaseMapper<AppGameBetting> {
+
+    List<AppGameBettingDetailsCountDTO> getCount(String strDate);
 }

+ 5 - 1
game-business/src/main/java/com/game/business/service/IAppGameBettingService.java

@@ -2,15 +2,19 @@ package com.game.business.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.AppGameBettingDetailsCountDTO;
 
 import java.util.List;
 
 public interface IAppGameBettingService extends IService<AppGameBetting> {
 
-
     List<AppGameBetting> getIsWinning(Long classId, Long gameId, String gameDate, Integer isWinning);
 
     boolean updateById(AppGameBetting appGameBetting);
 
     boolean save(AppGameBetting appGameBetting);
+
+    List<AppGameBettingDetailsCountDTO> getCount(String strDate);
+
+    List<AppGameBetting> selectListByGameId(Long gameId);
 }

+ 15 - 0
game-business/src/main/java/com/game/business/service/impl/AppGameBettingServiceImpl.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.game.business.domain.AppGameBetting;
+import com.game.business.dto.AppGameBettingDetailsCountDTO;
 import com.game.business.mapper.AppGameBettingMapper;
 import com.game.business.service.IAppGameBettingService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,4 +39,18 @@ public class AppGameBettingServiceImpl extends ServiceImpl<AppGameBettingMapper,
     public boolean save(AppGameBetting appGameBetting) {
         return appGameBettingMapper.insert(appGameBetting) > 0;
     }
+
+    @Override
+    public List<AppGameBettingDetailsCountDTO> getCount(String strDate) {
+        return appGameBettingMapper.getCount(strDate);
+    }
+
+    @Override
+    public List<AppGameBetting> selectListByGameId(Long gameId) {
+        LambdaQueryWrapper<AppGameBetting> queryWrapper = Wrappers.lambdaQuery();;
+        queryWrapper.eq(AppGameBetting::getGameId, gameId);
+        queryWrapper.ne(AppGameBetting::getIsWinning, 0);
+        queryWrapper.orderByDesc(AppGameBetting::getCreateTime);
+        return appGameBettingMapper.selectList(queryWrapper);
+    }
 }

+ 17 - 0
game-business/src/main/resources/mapper/business/AppGameBettingMapper.xml

@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.game.business.mapper.AppGameBettingMapper">
+
+    <select id="getCount" resultType="com.game.business.dto.AppGameBettingDetailsCountDTO">
+        select
+        game_id as gameId,
+        count(id) as bettingCount,
+        sum(betting_amount) as orderAmount,
+        sum(case when is_winning = 1 then (betting_amount * betting_multiple) else 0.00 end) as winAmount,
+        sum(case when is_winning = 2 then (betting_amount) else 0.00 end) as loseAmount
+        from app_game_betting  where date_format(create_time, '%Y-%m-%d') = #{strDate}
+        group by game_id
+    </select>
+</mapper>