From fed438fa23dac29a4f4dea4d63c320a86aa041f2 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 10 三月 2025 14:01:55 +0800 Subject: [PATCH] bug修改 --- cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TShopController.java | 5 - cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/util/MyFileUtil.java | 129 +++++++++++++++++++++++++++++++++++++++++++ cloud-server-other/src/main/java/com/dsh/other/controller/GameController.java | 11 ++- 3 files changed, 137 insertions(+), 8 deletions(-) diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TShopController.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TShopController.java index 27ded08..b793c91 100644 --- a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TShopController.java +++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/code/TShopController.java @@ -567,8 +567,6 @@ tStore.setOperatorId(UserExt.getUser().getObjectId()); } - user.setObjectId(tStore.getId()); - userService.updateById(user); // 添加门店 HashMap<String, String> map1 = new HashMap<>(); map1.put("sign","0DB011836143EEE2C2E072967C9F4E4B"); @@ -591,7 +589,8 @@ Integer integer = Integer.valueOf(space_id); tStore.setId(integer); storeService.save(tStore); - System.err.println(tStore); + user.setObjectId(tStore.getId()); + userService.updateById(user); ArrayList<StoreConfig> storeConfigs = new ArrayList<>(); for (int i = 1; i < 9; i++) { StoreConfig storeConfig = new StoreConfig(); diff --git a/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/util/MyFileUtil.java b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/util/MyFileUtil.java new file mode 100644 index 0000000..7a4d7e7 --- /dev/null +++ b/cloud-server-management/src/main/java/com/dsh/guns/modular/system/controller/util/MyFileUtil.java @@ -0,0 +1,129 @@ +package com.dsh.guns.modular.system.controller.util; + +import org.springframework.web.multipart.MultipartFile; + +import java.io.*; +import java.nio.file.Files; + + +/** + * @author RainbowCloud + */ +public class MyFileUtil { + + /** + * 将 File 转换为 MultipartFile。 + * + * @param file 要转换的文件 + * @param fieldName 字段名,通常用于表单中的文件字段名 + * @return 转换后的 MultipartFile + * @throws IOException 如果发生I/O错误 + */ + public static MultipartFile fileToMultipartFile(File file, String fieldName) throws IOException { + try { + if (file == null || !file.exists()) { + throw new FileNotFoundException("文件未找到:" + file); + } + byte[] content = Files.readAllBytes(file.toPath()); + return new ByteArrayMultipartFile(content, file.getName(), fieldName, Files.probeContentType(file.toPath())); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + // 删除临时文件 + file.delete(); + } + } + + /** + * 将 MultipartFile 转换为 File。 + * + * @param multipartFile 要转换的 MultipartFile + * @return 转换后的 File + * @throws IOException 如果发生I/O错误 + */ + public static File multipartFileToFile(MultipartFile multipartFile) throws IOException { + if (multipartFile.isEmpty()) { + throw new IOException("传入的MultipartFile为空"); + } + String originalFilename = multipartFile.getOriginalFilename(); + String tempFileSuffix = originalFilename != null ? originalFilename.substring(originalFilename.lastIndexOf('.')) : ".tmp"; + File tempFile = File.createTempFile("temp", tempFileSuffix); + try (InputStream ins = multipartFile.getInputStream(); + OutputStream os = new FileOutputStream(tempFile)) { + byte[] buffer = new byte[8192]; + int bytesRead; + while ((bytesRead = ins.read(buffer)) != -1) { + os.write(buffer, 0, bytesRead); + } + } + return tempFile; + } + + /** + * 内置一个简单的 MultipartFile 实现类,用于File转换 + */ + private static class ByteArrayMultipartFile implements MultipartFile { + private final byte[] content; + private final String name; + private final String originalFilename; + private final String contentType; + + /** + * 构造函数 + * + * @param content 文件内容 + * @param originalFilename 文件原始名字 + * @param name 字段名 + * @param contentType 文件类型 + */ + public ByteArrayMultipartFile(byte[] content, String originalFilename, String name, String contentType) { + this.content = content; + this.originalFilename = originalFilename; + this.name = name; + this.contentType = contentType; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String getOriginalFilename() { + return this.originalFilename; + } + + @Override + public String getContentType() { + return this.contentType; + } + + @Override + public boolean isEmpty() { + return (this.content == null || this.content.length == 0); + } + + @Override + public long getSize() { + return this.content.length; + } + + @Override + public byte[] getBytes() { + return this.content; + } + + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(this.content); + } + + @Override + public void transferTo(File dest) throws IOException, IllegalStateException { + try (OutputStream os = new FileOutputStream(dest)) { + os.write(this.content); + } + } + } + +} \ No newline at end of file diff --git a/cloud-server-other/src/main/java/com/dsh/other/controller/GameController.java b/cloud-server-other/src/main/java/com/dsh/other/controller/GameController.java index b5c911a..028ba01 100644 --- a/cloud-server-other/src/main/java/com/dsh/other/controller/GameController.java +++ b/cloud-server-other/src/main/java/com/dsh/other/controller/GameController.java @@ -150,10 +150,11 @@ if (null == uid) { return ResultUtil.tokenErr(); } - //判断当前用户是否是员工 + AppUser appUser1 = appUserClient.queryAppUser(uid); - User one = userService.getOne(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1)); - if (null != one) { + //判断当前用户是否是员工 + List<User> one = userService.list(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1)); + if (!one.isEmpty()) { return ResultUtil.success(1); } //普通用户校验当前时间是否在预约时间段内 @@ -209,8 +210,8 @@ } //判断当前用户是否是员工 AppUser appUser1 = appUserClient.queryAppUser(uid); - User one = userService.getOne(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1)); - if (null != one) { + List<User> one = userService.list(new QueryWrapper<User>().eq("phone", appUser1.getPhone()).eq("status", 1)); + if (!one.isEmpty()) { Integer integer = startGame(uid, gameType, gameId, spaceId, sutuId); return ResultUtil.success(); } -- Gitblit v1.7.1