Преглед изворни кода

Merge branch 'hjb' of SH-Arbitrate/Arbitrate-Backend into dev

hejinbo пре 2 година
родитељ
комит
1ddaf829fc

+ 5
- 1
ruoyi-common/pom.xml Прегледај датотеку

174
             <artifactId>documents4j-transformer-msoffice-word</artifactId>
174
             <artifactId>documents4j-transformer-msoffice-word</artifactId>
175
             <version>1.0.3</version>
175
             <version>1.0.3</version>
176
         </dependency>
176
         </dependency>
177
-
177
+        <dependency>
178
+            <groupId>org.apache.pdfbox</groupId>
179
+            <artifactId>pdfbox</artifactId>
180
+            <version>2.0.27</version>
181
+        </dependency>
178
 
182
 
179
 
183
 
180
 
184
 

+ 131
- 52
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java Прегледај датотеку

40
 import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO;
40
 import com.ruoyi.wisdomarbitrate.domain.vo.SendRoomNoMessageVO;
41
 import com.ruoyi.wisdomarbitrate.mapper.*;
41
 import com.ruoyi.wisdomarbitrate.mapper.*;
42
 import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
42
 import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
43
+import com.ruoyi.wisdomarbitrate.utils.OCRUtils;
43
 import com.ruoyi.wisdomarbitrate.utils.SignAward;
44
 import com.ruoyi.wisdomarbitrate.utils.SignAward;
44
 import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
45
 import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
45
 import com.tencentyun.TLSSigAPIv2;
46
 import com.tencentyun.TLSSigAPIv2;
50
 import org.apache.http.impl.client.CloseableHttpClient;
51
 import org.apache.http.impl.client.CloseableHttpClient;
51
 import org.apache.http.impl.client.HttpClients;
52
 import org.apache.http.impl.client.HttpClients;
52
 import org.apache.http.util.EntityUtils;
53
 import org.apache.http.util.EntityUtils;
54
+import org.apache.pdfbox.pdmodel.PDDocument;
53
 import org.apache.poi.xwpf.usermodel.Document;
55
 import org.apache.poi.xwpf.usermodel.Document;
54
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
56
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
55
 import org.springframework.beans.factory.annotation.Autowired;
57
 import org.springframework.beans.factory.annotation.Autowired;
980
             if (insertRow != 0 && CollectionUtil.isNotEmpty(caseAffiliates)) {
982
             if (insertRow != 0 && CollectionUtil.isNotEmpty(caseAffiliates)) {
981
                 caseAffiliates.forEach(caseAffiliate -> caseAffiliate.setCaseAppliLogId(caseApplication.getId()));
983
                 caseAffiliates.forEach(caseAffiliate -> caseAffiliate.setCaseAppliLogId(caseApplication.getId()));
982
                 // 插入案件日志人员相关表
984
                 // 插入案件日志人员相关表
983
-                if(CollectionUtil.isNotEmpty(caseAttachList)) {
985
+                if (CollectionUtil.isNotEmpty(caseAttachList)) {
984
                     List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
986
                     List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
985
                     // 插入日志附件表
987
                     // 插入日志附件表
986
-                    if(CollectionUtil.isNotEmpty(filterList)) {
988
+                    if (CollectionUtil.isNotEmpty(filterList)) {
987
                         for (CaseAttach caseAttach : filterList) {
989
                         for (CaseAttach caseAttach : filterList) {
988
                             // 查询附件表
990
                             // 查询附件表
989
                             CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
991
                             CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
992
                         }
994
                         }
993
                     }
995
                     }
994
 
996
 
995
-                }    caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
997
+                }
998
+                caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
996
             }
999
             }
997
         });
1000
         });
998
 
1001
 
1098
         }
1101
         }
1099
         List<CaseAttach> caseAttachList = caseApplication.getCaseAttachList();
1102
         List<CaseAttach> caseAttachList = caseApplication.getCaseAttachList();
1100
         // 立案申请状态直接修改主表信息
1103
         // 立案申请状态直接修改主表信息
