Browse Source

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	mainFactory/src/main/java/org/bfkj/protocol/ElasticHandler.java
#	mainFactory/src/main/resources/static/config.js
#	mainFactory/src/main/resources/static/index.html
#	mainFactory/src/main/resources/static/staticConfig.js
andy 1 year ago
parent
commit
d862d104d8

+ 19 - 2
mainFactory/src/main/java/org/bfkj/api/CommonApi.java

@@ -1,5 +1,6 @@
 package org.bfkj.api;
 
+import jakarta.servlet.http.HttpServletRequest;
 import org.bfkj.application.AuthApplicationImpl;
 import org.bfkj.application.DataProcess;
 import org.bfkj.config.AppConfig;
@@ -47,6 +48,22 @@ public class CommonApi {
         return authApplication.abnormalDataRecovery(params);
     }
 
+
+    @PostMapping("generalDataReception")
+    public Map<String, Object> dataCollect(@RequestBody Map<String, Object> params, HttpServletRequest httpServletRequest) {
+        params.put("id", "1");
+        Map<String, Object> rsMap = commonInterface(null, params, "1");
+        rsMap.put("requestId", httpServletRequest.getSession().getId());
+        if (rsMap.containsKey("code") && "-1".equals(rsMap.get("code"))) {
+            rsMap.put("code", "1");
+            rsMap.put("message", "数据收集失败");
+        } else {
+            rsMap.put("returnData", "数据收集成功");
+        }
+        return rsMap;
+    }
+
+
     /**
      * 查询入口CRUD
      */
@@ -133,7 +150,7 @@ public class CommonApi {
             return errMap;
 
         }
-        Object serviceId = params.get("serviceId");
+        Object serviceId = params.containsKey("serviceId") ? params.get("serviceId") : params.get("id");
         if (Objects.isNull(serviceId) || !params.containsKey("event")) {
             HashMap<String, Object> errMap = new HashMap<>();
             errMap.put("code", "-1");
@@ -170,7 +187,7 @@ public class CommonApi {
             errMap.put("message", "服务不可用:" + (null == dataProcessObj ? "" : dataProcessObj.getErrorMessage()));
             return errMap;
         }
-        return dataProcessObj.processData(params, token.get("user_id"));
+        return dataProcessObj.processData(params, Objects.nonNull(token) ? token.get("user_id") : null);
     }
 
 

+ 1 - 4
mainFactory/src/main/java/org/bfkj/application/AuthApplicationImpl.java

@@ -4,10 +4,7 @@ package org.bfkj.application;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.bfkj.config.AppConfig;
 import org.bfkj.config.ObjectMap;
-import org.bfkj.utils.LogUtils;
-import org.bfkj.utils.MapTools;
-import org.bfkj.utils.MyDbHelper;
-import org.bfkj.utils.RandomGraphic;
+import org.bfkj.utils.*;
 import org.springframework.stereotype.Service;
 
 import java.util.*;

+ 0 - 0
mainFactory/src/main/java/org/bfkj/config/ApplicationBaseConfig.java


+ 2 - 2
mainFactory/src/main/java/org/bfkj/utils/DataFormat.java

@@ -112,7 +112,7 @@ public class DataFormat {
                 String inData = Objects.toString(o);
                 if (MapTools.isBlank(inData)) continue;
                 int dataObjectIdIndex = inData.indexOf("dataObjectId");
-                String tpDataObjectId = inData.length() > 39 ? inData.substring(dataObjectIdIndex + 15, dataObjectIdIndex + 39) : null;
+                String tpDataObjectId = dataObjectIdIndex !=-1 &&  inData.length() > 39 ? inData.substring(dataObjectIdIndex + 15, dataObjectIdIndex + 39) : null;
                 rsList.addAll(typebHandler(inData, transMaps, MapTools.isBlank(tpDataObjectId) ? dataObjectId : tpDataObjectId));
             }
             return processSuccess(rsList);
