Browse Source

fix 发票,身份证识别

he2802 3 năm trước cách đây
mục cha
commit
c599971fb3

+ 18 - 26
zhongzheng-admin/src/main/java/com/zhongzheng/controller/order/OrderInvoiceController.java

@@ -1,20 +1,21 @@
 package com.zhongzheng.controller.order;
 
 import java.util.List;
-import java.util.Arrays;
+import java.util.Map;
 
+import cn.hutool.core.lang.Validator;
 import com.zhongzheng.modules.order.bo.OrderInvoiceAddBo;
 import com.zhongzheng.modules.order.bo.OrderInvoiceEditBo;
 import com.zhongzheng.modules.order.bo.OrderInvoiceQueryBo;
 import com.zhongzheng.modules.order.service.IOrderInvoiceService;
 import com.zhongzheng.modules.order.vo.OrderInvoiceVo;
+import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
+import com.zhongzheng.modules.tencentcloud.service.IFaceOcrService;
 import lombok.RequiredArgsConstructor;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -23,7 +24,6 @@ import com.zhongzheng.common.annotation.Log;
 import com.zhongzheng.common.core.controller.BaseController;
 import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.enums.BusinessType;
-import com.zhongzheng.common.utils.poi.ExcelUtil;
 import com.zhongzheng.common.core.page.TableDataInfo;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -42,6 +42,8 @@ public class OrderInvoiceController extends BaseController {
 
     private final IOrderInvoiceService iOrderInvoiceService;
 
+    private final IFaceOcrService iFaceOcrService;
+
     /**
      * 查询订单发票列表
      */
@@ -54,18 +56,7 @@ public class OrderInvoiceController extends BaseController {
         return getDataTable(list);
     }
 
-    /**
-     * 导出订单发票列表
-     */
-   /* @ApiOperation("导出订单发票列表")
-    @PreAuthorize("@ss.hasPermi('system:invoice:export')")
-    @Log(title = "订单发票", businessType = BusinessType.EXPORT)
-    @GetMapping("/export")
-    public AjaxResult<OrderInvoiceVo> export(OrderInvoiceQueryBo bo) {
-        List<OrderInvoiceVo> list = iOrderInvoiceService.queryList(bo);
-        ExcelUtil<OrderInvoiceVo> util = new ExcelUtil<OrderInvoiceVo>(OrderInvoiceVo.class);
-        return util.exportExcel(list, "订单发票");
-    }*/
+
 
     /**
      * 获取订单发票详细信息
@@ -99,14 +90,15 @@ public class OrderInvoiceController extends BaseController {
         return toAjax(iOrderInvoiceService.updateByEditBo(bo) ? 1 : 0);
     }
 
-    /**
-     * 删除订单发票
-     */
-   /* @ApiOperation("删除订单发票")
-    @PreAuthorize("@ss.hasPermi('system:invoice:remove')")
-    @Log(title = "订单发票" , businessType = BusinessType.DELETE)
-    @DeleteMapping("/{invoiceIds}")
-    public AjaxResult<Void> remove(@PathVariable Long[] invoiceIds) {
-        return toAjax(iOrderInvoiceService.deleteWithValidByIds(Arrays.asList(invoiceIds), true) ? 1 : 0);
-    }*/
+    @ApiOperation("发票识别")
+    @PostMapping("/vatInvoiceOCR")
+    public AjaxResult VatInvoiceOCR(@RequestBody InvoiceQueryBo bo){
+        Map<String, String> rs = iFaceOcrService.VatInvoiceOCR(bo);
+        if(Validator.isNotEmpty(rs)){
+            return AjaxResult.success(rs);
+        }else{
+            return AjaxResult.error();
+        }
+
+    }
 }

+ 2 - 2
zhongzheng-api/src/main/java/com/zhongzheng/controller/face/FaceController.java

@@ -6,7 +6,7 @@ import com.zhongzheng.common.core.domain.AjaxResult;
 import com.zhongzheng.common.utils.ServletUtils;
 import com.zhongzheng.framework.web.service.WxTokenService;
 import com.zhongzheng.modules.tencentcloud.bo.FaceQueryBo;
-import com.zhongzheng.modules.tencentcloud.service.IFaceService;
+import com.zhongzheng.modules.tencentcloud.service.IFaceOcrService;
 import com.zhongzheng.modules.user.entity.ClientLoginUser;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
