Browse Source

卡倍亿二期实施内容v1.0

wzy 9 months ago
parent
commit
80c96960b7

+ 3 - 2
mjava-kabeiyi/src/main/java/com/malk/kabeiyi/controller/KabeiyiController.java

@@ -85,8 +85,9 @@ public class KabeiyiController {
         return kabeiyiService.addPlanApproval(map);
     }
 
+    //ocr识别
     @GetMapping("/ocr")
-    public McR ocr(){
-        return kabeiyiService.ocr();
+    public McR ocr(String downloadUrl,String name,String type){
+        return kabeiyiService.ocr(downloadUrl,name,type);
     }
 }

+ 1 - 1
mjava-kabeiyi/src/main/java/com/malk/kabeiyi/service/KabeiyiService.java

@@ -35,7 +35,7 @@ public interface KabeiyiService {
      */
     McR addQuestionApproval(Map map);
 
-    McR ocr();
+    McR ocr(String downloadUrl,String name,String type);
 
     McR addPlanApproval(Map map);
 }

+ 76 - 6
mjava-kabeiyi/src/main/java/com/malk/kabeiyi/service/impl/KabeiyiServiceImpl.java

@@ -30,7 +30,15 @@ import org.springframework.beans.factory.annotation.Value;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.net.URLEncoder;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 @Slf4j
 @Service