1101
-            if (caseAttachList != null && caseAttachList.size() > 0
1102
-                    && caseApplication.getCaseStatus()!=null && caseApplication.getCaseStatus().equals(CaseApplicationConstants.CASE_APPLICATION)) {
1103
-                List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
1104
-                if(CollectionUtil.isNotEmpty(filterList)){
1105
-                    // 先删除2的附件在新增
1104
+        if (caseAttachList != null && caseAttachList.size() > 0
1105
+                && caseApplication.getCaseStatus() != null && caseApplication.getCaseStatus().equals(CaseApplicationConstants.CASE_APPLICATION)) {
1106
+            List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
1107
+            if (CollectionUtil.isNotEmpty(filterList)) {
1108
+                // 先删除2的附件在新增
1106
 //                    caseAttachMapper.deleteByCasedIdAndType(caseApplication.getId(),2,0);
1109
 //                    caseAttachMapper.deleteByCasedIdAndType(caseApplication.getId(),2,0);
1107
 //                for (CaseAttach caseAttach : filterList) {
1110
 //                for (CaseAttach caseAttach : filterList) {
1108
 //                    caseAttach.setCaseAppliId(caseApplication.getId());
1111
 //                    caseAttach.setCaseAppliId(caseApplication.getId());
1109
 //                    caseAttachMapper.save(caseAttach);
1112
 //                    caseAttachMapper.save(caseAttach);
1110
 //                }
1113
 //                }
1111
 
1114
 
1112
-                    for (CaseAttach caseAttach : caseAttachList) {
1113
-                        caseAttach.setCaseAppliId(caseApplication.getId());
1114
-                        caseAttachMapper.updateCaseAttach(caseAttach);
1115
-                    }
1115
+                for (CaseAttach caseAttach : caseAttachList) {
1116
+                    caseAttach.setCaseAppliId(caseApplication.getId());
1117
+                    caseAttachMapper.updateCaseAttach(caseAttach);
1118
+                }
1116
             }
1119
             }
1117
 
1120
 
1118
 
1121
 
1133
             try {
1136
             try {
1134
                 caseApplication.setCaseAppliId(caseApplication.getId());
1137
                 caseApplication.setCaseAppliId(caseApplication.getId());
1135
                 int insertRow = caseApplicationLogMapper.insert(caseApplication);
1138
                 int insertRow = caseApplicationLogMapper.insert(caseApplication);
1136
-                if (insertRow != 0 ) {
1137
-                    if( CollectionUtil.isNotEmpty(caseAffiliates)) {
1139
+                if (insertRow != 0) {
1140
+                    if (CollectionUtil.isNotEmpty(caseAffiliates)) {
1138
                         caseAffiliates.forEach(caseAffiliate -> caseAffiliate.setCaseAppliLogId(caseApplication.getId()));
1141
                         caseAffiliates.forEach(caseAffiliate -> caseAffiliate.setCaseAppliLogId(caseApplication.getId()));
1139
                         // 插入案件日志人员相关表
1142
                         // 插入案件日志人员相关表
1140
                         caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
1143
                         caseAffiliateLogMapper.batchCaseAffiliate(caseAffiliates);
1141
                     }
1144
                     }
1142
-                    if(CollectionUtil.isNotEmpty(caseAttachList)) {
1145
+                    if (CollectionUtil.isNotEmpty(caseAttachList)) {
1143
                         List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
1146
                         List<CaseAttach> filterList = caseAttachList.stream().filter(c -> c.getAnnexType().equals(2)).collect(Collectors.toList());
1144
                         // 插入日志附件表
1147
                         // 插入日志附件表
1145
-                       if(CollectionUtil.isNotEmpty(filterList)) {
1146
-                           for (CaseAttach caseAttach : filterList) {
1147
-                               // 查询附件表
1148
-                               CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
1149
-                               attach.setCaseAppliLogId(caseApplication.getId());
1150
-                               caseAttachLogMapper.save(attach);
1151
-                           }
1152
-                       }
1148
+                        if (CollectionUtil.isNotEmpty(filterList)) {
1149
+                            for (CaseAttach caseAttach : filterList) {
1150
+                                // 查询附件表
1151
+                                CaseAttach attach = caseAttachMapper.queryAnnexById(caseAttach.getAnnexId());
1152
+                                attach.setCaseAppliLogId(caseApplication.getId());
1153
+                                caseAttachLogMapper.save(attach);
1154
+                            }
1155
+                        }
1153
 
1156
 
1154
                     }
1157
                     }
1155
                 }
1158
                 }
2806
         if (CollectionUtil.isEmpty(reservedConferences)) {
2809
         if (CollectionUtil.isEmpty(reservedConferences)) {
2807
             return reservedConferences;
2810
             return reservedConferences;
2808
         }
2811
         }
2809
-        Map<Long,String> userIdMap = null;
2812
+        Map<Long, String> userIdMap = null;
2810
         List<Long> userIds = reservedConferences.stream().map(ReservedConference::getUserId).collect(Collectors.toList());
2813
         List<Long> userIds = reservedConferences.stream().map(ReservedConference::getUserId).collect(Collectors.toList());
2811
-        if(CollectionUtil.isNotEmpty(userIds)){
2814
+        if (CollectionUtil.isNotEmpty(userIds)) {
2812
             // 根据userids查询用户名
2815
             // 根据userids查询用户名
2813
             List<SysUser> userList = sysUserMapper.selectUserListByIds(userIds);
2816
             List<SysUser> userList = sysUserMapper.selectUserListByIds(userIds);
2814
-            if(CollectionUtil.isNotEmpty(userList)){
2815
-                userIdMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId,SysUser::getUserName));
2817
+            if (CollectionUtil.isNotEmpty(userList)) {
2818
+                userIdMap = userList.stream().collect(Collectors.toMap(SysUser::getUserId, SysUser::getUserName));
2816
             }
2819
             }
2817
         }
2820
         }
2818
         for (ReservedConference reservedConference : reservedConferences) {
2821
         for (ReservedConference reservedConference : reservedConferences) {
2819
-            if(null!=reservedConference.getUserId() && null!=userIdMap){
2822
+            if (null != reservedConference.getUserId() && null != userIdMap) {
2820
                 reservedConference.setUserName(userIdMap.get(reservedConference.getUserId()));
2823
                 reservedConference.setUserName(userIdMap.get(reservedConference.getUserId()));
2821
             }
2824
             }
2822
             Date startTime = reservedConference.getScheduleStartTime();
2825
             Date startTime = reservedConference.getScheduleStartTime();
2852
         if (file.isEmpty()) {
2855
         if (file.isEmpty()) {
2853
             return AjaxResult.error("请选择要上传的文件");
2856
             return AjaxResult.error("请选择要上传的文件");
2854
         }
2857
         }
2855
-        //String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
2856
         UUID uuid = UUID.randomUUID();
2858
         UUID uuid = UUID.randomUUID();
2857
-        String targetPath = "D:\\home\\unzip\\"+uuid+"\\";
2859
+        String targetPath = "\\home\\ruoyi\\uploadPath\\upload\\unzipFile\\";
2860
+        //String targetPath = "D:\\home\\unzip\\" + uuid + "\\";
2858
         File zipFile = null;
2861
         File zipFile = null;
2859
         InputStream ins = null;
2862
         InputStream ins = null;
2860
         try {
2863
         try {
2861
             ins = file.getInputStream();
2864
             ins = file.getInputStream();
2862
-            String savePath = "D:\\develop\\java\\";
2863
-            String saveName = uuid+file.getOriginalFilename();
2864
-            zipFile = new File(savePath+saveName);
2865
+            //上传的压缩包保存的路径
2866
+            //String savePath = "D:\\develop\\java\\";
2867
+            String savePath = "\\home\\ruoyi\\uploadPath\\upload\\zipFile\\";
2868
+            String saveName = uuid + file.getOriginalFilename();
2869
+            zipFile = new File(savePath + saveName);
2865
             inputChangeToFile(ins, zipFile);
2870
             inputChangeToFile(ins, zipFile);
2866
         } catch (IOException e) {
2871
         } catch (IOException e) {
2867
             e.printStackTrace();
2872
             e.printStackTrace();
2868
         }
2873
         }
2869
         //解压缩上传的压缩包
2874
         //解压缩上传的压缩包
2870
-        boolean unzipSuccess  = UnZipFileUtils.unZipFile(zipFile, targetPath);
2871
-        if (unzipSuccess ) {
2872
-            //去掉后缀名,拿到解压后的文件夹路径
2873
-            String fileName = file.getOriginalFilename();
2874
-            String nameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."));
2875
+        boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
2876
+        if (unzipSuccess) {
2875
             File directory = new File(targetPath);
2877
             File directory = new File(targetPath);
2876
             List<String> andConvertPDF = findAndConvertPDF(directory);
2878
             List<String> andConvertPDF = findAndConvertPDF(directory);
2877
-            if (andConvertPDF != null && andConvertPDF.size() > 0){
2878
-                // 返回找到的PDF文件路径
2879
-                return AjaxResult.success(andConvertPDF);
2880
-            }else {
2879
+            if (andConvertPDF != null && andConvertPDF.size() > 0) {
2880
+                //遍历路径
2881
+                for (String pdfUrl : andConvertPDF) {
2882
+                    //获取文件的页数
2883
+                    int fileNumPage = getFileNumPage(pdfUrl);
2884
+                    StringBuilder stringBuilder = new StringBuilder(); // 创建一个StringBuilder对象
2885
+                    for (int i = 0; i < fileNumPage; i++) {
2886
+                        //对接腾讯云接口.识别里面的数据
2887
+                        //暂时写死
2888
+                        String pdfFilePath = "http://121.40.189.20:9000/API/uploadPath/upload/2023/11/14/ca2ca4697e5449ff9b9d23f95b221f58.pdf";
2889
+                        String text = OCRUtils.pdfIdentifyText(pdfUrl, i + 1);
2890
+                        if (stringBuilder.length() > 0) {
2891
+                            stringBuilder.append(","); // 在已有内容的情况下添加逗号分隔符
2892
+                        }
2893
+                        stringBuilder.append(text); // 拼接当前的字符串
2894
+                    }
2895
+                    // 将字符串按逗号分隔符切割
2896
+                    String[] fields = stringBuilder.toString().split(",");
2897
+                    JSONObject jsonObject = new JSONObject(); // 创建一个空的JSON对象
2898
+                    for (String field : fields) {
2899
+                        // 对于每个字段,再按冒号分隔符拆分出键和值
2900
+                        String[] keyValue = field.split(":");
2901
+                        if (keyValue.length == 2) { // 对于合法的键值对,将其添加到JSON对象中
2902
+                            jsonObject.put(keyValue[0], keyValue[1]);
2903
+                        }
2904
+                    }
2905
+                    //调用新增案件的接口
2906
+                    CaseApplication caseApplication = new CaseApplication();
2907
+
2908
+                    caseApplication.setApplicationOrganId(jsonObject.getString("统一社会信用代码"));
2909
+                    caseApplication.setCompLegalPerson(jsonObject.getString("法定代表人"));
2910
+                    caseApplication.setResidenAffiliAppli(jsonObject.getString("住所"));
2911
+                    caseApplication.setContactAddressAgent(jsonObject.getString("联系地址"));
2912
+                    caseApplication.setNameAgent(jsonObject.getString("委托代理人"));
2913
+                    caseApplication.setContactTelphoneAgent(jsonObject.getString("联系电话"));
2914
+                    caseApplication.setDebtorName(jsonObject.getString("被申请人"));
2915
+                    caseApplication.setDebtorIdentityNum(jsonObject.getString("居民身份证号码"));
2916
+                    caseApplication.setArbitratClaims(jsonObject.getString("仲裁请求"));
2917
+                    caseApplication.setCaseSubjectAmount(new BigDecimal(1));
2918
+                    List<CaseAffiliate> caseAffiliates = new ArrayList<>();
2919
+                    CaseAffiliate caseAffiliate = new CaseAffiliate();
2920
+                    caseAffiliate.setIdentityType(1);
2921
+                    caseAffiliate.setName(jsonObject.getString("申请人"));
2922
+                    caseAffiliate.setIdentityNum("");
2923
+                    caseAffiliate.setContactTelphone(jsonObject.getString("申请人联系电话"));
2924
+                    caseAffiliates.add(caseAffiliate);
2925
+                    CaseAffiliate caseAffiliate1 = new CaseAffiliate();
2926
+                    caseAffiliate1.setIdentityType(2);
2927
+                    caseAffiliate1.setName(jsonObject.getString("被申请人"));
2928
+                    caseAffiliate1.setIdentityNum("");
2929
+                    caseAffiliate1.setContactTelphone(jsonObject.getString("被申请人联系电话"));
2930
+                    caseAffiliates.add(caseAffiliate1);
2931
+                    caseApplication.setCaseAffiliates(caseAffiliates);
2932
+                    this.insertcaseApplication(caseApplication);
2933
+                    if (null != caseApplication.getId()) {
2934
+                        // 绑定案件与申请书
2935
+                        File file1 = new File(pdfUrl);
2936
+                        CaseAttach caseAttach = new CaseAttach();
2937
+                        caseAttach.setCaseAppliId(caseApplication.getId());
2938
+                        String saveName = "/profile/upload/" + file1.getName();
2939
+                        String savePath = "/home/ruoyi/uploadPath/upload";
2940
+                        caseAttach.setAnnexPath(savePath);
2941
+                        caseAttach.setAnnexName(saveName);
2942
+                        caseAttach.setAnnexType(1);
2943
+                        caseAttachMapper.save(caseAttach);
2944
+                    }
2945
+                }
2946
+                return AjaxResult.success("导入成功");
2947
+            } else {
2881
                 // 没有找到符合条件的文件
2948
                 // 没有找到符合条件的文件
2882
                 return AjaxResult.error("未找到符合条件的文件");
2949
                 return AjaxResult.error("未找到符合条件的文件");
2883
             }
2950
             }
2884
-        }else {
2951
+        } else {
2885
             // 解压失败
2952
             // 解压失败
2886
             return AjaxResult.error("解压失败");
2953
             return AjaxResult.error("解压失败");
2887
         }
2954
         }
2888
 
2955
 
2889
     }
2956
     }
2957
+
2890
     public static List<String> findAndConvertPDF(File directory) {
2958
     public static List<String> findAndConvertPDF(File directory) {
2891
         List<String> pdfPaths = new ArrayList<>();
2959
         List<String> pdfPaths = new ArrayList<>();
2892
         if (directory.isFile()) {
2960
         if (directory.isFile()) {
2903
                         path = pdfPath;
2971
                         path = pdfPath;
2904
                     }
2972
                     }
2905
                 }
2973
                 }
2906
-                if (path!= null) {
2974
+                if (path != null) {
2907
                     pdfPaths.add(path);
2975
                     pdfPaths.add(path);
2908
                 }
2976
                 }
2909
             }
2977
             }
