From 2aa0ffa6eea188f44eabc50617ddf97c804fc89f Mon Sep 17 00:00:00 2001
From: aijinhui <aijinhui>
Date: 星期四, 21 九月 2023 16:32:49 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java | 64 +++++++++++++++++++++++++++----
1 files changed, 55 insertions(+), 9 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java b/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java
index b21d2c6..d88e965 100644
--- a/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/storage/minio/service/impl/StorageMinioEventServiceImpl.java
@@ -1,26 +1,30 @@
package com.ruoyi.storage.minio.service.impl;
+import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.storage.minio.domain.jsonbean.*;
+import com.ruoyi.utils.process.CmdUtils;
+import com.sun.jna.Platform;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import com.ruoyi.storage.minio.mapper.StorageMinioEventMapper;
import com.ruoyi.storage.minio.domain.StorageMinioEvent;
import com.ruoyi.storage.minio.service.IStorageMinioEventService;
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
import javax.annotation.Resource;
/**
@@ -35,9 +39,53 @@
@Resource
private StorageMinioEventMapper storageMinioEventMapper;
+ @Value("${minio.accessKey}")
+ String accessKey;
+ @Value("${minio.secretKey}")
+ String secretKey;
+ @Value("${minio.path}")
+ String path;
+ @Value("${minio.enabled}")
+ Boolean enabled;
+ String processName = "minio.exe";
+ @PostConstruct
+ public void initMinio() {
+ if (enabled) {
+ log.debug("鍒濆鍖栧惎鍔╩inio");
-
-
+ if (Platform.isWindows()) {
+ String exePath = System.getProperty("user.dir") + File.separator + "lib" + File.separator + "minio" + File.separator + processName;
+ Map<String, String> env=new HashMap<>();
+ env.put("MINIO_ROOT_USER",accessKey);
+ env.put("MINIO_ROOT_PASSWORD",secretKey);
+ List<String> cmd = new ArrayList<>();
+ cmd.add(exePath);
+ cmd.add("server");
+ cmd.add(path);
+ cmd.add("--console-address=0.0.0.0:9000");
+ cmd.add("--address=0.0.0.0:9001");
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
+ }
+ // 鍚姩鍚庡彴杩涚▼
+ CmdUtils.commandStart(processName, cmd, env);
+ // 鍚姩cmd绐楀彛
+ //String[] command = {"cmd", "/c", "start", exePath};
+ //CmdUtils.commandStart(command);
+ }
+ }
+ }
+ @PreDestroy
+ public void destroyMinio() {
+ if (enabled) {
+ log.info("閿�姣乵inio");
+ if (CmdUtils.isProcessRunning(processName)) {
+ // 杩涚▼宸茬粡鍦ㄨ繍琛岋紝缁撴潫璇ヨ繘绋�
+ CmdUtils.stopProcess(processName);
+ }
+ }
+ }
/**
* 鏌ヨ瀛樺偍浜嬩欢
@@ -137,10 +185,8 @@
log.debug("minio鎿嶄綔鏃ュ織鍏ュ簱鎴愬姛!銆�" + storageMinioEvent.getEventType() + "銆�");
}
}
- }
- catch (Exception ex)
- {
- log.error("minio浜嬩欢鏍煎紡鍖栧紓甯�:"+ex.getMessage());
+ } catch (Exception ex) {
+ log.error("minio浜嬩欢鏍煎紡鍖栧紓甯�:" + ex.getMessage());
}
}
}
--
Gitblit v1.9.3