@@ -47,6 +55,9 @@ public class KabeiyiServiceImpl implements KabeiyiService {
     @Autowired
     private YDClient ydClient;
 
+    @Autowired
+    private YDConf ydConf;
+
     @Autowired
     private DDConf ddConf;
 
@@ -62,6 +73,9 @@ public class KabeiyiServiceImpl implements KabeiyiService {
     @Value("${aliwork.accessKeySecret}")
     private String accessKeySecret;
 
+    @Value("${ocr.filePath}")
+    private String filePath;
+
     //审批实例url前缀(卡倍亿)
     private static final String PROC_INST_PREFIX_URL = "https://aflow.dingtalk.com/dingtalk/web/query/pchomepage.htm?from=oflow&op=true&corpid=dingc3a744cb591a7346f2c783f7214b6d69#/plainapproval?procInstId=";
     //宜搭-关联数据(卡倍亿)
@@ -318,8 +332,9 @@ public class KabeiyiServiceImpl implements KabeiyiService {
                 .formInstId(formInstId)
                 .build(), YDConf.FORM_QUERY.retrieve_id);
         Map formData = ddrNew.getFormData();
-        //审核人
-        List<String> reviewerUserIds = (List<String>) formData.get("employeeField_m061zye5_id");
+
+        List<String> reviewerUserIds = (List<String>) formData.get("employeeField_m061zye5_id");//审核人
+        String area = formData.get("selectField_m0w4kilf").toString();//审核区域
 
         List<Map> details = (List<Map>) formData.get("tableField_m0kqtqoy");
         String[] yida = McProject.getYida("1009");
@@ -337,6 +352,7 @@ public class KabeiyiServiceImpl implements KabeiyiService {
                 //根据userId获取部门id
                 List<String> rectificationUserIds = (List<String>) detail.get("employeeField_m061zyeq_id");
                 question.put("employeeField_m061zyeq",rectificationUserIds);//责任整改人
+                question.put("selectField_m0w4kilf",area);//审核区域
 
                 Map body2 = new HashMap<>();
                 body2.put("userid", rectificationUserIds.get(0));
@@ -364,17 +380,70 @@ public class KabeiyiServiceImpl implements KabeiyiService {
     }
 
     @Override
-    public McR ocr() {
+    public McR ocr(String downloadUrl,String name,String type) {
+        MDC.put("MDC_KEY_PID","1009");
+
         try {
-            String content = RecognizeAllText.recognizeText("C:\\Users\\EDY\\Desktop\\3.jpg","Table",accessKeyId,accessKeySecret);
+            String content = RecognizeAllText.recognizeText("C:\\Users\\EDY\\Desktop\\4.png", type, accessKeyId, accessKeySecret);
             return McR.success(content);
-        }catch (Exception e){
-            System.out.println(e.getMessage());
+        }catch (Exception e) {
+            e.printStackTrace();
+            log.info("识别失败:{}" + e.getMessage());
         }
 
+
+        //下载宜搭附件
+        /*try {
+            String[] yida = McProject.getYida("1009");
+            downloadFile(downloadUrl,filePath + name,yida[0],yida[1]);
+            log.info("文件下载成功!");
+        } catch (IOException e) {
+            e.printStackTrace();
+            log.info("文件下载失败:{}" + e.getMessage());
+        }
+        //ocr识别
+        try {
+            String content = RecognizeAllText.recognizeText(filePath + name, type, accessKeyId, accessKeySecret);
+            return McR.success(content);
+        }catch (Exception e) {
+            e.printStackTrace();
+            log.info("识别失败:{}" + e.getMessage());
+        }*/
         return McR.errorUnknown("识别失败!");
     }
 
+    public void downloadFile(String fileURL, String savePath,String appType,String systemToken) throws IOException {
+        //若是宜搭附件url 则需获得附件临时免登地址
+        Map<String,Object> param = new HashMap<>();
+        param.put("systemToken",systemToken);
+        param.put("userId",ddConf.getOperator());
+        param.put("fileUrl",fileURL);
+        fileURL = ((DDR_New) UtilHttp.doGet("https://api.dingtalk.com/v1.0/yida/apps/temporaryUrls/" + appType, ddClient.initTokenHeader(), param, DDR_New.class)).getResult().toString();
+
+        URL url = new URL(fileURL);
+        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
+        int responseCode = httpConn.getResponseCode();
+
+        // 检查HTTP响应代码是否为200
+        if (responseCode == HttpURLConnection.HTTP_OK) {
+            InputStream inputStream = httpConn.getInputStream();
+            FileOutputStream outputStream = new FileOutputStream(savePath);
+
+            byte[] buffer = new byte[4096];
+            int bytesRead = -1;
+
+            while ((bytesRead = inputStream.read(buffer)) != -1) {
+                outputStream.write(buffer, 0, bytesRead);
+            }
+
+            outputStream.close();
+            inputStream.close();
+        } else {
+            System.out.println("无法下载文件。HTTP响应代码: " + responseCode);
+        }
+        httpConn.disconnect();
+    }
+
     @Override
     public McR addPlanApproval(Map map) {
         MDC.put("MDC_KEY_PID","1009");
@@ -459,6 +528,7 @@ public class KabeiyiServiceImpl implements KabeiyiService {
         //更新审核计划下次发起审批时间及上次发起审批时间
         formData.put("dateField_m0nbpasw", lastTime);
         formData.put("dateField_m0nbpasq", nextDate);
+        formData.put("employeeField_m061zye5",reviewerUserIds);
         ydClient.operateData(YDParam.builder()
                         .formInstId(formInstId)
                         .updateFormDataJson(JSON.toJSONString(formData))

+ 19 - 1
mjava-kabeiyi/src/main/java/com/malk/kabeiyi/util/RecognizeAllText.java

@@ -82,8 +82,26 @@ public class RecognizeAllText {
         Map body = (Map) map.get("body");
         Map data = (Map) body.get("data");
         String content = String.valueOf(data.get("content"));
-
         System.out.println(content);
+        /*if (!type.equals("MixedInvoice")){
+
+        }else {
+            List<Map> subImages = (List<Map>) data.get("subImages");
+            for (Map subImage : subImages) {
+                String type2 = subImage.get("type").toString();
+                Map kvInfo = (Map) subImage.get("kvInfo");
+                Map<String, String> data2 = (Map) kvInfo.get("data");
+                content += type2 + ":\n";
+                List<String> valueList = new ArrayList<>();
+                for (String key : data2.keySet()) {
+                     valueList.add(data2.get(key));
+                }
+                content += String.join(",", valueList) + "\n";
+            }
+        }*/
+
+
+
         // Asynchronous processing of return values
         /*response.thenAccept(resp -> {
             System.out.println(new Gson().toJson(resp));

+ 6 - 5
mjava-kabeiyi/src/main/resources/application-dev.yml

@@ -37,6 +37,8 @@ dingtalk:
   corpId:
   aesKey:
   token:
+  operator: 344749020127590108
+
 #特充
 tcdingtalk:
   agentId: 3163661041
@@ -56,9 +58,8 @@ teambition:
 aliwork:
   appType: APP_HZ5V1PF2YGBIUCIYOSI5
   systemToken: DIC66I91HJ3MWKL3FAQ5UD46GIR129PR66KXLA
-  accessKeyId: LTAI5tCrLZLGgjfpBEvPK4er
-  accessKeySecret: lIoRZDrwFsJIV1sdGica8SyjViZFGV
+  accessKeyId: LTAI5tCrLZLGgjfpBEvPK4er # 阿里云accessKeyId
+  accessKeySecret: lIoRZDrwFsJIV1sdGica8SyjViZFGV # 阿里云accessKeySecret
 
-aliyun:
-  accessKeyId: LTAI5tCrLZLGgjfpBEvPK4er
-  accessKeySecret: lIoRZDrwFsJIV1sdGica8SyjViZFGV
+ocr:
+  filePath: d:\

+ 2 - 0
mjava-kabeiyi/src/main/resources/application-prod.yml

@@ -37,6 +37,8 @@ dingtalk:
   corpId:
   aesKey:
   token:
+  operator: 344749020127590108
+
 #特充
 tcdingtalk:
   agentId: 3163661041