@@ -141,7 +141,7 @@ public class DataFormat {
                         HashMap<String, Object> errorMap = new HashMap<>();
                         errorMap.put("dataObjectId", dataObjectId);
                         errorMap.put("errMessage", "报文数据格式错误");
-                        if (AppConfig.SOURCE_DATA){
+                        if (AppConfig.SOURCE_DATA) {
                             errorMap.put("sourceData", tempTypeStr);
                         }
                         if (!returnDataList.contains(errorMap)) {

+ 78 - 0
mainFactory/src/main/java/org/bfkj/utils/GenerateImage.java

@@ -0,0 +1,78 @@
+package org.bfkj.utils;
+
+import javax.imageio.ImageIO;
+import java.awt.*;
+import java.awt.image.BufferedImage;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+
+public class GenerateImage {
+    private static final int WIDTH = 120; // 图片宽度
+    private static final int HEIGHT = 40; // 图片高度
+    private static String IMAGE_FORMAT = "JPG";
+    private static Color[] COLORS = new Color[]{
+            new Color(0, 0, 255),
+            new Color(0, 255, 0),
+            new Color(255, 0, 0)
+    };
+    private static SecureRandom RANDOM = new SecureRandom();
+
+
+    public static Map<String, Object> generateVerifyCode(int verifySize, String sources) {
+        int codesLen = sources.length();
+        try {
+            StringBuilder verifyCode = new StringBuilder(verifySize);
+            for (int i = 0; i < verifySize; i++) {
+                verifyCode.append(sources.charAt(RANDOM.nextInt(codesLen - 1)));
+            }
+
+            BufferedImage image = createImage(verifyCode.toString());
+            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+            ImageIO.write(image, IMAGE_FORMAT, outputStream);
+
+            byte[] data = outputStream.toByteArray();
+            String base64Image = Base64.getEncoder().encodeToString(data).replaceAll("[\\s*\t\n\r]", "");
+            outputStream.close();
+            Map<String, Object> returnData = new HashMap<>();
+            returnData.put("verifyCode", verifyCode);
+            returnData.put("verifyCodeImage", base64Image);
+            return returnData;
+        } catch (IOException e) {
+            return null;
+        }
+    }
+    private static BufferedImage createImage(String verifyCode) {
+        BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
+        Graphics graphics = image.getGraphics();
+
+        graphics.setColor(Color.WHITE);
+        graphics.fillRect(0, 0, WIDTH, HEIGHT);
+
+        int desX,desY,distance=16;
+        for (int i = 0; i < verifyCode.length(); i++) {
+            graphics.setColor(COLORS[RANDOM.nextInt(COLORS.length)]);
+            desX = (i+1)*distance;
+            desY = distance+RANDOM.nextInt(HEIGHT-2*distance);
+            graphics.drawString(Character.toString(verifyCode.charAt(i)),desX,desY);
+        }
+
+        for(int x=0;x<150;x++){
+            graphics.setColor(getRandomColor());
+            graphics.drawOval(RANDOM.nextInt(WIDTH),RANDOM.nextInt(HEIGHT),1,1);
+        }
+
+        graphics.dispose();
+        return image;
+    }
+
+    private static Color getRandomColor() {
+        int r = RANDOM.nextInt(256);
+        int g = RANDOM.nextInt(256);
+        int b = RANDOM.nextInt(256);
+        return new Color(r,g,b);
+    }
+}

+ 5 - 1
mainFactory/src/main/java/org/bfkj/utils/MapTools.java

@@ -40,7 +40,11 @@ public class MapTools implements Serializable {
             return mapStrToObj(inStr, null);
         }
     }
-
+//
+//    public static void main(String[] args) {
+//        String xx = "{\"code\":200,\"success\":true,\"errorInfo\":\"default success info\",\"AAA\":[{\"messageType\":\"bpm报文\",\"message\":\"BPM\\n{\\\"meta\\\":{\\\"id\\\":\\\"JF03350431732\\\",\\\"type\\\":\\\"node\\\",\\\"st\\\":\\\"2023-05-16\\n17:16:32\\\"},\\\"data\\\":{\\\"code1\\\":\\\"3784602834\\\",\\\"terminal\\\":\\\"T2\\\",\\\"chute\\\":\\\"MU10\\\",\\\"flt\\\":\\\"CZ6738\\\",\\\"ftd\\\":\\\"2023-05-16\\\",\\\"n\\\":\\\"JD03\\\",\\\"t\\\":\\\"2023-05-16\\n17:16:09\\\"}}\\nENDBPM\",\"messageTime\":null,\"uuid\":\"1658401186878423042\"}]}";
+//        System.out.println(strToObj(xx.toString()));
+//    }
 
     private static Object mapStrToObj(String inMapStr, List<Object> itemMapList, String... strType) {//
         String beginChar = strType.length == 0 ? "{" : "[";//为了递归数组准备

+ 0 - 3
mainFactory/src/main/java/org/bfkj/utils/MyDbHelper.java

@@ -70,9 +70,6 @@ public class MyDbHelper {//目前只差主键的条件优化
         }
         config.setJdbcUrl(connectMaps.get("url").toString());
         config.setDriverClassName(connectMaps.get("driver-class-name").toString());
-
-        config.setPoolName("");
-
         theDataSource = new HikariDataSource(config);
         theJdbcTemplate = new JdbcTemplate(theDataSource);
         try (Connection theConnect = theDataSource.getConnection();//用于批量新增以及获取当前数据库的相关信息