From fd10f80a545f12fbba1b344e3c7ed8c9a1792781 Mon Sep 17 00:00:00 2001 From: hansha Date: Thu, 30 May 2024 08:45:53 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E7=94=A8=E7=AC=AC=E4=B8=89=E6=96=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=81=E6=89=AB=E6=8F=8F=E4=BB=AA=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 22 +-- .../src/main/resources/application.yml | 4 + .../controller/DangAnCollectController.java | 155 ++++++++++-------- .../da/dangan/util/CallThirdInterface.java | 74 +++++---- .../src/views/dangan/collection/index.vue | 3 +- .../src/views/dangan/pictureRecard/index.vue | 4 +- 6 files changed, 148 insertions(+), 114 deletions(-) diff --git a/README.md b/README.md index 9766014..d35b305 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,10 @@ -

- logo -

-

RuoYi v3.8.7

-

基于SpringBoot+Vue前后端分离的Java快速开发框架

-

- - - -

- ## 平台简介 -若依是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。 - * 前端采用Vue、Element UI。 * 后端采用Spring Boot、Spring Security、Redis & Jwt。 * 权限认证使用Jwt,支持多终端认证系统。 * 支持加载动态权限菜单,多方式轻松权限控制。 * 高效率开发,使用代码生成器可以一键生成前后端代码。 -* 提供了技术栈([Vue3](https://v3.cn.vuejs.org) [Element Plus](https://element-plus.org/zh-CN) [Vite](https://cn.vitejs.dev))版本[RuoYi-Vue3](https://github.com/yangzongzhuan/RuoYi-Vue3),保持同步更新。 -* 提供了单应用版本[RuoYi-Vue-fast](https://github.com/yangzongzhuan/RuoYi-Vue-fast),Oracle版本[RuoYi-Vue-Oracle](https://github.com/yangzongzhuan/RuoYi-Vue-Oracle),保持同步更新。 -* 不分离版本,请移步[RuoYi](https://gitee.com/y_project/RuoYi),微服务版本,请移步[RuoYi-Cloud](https://gitee.com/y_project/RuoYi-Cloud) -* 阿里云折扣场:[点我进入](http://aly.ruoyi.vip),腾讯云秒杀场:[点我进入](http://txy.ruoyi.vip)   -* 阿里云优惠券:[点我领取](https://www.aliyun.com/minisite/goods?userCode=brki8iof&share_source=copy_link),腾讯云优惠券:[点我领取](https://cloud.tencent.com/redirect.php?redirect=1025&cps_key=198c8df2ed259157187173bc7f4f32fd&from=console)   ## 内置功能 @@ -49,4 +31,6 @@ - admin/admin123 -#影源扫描仪 授权码:ND8NSUzCysU1gCr78aj57g== \ No newline at end of file +#影源扫描仪 授权码:V4tMKPYgFtW8vQr4C0s4/g== +测试临时码:D+1WT4eWDqLseG5433yq9w== +#系统中扫描上传 连接打印机的电脑需要安装两个:扫描仪驱动M3230.zip、webscan.exe插件 (已上传到项目) \ No newline at end of file diff --git a/dangan-admin/src/main/resources/application.yml b/dangan-admin/src/main/resources/application.yml index 6031bd8..8710dc8 100644 --- a/dangan-admin/src/main/resources/application.yml +++ b/dangan-admin/src/main/resources/application.yml @@ -127,3 +127,7 @@ xss: excludes: /system/notice # 匹配链接 urlPatterns: /system/*,/monitor/*,/tool/* + +ocr: + #第三方访问地址 + url: http://123.57.142.195:443/upload_api \ No newline at end of file diff --git a/dangan-dangan/src/main/java/com/da/dangan/controller/DangAnCollectController.java b/dangan-dangan/src/main/java/com/da/dangan/controller/DangAnCollectController.java index 9949569..7681d6d 100644 --- a/dangan-dangan/src/main/java/com/da/dangan/controller/DangAnCollectController.java +++ b/dangan-dangan/src/main/java/com/da/dangan/controller/DangAnCollectController.java @@ -8,8 +8,10 @@ import com.da.common.utils.file.FileUtils; import com.da.dangan.domain.DaPicturesRecard; import com.da.dangan.service.IDaCzrkdjService; import com.da.dangan.service.IDaPicturesRecardService; +import com.da.dangan.util.CallThirdInterface; import com.da.framework.config.ServerConfig; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -38,14 +40,15 @@ public class DangAnCollectController extends BaseController { private IDaCzrkdjService daCzrkdjService; private static final String FILE_DELIMETER = ","; + @Value("${ocr.url}") + private String url; + /** * 上传(单个) */ @PostMapping("/save") - public AjaxResult save(@RequestPart("file")MultipartFile file, @RequestPart("picRecard")DaPicturesRecard picRecard) - { - try - { + public AjaxResult save(@RequestPart("file") MultipartFile file, @RequestPart("picRecard") DaPicturesRecard picRecard) { + try { // 上传文件路径 String filePath = RuoYiConfig.getUploadPath(); // 上传并返回新文件名称 @@ -57,15 +60,13 @@ public class DangAnCollectController extends BaseController { picRecard.setCreateBy(getUsername()); AjaxResult ajax = AjaxResult.success(); daPicturesRecardService.insertDaPicturesRecard(picRecard); - ajax.put("data",picRecard); + ajax.put("data", picRecard); /*ajax.put("url", url); ajax.put("fileName", fileName); ajax.put("newFileName", FileUtils.getName(fileName)); ajax.put("originalFilename", file.getOriginalFilename());*/ return ajax; - } - catch (Exception e) - { + } catch (Exception e) { return AjaxResult.error(e.getMessage()); } } @@ -74,10 +75,8 @@ public class DangAnCollectController extends BaseController { * 通用上传(单个/多个) */ @PostMapping("/saves") - public AjaxResult saves(@RequestPart("files")MultipartFile[] files,@RequestPart("picRecard") DaPicturesRecard picRecard) throws Exception - { - try - { //数据存储 + public AjaxResult saves(@RequestPart("files") MultipartFile[] files, @RequestPart("picRecard") DaPicturesRecard picRecard) throws Exception { + try { //数据存储 List picRecards = new ArrayList<>(); // 上传文件路径 String filePath = RuoYiConfig.getUploadPath(); @@ -85,8 +84,7 @@ public class DangAnCollectController extends BaseController { List fileNames = new ArrayList(); List newFileNames = new ArrayList(); List originalFilenames = new ArrayList(); - for (MultipartFile file : files) - { + for (MultipartFile file : files) { // DaPicturesRecard newPicRecard = new DaPicturesRecard(); @@ -95,8 +93,8 @@ public class DangAnCollectController extends BaseController { String url = serverConfig.getUrl() + fileName; // 添加水印 - String updatedFilePath = removePathBeforeSecondSlash(fileName); - String watermarkFilePath = addWatermark(filePath + updatedFilePath); + /*String updatedFilePath = removePathBeforeSecondSlash(fileName); + String watermarkFilePath = addWatermark(filePath + updatedFilePath);*/ urls.add(url); fileNames.add(fileName); @@ -118,66 +116,36 @@ public class DangAnCollectController extends BaseController { ajax.put("fileNames", StringUtils.join(fileNames, FILE_DELIMETER)); ajax.put("newFileNames", StringUtils.join(newFileNames, FILE_DELIMETER)); ajax.put("originalFilenames", StringUtils.join(originalFilenames, FILE_DELIMETER));*/ - ajax.put("data",picRecards); + ajax.put("data", picRecards); return ajax; - } - catch (Exception e) - { - return AjaxResult.error(e.getMessage()); - } - } - /** - * 测试添加水印 - */ - @PostMapping("/tests") - public AjaxResult tests(MultipartFile[] files) throws Exception - { - try - { //数据存储 - List picRecards = new ArrayList<>(); - // 上传文件路径 - String filePath = RuoYiConfig.getUploadPath(); - for (MultipartFile file : files) - { - // 上传并返回新文件名称 - String fileName = FileUploadUtils.upload(filePath, file); - String url = serverConfig.getUrl() + fileName; - // 添加水印 - String updatedFilePath = removePathBeforeSecondSlash(fileName); - String watermarkFilePath = addWatermark(filePath + updatedFilePath); - } - AjaxResult ajax = AjaxResult.success(); - return ajax; - } - catch (Exception e) - { + } catch (Exception e) { return AjaxResult.error(e.getMessage()); } } - - /** - * 调用识别接口 + * 调用ocr识别接口 */ @PostMapping("/recongnize") - public AjaxResult recognize(@RequestBody DaPicturesRecard[] picRecards){ + public AjaxResult recognize(@RequestBody DaPicturesRecard[] picRecards) { try { //获取所有的文件 List files = new ArrayList<>(); for (DaPicturesRecard picRecard : picRecards) { - File file = new File(picRecard.getPicUrl()); + String path = getPath(picRecard.getPicUrl()); + File file = new File(path); files.add(file); } // TODO 调用第三方接口识别信息 - //String result= CallThirdInterface.callThirdInterface1(); - //String result= CallThirdInterface.callThirdInterface("url",files); + //String result= CallThirdInterface.callThirdInterface1(); + String result = CallThirdInterface.callThirdInterface(url, files, "option1"); + System.out.println(result); // TODO 根据业务类型存储识别后的信息 //daCzrkdjService.insertDaCzrkdj(); //修改图片信息记录表为已识别 - for(DaPicturesRecard picRecard:picRecards){ + for (DaPicturesRecard picRecard : picRecards) { picRecard.setRecognize("1"); daPicturesRecardService.updateDaPicturesRecard(picRecard); } @@ -185,17 +153,69 @@ public class DangAnCollectController extends BaseController { e.printStackTrace(); return AjaxResult.error(e.getMessage()); } - return AjaxResult.success(); } + + /** + * 测试第三方接口 + */ + @PostMapping("/test") + public String test(@RequestParam("files[]") MultipartFile[] files, @RequestParam("fileType") String fileType) throws Exception { + List fileList = new ArrayList<>(); + for (MultipartFile multipartFile : files) { + // 使用multipartFile的transferTo方法保存到临时文件 + File file = new File(multipartFile.getOriginalFilename()); + multipartFile.transferTo(file); + fileList.add(file); + } + String result = CallThirdInterface.callThirdInterface(url, fileList, fileType); + return result; + } + + /** + * 测试访问本地接口 + * + * @param url + * @return + * @throws Exception + */ + @PostMapping("/test2") + public String test(String url) throws Exception { + return CallThirdInterface.callThirdInterface1(url); + } + + /** + * 测试添加水印 + */ + @PostMapping("/test_water") + public AjaxResult tests(MultipartFile[] files) throws Exception { + try { //数据存储 + List picRecards = new ArrayList<>(); + // 上传文件路径 + String filePath = RuoYiConfig.getUploadPath(); + for (MultipartFile file : files) { + // 上传并返回新文件名称 + String fileName = FileUploadUtils.upload(filePath, file); + String url = serverConfig.getUrl() + fileName; + // 添加水印 + String updatedFilePath = removePathBeforeSecondSlash(fileName); + String watermarkFilePath = addWatermark(filePath + updatedFilePath); + } + AjaxResult ajax = AjaxResult.success(); + return ajax; + } catch (Exception e) { + return AjaxResult.error(e.getMessage()); + } + } + /** * 删除第二个斜杠之前的路径 + * * @param filePath * @return */ - private String removePathBeforeSecondSlash(String filePath) - { + private String removePathBeforeSecondSlash(String filePath) { int count = 0; int index = -1; for (int i = 0; i < filePath.length(); i++) { @@ -212,16 +232,17 @@ public class DangAnCollectController extends BaseController { } return filePath; } + /** * 添加水印 + * * @param filePath * @return * @throws IOException */ - private String addWatermark(String filePath) throws IOException - { //获取文件后缀 + private String addWatermark(String filePath) throws IOException { //获取文件后缀 int indexNum = filePath.lastIndexOf("."); - String fileExtension = filePath.substring(indexNum+1); + String fileExtension = filePath.substring(indexNum + 1); BufferedImage image = ImageIO.read(new File(filePath)); /*int h = bufferedImage.getHeight(); @@ -247,8 +268,8 @@ public class DangAnCollectController extends BaseController { g2d.rotate(-Math.toRadians(myDegree), (double) image.getWidth() / 2, (double) image.getHeight() / 2); //设置水印位置 - int x = (image.getWidth() - g2d.getFontMetrics().stringWidth(watermark)) /2; - int y = image.getHeight()/2; + int x = (image.getWidth() - g2d.getFontMetrics().stringWidth(watermark)) / 2; + int y = image.getHeight() / 2; g2d.drawString(watermark, x, y); // 保存添加水印后的图片,覆盖原始图片 @@ -258,5 +279,11 @@ public class DangAnCollectController extends BaseController { return filePath; } + public String getPath(String path) { + String profile = RuoYiConfig.getUploadPath(); + int i = path.indexOf("upload"); + String filePath = profile + path.substring(i + 6); + return filePath; + } } diff --git a/dangan-dangan/src/main/java/com/da/dangan/util/CallThirdInterface.java b/dangan-dangan/src/main/java/com/da/dangan/util/CallThirdInterface.java index 17fa951..5913537 100644 --- a/dangan-dangan/src/main/java/com/da/dangan/util/CallThirdInterface.java +++ b/dangan-dangan/src/main/java/com/da/dangan/util/CallThirdInterface.java @@ -1,56 +1,71 @@ package com.da.dangan.util; +import cn.hutool.core.util.CharsetUtil; import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpResponse; +import cn.hutool.http.HttpUtil; import cn.hutool.http.Method; import java.io.File; import java.net.HttpCookie; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 调用第三方接口,传文件,获取识别结果 */ public class CallThirdInterface { - public static String callThirdInterface1(){ - // 1. 创建HttpRequest对象 - 指定好 url 地址 - HttpRequest httpRequest = new HttpRequest("http://localhost/register"); - // 2. 设置请求方式,默认是GET请求 - httpRequest.setMethod(Method.POST); - // 3. 设置请求参数 可通过 form表单方法 设置 可以是文件类型 - // form方法有很多重载方法,可以一个一个参数设置,也可以将参数封装进一个map集合然后一块儿 - // File file = new File("C:\\Users\\hssym\\Downloads\\UBQ.png"); - // httpRequest.form("image",files); - // 4. 设置请求头 - // 请求头同样可以逐一设置,也可以封装到map中再统一设置 - // 设置的请求头是否可以覆盖等信息具体请看源码关于重载方法的说明 - // httpRequest.header("x-c-authorization","yourToken"); - // 5. 执行请求,得到http响应类 - HttpResponse execute = httpRequest.execute(); + public static String callThirdInterface1(String url){ + // 定义上传的URL + //String url = "http://yourserver.com:8080/upload"; + //添加json + /*JSONObject json = new JSONObject(); + json.put("username", "1332788xxxxxx"); + json.put("password", "123456.");*/ + //添加请求头,可多个 + HashMap headers = new HashMap<>();//存放请求头,可以存放多个请求头 + headers.put("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjA2NjhmYTM5LTE5OWEtNDAyYy1iYjJlLTk1MjI0OWExMTlhOSJ9.S5-6MC6xKHx1bGjuE0g_QR0vGTsAG1E6rmQCqm2GSMIgNNZkYCnZckegYI8UCCxuGkTV_GOFwmcGagG0IccNEw"); + // 定义要上传的文件 + // File file = new File("/path/to/your/file.txt"); - // 6. 解析这个http响应类,可以获取到响应主体、cookie、是否请求成功等信息 - boolean ok = execute.isOk(); // 是否请求成功 判断依据为:状态码范围在200~299内 - System.out.println(ok); - List cookies = execute.getCookies();// 获取所有cookie - cookies.forEach(System.out::println); // 如果为空不会遍历的 - String body = execute.body(); // 获取响应主体 - System.out.println(body); - return body; + // 定义其他要上传的表单参数 + Map map = new HashMap<>();//存放参数 + map.put("keyword", "王"); + map.put("ywTypes", 0); + // 使用Hutool的HttpUtil上传文件 + + String result = HttpUtil.createGet(url) + .addHeaders(headers) + .charset(CharsetUtil.CHARSET_UTF_8) + //.form("file", file) // 文件名称为"file" + .form(map)// 添加其他表单参数 + .execute().body() ; + // 输出结果 + System.out.println(result); + return result; } - public static String callThirdInterface(String url,List files){ + + public static String callThirdInterface(String url,List files,String fileType){ // 1. 创建HttpRequest对象 - 指定好 url 地址 HttpRequest httpRequest = new HttpRequest(url); // 2. 设置请求方式,默认是GET请求 httpRequest.setMethod(Method.POST); + // 3. 设置请求参数 可通过 form表单方法 设置 可以是文件类型 // form方法有很多重载方法,可以一个一个参数设置,也可以将参数封装进一个map集合然后一块儿 // File file = new File("C:\\Users\\hssym\\Downloads\\UBQ.png"); - httpRequest.form("image",files); + + httpRequest.charset(CharsetUtil.CHARSET_UTF_8); + httpRequest.form("files[]",files.toArray(new File[0])); + httpRequest.form("fileType",fileType); + // 4. 设置请求头 // 请求头同样可以逐一设置,也可以封装到map中再统一设置 - // 设置的请求头是否可以覆盖等信息具体请看源码关于重载方法的说明 - httpRequest.header("x-c-authorization","yourToken"); + // 设置的请求头,可添加多个 + // httpRequest.header("x-c-authorization","yourToken"); + // httpRequest.header("Content-Type", "multipart/form-data;charset=UTF-8"); // 5. 执行请求,得到http响应类 HttpResponse execute = httpRequest.execute(); @@ -60,6 +75,10 @@ public class CallThirdInterface { List cookies = execute.getCookies();// 获取所有cookie cookies.forEach(System.out::println); // 如果为空不会遍历的 String body = execute.body(); // 获取响应主体 + /*byte[] bytes = execute.bodyBytes(); + String body = new String (bytes,CharsetUtil.UTF_8);*/ + + // 输出结果 System.out.println(body); return body; } @@ -78,5 +97,4 @@ public class CallThirdInterface { } System.out.println(values); } - } diff --git a/dangan-ui/src/views/dangan/collection/index.vue b/dangan-ui/src/views/dangan/collection/index.vue index 6d35c48..23c889b 100644 --- a/dangan-ui/src/views/dangan/collection/index.vue +++ b/dangan-ui/src/views/dangan/collection/index.vue @@ -234,7 +234,8 @@ export default { _this.WebScan = new WebScan({ url:'http://localhost:18989/WebScan', wsUrl:'http://localhost:28989/', - licence:'D+1WT4eWDqLseG5433yq9w==' + /*licence:'D+1WT4eWDqLseG5433yq9w=='*/ + licence:'V4tMKPYgFtW8vQr4C0s4/g==' }); _this.WebScan.initSef('',function (result){ diff --git a/dangan-ui/src/views/dangan/pictureRecard/index.vue b/dangan-ui/src/views/dangan/pictureRecard/index.vue index 66394a4..15b0dc3 100644 --- a/dangan-ui/src/views/dangan/pictureRecard/index.vue +++ b/dangan-ui/src/views/dangan/pictureRecard/index.vue @@ -111,7 +111,7 @@ - + @@ -139,7 +139,7 @@ - +