KKSU
2024-03-01 3f7956fa7435a2b581336dc067cf8f25c1719e1c
src/main/java/cc/mrbird/febs/mall/service/impl/CJServiceImpl.java
@@ -26,6 +26,9 @@
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
@@ -37,8 +40,10 @@
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
@Service
@@ -60,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);
    }
@@ -90,49 +101,26 @@
        //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);
        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);
@@ -161,6 +149,12 @@
                DataDictionaryEnum.TIME_INTERVAL.getCode()
        );
        apiKjInfoVo.setDjs(Integer.parseInt(timeIntervalDic.getValue()));
        // 获取当前时间
        LocalDateTime currentTime = LocalDateTime.now();
        // 定义时间格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        apiKjInfoVo.setSystemTime(currentTime.format(formatter));
        return new FebsResponse().success().data(apiKjInfoVo);
    }
@@ -182,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("");
@@ -212,16 +206,14 @@
    @Override
    public FebsResponse tzInfo() {
        ArrayList<ApiTzInfoVo> objects = new ArrayList<>();
        List<TzInfo> tzInfos = tzInfoMapper.selectList(null);
        if(CollUtil.isNotEmpty(tzInfos)){
            for(TzInfo tzInfo : tzInfos){
                ApiTzInfoVo apiTzInfoVo = TzInfoConversion.INSTANCE.entityToVo(tzInfo);
                objects.add(apiTzInfoVo);
            }
        LinkedHashMap<String, JSON> tzInfo1 = new LinkedHashMap<>();
        Object tzInfoMap = redisUtils.get(AppContants.TZ_INFO);
        if(ObjectUtil.isEmpty(tzInfoMap)){
            tzInfo1 = this.getTzInfo();
        }else{
            tzInfo1 = JSONUtil.toBean(JSONUtil.parseObj(tzInfoMap), LinkedHashMap.class);
        }
        return new FebsResponse().success().data(objects);
        return new FebsResponse().success().data(tzInfo1);
    }
    @Override
@@ -233,8 +225,8 @@
                DataDictionaryEnum.NO_TIME.getType(),
                DataDictionaryEnum.NO_TIME.getCode()
        );
        if(noTimeDic.getValue().equals(2)){
            throw new FebsException("请等待下一期");
        if("2".equals(noTimeDic.getValue())){
            throw new FebsException("已停止投注");
        }
        List<ApiCreateItemDto> items = apiCreateDto.getItems();
@@ -248,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){
@@ -269,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());
@@ -309,6 +304,19 @@
        IPage<CjInfo> page = new Page<>(kjRecordDto.getPageNum(), kjRecordDto.getPageSize());
        IPage<CjInfo> pages = cjInfoMapper.selectTzListByMemberId(page, kjRecordDto);
        List<CjInfo> records = pages.getRecords();
        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);
            }
        }
        List<ApiTzListVo> apiTzListVos = CjInfoConversion.INSTANCE.entitysToVos(records);
        return new FebsResponse().success().data(apiTzListVos);
    }
@@ -333,9 +341,87 @@
        }
        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<>();
        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)) {
            redisUtils.del(AppContants.TZ_INFO);
        }
        JSON jsonStr = JSONUtil.parse(linkedHashMap);
        redisUtils.set(AppContants.TZ_INFO, jsonStr);
        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;
    }
    /**
@@ -344,6 +430,9 @@
     * @return 1-单数 2-双数
     */
    public static String judgeNumberOne(int num) {
        if(num > 24){
            return String.valueOf(num);
        }
        if (num % 2 == 0) {
            return "双";
        } else {
@@ -357,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());
        }
    }
}