fix(qrcode): 修复二维码生成时临时目录创建和异常处理问题
- 添加临时目录不存在时的创建逻辑并处理创建失败情况
- 统一异常处理,将WriterException和IOException合并处理
- 改进错误信息传递,保留原始异常堆栈信息
- 在调用层添加具体异常信息到服务异常中便于调试
- 更新AI助手配置以支持临时文件目录读取权限
| | |
| | | "Bash(echo \"EXIT=$?\")", |
| | | "Read(//tmp/**)", |
| | | "Bash(npm install *)", |
| | | "Bash(node -e \"require.resolve\\('html2canvas'\\) && console.log\\('html2canvas installed:', require\\('html2canvas/package.json'\\).version\\)\")" |
| | | "Bash(node -e \"require.resolve\\('html2canvas'\\) && console.log\\('html2canvas installed:', require\\('html2canvas/package.json'\\).version\\)\")", |
| | | "Read(//javaWork/product-inventory-management/file/temp/**)", |
| | | "Read(//d/javaWork/product-inventory-management/file/temp/**)" |
| | | ] |
| | | }, |
| | | "enabledMcpjsonServers": [ |
| | |
| | | hints.put(EncodeHintType.MARGIN, 0); |
| | | BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400, hints); |
| | | File file1 = new File(path, codeName + "." + imageType); |
| | | File parent = file1.getParentFile(); |
| | | if (parent != null && !parent.exists() && !parent.mkdirs()) { |
| | | throw new IOException("临时目录创建失败:" + parent.getPath()); |
| | | } |
| | | writeToFile(bitMatrix, imageType, file1); |
| | | return file1.getPath(); |
| | | } catch (WriterException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } catch (WriterException | IOException e) { |
| | | throw new RuntimeException("二维码生成失败:" + e.getMessage(), e); |
| | | } |
| | | throw new RuntimeException("二维码生成失败"); |
| | | } |
| | | |
| | | } |
| | |
| | | try { |
| | | codePath = new MatrixToImageWriter().code(taskDto.getId().toString(), tempDir); |
| | | } catch (Exception e) { |
| | | throw new ServiceException("生成二维码失败"); |
| | | throw new ServiceException("生成二维码失败:" + e.getMessage()); |
| | | } |
| | | |
| | | List<Map<String, Object>> images = buildTaskAttachmentImages(taskDto.getId()); |