Parcourir la source

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

wangqiong123 il y a 2 ans
Parent
révision
f62248e93e

+ 12
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/FatchRule.java Voir le fichier

25
 
25
 
26
     private Long templateId;
26
     private Long templateId;
27
     private String databaseName;
27
     private String databaseName;
28
+    /**
29
+     * 顺序,开始字段重复时,指定抓取第几个
30
+     */
31
+    private Integer startContentRepeatOrder;
32
+    /**
33
+     * 结束字段重复时指定的顺序,默认1,只能>0填正整数
34
+     */
35
+    private Integer endContentRepeatOrder;
36
+    /**
37
+     * 抓取方向,默认0,0-从前往后抓取,1-从后往前抓取
38
+     */
39
+    private Integer fatchOrder;
28
 
40
 
29
 }
41
 }

+ 3
- 13
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/DeptIdentifyServiceImpl.java Voir le fichier

535
 
535
 
536
     @Override
536
     @Override
537
     public List<FatchRule> getFatchRuleByTemplateid(TemplateManage templateManage) {
537
     public List<FatchRule> getFatchRuleByTemplateid(TemplateManage templateManage) {
538
-        TemplateFatchRule templateFatchRule = new TemplateFatchRule();
539
-        templateFatchRule.setTemplateId(templateManage.getId());
540
-        List<FatchRule>  fatchRules = new ArrayList<>();
541
-        int countTemplateFatchRule = templateFatchRuleMapper.selectTemplateFatchRulecount(templateFatchRule);
542
-        if(countTemplateFatchRule!=0){
538
+
543
             FatchRule fatchRule = new FatchRule();
539
             FatchRule fatchRule = new FatchRule();
544
             fatchRule.setTemplateId(templateManage.getId());
540
             fatchRule.setTemplateId(templateManage.getId());
545
-            fatchRules = fatchRuleMapper.selectFatchRuleList(fatchRule);
546
-            return fatchRules;
547
-        }else {
548
-            FatchRule fatchRule = new FatchRule();
549
-            fatchRule.setIsDefault(1);
550
-            fatchRules = fatchRuleMapper.selectFatchRuleListIsDefault(fatchRule);
551
-            return fatchRules;
552
-        }
541
+            return fatchRuleMapper.selectFatchRuleList(fatchRule);
542
+
553
     }
543
     }
554
 
544
 
555
     @Override
545
     @Override

+ 109
- 33
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/OCRUtils.java Voir le fichier

32
             , "委托代理人", "联系电话", "电子邮件", "被申请人", "居民身份证号码", "仲裁请求", "事实和理由"};
32
             , "委托代理人", "联系电话", "电子邮件", "被申请人", "居民身份证号码", "仲裁请求", "事实和理由"};
33
     // 贷款合同识别字段
33
     // 贷款合同识别字段
34
     private static final String[] contractName = {
34
     private static final String[] contractName = {
35
-            "合同编号","甲方(贷款人)" ,"或委托代理人签字:","本合同的初始贷款年利率为","乙方确认有效的电子信箱地址为"};
35
+            "合同编号", "甲方(贷款人)", "或委托代理人签字:", "本合同的初始贷款年利率为", "乙方确认有效的电子信箱地址为"};
36
     // 调解协议识别字段
36
     // 调解协议识别字段
37
-    private static final String[] accordName = {"金融消费纠纷基本情况","经调解,双方自愿达成如下协议"};
37
+    private static final String[] accordName = {"金融消费纠纷基本情况", "经调解,双方自愿达成如下协议"};
38
     // 授权委托书识别字段
38
     // 授权委托书识别字段
39
     private static final String[] powerAttorneyName = {"职务"};
39
     private static final String[] powerAttorneyName = {"职务"};
40
+
40
     /**
41
     /**
41
      * pdf识别成文字
42
      * pdf识别成文字
43
+     *
42
      * @param imageBase64
44
      * @param imageBase64
43
      * @param pageNumber
45
      * @param pageNumber
44
-     * @param fatchRules 抓取规则
46
+     * @param fatchRules  抓取规则
45
      * @return
47
      * @return
46
      */