2910
         } else if (directory.isDirectory()) {
2978
         } else if (directory.isDirectory()) {
2911
             searchAndConvertPDF(directory, pdfPaths);
2979
             searchAndConvertPDF(directory, pdfPaths);
2912
-        }else {
2980
+        } else {
2913
             return null;
2981
             return null;
2914
         }
2982
         }
2915
-      return pdfPaths;
2983
+        return pdfPaths;
2916
     }
2984
     }
2917
 
2985
 
2918
     public static boolean isPDF(File file) {
2986
     public static boolean isPDF(File file) {
2929
             return "";
2997
             return "";
2930
         }
2998
         }
2931
     }
2999
     }
3000
+
2932
     public static void searchAndConvertPDF(File directory, List<String> pdfPaths) {
3001
     public static void searchAndConvertPDF(File directory, List<String> pdfPaths) {
2933
         File[] files = directory.listFiles();
3002
         File[] files = directory.listFiles();
2934
         if (files != null) {
3003
         if (files != null) {
2954
             }
3023
             }
2955
         }
3024
         }
2956
     }
3025
     }
3026
+
2957
     private static String convertToPDF(File file) {
3027
     private static String convertToPDF(File file) {
2958
         String wordFilePath = file.getAbsolutePath();
3028
         String wordFilePath = file.getAbsolutePath();
2959
-        String pdfSaveDirectory ="D:\\home\\unzip\\wordToPDF\\";
3029
+       // String pdfSaveDirectory = "D:\\home\\unzip\\wordToPDF\\";
3030
+        String pdfSaveDirectory = "\\home\\ruoyi\\uploadPath\\upload\\wordToPDF\\";
2960
         File directory = new File(pdfSaveDirectory);
3031
         File directory = new File(pdfSaveDirectory);
2961
         if (!directory.exists()) {
3032
         if (!directory.exists()) {
2962
             directory.mkdirs();
3033
             directory.mkdirs();
2963
         }
3034
         }
2964
         String name = file.getName();
3035
         String name = file.getName();
2965
         String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
3036
         String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
2966
-        String pdfFilePath =pdfSaveDirectory+nameWithoutExtension+".pdf";
3037
+        String pdfFilePath = pdfSaveDirectory + nameWithoutExtension + ".pdf";
2967
         File inputWord = new File(wordFilePath);
3038
         File inputWord = new File(wordFilePath);
2968
         File outputFile = new File(pdfFilePath);
3039
         File outputFile = new File(pdfFilePath);
2969
-        try  {
3040
+        try {
2970
             InputStream docxInputStream = new FileInputStream(inputWord);
3041
             InputStream docxInputStream = new FileInputStream(inputWord);
2971
             OutputStream outputStream = new FileOutputStream(outputFile);
3042
             OutputStream outputStream = new FileOutputStream(outputFile);
2972
             IConverter converter = LocalConverter.builder().build();
3043
             IConverter converter = LocalConverter.builder().build();
2973
             converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
3044
             converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
2974
             docxInputStream.close();
3045
             docxInputStream.close();
2975
             outputStream.close();
3046
             outputStream.close();
2976
-            System.out.println("success");
2977
-            File file1= new File(pdfFilePath);
2978
-            System.out.println("这是转化后的PDF文件路径"+file1);
2979
 
3047
 
2980
         } catch (Exception e) {
3048
         } catch (Exception e) {
2981
             e.printStackTrace();
3049
             e.printStackTrace();
2982
         }
3050
         }
2983
         return pdfFilePath;
3051
         return pdfFilePath;
2984
     }
3052
     }
