Browse Source

处理上传保单解析签单时间的逻辑

hxl13994548489 1 năm trước cách đây
mục cha
commit
a67005c2ee

+ 11 - 4
src/main/java/com/ydtech/modules/order/controller/OrderTaskImageController.java

@@ -137,8 +137,15 @@ public class OrderTaskImageController extends BaseController {
     }
 
 
-
-
-
-
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2025/6/25 8:46
+     *  @Description:  交强保单和商业保单上传解析签单时间
+     */
+    @PostMapping("/uploadFileToTraferSignDateTime")
+    @ApiOperation(value = "文件上传并解析签单时间")
+    public HttpResult<InsUploadFiles> uploadFileToTraferSignDateTime(@CheckObjectNotNull(message = "上传文件不能为空") MultipartFile multipartFile, String type, String companyId,String fileType,HttpServletRequest request) throws IOException {
+        return insUploadFilesService.uploadFileToTraferSignDateTime(multipartFile, getUserName(), type,companyId,fileType);
+    }
 }

+ 35 - 6
src/main/java/com/ydtech/modules/order/entity/api/pingan/utils/PDFUtil.java

@@ -445,11 +445,17 @@ public class PDFUtil {
             payDate = payDate.replaceAll("\\s+", "");
             payDate = payDate.replaceAll("[\u4e00-\u9fa5]", "");
             System.out.println(payDate.length());
-            if(payDate.length() == 18){
+            if(payDate.length() == 18 ){
                 payDate = payDate.substring(0,10)+" "+ payDate.substring(10,18);
             }else if(payDate.length() == 15){
-                    payDate = payDate.substring(0,10)+" "+ payDate.substring(10,15)+":00";
-            }else if(payDate.length() == 10){
+                payDate = payDate.substring(0,10)+" "+ payDate.substring(10,15)+":00";
+            }else if(payDate.length() == 16 || payDate.length() == 17){
+               //截取后8位
+                String minutes_str = payDate.substring(payDate.length() - 8);
+                String day_str = payDate.replaceAll(minutes_str, "");
+                payDate = getContentStrByLine(day_str,1)+" "+minutes_str;
+            }
+            else if(payDate.length() == 10){
                 payDate = payDate+" 00:00:00";
             }
             return LocalDateTime.parse(payDate, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
@@ -494,7 +500,24 @@ public class PDFUtil {
     }
 
     public static String  getContentStr(String input){
-        Pattern pattern = Pattern.compile("(\\d{4})年(\\d{1,2})月(\\d{1,2})日");
+        Pattern pattern =  Pattern.compile("(\\d{4})年(\\d{1,2})月(\\d{1,2})日");
+        Matcher matcher = pattern.matcher(input);
+        if (matcher.matches()) {
+            String year = matcher.group(1);
+            String month = matcher.group(2);
+            String day = matcher.group(3);
+            return year+"-"+((Integer.parseInt(month)<10 && month.length()==1) ?"0"+month:month)+"-"+((Integer.parseInt(day)<10 && day.length()==1)  ?"0"+day:day);
+        } else {
+            return null;
+        }
+    }
+    public static String  getContentStrByLine(String input,int type){
+        Pattern pattern = null;
+        if(type == 1){
+            pattern = Pattern.compile("(\\d{4})-(\\d{1,2})-(\\d{1,2})");
+        }else if(type == 2){
+            pattern = Pattern.compile("(\\d{4})/(\\d{1,2})/(\\d{1,2})");
+        }
         Matcher matcher = pattern.matcher(input);
         if (matcher.matches()) {
             String year = matcher.group(1);
@@ -505,7 +528,6 @@ public class PDFUtil {
             return null;
         }
     }
-
     public static String  getContentStr(String input, String beginStr, String endStr){
         // 创建正则表达式,其中"(?s)"表示忽略换行符,"."匹配任何字符(包括换行符)
         String regex = "(?s)" + Pattern.quote(beginStr) + "(.+?)" + Pattern.quote(endStr);
@@ -513,7 +535,14 @@ public class PDFUtil {
         Matcher matcher = pattern.matcher(input);
 
         if (matcher.find()) {
-            return matcher.group(1);
+            String groupStr = matcher.group(1);
+            //String regexNew = "[\\u4e00-\\u9fa5&&[^年月日时]]";
+            String regexNew = "[a-zA-Z]|[\u4E00-\u9FFF&&[^年月日时]]";
+            //去除年月日时之外的汉字
+            if(groupStr!=null && !"".equals(groupStr)){
+                return groupStr.replaceAll(regexNew, "");
+            }
+            return null;
         } else {
             return null;
         }

+ 4 - 0
src/main/java/com/ydtech/modules/order/entity/po/InsUploadFiles.java

@@ -56,4 +56,8 @@ public class InsUploadFiles implements Serializable {
 
     @TableField(exist = false)
     private static final long serialVersionUID = 1L;
+
+    //add  by  hxl  2025-06-25  添加签单时间
+    @TableField(exist = false)
+    private String signTime;
 }

+ 8 - 1
src/main/java/com/ydtech/modules/order/service/InsUploadFilesService.java

@@ -2,6 +2,7 @@ package com.ydtech.modules.order.service;
 
 import cn.hutool.core.util.ObjectUtil;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.ydtech.core.page.HttpResult;
 import com.ydtech.modules.order.entity.po.InsUploadFiles;
 import com.ydtech.modules.protocol.utils.AssertionUtils;
 import org.springframework.web.multipart.MultipartFile;
@@ -42,5 +43,11 @@ public interface InsUploadFilesService extends IService<InsUploadFiles> {
         return insUploadFiles;
     }
 
-
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2025/6/25 8:50
+     *  @Description: 上传文件并解析签单时间
+     */
+    HttpResult uploadFileToTraferSignDateTime(MultipartFile multipartFile, String userName, String type, String companyId,String fileType) throws IOException;
 }

+ 68 - 2
src/main/java/com/ydtech/modules/order/service/impl/InsUploadFilesServiceImpl.java

@@ -2,16 +2,24 @@ package com.ydtech.modules.order.service.impl;
 
 import cn.hutool.core.date.DateTime;
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ydtech.constants.enums.FileType;
+import com.ydtech.core.page.HttpResult;
 import com.ydtech.exception.SystemException;
 import com.ydtech.modules.order.dao.InsUploadFilesMapper;
+import com.ydtech.modules.order.entity.api.pingan.utils.PDFUtil;
+import com.ydtech.modules.order.entity.po.InsOrderReadPdf;
 import com.ydtech.modules.order.entity.po.InsUploadFiles;
+import com.ydtech.modules.order.service.InsOrderReadPdfService;
 import com.ydtech.modules.order.service.InsUploadFilesService;
 import com.ydtech.utils.ImageCompressionUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Lazy;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -19,7 +27,11 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
 
 /**
  * @author wenks
@@ -39,6 +51,10 @@ public class InsUploadFilesServiceImpl extends ServiceImpl<InsUploadFilesMapper,
 
     private static final int desFileSize = 300;
 
+    @Lazy
+    @Autowired
+    private InsOrderReadPdfService insOrderReadPdfService;
+
     @Override
     public InsUploadFiles uploadFile(MultipartFile multipartFile, String username, String type) throws IOException {
         String fileMD5 = DigestUtils.md5Hex(multipartFile.getBytes());
@@ -99,8 +115,6 @@ public class InsUploadFilesServiceImpl extends ServiceImpl<InsUploadFilesMapper,
             throw new SystemException("上传过程中出错" + e.getMessage());
         }
     }
-
-
     /**
      * 自动生成目录
      *
@@ -126,6 +140,58 @@ public class InsUploadFilesServiceImpl extends ServiceImpl<InsUploadFilesMapper,
         return stringBuilder.toString();
     }
 
+    /**
+     *  @version
+     *  @author: hxl
+     *  @Date: 2025/6/25 8:52
+     *  @Description:  上传文件并解析签单时间
+     */
+    @Override
+    public HttpResult uploadFileToTraferSignDateTime(MultipartFile multipartFile, String userName, String type, String companyId,String fileType) {
+
+        InsUploadFiles insUploadFiles =null;
+        try {
+            insUploadFiles = uploadFile(multipartFile, userName, type);
+        }catch (Exception e){
+            return HttpResult.error("上传文件失败!");
+        }
+        if(StringUtils.isNotBlank(fileType) &&("1".equals(fileType) || "2".equals(fileType))){
+             if(StringUtils.isBlank(companyId)){
+                 return HttpResult.error("保险公司不能为空!");
+             }
+             if(StringUtils.isBlank(fileType)){
+                 return HttpResult.error("保单类型不能为空!");
+             }
+            if(insUploadFiles!=null){
+                //通过保险公司配置读取截取的前缀和后缀
+                LambdaQueryWrapper<InsOrderReadPdf> qws = new LambdaQueryWrapper<>();
+                qws.eq(InsOrderReadPdf::getCompanyId, companyId);
+                qws.eq(InsOrderReadPdf::getType, fileType);
+                List<InsOrderReadPdf> list = insOrderReadPdfService.list(qws);
+                HashMap<String, LocalDateTime> map = new HashMap<>();
+                String pdfText = PDFUtil.getPdfText(insUploadFiles.getFilePath());
+                if (StringUtils.isNotBlank(pdfText)) {
+                    if (list != null && list.size() > 0) {
+                        for (InsOrderReadPdf insOrderReadPdf : list) {
+                            LocalDateTime pdfContentDate =null;
+                            try{
+                                pdfContentDate = PDFUtil.getPdfContentDate(pdfText, insOrderReadPdf.getReadBegin(), insOrderReadPdf.getReadEnd(), insOrderReadPdf.getReadType());
+                            }catch (Exception e){
+
+                            }
+                            map.put(insOrderReadPdf.getOrderMsg(), pdfContentDate);
+                        }
+                    }
+                }
+                if(map.get("signingTime")!=null){
+                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                    String  signingTimeStr = map.get("signingTime").format(formatter);
+                    insUploadFiles.setSignTime(signingTimeStr);
+                }
+            }
+        }
+        return HttpResult.ok(insUploadFiles);
+    }
 }