From 9486766c806fe1d9e082b2fd02ea1cc558f1b443 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 08 五月 2025 09:21:57 +0800
Subject: [PATCH] bug修改

---
 cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/BallController.java |  333 +++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 239 insertions(+), 94 deletions(-)

diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/BallController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/BallController.java
index b87153f..4e0c28d 100644
--- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/BallController.java
+++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/system/BallController.java
@@ -1,6 +1,5 @@
 package com.dsh.guns.modular.system.controller.system;
 
-import com.alibaba.fastjson.JSONArray;
 import com.alibaba.nacos.common.utils.Md5Utils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -20,6 +19,7 @@
 import com.dsh.course.feignClient.other.SiteClient;
 import com.dsh.course.feignClient.other.model.Site;
 import com.dsh.course.service.TGameConfigService;
+import com.dsh.course.util.UUIDUtil;
 import com.dsh.guns.config.UserExt;
 import com.dsh.guns.core.base.controller.BaseController;
 import com.dsh.guns.core.util.ToolUtil;
@@ -27,20 +27,39 @@
 import com.dsh.guns.modular.system.model.*;
 import com.dsh.guns.modular.system.model.dto.*;
 import com.dsh.guns.modular.system.service.*;
-import com.dsh.guns.modular.system.util.DateComparisonExample;
-import com.dsh.guns.modular.system.util.HttpRequestUtil;
-import com.dsh.guns.modular.system.util.ResultUtil;
+import com.dsh.guns.modular.system.util.*;
 import com.dsh.course.entity.SiteLock;
+import com.google.gson.Gson;
+import com.google.zxing.BarcodeFormat;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.WriterException;
+import com.google.zxing.client.j2se.MatrixToImageWriter;
+import com.google.zxing.common.BitMatrix;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.tomcat.util.http.fileupload.ByteArrayOutputStream;
+import org.json.JSONArray;
 import org.json.JSONObject;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.mock.web.MockMultipartFile;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 import javax.annotation.Resource;
+import javax.imageio.ImageIO;
 
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.IOException;
 import java.math.BigDecimal;
 
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
@@ -87,10 +106,8 @@
     @Autowired
     private AppUserClient appUserClient;
 