3053
+
3054
+    private static int getFileNumPage(String pdfUrl) {
3055
+        File pdfFile = new File(pdfUrl);
3056
+        int pageCount = 0;
3057
+        try (PDDocument document = PDDocument.load(pdfFile)) {
3058
+            pageCount = document.getNumberOfPages();
3059
+        } catch (IOException e) {
3060
+            e.printStackTrace();
3061
+        }
3062
+        return pageCount;
3063
+    }
2985
 }
3064
 }
2986
 
3065
 
2987
 
3066
 

+ 95
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/OCRUtils.java Прегледај датотеку

1
+package com.ruoyi.wisdomarbitrate.utils;
2
+
3
+import com.tencentcloudapi.bsca.v20210811.models.LicenseSummary;
4
+import com.tencentcloudapi.common.Credential;
5
+import com.tencentcloudapi.common.exception.TencentCloudSDKException;
6
+import com.tencentcloudapi.common.profile.ClientProfile;
7
+import com.tencentcloudapi.common.profile.HttpProfile;
8
+import com.tencentcloudapi.ocr.v20181119.OcrClient;
9
+import com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Request;
10
+import com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Response;
11
+import org.json.JSONArray;
12
+import org.json.JSONObject;
13
+
14
+import java.util.ArrayList;
15
+import java.util.List;
16
+
17
+public class OCRUtils {
18
+    //API的SecretId
19
+    private static final String SECRET_ID = "AKIDeEf2A8uX1HSainvvnXAc3X9ZlhtyvkMp";
20
+    //API的SecretKey
21
+    private static final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
22
+
23
+    public static String pdfIdentifyText(String ImageUrl, Integer PageNumber) {
24
+        try {
25
+            // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
26
+            // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
27
+            // 密钥可前往官网控制台 https://console.cloud.tencent.com/cam/capi 进行获取
28
+            Credential cred = new Credential(SECRET_ID, SECRET_KEY);
29
+            // 实例化一个http选项,可选的,没有特殊需求可以跳过
30
+            HttpProfile httpProfile = new HttpProfile();
31
+            httpProfile.setEndpoint("ocr.tencentcloudapi.com");
32
+            // 实例化一个client选项,可选的,没有特殊需求可以跳过
33
+            ClientProfile clientProfile = new ClientProfile();
34
+            clientProfile.setHttpProfile(httpProfile);
35
+            // 实例化要请求产品的client对象,clientProfile是可选的
36
+            OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
37
+            // 实例化一个请求对象,每个接口都会对应一个request对象
38
+            SmartStructuralOCRV2Request req = new SmartStructuralOCRV2Request();
39
+            req.setImageUrl(ImageUrl);
40
+            req.setIsPdf(true);
41
+            req.setPdfPageNumber(PageNumber.longValue());
42
+            String[] itemNames1 = {"申请人", "统一社会信用代码", "法定代表人", "住所", "联系地址", "委托代理人"
43
+                    , "联系电话", "电子邮件", "被申请人", "居民身份证号码", "住所", "联系电话", "电子邮件", "仲裁请求"
44
+                    , "事实和理由"};
45
+            req.setItemNames(itemNames1);
46
+            // 返回的resp是一个SmartStructuralOCRV2Response的实例,与请求对象对应
47
+            SmartStructuralOCRV2Response resp = client.SmartStructuralOCRV2(req);
48
+            // 输出json格式的字符串回包
49
+            System.out.println(SmartStructuralOCRV2Response.toJsonString(resp));
50
+            //解析数据
51
+            String s = SmartStructuralOCRV2Response.toJsonString(resp);
52
+            // 解析JSON数据
53
+            JSONObject jsonObject = new JSONObject(s);
54
+            JSONArray structuralList = jsonObject.getJSONArray("StructuralList");
55
+            // 遍历StructuralList中的Groups,获取Key对应的AutoName和Value对应的AutoConten
56
+            StringBuilder stringBuilder = new StringBuilder(); // 创建一个StringBuilder对象
57
+            for (int i = 0; i < structuralList.length(); i++) {
58
+                JSONArray groups = structuralList.getJSONObject(i).getJSONArray("Groups");
59
+                for (int j = 0; j < groups.length(); j++) {
60
+                    JSONArray lines = groups.getJSONObject(j).getJSONArray("Lines");
61
+                    for (int k = 0; k < lines.length(); k++) {
62
+                        JSONObject line = lines.getJSONObject(k);
63
+                        JSONObject key = line.getJSONObject("Key");
64
+                        JSONObject value = line.getJSONObject("Value");
65
+                        String autoName = key.getString("AutoName");
66
+                        String autoContent = value.getString("AutoContent");
67
+                        String text = autoName + ":" + autoContent;
68
+                        if (stringBuilder.length() > 0) {
69
+                            stringBuilder.append(","); // 在已有内容的情况下添加逗号分隔符
70
+                        }
71
+                        stringBuilder.append(text); // 拼接当前的字符串
72
+                    }
73
+                }
74
+            }
75
+            return stringBuilder.toString(); // 获取最终的拼接结果
76
+        } catch (TencentCloudSDKException e) {
77
+            System.out.println(e.toString());
78
+        }
79
+        return null;
80
+    }
81
+
82
+    public static void main(String[] args) {
83
+        String input = "申请人:招商银行,住所:上海嘉定区,联系地址:上海徐汇区,法定代表人:招商法人,委托代理人:黄海龙,被申请人:白贵勇,住所:陕西,联系地址:陕西,仲裁请求:仲裁委主任依据《2022年版仲裁规则》第三十一条第(四)项、第三十二条的规定指定白贵勇仲裁员为仲裁庭的仲裁员。本案由白贵勇仲裁员成立仲裁庭进行审理。,事实和理由:(一)申请人的仲裁请求及事实和理由,申请人:债务纠纷";
84
+        String[] fields = input.split(",");
85
+        JSONObject jsonObject = new JSONObject(); // 创建一个空的JSON对象
86
+        for (String field : fields) {
87
+            // 对于每个字段,再按冒号分隔符拆分出键和值
88
+            String[] keyValue = field.split(":");
89
+            if (keyValue.length == 2) { // 对于合法的键值对,将其添加到JSON对象中
90
+                jsonObject.put(keyValue[0], keyValue[1]);
91
+            }
92
+        }
93
+        System.out.println(jsonObject.toString());
94
+    }
95
+}

