|
@@ -2,6 +2,7 @@ package com.xzl.web.controller.userPortrait;
|
|
|
|
|
|
import com.xzl.common.utils.DateUtils;
|
|
import com.xzl.common.utils.DateUtils;
|
|
import org.aspectj.util.FileUtil;
|
|
import org.aspectj.util.FileUtil;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -30,13 +31,16 @@ import java.util.Map;
|
|
@RequestMapping("/user-portait")
|
|
@RequestMapping("/user-portait")
|
|
public class ViewController {
|
|
public class ViewController {
|
|
|
|
|
|
- String path = "/usr/local/python/";
|
|
|
|
|
|
+ @Value("${pythonFilePath}")
|
|
|
|
+ String pythonFilePath;
|
|
|
|
|
|
|
|
+ @Value("${pythonPath}")
|
|
|
|
+ String pythonPath;
|
|
|
|
|
|
@GetMapping("/show")
|
|
@GetMapping("/show")
|
|
public void show(HttpServletResponse response) throws Exception {
|
|
public void show(HttpServletResponse response) throws Exception {
|
|
String wordcloudImageFileName = "wordcloud.png";
|
|
String wordcloudImageFileName = "wordcloud.png";
|
|
- File wordcloudImageFile = new File(path, wordcloudImageFileName);
|
|
|
|
|
|
+ File wordcloudImageFile = new File(pythonFilePath, wordcloudImageFileName);
|
|
if (wordcloudImageFile.exists()) {
|
|
if (wordcloudImageFile.exists()) {
|
|
InputStream inputStream = null;
|
|
InputStream inputStream = null;
|
|
ServletOutputStream outputStream = null;
|
|
ServletOutputStream outputStream = null;
|
|
@@ -71,32 +75,25 @@ public class ViewController {
|
|
Map rs = new HashMap();
|
|
Map rs = new HashMap();
|
|
// 先判断有没有 wordcloud.txt, 没有就生成一个,有就备份一个,然后重新生成新的内容
|
|
// 先判断有没有 wordcloud.txt, 没有就生成一个,有就备份一个,然后重新生成新的内容
|
|
String wordcloudFileName = "wordcloud.txt";
|
|
String wordcloudFileName = "wordcloud.txt";
|
|
- File wordcloudFile = new File(path, wordcloudFileName);
|
|
|
|
|
|
+ File wordcloudFile = new File(pythonFilePath, wordcloudFileName);
|
|
|
|
|
|
String wordcloudImageFileName = "wordcloud.png";
|
|
String wordcloudImageFileName = "wordcloud.png";
|
|
- File wordcloudImageFile = new File(path, wordcloudImageFileName);
|
|
|
|
|
|
+ File wordcloudImageFile = new File(pythonFilePath, wordcloudImageFileName);
|
|
|
|
|
|
// 如果词云文件存在,就先都备份一下,然后再生成新的
|
|
// 如果词云文件存在,就先都备份一下,然后再生成新的
|
|
String timePrefix = DateUtils.dateTimeNow();
|
|
String timePrefix = DateUtils.dateTimeNow();
|
|
if (wordcloudFile.exists()) {
|
|
if (wordcloudFile.exists()) {
|
|
- FileUtil.copyFile(wordcloudFile, new File(path, timePrefix + "-" + wordcloudFileName));
|
|
|
|
|
|
+ FileUtil.copyFile(wordcloudFile, new File(pythonFilePath, timePrefix + "-" + wordcloudFileName));
|
|
}
|
|
}
|
|
if (wordcloudImageFile.exists()) {
|
|
if (wordcloudImageFile.exists()) {
|
|
- FileUtil.copyFile(wordcloudImageFile, new File(path, timePrefix + "-" + wordcloudImageFileName));
|
|
|
|
|
|
+ FileUtil.copyFile(wordcloudImageFile, new File(pythonFilePath, timePrefix + "-" + wordcloudImageFileName));
|
|
}
|
|
}
|
|
- // 获取新的内容,写入 wordcloud.txt
|
|
|
|
|
|
+ //TODO 获取新的内容,写入 wordcloud.txt
|
|
|
|
|
|
// 调用python脚本, 生成新的词云图片
|
|
// 调用python脚本, 生成新的词云图片
|
|
- String[] commands = {"/usr/local/Cellar/python@3.10/3.10.11/bin/python3.10", "/usr/local/python/word-cloud.py"};
|
|
|
|
|
|
+ String[] commands = {pythonPath, "/usr/local/python/word-cloud.py"};
|
|
ProcessBuilder processBuilder = new ProcessBuilder(commands);
|
|
ProcessBuilder processBuilder = new ProcessBuilder(commands);
|
|
Process process = processBuilder.start();
|
|
Process process = processBuilder.start();
|
|
-
|
|
|
|
- // 读取命令执行结果
|
|
|
|
-// BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
|
|
-// String line;
|
|
|
|
-// while ((line = reader.readLine()) != null) {
|
|
|
|
-// System.out.println(line);
|
|
|
|
-// }
|
|
|
|
// 等待命令执行完成
|
|
// 等待命令执行完成
|
|
int exitCode = process.waitFor();
|
|
int exitCode = process.waitFor();
|
|
System.out.println("命令执行结果:" + exitCode);
|
|
System.out.println("命令执行结果:" + exitCode);
|