|
@@ -3,6 +3,7 @@ package com.ssj.service.kmt.kmt.service.impl;
|
|
|
import com.alibaba.dubbo.config.annotation.Service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.aliyun.oss.OSSClient;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.ssj.bean.kmt.kmt.domain.KmtExerciseBook;
|
|
|
import com.ssj.bean.kmt.kmt.domain.KmtExerciseQuestion;
|
|
@@ -44,6 +45,10 @@ import javax.imageio.ImageIO;
|
|
|
import java.awt.image.BufferedImage;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.URL;
|
|
|
import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
@@ -541,12 +546,12 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
|
|
|
request.getEndX(), request.getEndY(), request.getQuestionId());
|
|
|
ResponseEntity responseEntity = new ResponseEntity();
|
|
|
TbLibManager manager = bookManagerDao.findByUserIdAndType(userId, 18);
|
|
|
- if (manager != null && kmtExerciseQuestion.getDealStatus() > 3 && kmtExerciseQuestion.getDealStatus() != 7) {
|
|
|
+ if (manager != null && kmtExerciseQuestion != null && kmtExerciseQuestion.getDealStatus() > 3 && kmtExerciseQuestion.getDealStatus() != 7) {
|
|
|
String path = this.removeQuestionNumMark(request.getStartX(), request.getStartY(), request.getEndX(), request.getEndY(), kmtExerciseQuestion.getImage());
|
|
|
String content = JSONFileUtil.readJSONFile(PropertiesUtil.getValue("EXERCISE_JSON_FILE_PATH") + kmtExerciseQuestion.getQuestionPath());
|
|
|
if (StringUtil.isNotBlank(content) && StringUtil.isNotBlank(path)) {
|
|
|
Map<String, Object> map = JSON.parseObject(content, Map.class);
|
|
|
- map.put("question_json", Collections.singletonList(ExerciseUtil.getExerciseQuestionAnswerValue(PropertiesUtil.getValue("STATIC_FILE_URL") + path)));
|
|
|
+ map.put("question_json", Collections.singletonList(ExerciseUtil.getExerciseQuestionAnswerValue(path)));
|
|
|
JSONFileUtil.saveJSONFile(PropertiesUtil.getValue("EXERCISE_JSON_FILE_PATH") + kmtExerciseQuestion.getQuestionPath(), JSON.toJSONString(map));
|
|
|
}
|
|
|
}
|
|
@@ -600,13 +605,14 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
|
|
|
}
|
|
|
|
|
|
private String createNewFile (int startX, int startY, int endX, int endY, String relatePath) {
|
|
|
+ String prefix = PropertiesUtil.getValue("file_save_path");
|
|
|
String dir = relatePath.substring(0, relatePath.lastIndexOf("/") + 1);
|
|
|
String fileName = relatePath.substring(relatePath.lastIndexOf("/") + 1, relatePath.lastIndexOf("."));
|
|
|
- String resultFilePath = dir + "result_" + fileName + relatePath.substring(relatePath.lastIndexOf("."));
|
|
|
- OSSUtils.downloadFile(resultFilePath, relatePath.substring(1));
|
|
|
- drawImagePartColorByPosition(startX, startY, endX, endY, resultFilePath);
|
|
|
- OSSUtils.uploadFile(resultFilePath, resultFilePath.replace(PropertiesUtil.getValue("file_save_path") + "/", ""));
|
|
|
- return resultFilePath.replace(PropertiesUtil.getValue("file_save_path"), "");
|
|
|
+ String resultFilePath = prefix + dir + "result_" + fileName + relatePath.substring(relatePath.lastIndexOf("."));
|
|
|
+// OSSUtils.downloadFile(resultFilePath, relatePath.substring(1));
|
|
|
+ drawImagePartColorByPosition(startX, startY, endX, endY, resultFilePath, relatePath);
|
|
|
+ OSSUtils.uploadFile(resultFilePath, resultFilePath.replace(prefix + "/", ""));
|
|
|
+ return resultFilePath.replace(prefix, "");
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -617,13 +623,14 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
|
|
|
* @param maxy
|
|
|
* @param filePath
|
|
|
*/
|
|
|
- public void drawImagePartColorByPosition (int minx, int miny, int maxx, int maxy, String filePath) {
|
|
|
+ public void drawImagePartColorByPosition (int minx, int miny, int maxx, int maxy, String filePath, String relatePath) {
|
|
|
BufferedImage bi = null;
|
|
|
try {
|
|
|
//有宽高的才处理
|
|
|
if (maxx > 0 && maxy > 0){
|
|
|
- File file = new File(filePath);
|
|
|
- bi = ImageIO.read(file);
|
|
|
+ String prefix = PropertiesUtil.getValue("OSS_INTERNAL_PATH");
|
|
|
+// String prefix = "https://xt-sharingschool.oss-cn-shenzhen.aliyuncs.com";
|
|
|
+ bi = ImageIO.read(getImageStream(prefix + relatePath));
|
|
|
int pixel = bi.getRGB(minx, miny); //左上角像素值
|
|
|
// int pixel = -256;
|
|
|
for (int i = minx; i < maxx; i++) {
|
|
@@ -631,7 +638,12 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
|
|
|
bi.setRGB(i, j, pixel);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ File file = new File(filePath);
|
|
|
+ String dirPath = filePath.substring(0, filePath.lastIndexOf("/") + 1);
|
|
|
+ File dir = new File(dirPath);
|
|
|
+ if (!dir.exists()){
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
FileOutputStream ops = new FileOutputStream(file);
|
|
|
ImageIO.write(bi, filePath.substring(filePath.lastIndexOf(".") + 1), ops);
|
|
|
ops.flush();
|
|
@@ -641,4 +653,26 @@ public class KmtExerciseQuestionDealServiceImpl implements KmtExerciseQuestionDe
|
|
|
logger.error("异常", e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取网络图片流
|
|
|
+ *
|
|
|
+ * @param url
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private InputStream getImageStream(String url) {
|
|
|
+ try {
|
|
|
+ HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
|
|
|
+ connection.setReadTimeout(5000);
|
|
|
+ connection.setConnectTimeout(5000);
|
|
|
+ connection.setRequestMethod("GET");
|
|
|
+ if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
|
|
|
+ InputStream inputStream = connection.getInputStream();
|
|
|
+ return inputStream;
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ logger.error("获取网络图片出现异常,图片路径为:" + url);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|