+ 41
- 5
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/Tset.java Прегледај датотеку

1
 package com.ruoyi.wisdomarbitrate.utils;
1
 package com.ruoyi.wisdomarbitrate.utils;
2
 
2
 
3
+
3
 import com.documents4j.api.DocumentType;
4
 import com.documents4j.api.DocumentType;
4
 import com.documents4j.api.IConverter;
5
 import com.documents4j.api.IConverter;
5
 import com.documents4j.job.LocalConverter;
6
 import com.documents4j.job.LocalConverter;
10
 import com.tencentcloudapi.ocr.v20181119.OcrClient;
11
 import com.tencentcloudapi.ocr.v20181119.OcrClient;
11
 import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRRequest;
12
 import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRRequest;
12
 import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRResponse;
13
 import com.tencentcloudapi.ocr.v20181119.models.GeneralAccurateOCRResponse;
14
+import com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Request;
15
+import com.tencentcloudapi.ocr.v20181119.models.SmartStructuralOCRV2Response;
16
+import org.apache.pdfbox.pdmodel.PDDocument;
17
+import org.json.JSONArray;
18
+import org.json.JSONObject;
13
 
19
 
14
 
20
 
15
 import java.io.*;
21
 import java.io.*;
22
+import java.util.ArrayList;
23
+import java.util.List;
16
 
