From 4f310cf310b2c17daa3b28fe8f27a5ca7770b5f1 Mon Sep 17 00:00:00 2001
From: lxd <1004405501@qq.com>
Date: Wed, 18 Sep 2024 17:13:34 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=BC=A0ftp?=
=?UTF-8?q?=E5=9B=BE=E7=89=87=E6=96=B9=E6=B3=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../yudao-module-ultrasoniccom-biz/pom.xml | 4 +
.../medicalimg/insimagescreenshotVO.java | 9 ++
.../ultrasonic/ultrasonicController.java | 88 ++++++++++++++++++-
3 files changed, 97 insertions(+), 4 deletions(-)
diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/pom.xml b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/pom.xml
index 19e9714da..bdf398aaa 100644
--- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/pom.xml
+++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/pom.xml
@@ -130,6 +130,10 @@
yudao-spring-boot-starter-excel
2.1.0-jdk8-snapshot
+
+ commons-net
+ commons-net
+
diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/medicalimg/insimagescreenshotVO.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/medicalimg/insimagescreenshotVO.java
index caf5ebb79..467b00b50 100644
--- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/medicalimg/insimagescreenshotVO.java
+++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/medicalimg/insimagescreenshotVO.java
@@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.ultrasoniccom.controller.admin.ultrasonic.medica
import lombok.Data;
+import java.time.LocalDateTime;
+
@Data
public class insimagescreenshotVO {
@@ -9,4 +11,11 @@ public class insimagescreenshotVO {
private String ID;
private String imagebase;
+
+ private String imgType;
+
+ private String imgDescription;
+
+ private String orgId;
+
}
diff --git a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java
index fbd62f079..8562506e9 100644
--- a/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java
+++ b/yudao-module-ultrasoniccom/yudao-module-ultrasoniccom-biz/src/main/java/cn/iocoder/yudao/module/ultrasoniccom/controller/admin/ultrasonic/ultrasonicController.java
@@ -23,6 +23,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -31,6 +33,10 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.SocketException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
@@ -371,19 +377,93 @@ public class ultrasonicController {
LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
//当前登陆用户
- AdminUserDO user = userService.getUser(getLoginUserId());
+ // AdminUserDO user = userService.getUser(getLoginUserId());
// 生成随机 UUID
UUID randomUUID = UUID.randomUUID();
medicalimgDO medicalimgDO = new medicalimgDO();
medicalimgDO.setId(randomUUID.toString());
medicalimgDO.setImgUrl(insimagescreenshotVO.getImagebase());
- medicalimgDO.setCreatePerson(user.getUsername());
+ medicalimgDO.setCreatePerson("");
medicalimgDO.setCreateDate(dateTime);
medicalimgDO.setRegId(insimagescreenshotVO.getID());
- medicalimgDO.setOrgId(user.getOrgId());
+ medicalimgDO.setOrgId(insimagescreenshotVO.getOrgId());
medicalimgDO.setSelected("0");
- medicalimgDO.setImgType("1");
+ medicalimgDO.setImgType(insimagescreenshotVO.getImgType());
return medicalimgService.insimage(medicalimgDO);
}
+ @PostMapping("/ftpimage")
+ @Operation(summary = "获取图片上传ftp")
+ public void FtpImage(@RequestBody insimagescreenshotVO insimagescreenshotVO)
+ {
+ String base64String = insimagescreenshotVO.getImagebase();
+ String ftpServer = "114.55.171.231";
+ int ftpPort = 21; // FTP端口,默认为21
+ String ftpUser = "pacs";
+ String ftpPassword = "pacs";
+ String uploadPath = "/";
+ String fileName = System.currentTimeMillis()+".jpg";
+
+ FTPClient ftpClient = new FTPClient();
+
+ ftpClient.enterLocalPassiveMode();
+ try {
+ // 连接FTP服务器
+ ftpClient.connect(ftpServer, ftpPort);
+ ftpClient.login(ftpUser, ftpPassword);
+
+ // 设置文件传输类型为二进制
+ ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
+ // 解码Base64字符串
+ String base64Image = base64String.split(",")[1]; // 去掉数据URL的头部
+ // 解码Base64字符串
+ byte[] decodedBytes = Base64.getDecoder().decode(base64Image);
+
+ // 创建输入流
+ InputStream inputStream = new ByteArrayInputStream(decodedBytes);
+
+ // 上传文件
+ boolean result = ftpClient.storeFile(uploadPath + "/" + fileName, inputStream);
+ if (result) {
+ //上传成功
+ //当前时间
+ LocalDateTime dateTime = LocalDateTime.parse(LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")),
+ DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ AdminUserDO user = userService.getUser(getLoginUserId());
+ // 生成随机 UUID
+ UUID randomUUID = UUID.randomUUID();
+ medicalimgDO medicalimgDO = new medicalimgDO();
+ medicalimgDO.setId(randomUUID.toString());
+ medicalimgDO.setImgUrl("/video/"+fileName);
+ medicalimgDO.setCreatePerson("");
+ medicalimgDO.setCreateDate(dateTime);
+ medicalimgDO.setRegId(insimagescreenshotVO.getID());
+ medicalimgDO.setOrgId(user.getOrgId());
+ medicalimgDO.setSelected("0");
+ medicalimgDO.setImgType("1");
+ int count=medicalimgService.insimage(medicalimgDO);
+ } else {
+ System.out.println("文件上传失败");
+ }
+
+ // 断开连接
+ ftpClient.logout();
+ ftpClient.disconnect();
+ } catch (SocketException e) {
+ System.err.println("无法连接到FTP服务器: " + e.getMessage());
+ } catch (IOException e) {
+ System.err.println("IO异常: " + e.getMessage());
+ } finally {
+ try {
+ if (ftpClient.isConnected()) {
+ ftpClient.disconnect();
+ }
+ } catch (IOException ignored) {
+
+ }
+ }
+
+
+ }
+
}