Explorar o código

裂解炉炉管测压
- 图片识别返回数组排序,
- 图片识别添加出/入口参数

wangggziwen hai 11 meses
pai
achega
a12349ec54

+ 121 - 4
master/src/main/java/com/ruoyi/project/production/controller/TFurnancePressureController.java

@@ -7,6 +7,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.file.FileUploadUtils;
@@ -77,7 +78,8 @@ public class TFurnancePressureController extends BaseController
     @PostMapping("/scan")
     public AjaxResult scan(@RequestParam("file") MultipartFile file,
                            @RequestParam("furnanceName") String furnanceName,
-                           @RequestParam("pass") int pass) throws IOException {
+                           @RequestParam("pass") int pass,
+                           @RequestParam("isInlet") boolean isInlet) throws IOException {
         // 判断图片中的压力仪表数量
         int num = 0;
         switch (furnanceName) {
@@ -90,7 +92,7 @@ public class TFurnancePressureController extends BaseController
             case "H116":
             case "H117":
             case "H110": num = 11; break;
-            case "H130": num = 7; break;
+            case "H130": num = isInlet ? 1 : 2; break;
         }
 //        // 调用图片识别接口
         String goodsUrl = "http://cpms.v6.idcfengye.com/detection_web";
@@ -109,9 +111,124 @@ public class TFurnancePressureController extends BaseController
         } catch (Exception e) {
             e.printStackTrace();
         }
-
+        // 获取数组
         JSONObject json = JSONObject.parseObject(str);
-        return AjaxResult.success(json.get("data"));
+        JSONArray jsonArray = json.getJSONObject("data").getJSONArray("readings");
+        // 转换为String数组(排序前的数组)
+        String[] stringArray = new String[jsonArray.size()];
+        for (int i = 0; i < jsonArray.size(); i++) {
+            stringArray[i] = jsonArray.getString(i);
+        }
+        // 排序后的数组
+        String[] newArray = new String[jsonArray.size()];
+        // 数组排序(格式:入,出,出,出,...)
+        switch (furnanceName) {
+            case "H109":
+                if (jsonArray.size() == 15) {
+                    String temp0 = stringArray[0];
+                    String temp1 = stringArray[1];
+                    String temp2 = stringArray[2];
+                    String temp3 = stringArray[3];
+                    String temp4 = stringArray[4];
+                    String temp5 = stringArray[5];
+                    String temp6 = stringArray[6];
+                    String temp7 = stringArray[7];
+                    String temp8 = stringArray[8];
+                    String temp9 = stringArray[9];
+                    String temp10 = stringArray[10];
+                    String temp11 = stringArray[11];
+                    String temp12 = stringArray[12];
+                    String temp13 = stringArray[13];
+                    String temp14 = stringArray[14];
+                    if (pass % 2 == 1) {
+                        newArray[0] = temp0;
+                        newArray[1] = temp14;
+                        newArray[2] = temp7;
+                        newArray[3] = temp13;
+                        newArray[4] = temp6;
+                        newArray[5] = temp12;
+                        newArray[6] = temp5;
+                        newArray[7] = temp11;
+                        newArray[8] = temp4;
+                        newArray[9] = temp10;
+                        newArray[10] = temp3;
+                        newArray[11] = temp9;
+                        newArray[12] = temp2;
+                        newArray[13] = temp8;
+                        newArray[14] = temp1;
+                    } else {
+                        newArray[0] = temp0;
+                        newArray[1] = temp1;
+                        newArray[2] = temp8;
+                        newArray[3] = temp2;
+                        newArray[4] = temp9;
+                        newArray[5] = temp3;
+                        newArray[6] = temp10;
+                        newArray[7] = temp4;
+                        newArray[8] = temp11;
+                        newArray[9] = temp5;
+                        newArray[10] = temp12;
+                        newArray[11] = temp6;
+                        newArray[12] = temp13;
+                        newArray[13] = temp7;
+                        newArray[14] = temp14;
+                    }
+                }
+                break;
+            case "H111":
+            case "H112":
+            case "H113":
+            case "H114":
+            case "H115":
+            case "H116":
+            case "H117":
+            case "H110":
+                if (jsonArray.size() == 11) {
+                    String temp0 = stringArray[0];
+                    String temp1 = stringArray[1];
+                    String temp2 = stringArray[2];
+                    String temp3 = stringArray[3];
+                    String temp4 = stringArray[4];
+                    String temp5 = stringArray[5];
+                    String temp6 = stringArray[6];
+                    String temp7 = stringArray[7];
+                    String temp8 = stringArray[8];
+                    String temp9 = stringArray[9];
+                    String temp10 = stringArray[10];
+                    if (pass % 2 == 1) {
+                        newArray[0] = temp0;
+                        newArray[1] = temp10;
+                        newArray[2] = temp5;
+                        newArray[3] = temp9;
+                        newArray[4] = temp4;
+                        newArray[5] = temp8;
+                        newArray[6] = temp3;
+                        newArray[7] = temp7;
+                        newArray[8] = temp2;
+                        newArray[9] = temp6;
+                        newArray[10] = temp1;
+                    } else {
+                        newArray[0] = temp0;
+                        newArray[1] = temp1;
+                        newArray[2] = temp6;
+                        newArray[3] = temp2;
+                        newArray[4] = temp7;
+                        newArray[5] = temp3;
+                        newArray[6] = temp8;
+                        newArray[7] = temp4;
+                        newArray[8] = temp9;
+                        newArray[9] = temp5;
+                        newArray[10] = temp10;
+                    }
+                }
+                break;
+            case "H130":
+                break;
+        }
+        //组装返回
+        JSONObject returnObj = new JSONObject();
+        returnObj.put("readings", newArray);
+        return AjaxResult.success(returnObj);
     }
 
     /**