24
 
17
 public class Tset {
25
 public class Tset {
18
     public static void main(String[] args) {
26
     public static void main(String[] args) {
21
         //API的SecretKey
29
         //API的SecretKey
22
          final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
30
          final String SECRET_KEY = "QjphKo8zkHZigT8j9PVtFPJyfIvO3d6V";
23
 
31
 
24
-        String pdfFilePath = "D:\\data\\1. 仲裁申请书-陈博.pdf";
32
+        String pdfFilePath = "http://121.40.189.20:8000/API/uploadPath/upload/1.pdf";
33
+       // String pdfFilePath = "http://121.40.189.20:9000/API/uploadPath/upload/2023/11/14/ca2ca4697e5449ff9b9d23f95b221f58.pdf";
25
 
34
 
26
         try{
35
         try{
27
             // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
36
             // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
37
             // 实例化要请求产品的client对象,clientProfile是可选的
46
             // 实例化要请求产品的client对象,clientProfile是可选的
38
             OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
47
             OcrClient client = new OcrClient(cred, "ap-beijing", clientProfile);
39
             // 实例化一个请求对象,每个接口都会对应一个request对象
48
             // 实例化一个请求对象,每个接口都会对应一个request对象
40
-            GeneralAccurateOCRRequest req = new GeneralAccurateOCRRequest();
49
+            SmartStructuralOCRV2Request req = new SmartStructuralOCRV2Request();
41
             req.setImageUrl(pdfFilePath);
50
             req.setImageUrl(pdfFilePath);
42
             req.setIsPdf(true);
51
             req.setIsPdf(true);
43
             req.setPdfPageNumber(1L);
52
             req.setPdfPageNumber(1L);
44
-            // 返回的resp是一个GeneralAccurateOCRResponse的实例,与请求对象对应
45
-            GeneralAccurateOCRResponse resp = client.GeneralAccurateOCR(req);
53
+            String[] itemNames1 = {"申请人", "住所"};
54
+            req.setItemNames(itemNames1);
55
+            // 返回的resp是一个SmartStructuralOCRV2Response的实例,与请求对象对应
56
+            SmartStructuralOCRV2Response resp = client.SmartStructuralOCRV2(req);
46
             // 输出json格式的字符串回包
57
             // 输出json格式的字符串回包
47
-            System.out.println(GeneralAccurateOCRResponse.toJsonString(resp));
58
+            System.out.println(SmartStructuralOCRV2Response.toJsonString(resp));
59
+            //解析数据
60
+            String s = SmartStructuralOCRV2Response.toJsonString(resp);
61
+            // 解析JSON数据
62
+            JSONObject jsonObject = new JSONObject(s);
63
+            JSONArray structuralList = jsonObject.getJSONArray("StructuralList");
64
+            // 遍历StructuralList中的Groups,获取Key对应的AutoName和Value对应的AutoContent
65
+            List<String> strings = new ArrayList<>();
66
+            for (int i = 0; i < structuralList.length(); i++) {
67
+                JSONArray groups = structuralList.getJSONObject(i).getJSONArray("Groups");
68
+                for (int j = 0; j < groups.length(); j++) {
69
+                    JSONArray lines = groups.getJSONObject(j).getJSONArray("Lines");
70
+                    for (int k = 0; k < lines.length(); k++) {
71
+                        JSONObject line = lines.getJSONObject(k);
72
+                        JSONObject key = line.getJSONObject("Key");
73
+                        JSONObject value = line.getJSONObject("Value");
74
+                        String autoName = key.getString("AutoName");
75
+                        String autoContent = value.getString("AutoContent");
76
+                        String  text = autoName +":"+ autoContent;
77
+                        strings.add(text);
78
+                    }
79
+                }
80
+            }
81
+            System.out.println(strings);
82
+
48
         } catch (TencentCloudSDKException e) {
83
         } catch (TencentCloudSDKException e) {
49
             System.out.println(e.toString());
84
             System.out.println(e.toString());
50
         }
85
         }
86
+
51
     }
87
     }
52
 }
88
 }