48
      */
47
     public static String pdfIdentifyText(String imageBase64, Integer pageNumber, List<FatchRule> fatchRules) {
49
     public static String pdfIdentifyText(String imageBase64, Integer pageNumber, List<FatchRule> fatchRules) {
48
-        StringBuilder respStr=new StringBuilder();
50
+        StringBuilder respStr = new StringBuilder();
49
         try {
51
         try {
50
             // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
52
             // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
51
             // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
53
             // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
76
             for (TextDetection textDetection : textDetections) {
78
             for (TextDetection textDetection : textDetections) {
77
                 respStr.append(textDetection.getDetectedText());
79
                 respStr.append(textDetection.getDetectedText());
78
             }
80
             }
79
-        }catch (TencentCloudSDKException e){
81
+        } catch (TencentCloudSDKException e) {
80
             throw new ServiceException("ocr识别失败");
82
             throw new ServiceException("ocr识别失败");
81
         }
83
         }
82
-        if(respStr.toString().endsWith(String.valueOf(pageNumber))){
84
+        if (respStr.toString().endsWith(String.valueOf(pageNumber))) {
83
             int lastIndexOf = respStr.toString().lastIndexOf(String.valueOf(pageNumber));
85
             int lastIndexOf = respStr.toString().lastIndexOf(String.valueOf(pageNumber));
84
-            return respStr.toString().substring(0,lastIndexOf);
86
+            return respStr.toString().substring(0, lastIndexOf);
85
         }
87
         }
86
         return respStr.toString();
88
         return respStr.toString();
87
 
89
 
88
 
90
 
89
-
90
 //
91
 //
91
 //            //解析数据
92
 //            //解析数据
92
 //            String s = GeneralAccurateOCRResponse.toJsonString(resp);
93
 //            String s = GeneralAccurateOCRResponse.toJsonString(resp);
121
 
122
 
122
     /**
123
     /**
123
      * pdf识别成文字
124
      * pdf识别成文字
125
+     *
124
      * @param imageBase64
126
      * @param imageBase64
125
      * @param pageNumber
127
      * @param pageNumber
126
-     * @param type pdf类型
128
+     * @param type        pdf类型
127
      * @return
129
      * @return
128
      */
130
      */
129
-    public static String pdfIdentifyText1(String imageBase64, Integer pageNumber,String type) {
131
+    public static String pdfIdentifyText1(String imageBase64, Integer pageNumber, String type) {
130
         try {
132
         try {
131
             // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
133
             // 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey,此处还需注意密钥对的保密
132
             // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
134
             // 代码泄露可能会导致 SecretId 和 SecretKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考,建议采用更安全的方式来使用密钥,请参见:https://cloud.tencent.com/document/product/1278/85305
145
             req.setImageBase64(imageBase64);
147
             req.setImageBase64(imageBase64);
146
             req.setIsPdf(true);
148
             req.setIsPdf(true);
147
             req.setPdfPageNumber(pageNumber.longValue());
149
             req.setPdfPageNumber(pageNumber.longValue());
148
-            if(type.contains("申请书")){
150
+            if (type.contains("申请书")) {
149
                 req.setItemNames(applicantName);
151
                 req.setItemNames(applicantName);
150
-            }else if(type.contains("调解协议")){
152
+            } else if (type.contains("调解协议")) {
151
                 req.setItemNames(accordName);
153
                 req.setItemNames(accordName);
152
-            }else if(type.contains("合同")){
154
+            } else if (type.contains("合同")) {
153
                 req.setItemNames(contractName);
155
                 req.setItemNames(contractName);
154
-            }else if(type.contains("授权委托书")){
156
+            } else if (type.contains("授权委托书")) {
155
                 req.setItemNames(powerAttorneyName);
157
                 req.setItemNames(powerAttorneyName);
156
             }
158
             }
157
 
159
 
190
         }
192
         }
191
         return null;
193
         return null;
192
     }
194
     }
193
-    public static String pdfConvertBase64(String pathUrl){
195
+
196
+    public static String pdfConvertBase64(String pathUrl) {
194
         try {
197
         try {
195
             File file = new File(pathUrl);
198
             File file = new File(pathUrl);
196
             FileInputStream fileInputStream = new FileInputStream(file);
199
             FileInputStream fileInputStream = new FileInputStream(file);
207
 
210
 
208
     /**
211
     /**
209
      * 根据抓取规则获取内容
212
      * 根据抓取规则获取内容
210
-     * @param ocrText ocr识别的text
213
+     *
214
+     * @param ocrText    ocr识别的text
211
      * @param fatchRules 抓取规则
215
      * @param fatchRules 抓取规则
212
      * @return
216
      * @return
213
      */
217
      */
214
     public static void fatchRuleGetContent(String ocrText, List<FatchRule> fatchRules, Map<String, String> fatchMap) {
218
     public static void fatchRuleGetContent(String ocrText, List<FatchRule> fatchRules, Map<String, String> fatchMap) {
215
-
219
+        String text = ocrText;
216
         if (CollectionUtil.isNotEmpty(fatchRules)) {
220
         if (CollectionUtil.isNotEmpty(fatchRules)) {
217
 
221
 
218
             for (FatchRule fatchRule : fatchRules) {
222
             for (FatchRule fatchRule : fatchRules) {
219
-                if (StrUtil.isEmpty(fatchRule.getStartContent())) {
220
-                    continue;
221
-                }
223
+                // 从后往前抓取
224
+                if (fatchRule.getFatchOrder() != null && fatchRule.getFatchOrder() == 1) {
225
+//                    String reverseText = StrUtil.reverse(ocrText);
226
+//                    if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())) {
227
+//                        fatchMap.put(fatchRule.getColumnName(), trimStr(text));
228
+//                    } else if(StrUtil.isEmpty(fatchRule.getStartContent())&&StrUtil.isNotEmpty(fatchRule.getEndContent())){
229
+//                        // 开始字段为空,结束字段不为空
230
+//                        String endReverseText = StrUtil.reverse(fatchRule.getEndContent());
231
+//                        int endContIndex = StrUtil.ordinalIndexOf(reverseText, endReverseText, fatchRule.getEndContentRepeatOrder());
232
+//                        if (endContIndex != -1) {
233
+//                            String substring = text.substring(0, endContIndex);
234
+//                            fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
235
+//                        }
236
+//
237
+//
238
+//                    }else if(StrUtil.isNotEmpty(fatchRule.getStartContent())&&StrUtil.isEmpty(fatchRule.getEndContent())){
239
+//                        // 开始字段不为空,结束字段为空
240
+//                        // 开始字段为空,结束字段不为空
241
+//                        String startReverseText = StrUtil.reverse(fatchRule.getStartContent());
242
+//                        int startContIndex = StrUtil.ordinalIndexOf(reverseText, startReverseText, fatchRule.getStartContentRepeatOrder());
243
+//                        if (startContIndex != -1) {
244
+//                            String substring = text.substring(0, startContIndex);
245
+//                            fatchMap.put(fatchRule.getColumnName(), trimStr(StrUtil.reverse(substring)));
246
+//                        }
247
+//
248
+//                    }else if(StrUtil.isNotEmpty(fatchRule.getStartContent())&&StrUtil.isNotEmpty(fatchRule.getEndContent())){
249
+//                        String startReverseText = StrUtil.reverse(fatchRule.getStartContent());
250
+//                        String endReverseText = StrUtil.reverse(fatchRule.getEndContent());
251
+//                        int startContIndex = StrUtil.ordinalIndexOf(reverseText, startReverseText, fatchRule.getStartContentRepeatOrder());
252
+//                        if (startContIndex != -1) {
253
+//                        // 结束字段不为空
254
+//                        int endContIndex = StrUtil.ordinalIndexOf(reverseText, endReverseText, fatchRule.getEndContentRepeatOrder());
255
+//                        if (endContIndex != -1 && (startContIndex + fatchRule.getStartContent().length()) <= text.length()) {
256
+//                            String substring = text.substring(startContIndex + fatchRule.getStartContent().length(), endContIndex);
257
+//                            // 去除\n
258
+//                            fatchMap.put(fatchRule.getColumnName(),trimStr(StrUtil.reverse(substring)));
259
+//                        }
260
+//                        }
261
+//                    }
262
+                } else {
263
+                    // 开始为空结束为空
264
+                    if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())) {
265
+                        fatchMap.put(fatchRule.getColumnName(), trimStr(text));
266
+                    } else if (StrUtil.isNotEmpty(fatchRule.getStartContent())) {
267
+                        int startContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getStartContent(), fatchRule.getStartContentRepeatOrder());
268
+                        if (startContIndex != -1) {
269
+                            // 开始不为空结束为空
270
+                            if (StrUtil.isEmpty(fatchRule.getEndContent())) {
271
+                                if ((startContIndex + fatchRule.getStartContent().length()) <= text.length()) {
272
+                                    String substring = text.substring(startContIndex + fatchRule.getStartContent().length());
273
+                                    // 去除\n
274
+                                    fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
275
+                                }
222
 
276
 
223
-                if (StrUtil.isNotEmpty(fatchRule.getStartContent()) && StrUtil.isNotEmpty(fatchRule.getEndContent())) {
224
-                    String s = StringUtils.substringBetween(ocrText, fatchRule.getStartContent(), fatchRule.getEndContent());
225
-                    if(StrUtil.isNotEmpty(s)){
226
-                        fatchMap.put(fatchRule.getColumnName(), StrUtil.trim(s));
227
-                    }else {
228
-                        fatchMap.put(fatchRule.getColumnName(),"");
229
-                    }
277
+                            } else {
278
+                                // 开始不为空结束不为空
279
+                                int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder());
280
+                                if (endContIndex != -1 && (startContIndex + fatchRule.getStartContent().length()) <= text.length()) {
281
+                                    String substring = text.substring(startContIndex + fatchRule.getStartContent().length(), endContIndex);
282
+                                    // 去除\n
283
+                                    fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
284
+                                }
230
 
285
 
231
-                }else if(StrUtil.isNotEmpty(fatchRule.getStartContent()) && StrUtil.isEmpty(fatchRule.getEndContent())){
232
-                    String s = StringUtils.substringAfter(ocrText,fatchRule.getStartContent());
233
-                    if(StrUtil.isNotEmpty(s)){
234
-                        fatchMap.put(fatchRule.getColumnName(), StrUtil.trim(s));
235
-                    }else {
236
-                        fatchMap.put(fatchRule.getColumnName(),"");
286
+                            }
287
+//
288
+                        }
289
+
290
+                    } else if (StrUtil.isEmpty(fatchRule.getStartContent()) && StrUtil.isNotEmpty(fatchRule.getEndContent())) {
291
+                        // 开始为空结束不为空
292
+                        int endContIndex = StrUtil.ordinalIndexOf(text, fatchRule.getEndContent(), fatchRule.getEndContentRepeatOrder());
293
+                        if (endContIndex != -1) {
294
+                            String substring = text.substring(0, endContIndex);
295
+                            fatchMap.put(fatchRule.getColumnName(), trimStr(substring));
296
+                        }
237
                     }
297
                     }
238
                 }
298
                 }
239
             }
299
             }
241
 
301
 
242
 
302
 
243
     }
303
     }
304
+
305
+    /**
306
+     * 去除末尾空格
307
+     *
308
+     * @param substring
309
+     * @return
310
+     */
311
+    private static String trimStr(String substring) {
312
+        if (StrUtil.isNotEmpty(substring)) {
313
+            return StrUtil.trim(substring);
314
+        } else {
315
+            return "";
316
+        }
317
+
318
+    }
319
+
244
 }
320
 }

+ 12
- 5
ruoyi-system/src/main/resources/mapper/wisdomarbitrate/FatchRuleMapper.xml Voir le fichier

12
         <result column="column" property="column" />
12
         <result column="column" property="column" />
13
         <result column="column_name" property="columnName" />
13
         <result column="column_name" property="columnName" />
14
         <result column="is_default" property="isDefault" />
14
         <result column="is_default" property="isDefault" />
15
+        <result column="start_content_repeat_order" property="startContentRepeatOrder" />
16
+        <result column="end_content_repeat_order" property="endContentRepeatOrder" />
17
+        <result column="fatch_order" property="fatchOrder" />
15
     </resultMap>
18
     </resultMap>
16
     <select id="listByTemplateId" resultMap="BaseResultMap">
19
     <select id="listByTemplateId" resultMap="BaseResultMap">
17
-        select fr.* from fatch_rule fr join template_fatch_rule tfr on fr.id=tfr.fatch_rule_id
18
-        where template_id=#{templateId}
20
+        select f.id ,f.file_name ,f.start_content ,f.end_content ,
21
+        f.`column` , ifnull(f.is_default,0) is_default ,f.`column_name`,ifnull(f.start_content_repeat_order,1) start_content_repeat_order,ifnull(f.end_content_repeat_order,1) end_content_repeat_order,ifnull(f.fatch_order,0) fatch_order
22
+         from fatch_rule f join template_fatch_rule tfr on f.id=tfr.fatch_rule_id
23
+        where tfr.template_id=#{templateId}
19
     </select>
24
     </select>
20
 
25
 
21
     <select id="selectFatchRuleList" parameterType="FatchRule" resultMap="BaseResultMap">
26
     <select id="selectFatchRuleList" parameterType="FatchRule" resultMap="BaseResultMap">
22
         SELECT f.id ,f.file_name ,f.start_content ,f.end_content ,
27
         SELECT f.id ,f.file_name ,f.start_content ,f.end_content ,
23
-        f.`column` ,f.is_default ,f.`column_name`
28
+        f.`column` ,f.is_default ,f.`column_name`,f.start_content_repeat_order,f.end_content_repeat_order,f.fatch_order
24
         FROM template_fatch_rule tf
29
         FROM template_fatch_rule tf
25
         left join template_manage t on tf.template_id  = t.id
30
         left join template_manage t on tf.template_id  = t.id
26
         LEFT JOIN fatch_rule f on tf.fatch_rule_id  = f.id
31
         LEFT JOIN fatch_rule f on tf.fatch_rule_id  = f.id
89
         <if test="endContent != null and endContent != ''">end_content,</if>
94
         <if test="endContent != null and endContent != ''">end_content,</if>
90
         <if test="column != null and column != ''">`column`,</if>
95
         <if test="column != null and column != ''">`column`,</if>
91
         <if test="columnName != null and columnName != ''">`column_name`,</if>
96
         <if test="columnName != null and columnName != ''">`column_name`,</if>
92
-        <if test="isDefault != null">is_default</if>
97
+        <if test="isDefault != null">is_default,</if>
98
+        start_content_repeat_order,end_content_repeat_order,fatch_order
93
         )values(
99
         )values(
94
         <if test="fileName != null and fileName != ''">#{fileName},</if>
100
         <if test="fileName != null and fileName != ''">#{fileName},</if>
95
         <if test="startContent != null and startContent != ''">#{startContent},</if>
101
         <if test="startContent != null and startContent != ''">#{startContent},</if>
96
         <if test="endContent != null and endContent != ''">#{endContent},</if>
102
         <if test="endContent != null and endContent != ''">#{endContent},</if>
97
         <if test="column != null and column != ''">#{column},</if>
103
         <if test="column != null and column != ''">#{column},</if>
98
         <if test="columnName != null and columnName != ''">#{columnName},</if>
104
         <if test="columnName != null and columnName != ''">#{columnName},</if>
99
-        <if test="isDefault != null">#{isDefault}</if>
105
+        <if test="isDefault != null">#{isDefault},</if>
106
+        #{startContentRepeatOrder},#{endContentRepeatOrder},#{fatchOrder}
100
         )
107
         )
101
     </insert>
108
     </insert>
102
 
109