From 3f7956fa7435a2b581336dc067cf8f25c1719e1c Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Fri, 01 Mar 2024 10:44:22 +0800
Subject: [PATCH] 抽奖

---
 src/main/java/cc/mrbird/febs/mall/service/impl/CJServiceImpl.java |  319 ++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 233 insertions(+), 86 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/CJServiceImpl.java b/src/main/java/cc/mrbird/febs/mall/service/impl/CJServiceImpl.java
index 76e0c51..901e7bc 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/CJServiceImpl.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/CJServiceImpl.java
@@ -42,10 +42,8 @@
 import java.text.ParseException;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Slf4j
 @Service
@@ -67,6 +65,12 @@
     public FebsResponse kjRecord(KjRecordDto kjRecordDto) {
         IPage<ApiKjRecordVo> page = new Page<>(kjRecordDto.getPageNum(), kjRecordDto.getPageSize());
         IPage<ApiKjRecordVo> pages = kjRecordMapper.selectListInPage(page, kjRecordDto);
+        List<ApiKjRecordVo> records = pages.getRecords();
+        if(CollUtil.isNotEmpty(records)){
+            for(ApiKjRecordVo apiKjRecordVo : records){
+                apiKjRecordVo.setKjNum(this.getKjNo(apiKjRecordVo.getKjNum()));
+            }
+        }
         return new FebsResponse().success().data(pages);
     }
 
@@ -95,51 +99,28 @@
         agentProducer.sendNoTimeDelayMsg(kjNo, (AppContants.KJ_RECORD_TIME_INTERVAL-1) * 60 * 1000L);//提一分钟停止下注
 
         //todo 测试下注
