diff --git a/jyjz-system/jyjz-system-oa/pom.xml b/jyjz-system/jyjz-system-oa/pom.xml index 0107465..f1240af 100644 --- a/jyjz-system/jyjz-system-oa/pom.xml +++ b/jyjz-system/jyjz-system-oa/pom.xml @@ -27,7 +27,11 @@ org.apache.httpcomponents httpcore - + + net.coobird + thumbnailator + 0.4.14 + commons-configuration commons-configuration diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/dataobject/OcrPicture.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/dataobject/OcrPicture.java index 30a4726..dd56dc1 100644 --- a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/dataobject/OcrPicture.java +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/dataobject/OcrPicture.java @@ -323,6 +323,16 @@ public class OcrPicture implements BaseDto, java.io.Serializable { @TableField(exist = false) private String result; + @ApiModelProperty(value = "缩略图服务器绝对路径") + @Schema(description = "缩略图服务器绝对路径") + @TableField(value = "local_thumbnail_url") + private String localThumbnailUrl; + + @ApiModelProperty(value = "缩略图请求地址") + @Schema(description = "缩略图请求地址") + @TableField(value = "server_thumbnail_url") + private String serverThumbnailUrl; + //图片分类 @TableField(exist = false) private OcrPictureclass ocrPictureclass; @@ -398,7 +408,9 @@ public class OcrPicture implements BaseDto, java.io.Serializable { new SimpleEntry<>("field17", "field17"), new SimpleEntry<>("field18", "field18"), new SimpleEntry<>("localpictrueurl", "localpictrueurl"), - new SimpleEntry<>("imgHash", "imgHash") + new SimpleEntry<>("imgHash", "imgHash"), + new SimpleEntry<>("serverThumbnailUrl", "serverThumbnailUrl"), + new SimpleEntry<>("localThumbnailUrl", "localThumbnailUrl") ) .collect(Collectors.toMap(SimpleEntry::getKey, SimpleEntry::getValue)); diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/OcrPictureService.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/OcrPictureService.java index bd86dd7..c6cf939 100644 --- a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/OcrPictureService.java +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/OcrPictureService.java @@ -101,4 +101,6 @@ public interface OcrPictureService extends BaseService { ResultVo createPackageTask(List pageList, String tenantId, UserToken userToken, String searchMonth, HttpServletRequest req, String buessinessno); Map getOcrPictureClassifyAndHash(String img); + + String getServerUrl(); } diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/impl/OcrPictureServiceImpl.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/impl/OcrPictureServiceImpl.java index 20cd7b4..9cb210d 100644 --- a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/impl/OcrPictureServiceImpl.java +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/service/impl/OcrPictureServiceImpl.java @@ -54,6 +54,10 @@ public class OcrPictureServiceImpl extends BaseServiceImpl().eq(OcrTaskchildPicture::getPictureid, ocrPicture.getId())); ocrTaskchildPicture.setBuessinessno(buessinessno); diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/thread/tasks/PictureImgToLocalTask.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/thread/tasks/PictureImgToLocalTask.java index f9dc5f2..e241146 100644 --- a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/thread/tasks/PictureImgToLocalTask.java +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/thread/tasks/PictureImgToLocalTask.java @@ -10,11 +10,14 @@ import cn.jyjz.xiaoyao.ocr.service.OcrPictureService; import cn.jyjz.xiaoyao.ocr.thread.entity.PictureImgToLocalEntity; import cn.jyjz.xiaoyao.ocr.util.DownloadImgUtil; import cn.jyjz.xiaoyao.ocr.util.ImageClassUtil; +import cn.jyjz.xiaoyao.ocr.util.ImageUtils; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import net.coobird.thumbnailator.Thumbnails; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.IOException; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; @@ -48,6 +51,12 @@ public class PictureImgToLocalTask implements Runnable { if (ObjectUtil.isNotEmpty(picture)) { picture.setLocalpictrueurl(pictureImgToLocal.getLocalPath()); picture.setIsdownload(1); + try { + picture.setLocalThumbnailUrl(ImageUtils.generateThumbnail(pictureImgToLocal.getLocalPath(),182)); + picture.setServerThumbnailUrl(ocrPictureService.getServerUrl()+ImageUtils.getFileExtension(picture.getLocalpictrueurl())); + } catch (IOException e) { + throw new RuntimeException(e); + } Map ocrPictureClassifyAndHash = ocrPictureService.getOcrPictureClassifyAndHash(picture.getLocalpictrueurl()); if(ocrPictureClassifyAndHash!=null){ picture.setImgHash(ocrPictureClassifyAndHash.get("hash")); diff --git a/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/ImageUtils.java b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/ImageUtils.java new file mode 100644 index 0000000..10e55b8 --- /dev/null +++ b/jyjz-system/jyjz-system-oa/src/main/java/cn/jyjz/xiaoyao/ocr/util/ImageUtils.java @@ -0,0 +1,49 @@ +package cn.jyjz.xiaoyao.ocr.util; + +import net.coobird.thumbnailator.Thumbnails; + +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.UUID; + +/** + * @Title: + * @Description: 图片设置 + * @Author 郭向斌 + * @Date 2024-03-18 15:29 + * @Version V1.0 + */ +public class ImageUtils { + public static String generateThumbnail(String inputImagePath, Integer newWidth) throws IOException { + if(newWidth==null){ + newWidth=182; + } + String directoryPath = inputImagePath.substring(0, inputImagePath.lastIndexOf("/") + 1); + File inputFile = new File(inputImagePath); + String outputImagePath = directoryPath+ "thumbnail_" + inputFile.getName(); + BufferedImage bufferedImage = Thumbnails.of(inputFile).scale(1).asBufferedImage(); + int width = bufferedImage.getWidth(); + int height = bufferedImage.getHeight(); + int newHeight = (int) Math.round((double) height * newWidth / width); + + Thumbnails.of(inputFile).size(newWidth, newHeight).outputFormat( getFileExtension(inputFile.getName())).toFile(new File(outputImagePath)); + return outputImagePath; + } + + + public static String getFileExtension(String fileName) { + if (fileName.lastIndexOf(".") != -1 && fileName.lastIndexOf(".") != 0) { + return fileName.substring(fileName.lastIndexOf(".") + 1); + } else { + return "jpg"; // 没有后缀名或者文件名以点号开头 + } + } + + public static void main(String[] args) throws IOException { + String url="C:\\Users\\郭向斌\\Downloads\\1-星浩.png"; + String s = generateThumbnail(url,180); + System.out.println(s); + + } +} diff --git a/runstart/src/main/resources/application-pro.yml b/runstart/src/main/resources/application-pro.yml index ff93c79..bd2ceb8 100644 --- a/runstart/src/main/resources/application-pro.yml +++ b/runstart/src/main/resources/application-pro.yml @@ -289,3 +289,4 @@ ocr: image: similarityPath: http://127.0.0.1:8000/api/similarity/ classifyPath: http://127.0.0.1:8000/api/classify/ + serverUrl: http://47.93.59.251/api/image/ \ No newline at end of file