Browse Source

【情报二期】数据域服务 - kafka数据消费业务代码

peifj 3 months ago
parent
commit
4e0a7a655e

+ 9 - 9
src/main/java/com/hhwy/qbeqsjy/APP.java

@@ -12,15 +12,15 @@ public class APP {
 //        JSONArray jsonArray = JSONArray.parseArray("[\"991C1223\", \"991C1071\", \"991C2304\"]");
 //        System.out.println(jsonArray);
 
-        int threadNum = 4;
-        int accountsPerThread = 2 / threadNum;
-        System.out.println(accountsPerThread);
-        int i = 3;
-        int startIndex = i * accountsPerThread;
-        int endIndex = (i == threadNum - 1) ? 2 : (i + 1) * accountsPerThread;
-
-        System.out.println(startIndex);
-        System.out.println(endIndex);
+//        int threadNum = 4;
+//        int accountsPerThread = 2 / threadNum;
+//        System.out.println(accountsPerThread);
+//        int i = 3;
+//        int startIndex = i * accountsPerThread;
+//        int endIndex = (i == threadNum - 1) ? 2 : (i + 1) * accountsPerThread;
+//
+//        System.out.println(startIndex);
+//        System.out.println(endIndex);
         // 0,1   1,2   2,3   3,6
 
 

+ 69 - 6
src/main/java/com/hhwy/qbeqsjy/controller/CtrlController.java

@@ -9,7 +9,6 @@ import com.hhwy.qbeqsjy.service.CtrlService;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 import java.util.List;
 import java.util.Map;
@@ -20,8 +19,6 @@ import java.util.Map;
 @RequestMapping("/api/v1/")
 public class CtrlController {
 
-    @Value("${clue.type.list}")
-    private String accountTypeList;
     @Autowired
     private CtrlService ctrlService;
 
@@ -35,8 +32,8 @@ public class CtrlController {
      * {
      *     "taskId":"59275350793392128",
      *     "endCtrlTime":"2025-03-20 00:00:00",
-     *     "resourceIdList":["aaa","bbb","ccc"],
-     *     "areaIdList":["111","222"],
+     *     "resourceIdList":["aaaa","bbbb","cccc"],
+     *     "areaIdList":["dddd","eeee"],
      *     "clueList":[
      *         {
      *             "clue":"xxxxxxxxxxx",
@@ -58,7 +55,7 @@ public class CtrlController {
             ctrlService.processCtrl(ctrlDTO);
             return AjaxResult.success(Constants.CTRL_ING_MSG);
         }catch (Exception e){
-            log.error("布控任务下发发生异常", e);
+            log.error("任务布控发生异常", e);
         }
         return AjaxResult.error(Constants.SERVER_ERROR_MSG);
     }
@@ -94,8 +91,74 @@ public class CtrlController {
             log.error("任务停控发生异常", e);
         }
         return AjaxResult.error(Constants.SERVER_ERROR_MSG);
+    }
+
 
+    /**
+     * 保存布控任务对应区域信息
+     * @param reqBody
+     * @return
+     *
+     * 请求参数:
+     * {
+     *     "taskId":"59275350793392128",
+     *     "areaList":[
+     *         {
+     *             "areaId":"xxx",
+     *             "areaName":"xxx",
+     *             "location":[
+     * 			                    {
+     * 				    "lon":"xxx",
+     * 					"lat":"xxx"
+     * 				},
+     * 				{
+     * 				    "lon":"xxx",
+     * 					"lat":"xxx"
+     * 				}
+     * 				......
+     * 			]
+     *         }
+     *     ]
+     * }
+     */
+    @PostMapping("/saveCtrlAreaInfo")
+    public AjaxResult saveCtrlAreaInfo(@RequestBody JSONObject reqBody){
+        String taskId = reqBody.getString("taskId");
+        JSONArray areaList = reqBody.getJSONArray("areaList");
+        if(StringUtils.isBlank(taskId) || areaList == null || areaList.size() == 0){
+            return AjaxResult.error(Constants.PARAMS_EMPTY_MSG);
+        }
+        try{
+            return ctrlService.saveCtrlAreaInfo(taskId, areaList)? AjaxResult.success() : AjaxResult.error();
+        } catch (Exception e){
+            log.error("保存任务区域信息发生异常", e);
+        }
+        return AjaxResult.error(Constants.SERVER_ERROR_MSG);
     }
 
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 }

+ 38 - 4
src/main/java/com/hhwy/qbeqsjy/dao/CtrlDao.java

@@ -22,8 +22,8 @@ public class CtrlDao {
     public boolean batchInsertCtrlErrorInfo(List<Object[]> ctrlErrorList){
         String sql = "insert into t_ctrl_error_info (task_id, clue, clue_type, end_ctrl_time, resource_id_list, area_id_list, create_time) values (?, ?, ?, ?, ?, ?, ?)";
         try {
-            int[] batchUpdate = gaussDBJdbcTemplate.batchUpdate(sql, ctrlErrorList);
-            return batchUpdate.length == ctrlErrorList.size();
+            int[] insertRows = gaussDBJdbcTemplate.batchUpdate(sql, ctrlErrorList);
+            return insertRows.length == ctrlErrorList.size();
         } catch (Exception e){
             log.error("【批量插入布控失败线索数据发生异常】 异常信息:", e);
         }
@@ -39,8 +39,8 @@ public class CtrlDao {
     public boolean batchInsertStopCtrlErrorInfo(List<Object[]> stopCtrlErrorList){
         String sql = "insert into t_stop_ctrl_error_info (task_id, clue, clue_type, create_time) values (?, ?, ?, ?)";
         try {
-            int[] batchUpdate = gaussDBJdbcTemplate.batchUpdate(sql, stopCtrlErrorList);
-            return batchUpdate.length == stopCtrlErrorList.size();
+            int[] insertRows = gaussDBJdbcTemplate.batchUpdate(sql, stopCtrlErrorList);
+            return insertRows.length == stopCtrlErrorList.size();
         } catch (Exception e){
             log.error("【批量插入停控失败线索数据发生异常】 异常信息:", e);
         }
@@ -48,5 +48,39 @@ public class CtrlDao {
     }
 
 
+    /**
+     * 批量插入布控任务区域信息
+     * @param ctrlAreaInfoList
+     * @return
+     */
+    public boolean batchInsertCtrlAreaInfo(List<Object[]> ctrlAreaInfoList){
+        String sql = "insert into t_ctrl_area_info (task_id, area_id, area_name, location, create_time) values (?, ?, ?, ?, ?)";
+        try {
+            int[] insertRows = gaussDBJdbcTemplate.batchUpdate(sql, ctrlAreaInfoList);
+            return insertRows.length == ctrlAreaInfoList.size();
+        } catch (Exception e){
+            log.error("【批量插入布控任务区域信息发生异常】 异常信息:", e);
+        }
+        return false;
+    }
+
+
+    /**
+     * 批量插入布控任务预警结果数据
+     * @param warningInfoList
+     * @return
+     */
+    public boolean batchInsertWarningInfo(List<Object[]> warningInfoList){
+        String sql = "insert into t_ctrl_area_info (task_id, clue, warning_msg, create_time) values (?, ?, ?, ?)";
+        try {
+            int[] insertRows = gaussDBJdbcTemplate.batchUpdate(sql, warningInfoList);
+            return insertRows.length == warningInfoList.size();
+        } catch (Exception e){
+            log.error("【批量插入布控任务预警结果数据发生异常】 异常信息:", e);
+        }
+        return false;
+    }
+
+
 
 }

+ 28 - 0
src/main/java/com/hhwy/qbeqsjy/service/CtrlService.java

@@ -14,6 +14,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
 import javax.annotation.Resource;
 import java.io.*;
 import java.util.*;
@@ -472,4 +474,30 @@ public class CtrlService {
     }
 
 
+    /**
+     * 保存布控任务区域信息
+     * @param taskId
+     * @param areaList
+     * @return
+     */
+    @Transactional
+    public boolean saveCtrlAreaInfo(String taskId, JSONArray areaList){
+        List<Object[]> ctrlAreaInfoList = new ArrayList<>();
+        Date createTime = new Date();
+        for (Object item : areaList) {
+            JSONObject areaObj = (JSONObject) item;
+            if(!areaObj.isEmpty()){
+                String areaId = areaObj.getString("areaId");
+                String areaName = areaObj.getString("areaName");
+                JSONArray location = areaObj.getJSONArray("location");
+                Object[] ctrlAreaInfo = new Object[]{taskId, areaId, areaName, location, createTime};
+                ctrlAreaInfoList.add(ctrlAreaInfo);
+            }
+        }
+        return ctrlDao.batchInsertCtrlAreaInfo(ctrlAreaInfoList);
+    }
+
+
+
+
 }

+ 16 - 0
src/main/java/com/hhwy/qbeqsjy/strategy/DataParseStrategy.java

@@ -0,0 +1,16 @@
+package com.hhwy.qbeqsjy.strategy;
+
+
+import com.alibaba.fastjson.JSONObject;
+
+/**
+ * 预警数据(JSON)解析策略接口
+ */
+public interface DataParseStrategy {
+
+    /**
+     * 定义数据解析方法
+     */
+    void doParse(JSONObject warningInfo);
+
+}

+ 16 - 0
src/main/java/com/hhwy/qbeqsjy/strategy/impl/Auth.java

@@ -0,0 +1,16 @@
+package com.hhwy.qbeqsjy.strategy.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.hhwy.qbeqsjy.strategy.DataParseStrategy;
+
+
+/**
+ * AUTH表预警数据解析规则类
+ */
+public class Auth implements DataParseStrategy {
+    @Override
+    public void doParse(JSONObject warningInfo) {
+
+
+    }
+}

+ 3 - 6
src/main/resources/application.properties

@@ -52,12 +52,9 @@ ctrl.txt.output.path=/home/qbeqsjy/ctrl_error/
 stop.ctrl.txt.output.path=/home/qbeqsjy/stop_ctrl_error/
 
 # \u5E03\u63A7\u8D44\u6E90\u5217\u8868
-# \u4E1A\u52A1ID\uFF1A\u70FD\u706B\u76D8\u53E4\u5E73\u53F0\u6570\u636E\u8D44\u6E90\u6807\u8BC6\u7B26
-1=134B102
-2=
-3=
-4=
-5=
+# \u6570\u636E\u8D44\u6E90\u7F16\u7801=\u539F\u59CB\u5B57\u6BB5
+134B102=
+