-//        ApiCreateDto apiCreateDto = new ApiCreateDto();
-//        List<ApiCreateItemDto> items = new ArrayList<>();
-//        ApiCreateItemDto apiCreateItemDto = new ApiCreateItemDto();
-//        apiCreateItemDto.setId(1L);
-//        apiCreateItemDto.setTzAmount(new BigDecimal("10"));
-//        items.add(apiCreateItemDto);
-//
-//        ApiCreateItemDto apiCreateItemDto2 = new ApiCreateItemDto();
-//        apiCreateItemDto2.setId(2L);
-//        apiCreateItemDto2.setTzAmount(new BigDecimal("10"));
-//        items.add(apiCreateItemDto2);
-//
-//        ApiCreateItemDto apiCreateItemDto3 = new ApiCreateItemDto();
-//        apiCreateItemDto3.setId(3L);
-//        apiCreateItemDto3.setTzAmount(new BigDecimal("10"));
-//        items.add(apiCreateItemDto3);
-//
-//        ApiCreateItemDto apiCreateItemDto4 = new ApiCreateItemDto();
-//        apiCreateItemDto4.setId(4L);
-//        apiCreateItemDto4.setTzAmount(new BigDecimal("10"));
-//        items.add(apiCreateItemDto4);
-//
-//        ApiCreateItemDto apiCreateItemDto5 = new ApiCreateItemDto();
-//        int randomInt = RandomUtil.randomInt(1, 25);
-//        apiCreateItemDto5.setId(Long.parseLong(String.valueOf(randomInt)));
-//        apiCreateItemDto5.setTzAmount(new BigDecimal("10"));
-//        items.add(apiCreateItemDto5);
-//        apiCreateDto.setItems(items);
-//
-//        for(int i = 0;i<=100;i++){
-//            asyncCjService.create(apiCreateDto);
-//        }
-
+        ApiCreateDto apiCreateDto = new ApiCreateDto();
+        List<ApiCreateItemDto> items = new ArrayList<>();
+        for(int i = 1;i<= 43;i++){
+            ApiCreateItemDto apiCreateItemDto6 = new ApiCreateItemDto();
+            apiCreateItemDto6.setId(Long.parseLong(String.valueOf(i)));
+            apiCreateItemDto6.setTzAmount(new BigDecimal("10"));
+            items.add(apiCreateItemDto6);
+        }
+        apiCreateDto.setItems(items);
+        asyncCjService.create(apiCreateDto,1L);
     }
 
     @Override
     public FebsResponse kjInfo() {
         ApiKjInfoVo apiKjInfoVo = new ApiKjInfoVo();
         String kjNoOld = redisUtils.getString(AppContants.KJ_RECORD_NO_OLD);
-        String kjNumOld = redisUtils.getString(AppContants.KJ_RECORD_NUM_OLD);
+        String kjNumOld = this.getKjNo(redisUtils.getString(AppContants.KJ_RECORD_NUM_OLD));
         if(StrUtil.isBlank(kjNoOld)){
             KjRecord kjRecordOld = kjRecordMapper.selectOneByLimitZero(1,1);
             if(ObjectUtil.isNotEmpty(kjRecordOld)){
                 apiKjInfoVo.setKjNoOld(kjRecordOld.getKjNo());
-                apiKjInfoVo.setKjNumOld(kjRecordOld.getKjNum());
+                apiKjInfoVo.setKjNumOld(this.getKjNo(kjRecordOld.getKjNum()));
             }
         }else{
             apiKjInfoVo.setKjNoOld(kjNoOld);
@@ -195,7 +176,7 @@
                 DataDictionaryEnum.OPEN_PRICE.getType(),
                 DataDictionaryEnum.OPEN_PRICE.getCode()
         );
-        int randomInt = RandomUtil.randomInt(1, 25);
+        int randomInt = RandomUtil.randomInt(1, 27);
         if(StrUtil.isNotEmpty(openPriceDic.getValue())){
             randomInt = Integer.parseInt(openPriceDic.getValue());
             openPriceDic.setValue("");
@@ -259,6 +240,12 @@
             if(BigDecimal.ZERO.compareTo(tzAmount) >= 0){
                 throw new FebsException("金额必须大于0");
             }
+            Long id = apiCreateItemDto.getId();//投注ID
+            TzInfo tzInfo = tzInfoMapper.selectById(id);
+            if(ObjectUtil.isEmpty(tzInfo)){
+                throw new FebsException("参数有误,请刷新页面");
+            }
+            apiCreateItemDto.setTzInfo(tzInfo);
             totalAmount = totalAmount.add(tzAmount);
         }
         if(mallMemberWallet.getBalance().compareTo(totalAmount) < 0){
@@ -280,10 +267,7 @@
 
         for(ApiCreateItemDto apiCreateItemDto : items){
             Long id = apiCreateItemDto.getId();//投注ID
-            TzInfo tzInfo = tzInfoMapper.selectById(id);
-            if(ObjectUtil.isEmpty(tzInfo)){
-                throw new FebsException("参数有误,请刷新页面");
-            }
+            TzInfo tzInfo = apiCreateItemDto.getTzInfo();
             BigDecimal tzAmount = apiCreateItemDto.getTzAmount().setScale(2,BigDecimal.ROUND_DOWN);//投注金额
             CjItem cjItem = new CjItem();
             cjItem.setInfoId(cjInfo.getId());
@@ -323,7 +307,13 @@
         if(CollUtil.isNotEmpty(records)){
             for(CjInfo item : records){
                 Long id = item.getId();
+                item.setKjNum(this.getKjNo(item.getKjNum()));
                 List<CjItem> cjItems = cjItemMapper.selectListByInfoId(id);
+                if(CollUtil.isNotEmpty(cjItems)){
+                    for(CjItem cjItem : cjItems){
+                        cjItem.setKjNum(this.getKjNo(cjItem.getKjNum()));
+                    }
+                }
                 item.setItems(cjItems);
             }
         }
@@ -351,51 +341,59 @@
         }
         String danshuang = judgeNumberOne(Integer.parseInt(kjNum));
         String daXiao = judgeNumberTwo(Integer.parseInt(kjNum));
+
+        DataDictionaryCustom redBallDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.RED_BALL.getType(),
+                DataDictionaryEnum.RED_BALL.getCode()
+        );
+        String hong = judgeNumberHong(kjNum, redBallDic);
+
+        DataDictionaryCustom blueBallDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.BLUE_BALL.getType(),
+                DataDictionaryEnum.BLUE_BALL.getCode()
+        );
+        String lan = judgeNumberLan(kjNum, blueBallDic);
+        DataDictionaryCustom colorBallDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.COLOR_BALL.getType(),
+                DataDictionaryEnum.COLOR_BALL.getCode()
+        );
+        String caiqiu = judgeNumberColor(kjNum, colorBallDic);
+        String liugehao = getGroupNumberSix(Integer.parseInt(kjNum));
+        String sangehao = getGroupNumberThree(Integer.parseInt(kjNum));
+
         for(CjInfo cjInfo : cjInfos){
-            asyncCjService.openPriceAsync(cjInfo,kjNum,danshuang,daXiao);
+            asyncCjService.openPriceAsync(cjInfo,kjNum,danshuang,daXiao,hong,lan,caiqiu,liugehao,sangehao);
         }
     }
 
     @Override
     public LinkedHashMap<String, JSON> getTzInfo() {
         LinkedHashMap<String, JSON> linkedHashMap = new LinkedHashMap<>();
-
-        ArrayList<ApiTzInfoVo> objectDaxiao = new ArrayList<>();
-        QueryWrapper<TzInfo> daxiaoQueryWrapper = new QueryWrapper<>();
-        daxiaoQueryWrapper.eq("type",1);
-        List<TzInfo> daXiaos = tzInfoMapper.selectList(daxiaoQueryWrapper);
-        if(CollUtil.isNotEmpty(daXiaos)){
-            for(TzInfo tzInfoRedis : daXiaos){
-                ApiTzInfoVo apiTzInfoVo = TzInfoConversion.INSTANCE.entityToVo(tzInfoRedis);
-                objectDaxiao.add(apiTzInfoVo);
-            }
-        }
-        linkedHashMap.put("daXiao", JSONUtil.parse(objectDaxiao));
-
-        ArrayList<ApiTzInfoVo> objectDanshuang = new ArrayList<>();
-        QueryWrapper<TzInfo> danshuangQueryWrapper = new QueryWrapper<>();
-        danshuangQueryWrapper.eq("type",2);
-        List<TzInfo> danShuangs = tzInfoMapper.selectList(danshuangQueryWrapper);
-        if(CollUtil.isNotEmpty(danShuangs)){
-            for(TzInfo tzInfoRedis : danShuangs){
-                ApiTzInfoVo apiTzInfoVo = TzInfoConversion.INSTANCE.entityToVo(tzInfoRedis);
-                objectDanshuang.add(apiTzInfoVo);
-            }
-        }
-        linkedHashMap.put("danShuang",JSONUtil.parse(objectDanshuang));
-
-        ArrayList<ApiTzInfoVo> objectShuZi = new ArrayList<>();
-        QueryWrapper<TzInfo> shuZiQueryWrapper = new QueryWrapper<>();
-        shuZiQueryWrapper.eq("type",3);
-        List<TzInfo> shuZis = tzInfoMapper.selectList(shuZiQueryWrapper);
-        if(CollUtil.isNotEmpty(shuZis)){
-            for(TzInfo tzInfoRedis : shuZis){
-                ApiTzInfoVo apiTzInfoVo = TzInfoConversion.INSTANCE.entityToVo(tzInfoRedis);
-                objectShuZi.add(apiTzInfoVo);
-            }
-        }
-        linkedHashMap.put("shuZi",JSONUtil.parse(objectShuZi));
-
+        List<TzInfo> tzInfos = tzInfoMapper.selectList(null);
+        linkedHashMap.put("daXiao", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 1).collect(Collectors.toList()))));
+        linkedHashMap.put("danShuang", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 2).collect(Collectors.toList()))));
+        linkedHashMap.put("shuZi", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 3).collect(Collectors.toList()))));
+        linkedHashMap.put("hong", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 4).collect(Collectors.toList()))));
+        linkedHashMap.put("caiqiu", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 5).collect(Collectors.toList()))));
+        linkedHashMap.put("liuHao", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 6).collect(Collectors.toList()))));
+        linkedHashMap.put("sanHao", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 7).collect(Collectors.toList()))));
+        linkedHashMap.put("lan", JSONUtil.parse(
+                TzInfoConversion.INSTANCE.entitysToVo(
+                        tzInfos.stream().filter(tzInfo -> tzInfo.getType() == 8).collect(Collectors.toList()))));
         //投注信息
         String tzInfoNoExit = redisUtils.getString(AppContants.TZ_INFO);
         if (StrUtil.isNotBlank(tzInfoNoExit)) {
@@ -406,12 +404,35 @@
         return linkedHashMap;
     }
 