-
     @RequestMapping("/tolist")
     public String tolist(Model model) {
-
         List<TCity> list = cityService.list(new LambdaQueryWrapper<TCity>().eq(TCity::getParentId, 0));
         model.addAttribute("list",list);
         String roleid = UserExt.getUser().getRoleid();
@@ -172,7 +189,6 @@
 
         SiteBooking byId = iSiteBookingService.getById(id);
         String money = byId.getMoney();
-        // todo 这里手动支付 默认按照现金当作支付金额 后续可能要问下产品
         String[] split = money.split(",");
         Double aDouble = Double.valueOf(split[0]);
         System.out.println("============"+id);
@@ -197,7 +213,7 @@
     @RequestMapping("/list")
     @ResponseBody
     public List<Game> changelist(BallQueryDto ballQueryDto) {
-System.out.println("=======ballQueryDto=========="+ballQueryDto);
+        System.out.println("=======ballQueryDto=========="+ballQueryDto);
         User user = UserExt.getUser();
         ballQueryDto.setType(user.getObjectType());
         ballQueryDto.setId(user.getObjectId());
@@ -215,7 +231,26 @@
         return ResultUtil.success();
     }
 
+    public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException {
+        // 将 BufferedImage 转换为字节数组
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ImageIO.write(bufferedImage, "png", baos);
+        byte[] bytes = baos.toByteArray();
 
+        // 创建 ByteArrayResource
+        ByteArrayResource resource = new ByteArrayResource(bytes);
+
+        // 创建 MockMultipartFile
+        MockMultipartFile multipartFile = new MockMultipartFile(
+                "file",
+                fileName,
+                "image/png",
+                resource.getInputStream()
+        );
+
+        return multipartFile;
+    }
+    
     @RequestMapping("/save")
     @ResponseBody
     public ResultUtil save(Integer id, String operationId, String red, String blue, String province, String city, Integer site, Integer store
@@ -229,14 +264,15 @@
             , String zs, BigDecimal zsCoin, BigDecimal zsCash, String zsImage, BigDecimal zsInt, Integer zsId,Integer zsIId
             , String zs2, BigDecimal zs2Coin, BigDecimal zs2Cash, String zs2Image, BigDecimal zs2Int, Integer zs2Id,Integer zs2IId
             , String ly, BigDecimal lyCoin, BigDecimal lyCash, String lyImage, BigDecimal lyInt, Integer lyId,Integer lyIId
+            , String v3, BigDecimal v3Coin, BigDecimal v3Cash, String v3Image, BigDecimal v3Int, Integer v3Id,Integer v3IId
                            ,String sutuName
 
-    ) {
+    ) throws Exception {
 
         Game game = new Game();
-        game.setRed(red);
+        game.setRedName(red);
         game.setState(0);
-        game.setBlue(blue);
+        game.setBlueName(blue);
 
 
         Integer objectType = UserExt.getUser().getObjectType();
@@ -260,35 +296,120 @@
         game.setId(id);
 
 
+
         if (!operationId.equals("平台")){
         game.setOperationId(Integer.valueOf(operationId));}
         else {
             game.setOperationId(0);
         }
         System.out.println("============"+game);
-
-        // 添加sutu编号
-        HashMap<String, String> map3 = new HashMap<>();
-        // 添加sutu编号
-        // 添加门禁 红蓝方
-        TSite si = siteService.getById(site);
-        TStore st = storeService.getById(store);
-//        map3.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
-//        map3.put("space_id", si.getId() + "");
-//        map3.put("name", ToolUtil.isEmpty(sutuName) ? "" : sutuName);
-//        map3.put("city_code", "");
-//        String s3 = HttpRequestUtil.postRequest("https://try.daowepark.com/v7/user_api/general/addDevice", map3);
-//        System.out.println("---------------------------"+s3);
-//        JSONObject jsonObject = new JSONObject(s3);
-//        // 获取 data 字段的值
-//        JSONObject dataObject = jsonObject.getJSONObject("data");
-//        // 获取 sutu_id 字段的值
-//        String sutuIdValue = dataObject.getString("sutu_id");
-//        Integer sutuId = Integer.valueOf(sutuIdValue);
-//        game.setSutuId(sutuId);
+    
+        // 判断是新增还是修改 修改不会重新生成sutuId
+        if (game.getId()==null) {
+            HashMap<String, String> map5 = new HashMap<>();
+            map5.put("space_id", store + "");
+            map5.put("area_id", site + "");
+            String s5 = HttpRequestUtil.getRequest("https://port.daowepark.com/v7/user_api/general/get_space_sutu", map5);
+            System.err.println(s5);
+            JSONObject jsonObject5 = new JSONObject(s5);
+            JSONArray data = jsonObject5.getJSONArray("data");
+            Integer temp = null;  // 临时sutuid
+            Integer temp1 = null; // 临时sutuid
+            TSite si = siteService.getById(site);
+            if (data.length() == 0) {
+                // 这个场地没有添加过sutu
+                HashMap<String, String> map3 = new HashMap<>();
+                HashMap<String, String> map4 = new HashMap<>();
+                // 添加sutu编号
+                // 调用两次 创建sutu
+                map3.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
+                map4.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
+                map3.put("space_id", store + "");
+                map3.put("area_id", si.getId() + "");
+                map4.put("space_id", store + "");
+                map4.put("area_id", si.getId() + "");
+                map3.put("name", blue);
+                map4.put("name", red);
+                map3.put("city_code", city);
+                map4.put("city_code", city);
+                String s3 = HttpRequestUtil.postRequest("https://port.daowepark.com/v7/user_api/general/addSpaceSutu", map3);
+                String s4 = HttpRequestUtil.postRequest("https://port.daowepark.com/v7/user_api/general/addSpaceSutu", map4);
+                JSONObject jsonObject = new JSONObject(s3);
+                JSONObject jsonObject1 = new JSONObject(s4);
+                // 获取 data 字段的值
+                JSONObject dataObject = jsonObject.getJSONObject("data");
+                JSONObject dataObject1 = jsonObject1.getJSONObject("data");
+                // 获取 sutu_id 字段的值
+                String sutuIdValue = dataObject.getString("sutu_id");
+                String sutuIdValue1 = dataObject1.getString("sutu_id");
+                Integer sutuId = Integer.valueOf(sutuIdValue);
+                Integer sutuId1 = Integer.valueOf(sutuIdValue1);
+                game.setBlue("" + sutuId);
+                game.setRed("" + sutuId1);
+                // 生成红蓝sutu二维码
+                HashMap<String, String> blueCode = new HashMap<>();
+                blueCode.put("scan_type", "1000");
+                blueCode.put("sutu_id", "" + sutuId);
+                blueCode.put("space_id", si.getId() + "");
+                HashMap<String, String> redCode = new HashMap<>();
+                redCode.put("scan_type", "1000");
+                redCode.put("sutu_id", sutuId1 + "");
+                redCode.put("space_id", si.getId() + "");
+                String blueS = "{\"scan_type\": 1000, \"space_id\": " + si.getId() + ", \"sutu_id\": " + sutuId + "}";
+                String redS = "{\"scan_type\": 1000, \"space_id\": " + si.getId() + ", \"sutu_id\": " + sutuId1 + "}";
+                MyQrCodeUtil.createCodeToFile(blueS);
+                MyQrCodeUtil.createCodeToFile(redS);
+                BufferedImage blueImage = QRCodeUtil.createImage(blueS);
+                BufferedImage redImage = QRCodeUtil.createImage(redS);
+                MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
+                MultipartFile redFile = convert(redImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
+                String s = OssUploadUtil.ossUpload("img/", blueFile);
+                String s1 = OssUploadUtil.ossUpload("img/", redFile);
+                game.setBlueCode(s);
+                game.setRedCode(s1);
+            } else {
+                Integer sutuid = 0;
+                Integer sutuid1 = 0;
+                JSONObject element = data.getJSONObject(0);
+                if (site == 27) {
+                    sutuid = 1036;
+                    sutuid1 = 1037;
+                    game.setBlue(sutuid.toString());
+                    game.setRed(sutuid1.toString());
+                } else {
+                    sutuid = element.getInt("id");
+                    game.setBlue(sutuid.toString());
+                    JSONObject element1 = data.getJSONObject(1);
+                    sutuid1 = element1.getInt("id");
+                    game.setRed(sutuid1.toString());
+                }
+                // 生成红蓝sutu二维码
+                HashMap<String, String> blueCode = new HashMap<>();
+                blueCode.put("scan_type", "1000");
+                blueCode.put("sutu_id", "" + sutuid);
+                blueCode.put("space_id", si.getId() + "");
+                HashMap<String, String> redCode = new HashMap<>();
+                redCode.put("scan_type", "1000");
+                redCode.put("sutu_id", sutuid1 + "");
+                redCode.put("space_id", si.getId() + "");
+                String blueS = "{\"scan_type\": 1000, \"space_id\": " + si.getId() + ", \"sutu_id\": " + sutuid + "}";
+                String redS = "{\"scan_type\": 1000, \"space_id\": " + si.getId() + ", \"sutu_id\": " + sutuid1 + "}";
+                MyQrCodeUtil.createCodeToFile(blueS);
+                MyQrCodeUtil.createCodeToFile(redS);
+                BufferedImage blueImage = QRCodeUtil.createImage(blueS);
+                BufferedImage redImage = QRCodeUtil.createImage(redS);
+                MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
+                MultipartFile redFile = convert(redImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
+                String s = OssUploadUtil.ossUpload("img/", blueFile);
+                String s1 = OssUploadUtil.ossUpload("img/", redFile);
+                game.setBlueCode(s);
+                game.setRedCode(s1);
+            }
+    
+        }
+        
         Integer gameId = ballClient.save(game);
         List<TGameConfig> gameConfigList = new ArrayList<>();
-
         //玩湃跨城赛
         TGameConfig gameConfigkuacheng = new TGameConfig();
         gameConfigkuacheng.setId(kcId);
@@ -302,9 +423,7 @@
         System.out.println("========gameConfig======"+gameConfigkuacheng);
         gameConfigList.add(gameConfigkuacheng);
         System.out.println("======gameConfigList======="+gameConfigList);
-
         //社区冠军赛
-
         TGameConfig gameConfigshequ = new TGameConfig();
         gameConfigshequ.setId(shequIId);
         gameConfigshequ.setGameId(shequId);
@@ -415,22 +534,34 @@
         gameConfigly.setIntegral(lyInt);
         gameConfigly.setOtherId(gameId);
         gameConfigList.add(gameConfigly);
+    
+        //激战3V3
+        TGameConfig gameConfigv3 = new TGameConfig();
+        gameConfigv3.setGameId(v3Id);
+        gameConfigv3.setId(v3IId);
+        gameConfigv3.setCash(v3Cash);
+        gameConfigv3.setImg(v3Image);
+        gameConfigv3.setName(v3);
+        gameConfigv3.setPlayCoin(v3Coin);
+        gameConfigv3.setIntegral(v3Int);
+        gameConfigv3.setOtherId(gameId);
+        gameConfigList.add(gameConfigv3);
         HashMap<String, String> map1 = new HashMap<>();
         HashMap<String, String> map2 = new HashMap<>();
 
 
-        map1.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
-        map1.put("space_id", si.getId() + "");
-        map1.put("device_id", red);
-        map1.put("region_id", st.getId() + "");
-        // 添加门禁
-        String s1 = HttpRequestUtil.postRequest("https://try.daowepark.com/v7/user_api/general/addDevice", map1);
-        map2.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
-        map2.put("space_id", si.getId() + "");
-        map2.put("device_id", blue);
-        map2.put("region_id", st.getId() + "");
-        // 添加门禁
-        String s2 = HttpRequestUtil.postRequest("https://try.daowepark.com/v7/user_api/general/addDevice", map2);
+//        map1.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
+//        map1.put("space_id", si.getId() + "");
+//        map1.put("device_id", red);
+//        map1.put("region_id", st.getId() + "");
+//        // 添加门禁
+//        String s1 = HttpRequestUtil.postRequest("https://port.daowepark.com/v7/user_api/general/addDevice", map1);
+//        map2.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
+//        map2.put("space_id", si.getId() + "");
+//        map2.put("device_id", blue);
+//        map2.put("region_id", st.getId() + "");
+//        // 添加门禁
+//        String s2 = HttpRequestUtil.postRequest("https://port.daowepark.com/v7/user_api/general/addDevice", map2);
 
 
 
@@ -438,6 +569,8 @@
         return null;
     }
 
+
+    
     @RequestMapping("/pre_add")
     public String add(Model model) {
 
@@ -518,6 +651,9 @@
 
         TGameConfig ly = gameConfigService.getOne(new QueryWrapper<TGameConfig>().eq("otherId", id).eq("gameId", 5));
         model.addAttribute("ly",ly);
+    
+        TGameConfig v3 = gameConfigService.getOne(new QueryWrapper<TGameConfig>().eq("otherId", id).eq("gameId", 0));
+        model.addAttribute("v3",v3);
 
 
         Integer objectType = UserExt.getUser().getObjectType();
@@ -587,7 +723,9 @@
 
         TGameConfig ly = gameConfigService.getOne(new QueryWrapper<TGameConfig>().eq("otherId", id).eq("gameId", 5));
         model.addAttribute("ly",ly);
-
+        
+        TGameConfig v3 = gameConfigService.getOne(new QueryWrapper<TGameConfig>().eq("otherId", id).eq("gameId", 0));
+        model.addAttribute("v3",v3);
 
 
         return PREFIX+"ball_pre_info.html";
@@ -730,6 +868,7 @@
 
 @Autowired
 private IUserService userService;
+
     @RequestMapping("/yueyue_info/{id}")
     public String yueyue_info(@PathVariable("id") Integer id,Model model) {
 
@@ -795,8 +934,7 @@
 
         List<OrderDto> timeRanges = new ArrayList<>();
 
-
-        Site site =  siteClient.listById(book.getSiteId());
+        TSite site = siteService.getById(book.getSiteId());
         System.out.println("================"+site);
         String appointmentStartTime = site.getAppointmentStartTime();
         String appointmentEndTime = site.getAppointmentEndTime();
@@ -885,9 +1023,33 @@
                 List<TCoursePackage> coursePackageByStoreId = coursePackageClient.getCoursePackageByStoreId(storeId);
                 tCoursePackages.addAll(coursePackageByStoreId);
             }
+
             List<Integer> coursePackageByStoreIds = tCoursePackages.stream().distinct().map(TCoursePackage::getId).collect(Collectors.toList());
+            if (tCoursePackages.isEmpty()){
+                coursePackageByStoreIds.add(-1);
+            }
+            studentQeryDto.setCoursePackageIds(coursePackageByStoreIds);
+
+        }
+        // 如果当前登陆人是门店 只查询该门店下的课包的数据
+        if(UserExt.getUser().getObjectType() == 3){
+            // 先查询这个运营商下的所有门店ids
+
+            List<Integer> storeIds = new ArrayList<>();
+            storeIds.add(UserExt.getUser().getObjectId());
+            // 根据门店ids 查询所有课包ids
+            List<TCoursePackage> tCoursePackages = new ArrayList<>();
+            for (Integer storeId : storeIds) {
+                List<TCoursePackage> coursePackageByStoreId = coursePackageClient.getCoursePackageByStoreId(storeId);
+                tCoursePackages.addAll(coursePackageByStoreId);
+            }
+            List<Integer> coursePackageByStoreIds = tCoursePackages.stream().distinct().map(TCoursePackage::getId).collect(Collectors.toList());
+            if (tCoursePackages.isEmpty()){
+                coursePackageByStoreIds.add(-1);
+            }
             studentQeryDto.setCoursePackageIds(coursePackageByStoreIds);
         }
+
         List<Map<String, Object>>  pays = coursePackageClient.getStudentTotal(studentQeryDto);
         return pays;
     }
@@ -992,22 +1154,22 @@
                 }
             }
 