@@ -28,7 +28,7 @@ import java.util.Map;
 @RequestMapping("/face")
 public class FaceController extends BaseController {
 
-    private final IFaceService iFaceService;
+    private final IFaceOcrService iFaceService;
 
     private final WxTokenService wxTokenService;
 

+ 0 - 3
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/bo/InvoiceQueryBo.java

@@ -22,7 +22,4 @@ public class InvoiceQueryBo extends BaseEntity {
 	private String ImageUrl;
 
 
-	@ApiModelProperty("班级ID")
-	private Long gradeId;
-
 }

+ 1 - 1
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/IFaceService.java → zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/IFaceOcrService.java

@@ -7,7 +7,7 @@ import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
 
 import java.util.Map;
 
-public interface IFaceService {
+public interface IFaceOcrService {
 
 
     Integer CompareFace(FaceQueryBo bo);

+ 14 - 21
zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/impl/FaceServiceImpl.java → zhongzheng-system/src/main/java/com/zhongzheng/modules/tencentcloud/service/impl/FaceOcrServiceImpl.java

@@ -1,29 +1,17 @@
 package com.zhongzheng.modules.tencentcloud.service.impl;
 
 
-import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.lang.Validator;
 import com.alibaba.fastjson.JSONObject;
 import com.tencentcloudapi.common.Credential;
 import com.tencentcloudapi.common.exception.TencentCloudSDKException;
 import com.tencentcloudapi.common.profile.ClientProfile;
-import com.tencentcloudapi.common.profile.HttpProfile;
-import com.tencentcloudapi.faceid.v20180301.FaceidClient;
-import com.tencentcloudapi.faceid.v20180301.models.DetectAuthRequest;
-import com.tencentcloudapi.faceid.v20180301.models.DetectAuthResponse;
-import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoRequest;
-import com.tencentcloudapi.faceid.v20180301.models.GetDetectInfoResponse;
 import com.tencentcloudapi.iai.v20200303.IaiClient;
 import com.tencentcloudapi.iai.v20200303.models.CompareFaceRequest;
 import com.tencentcloudapi.iai.v20200303.models.CompareFaceResponse;
 import com.tencentcloudapi.ocr.v20181119.OcrClient;
-import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRRequest;
-import com.tencentcloudapi.ocr.v20181119.models.IDCardOCRResponse;
-import com.tencentcloudapi.ocr.v20181119.models.VatInvoiceOCRRequest;
-import com.tencentcloudapi.ocr.v20181119.models.VatInvoiceOCRResponse;
+import com.tencentcloudapi.ocr.v20181119.models.*;
 import com.zhongzheng.common.exception.CustomException;
-import com.zhongzheng.common.utils.DateUtils;
-import com.zhongzheng.common.utils.file.ImageUtils;
 import com.zhongzheng.modules.alioss.bo.OssRequest;
 import com.zhongzheng.modules.alioss.service.OssService;
 import com.zhongzheng.modules.base.bo.UserProfileFit;
@@ -32,22 +20,17 @@ import com.zhongzheng.modules.base.service.IUserProfileService;
 import com.zhongzheng.modules.base.vo.UserProfileVo;
 import com.zhongzheng.modules.tencentcloud.bo.FaceQueryBo;
 import com.zhongzheng.modules.tencentcloud.bo.InvoiceQueryBo;
-import com.zhongzheng.modules.tencentcloud.service.IFaceService;
-import com.zhongzheng.modules.user.service.IUserOcrService;
+import com.zhongzheng.modules.tencentcloud.service.IFaceOcrService;
 import com.zhongzheng.modules.user.service.IUserService;
-import com.zhongzheng.modules.user.vo.UserVo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import springfox.documentation.spring.web.json.Json;
 
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.Map;
 
 @Service
-public class FaceServiceImpl implements IFaceService {
+public class FaceOcrServiceImpl implements IFaceOcrService {
 
     @Value("${tencent.cloud.SecretId}")
     private String SecretId;
@@ -163,10 +146,20 @@ public class FaceServiceImpl implements IFaceService {
             req.setIsPdf(true);
             req.setImageUrl(ossHost+"/"+bo.getImageUrl());
             VatInvoiceOCRResponse resp = client.VatInvoiceOCR(req);
+            TextVatInvoice[] textArr = resp.getVatInvoiceInfos();
+            Map<String,String> rs = new HashMap<>();
+            for(TextVatInvoice text : textArr){
+                if(text.getName().equals("发票代码")){
+                    rs.put("invoiceCode",text.getValue());
+                }
+                if(text.getName().equals("发票号码")){
+                    rs.put("invoiceNum",text.getValue());
+                }
+            }
+            return rs;
         }catch (TencentCloudSDKException e){
             System.out.println("错误"+e.getMessage());
         }
-
         return null;
     }
 }