From 2bd77f375024d0d6df28abd38dc7457f11f18a8b Mon Sep 17 00:00:00 2001 From: Wtd <1658714322@qq.com> Date: Fri, 20 Oct 2023 20:05:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=BC=A0=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/bootstrap.yml | 2 +- .../february-patient-circle-server/pom.xml | 16 ++++- .../circle/controller/PatientController.java | 4 ++ .../circle/service/PatientService.java | 1 + .../service/impl/PatientServiceImpl.java | 16 ++++- .../february/patient/circle/util/OssUtil.java | 71 +++++++++++++++++++ .../src/main/resources/bootstrap.yml | 16 ++++- 7 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/util/OssUtil.java diff --git a/february-modules/february-job/february-job-server/src/main/resources/bootstrap.yml b/february-modules/february-job/february-job-server/src/main/resources/bootstrap.yml index 43d2411..d376cb2 100644 --- a/february-modules/february-job/february-job-server/src/main/resources/bootstrap.yml +++ b/february-modules/february-job/february-job-server/src/main/resources/bootstrap.yml @@ -1,6 +1,6 @@ # Tomcat server: - port: 9203 + port: 9204 # Spring spring: diff --git a/february-patient/february-patient-circle/february-patient-circle-server/pom.xml b/february-patient/february-patient-circle/february-patient-circle-server/pom.xml index b21b27b..f3f3236 100644 --- a/february-patient/february-patient-circle/february-patient-circle-server/pom.xml +++ b/february-patient/february-patient-circle/february-patient-circle-server/pom.xml @@ -17,7 +17,11 @@ UTF-8 - + + com.github.tobato + fastdfs-client + 1.26.5 + com.february february-patient-circle-common @@ -47,6 +51,16 @@ com.github.tobato fastdfs-client + + com.aliyun.oss + aliyun-sdk-oss + 3.11.0 + + + joda-time + joda-time + 2.10.10 + diff --git a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/controller/PatientController.java b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/controller/PatientController.java index 5841030..25e5f85 100644 --- a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/controller/PatientController.java +++ b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/controller/PatientController.java @@ -130,4 +130,8 @@ public class PatientController { public Result patientToSick(@RequestBody ReviewPatientRequest reviewPatientRequest){ return patientService.patientToSick(reviewPatientRequest); } + @PostMapping("/uploadMsg") + public Result uploadMsg(@RequestParam("file")MultipartFile file){ + return patientService.uploadMsg(file); + } } diff --git a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/PatientService.java b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/PatientService.java index fb921ca..d031201 100644 --- a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/PatientService.java +++ b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/PatientService.java @@ -43,4 +43,5 @@ public interface PatientService { Result patientToSick(ReviewPatientRequest reviewPatientRequest); + Result uploadMsg(MultipartFile file); } diff --git a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/impl/PatientServiceImpl.java b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/impl/PatientServiceImpl.java index 418054a..428f004 100644 --- a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/impl/PatientServiceImpl.java +++ b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/service/impl/PatientServiceImpl.java @@ -10,6 +10,7 @@ import com.february.patient.circle.mapper.PatientMapper; import com.february.patient.circle.result.Result; import com.february.patient.circle.service.PatientService; import com.february.patient.circle.util.FastUtil; +import com.february.patient.circle.util.OssUtil; import io.swagger.models.auth.In; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -29,6 +30,8 @@ public class PatientServiceImpl implements PatientService { private PatientMapper patientMapper; @Autowired private FastUtil fastUtil; + @Autowired + private OssUtil ossUtil; @Override public Result> patientCircleList(Integer userId) { List list=patientMapper.patientCircleList(userId); @@ -87,7 +90,7 @@ public class PatientServiceImpl implements PatientService { public Result upload(MultipartFile file) { try { String upload = fastUtil.upload(file); - return Result.success("http://192.168.192.128:8888/"+upload,"上传成功"); + return Result.success("http://10.100.1.2:8888/"+upload,"上传成功"); }catch (Exception e){ e.printStackTrace(); } @@ -108,4 +111,15 @@ public class PatientServiceImpl implements PatientService { } return Result.success("评论失败"); } + + @Override + public Result uploadMsg(MultipartFile file) { + try { + String s = OssUtil.UploadImage(file); + return Result.success(s); + }catch (Exception e){ + e.printStackTrace(); + } + return Result.success("上传失败"); + } } diff --git a/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/util/OssUtil.java b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/util/OssUtil.java new file mode 100644 index 0000000..d687a40 --- /dev/null +++ b/february-patient/february-patient-circle/february-patient-circle-server/src/main/java/com/february/patient/circle/util/OssUtil.java @@ -0,0 +1,71 @@ +package com.february.patient.circle.util; + + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import org.joda.time.DateTime; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import java.io.IOException; +import java.io.InputStream; +import java.util.UUID; + +/** + * @author Administrator + */ +@Component +public class OssUtil { + + static String endpoint = "oss-cn-shanghai.aliyuncs.com"; + static String accessKeyId = "LTAI5tMtBBNwEhU9PxTgQJd9"; + static String accessKeySecret = "y9pJbQtL7cSAlSPmTFugI8aH86mLzE"; + static String bucketName = "srb-file-cong"; + static String filePath = "avatar"; + + public static String UploadImage(MultipartFile file) throws IOException { + +// String filePath = "C:\\Users\\Administrator\\Pictures\\微信图片\\QQ图片20231015190011.jpg"; + + // 获取文件的输入流 + InputStream inputStream = file.getInputStream(); + + // 获取文件的原始名称 + String originalFilename = file.getOriginalFilename(); + + // 路径 + 名称 + String fileName = originalFilename; + + // 创建OSSClient实例。 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + + // 日期格式化 + String folderTime = new DateTime().toString("/yyyy/MM/dd/"); + + // 唯一ID + 切割.之后的文件类型 + fileName = filePath + folderTime + UUID.randomUUID().toString() + fileName.substring(fileName.lastIndexOf(".")); + + // 上传文件。 + ossClient.putObject(bucketName, fileName, inputStream); + + // 释放OSSClient资源。 + ossClient.shutdown(); + + return "https://" + bucketName + "." + endpoint + "/" + fileName; + } + + public static void removeFile(String url) { + + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + String host = "https://" + bucketName + "." + endpoint + "/"; + String objectName = url.substring(host.length()); + try { + ossClient.deleteObject(bucketName, objectName); + } catch (Exception e) { + e.printStackTrace(); + } finally { + ossClient.shutdown(); + } + + } +} diff --git a/february-patient/february-patient-circle/february-patient-circle-server/src/main/resources/bootstrap.yml b/february-patient/february-patient-circle/february-patient-circle-server/src/main/resources/bootstrap.yml index 1d5a3b3..8a1f4e0 100644 --- a/february-patient/february-patient-circle/february-patient-circle-server/src/main/resources/bootstrap.yml +++ b/february-patient/february-patient-circle/february-patient-circle-server/src/main/resources/bootstrap.yml @@ -1,7 +1,9 @@ # Tomcat server: port: 9203 - +mybatis: + configuration: + map-underscore-to-camel-case: true # Spring spring: application: @@ -25,3 +27,15 @@ spring: - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} rabbitmq: host: 10.100.1.3 +fdfs: + so-timeout: 1500 # socket 连接时长 + connect-timeout: 600 # 连接 tracker 服务器超时时长 + # 这两个是你服务器的 IP 地址,注意 23000 端口也要打开,阿里云服务器记得配置安全组。tracker 要和 stroage 服务进行交流 + tracker-list: 10.100.1.2:22122 + web-server-url: 10.100.1.2:8888 + pool: + jmx-enabled: false + # 生成缩略图 + thumb-image: + height: 500 + width: 500