+    @Override
+    public String getKjNo(String num) {
+        DataDictionaryCustom redBallDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.RED_BALL.getType(),
+                DataDictionaryEnum.RED_BALL.getCode()
+        );
+
+        DataDictionaryCustom blueBallDic = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(
+                DataDictionaryEnum.BLUE_BALL.getType(),
+                DataDictionaryEnum.BLUE_BALL.getCode()
+        );
+        if(redBallDic.getValue().equals(num)){
+            return "红";
+        }
+        if(blueBallDic.getValue().equals(num)){
+            return "蓝";
+        }
+        return num;
+    }
+
     /**
      * 取模运算符%来判断该数字是否为偶数。如果余数为0,则该数字为偶数,返回"双数";否则,该数字为奇数,返回"单数"
      * @param num
      * @return 1-单数 2-双数
      */
     public static String judgeNumberOne(int num) {
+        if(num > 24){
+            return String.valueOf(num);
+        }
         if (num % 2 == 0) {
             return "双";
         } else {
@@ -425,11 +446,137 @@
      * @return 1-小数 2-大数
      */
     public static String judgeNumberTwo(int num) {
-        if (num <= 12) {
-            return "小";
-        } else {
-            return "大";
+        if(num > 24){
+            return String.valueOf(num);
         }
+        if (num <= 12) {
+            return "龙1-12";
+        } else {
+            return "虎13-24";
+        }
+    }
+
+    /**
+     * 红
+     * @param num
+     */
+    public static String judgeNumberHong(String num,DataDictionaryCustom redBallDic) {
+        String redBall = redBallDic.getValue();
+        if (redBall.equals(num)) {
+            return "红球";
+        } else {
+            return num;
+        }
+    }
+
+    /**
+     * 蓝
+     * @param num
+     */
+    public static String judgeNumberLan(String num,DataDictionaryCustom blueBallDic) {
+        String blueBall = blueBallDic.getValue();
+        if (blueBall.equals(num)) {
+            return "蓝球";
+        } else {
+            return num;
+        }
+    }
+
+    /**
+     * 彩球
+     * @param num
+     */
+    public static String judgeNumberColor(String num,DataDictionaryCustom colorBallDic) {
+        String colorBall = colorBallDic.getValue();
+        List<String> colorBallList = Arrays.asList(StrUtil.split(colorBall, ","));
+        if (colorBallList.contains(num)) {
+            return "彩球";
+        } else {
+            return num;
+        }
+    }
+
+    /**
+     * 六个号
+     * 判断数字属于哪一组并返回组号
+     * @param number 1-24之间的数字
+     * @return 组号(1, 2, 3, 4)
+     */
+    /**
+     * 判断一个数字属于哪个组并返回组号
+     *
+     * @param num 输入的数字(1-24之间)
+     * @return 组号(1-4之间)
+     */
+    public static String getGroupNumberSix(int num) {
+        if(num > 24){
+            return String.valueOf(num);
+        }
+        // 使用整除来确定组号
+        int i = (num - 1) / 6 + 1;
+        if(1 == i){
+            return "1-6";
+        }else if(2 == i){
+            return "7-12";
+        }else if(3 == i){
+            return "13-18";
+        }else{
+            return "19-24";
+        }
+    }
+
+    /**
+     * 六个号
+     * 判断数字属于哪一组并返回组号
+     * @param number 1-24之间的数字
+     * @return 组号(1, 2, 3, 4)
+     */
+    /**
+     * 判断一个数字属于哪个组并返回组号
+     *
+     * @param num 输入的数字(1-24之间)
+     * @return 组号(1-4之间)
+     */
+    public static String getGroupNumberThree(int num) {
+        if(num > 24){
+            return String.valueOf(num);
+        }
+        // 使用整除来确定组号
+        int i = (num - 1) / 3 + 1;
+        if(1 == i){
+            return "1-3";
+        }else if(2 == i){
+            return "4-6";
+        }else if(3 == i){
+            return "7-9";
+        }else if(4 == i){
+            return "10-12";
+        }else if(5 == i){
+            return "13-15";
+        }else if(6 == i){
+            return "16-18";
+        }else if(7 == i){
+            return "19-21";
+        }else{
+            return "22-24";
+        }
+    }
+
+    public static void main(String[] args) {
+        ArrayList<Integer> CjItemUpdateList = new ArrayList<>();
+        for(int i =1 ;i<=10000;i++){
+            CjItemUpdateList.add(i);
+        }
+        int listSize= CjItemUpdateList.size();
+        int toIndex = 500;
+        for(int i = 0; i<CjItemUpdateList.size(); i+=toIndex){
+            if(i + toIndex > listSize){        //作用为toIndex最后没有1000条数据则剩余几条newList中就装几条
+                toIndex = listSize - i;
+            }
+            List<Integer> newList = new ArrayList<>(CjItemUpdateList.subList(i, i + toIndex));
+            System.out.println(newList.toString());
+        }
+
     }
 
 }

--
Gitblit v1.9.1