-            if (Integer.parseInt(vo.get("status").toString())==1 ){
-                String dateTimeStr = vo.get("times").toString();
-                String formattedDateTimeStr = dateTimeStr.substring(0, 11) + dateTimeStr.substring(17);
-
-                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-                try {
-                    Date date = sdf.parse(formattedDateTimeStr);
-                    if (new Date().after(date)){
-                        vo.put("status",4);
-                    }
-
-                    System.out.println(date);
-                } catch (ParseException e) {
-                    e.printStackTrace();
-                }
-            }
+//            if (Integer.parseInt(vo.get("status").toString())==1 ){
+//                String dateTimeStr = vo.get("times").toString();
+//                String formattedDateTimeStr = dateTimeStr.substring(0, 11) + dateTimeStr.substring(17);
+//
+//                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+//                try {
+//                    Date date = sdf.parse(formattedDateTimeStr);
+//                    if (new Date().after(date)){
+//                        vo.put("status",4);
+//                    }
+//
+//                    System.out.println(date);
+//                } catch (ParseException e) {
+//                    e.printStackTrace();
+//                }
+//            }
         }
         return orders;
     }
@@ -1360,42 +1522,25 @@
         String[] dates = times.split(";");
 
         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+        try {
+            String start = dates[0];
+            String startDateStr = start.substring(0, start.lastIndexOf("-"));
+            Date startDate = format.parse(startDateStr);
 
-        Date minDate = null;
-        Date maxDate = null;
-
-        for (String dateStr : dates) {
-            String[] dateRange = dateStr.split("-");
-            String startDateStr = dateRange[0].trim();
-            String endDateStr = dateRange[1].trim();
-
-            try {
-                Date startDate = format.parse(startDateStr);
-                Date endDate = format.parse(endDateStr);
-
-                if (minDate == null || startDate.before(minDate)) {
-                    minDate = startDate;
-                }
-                if (maxDate == null || endDate.after(maxDate)) {
-                    maxDate = endDate;
-                }
-            } catch (Exception e) {
-                e.printStackTrace();
-            }
+            String end = dates[dates.length - 1];
+            String[] str = end.split(" ");
+            String endDateStr = str[0] + " " + str[1].substring(str[1].indexOf("-") + 1);
+            Date endDate = format.parse(endDateStr);
+            siteBooking.setStartTime(startDate);
+            siteBooking.setEndTime(endDate);
+        } catch (Exception e) {
+            e.printStackTrace();
         }
-
-        System.out.println("最小日期:" + minDate);
-        System.out.println("最大日期:" + maxDate);
-        siteBooking.setStartTime(minDate);
-        siteBooking.setEndTime(maxDate);
         siteBooking.setPayType(2);
-
         //存多少钱
         String money = siteBooking.getMoney();
         String[] moneys = money.split(",");
         siteBooking.setPayMoney(Double.valueOf(moneys[0]));
-
-
         // 查询当前预约人是否是会员
         String phone = siteBooking.getPhone();
         String booker = siteBooking.getBooker();

--
Gitblit v1.7.1