From 16ddfc8e22559480a2b039b896f1e882f286c9c9 Mon Sep 17 00:00:00 2001
From: 6c <420680616@qq.com>
Date: 星期五, 12 十二月 2025 15:10:47 +0800
Subject: [PATCH] 接口集成

---
 src/main/java/com/product/integration/config/IntegrationCode.java                    |    8 
 src/main/java/com/product/integration/controller/InterfaceIntegrationController.java |   36 ++++
 src/main/java/com/product/integration/service/InterfaceIntegrationService.java       |  475 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/main/java/com/product/integration/config/CmnConst.java                           |   21 ++
 4 files changed, 533 insertions(+), 7 deletions(-)

diff --git a/src/main/java/com/product/integration/config/CmnConst.java b/src/main/java/com/product/integration/config/CmnConst.java
index f0e1f15..8a88796 100644
--- a/src/main/java/com/product/integration/config/CmnConst.java
+++ b/src/main/java/com/product/integration/config/CmnConst.java
@@ -20,6 +20,8 @@
     public static final String PRODUCT_SYS_INTERFACE_INTEGRATION_REQUEST_PARAM = "product_sys_interface_integration_request_param";
     public static final String PRODUCT_SYS_INTERFACE_INTEGRATION_REQUEST_HEADER = "product_sys_interface_integration_request_header";
     public static final String PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO = "product_sys_interface_integration_response_info";
+    public static final String PRODUCT_SYS_INTERFACE_INTEGRATION_LOG = "product_sys_interface_integration_log";
+    public static final String PRODUCT_SYS_TIMED_TASK = "product_sys_timed_task";
 
     // 瀛楁-閫氱敤
     public static final String ID = "id";
@@ -46,4 +48,23 @@
     public static final String RESPONSE_CUSTOM_METHOD = "response_custom_method";
     public static final String AFTER_SAVE_CUSTOM_METHOD = "after_save_custom_method";
     public static final String PARENT_UUID = "parent_uuid";
+    public static final String VALUE = "value";
+    public static final String CONFIG_UUID = "config_uuid";
+    public static final String CODE = "code";
+    public static final String MESSAGE = "message";
+    public static final String CONTENT = "content";
+    public static final String ERROR_INFO = "error_info";
+    public static final String TABLE = "table";
+    public static final String JOB_NAME = "job_name";
+    public static final String JOB_GROUP = "job_group";
+    public static final String IS_CONCEAL = "is_conceal";
+    public static final String MISFIRE_POLICY = "misfire_policy";
+    public static final String CONCURRENT = "concurrent";
+    public static final String CRON_EXPRESSION = "cron_expression";
+    public static final String INVOKE_TARGET = "invoke_target";
+    public static final String STATUS = "status";
+    public static final String OPEN_TRANSACTION = "open_transaction";
+    public static final String FREQUENCY = "frequency";
+    public static final String FIELD_NAME = "field_name";
+    public static final String FIELD_TYPE = "field_type";
 }
diff --git a/src/main/java/com/product/integration/config/IntegrationCode.java b/src/main/java/com/product/integration/config/IntegrationCode.java
index 42dff63..322f3ca 100644
--- a/src/main/java/com/product/integration/config/IntegrationCode.java
+++ b/src/main/java/com/product/integration/config/IntegrationCode.java
@@ -11,8 +11,14 @@
     SAVE_FAIL("淇濆瓨澶辫触", "001"),
     FIND_FAIL("鏌ヨ澶辫触", "002"),
     DELETE_FAIL("鍒犻櫎澶辫触", "003"),
+    GET_SYSTEM_CACHE_TABLE_STRUCTURE_FAIL("鑾峰彇绯荤粺缂撳瓨涓〃缁撴瀯澶辫触", "004"),
+    GET_SYSTEM_CACHE_FIELD_INFO_FAIL("鑾峰彇绯荤粺缂撳瓨涓瓧娈典俊鎭け璐�", "005"),
+    TEST_METHOD_FAIL("娴嬭瘯鏂规硶鎶ラ敊", "009"),
 
-    SAVE_DEAL_RESPONSE_INFO("淇濆瓨-澶勭悊鍝嶅簲鏁版嵁缁撴瀯澶辫触", "010"),
+    INTERFACE_INTEGRATION_SAVE_DEAL_RESPONSE_INFO_FAIL("鎺ュ彛闆嗘垚淇濆瓨-澶勭悊鍝嶅簲鏁版嵁缁撴瀯澶辫触", "010"),
+    INTERFACE_INTEGRATION_REQUEST_DATA_FAIL("鎺ュ彛闆嗘垚璇锋眰鏁版嵁澶辫触", "011"),
+    INTERFACE_INTEGRATION_REQUEST_DEAL_DATA_FAIL("鎺ュ彛闆嗘垚璇锋眰澶勭悊鏁版嵁澶辫触", "012"),
+    INTERFACE_INTEGRATION_EXECUTE_FAIL("鎺ュ彛闆嗘垚鎵ц澶辫触", "013"),
 	;
 	private String text;
 	private String value;
diff --git a/src/main/java/com/product/integration/controller/InterfaceIntegrationController.java b/src/main/java/com/product/integration/controller/InterfaceIntegrationController.java
index ee4a7ba..ae8ecd4 100644
--- a/src/main/java/com/product/integration/controller/InterfaceIntegrationController.java
+++ b/src/main/java/com/product/integration/controller/InterfaceIntegrationController.java
@@ -103,4 +103,40 @@
             return error(IntegrationCode.SAVE_FAIL);
         }
     }
+
+    /**
+     * 绔嬪嵆鎵ц
+     * @param request
+     * @return
+     */
+    @RequestMapping(value = "/execute/{version}")
+    @ApiVersion(1)
+    public String execute(HttpServletRequest request) {
+        try {
+            FieldSetEntity fse = null;
+            Object bean = request.getAttribute(CoreConst.API_POST_REQUEST_DATA);
+            if (bean != null) {
+                RequestParameterEntity reqp = (RequestParameterEntity) bean;
+                fse = reqp.getFormData();
+            }
+            if (bean == null || fse == null) {
+                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
+                return error(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText());
+            }
+            if (fse.getTableName() == null || !CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION.equals(fse.getTableName())) {
+                SpringMVCContextHolder.getSystemLogger().error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
+                return error(SystemCode.SYSTEM_TABLE_NODATA.getValue(), SystemCode.SYSTEM_TABLE_NODATA.getText());
+            }
+            interfaceIntegrationService.timedTaskTrigger(fse.getUUID());
+            return OK();
+        } catch (BaseException e) {
+            e.printStackTrace();
+            SpringMVCContextHolder.getSystemLogger().error(e);
+            return error(e);
+        } catch (Exception e) {
+            e.printStackTrace();
+            SpringMVCContextHolder.getSystemLogger().error(e);
+            return error(IntegrationCode.INTERFACE_INTEGRATION_EXECUTE_FAIL);
+        }
+    }
 }
diff --git a/src/main/java/com/product/integration/service/InterfaceIntegrationService.java b/src/main/java/com/product/integration/service/InterfaceIntegrationService.java
index 6c51293..3ff3545 100644
--- a/src/main/java/com/product/integration/service/InterfaceIntegrationService.java
+++ b/src/main/java/com/product/integration/service/InterfaceIntegrationService.java
@@ -2,23 +2,37 @@
 
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
 import com.product.admin.service.PublicService;
+import com.product.common.lang.ExceptionUtils;
 import com.product.common.lang.StringUtils;
+import com.product.core.cache.DataPoolCacheImpl;
+import com.product.core.config.Global;
 import com.product.core.dao.BaseDao;
 import com.product.core.entity.DataTableEntity;
 import com.product.core.entity.FieldSetEntity;
+import com.product.core.entity.RequestParameterEntity;
+import com.product.core.exception.BaseException;
 import com.product.core.spring.context.SpringMVCContextHolder;
+import com.product.core.util.ReflectUtil;
+import com.product.file.service.FileManagerService;
 import com.product.integration.config.CmnConst;
 import com.product.integration.config.IntegrationCode;
 import com.product.integration.service.idel.IInterfaceIntegrationService;
 import com.product.util.BaseUtil;
+import com.product.util.SystemParamReplace;
+import com.product.util.http.HttpRequestUtil;
+import okhttp3.MultipartBody;
+import okhttp3.RequestBody;
+import org.apache.commons.io.FileUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
+import java.io.File;
+import java.io.IOException;
+import java.util.*;
 
 /**
  * 瀹炵幇鍔熻兘锛�
@@ -32,6 +46,8 @@
     private BaseDao baseDao;
     @Autowired
     private PublicService publicService;
+    @Autowired
+    private FileManagerService fileManagerService;
 
     /**
      * 鏌ヨ鏁版嵁
@@ -43,7 +59,7 @@
         DataTableEntity responseInfoDte = integrationFse.getSubDataTable(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO);
         Map<String, String> acceptKayMap = Maps.newHashMap();
         acceptKayMap.put("uuid", "front_uuid");
-        JSONArray arr = BaseUtil.dataTableToTreeData(responseInfoDte, CmnConst.TRICODE, acceptKayMap, null, null);
+        JSONArray arr = BaseUtil.dataTableToTreeData(responseInfoDte, CmnConst.TRICODE, 3, acceptKayMap, null, null);
         integrationFse.removeSubData(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO);
         integrationFse.setValue(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO, arr.toString());
         return integrationFse;
@@ -66,7 +82,12 @@
 
         DataTableEntity responseInfoDte = dealResponseInfo(responseInfo);
         fse.addSubDataTable(responseInfoDte);
-        return publicService.saveFieldSetEntity(fse);
+        uuid = publicService.saveFieldSetEntity(fse);
+
+        // 楠岃瘉瀹氭椂浠诲姟鏄惁鍒涘缓锛岃嫢鏄湭鍒涘缓锛岄偅涔堝垱寤哄畾鏃朵换鍔�
+        generateTimedTask(fse);
+
+        return uuid;
     }
     /**
      * 澶勭悊鍝嶅簲鏁版嵁缁撴瀯
@@ -80,7 +101,7 @@
                 saveDealResponseInfoPart(responseInfoDte, JSONArray.parseArray(responseInfo), "");
             }
         } catch (Exception e) {
-            SpringMVCContextHolder.getSystemLogger().error(IntegrationCode.SAVE_DEAL_RESPONSE_INFO);
+            SpringMVCContextHolder.getSystemLogger().error(IntegrationCode.INTERFACE_INTEGRATION_SAVE_DEAL_RESPONSE_INFO_FAIL);
         }
         return responseInfoDte;
     }
@@ -112,4 +133,446 @@
             saveDealResponseInfoPart(responseInfoDte, responseInfoObj.getJSONArray(CmnConst.CHILDREN), code);
         }
     }
+
+    /**
+     * 楠岃瘉瀹氭椂浠诲姟鏄惁鍒涘缓锛岃嫢鏄湭鍒涘缓锛岄偅涔堝垱寤哄畾鏃朵换鍔�
+     * @param fse
+     */
+    public void generateTimedTask(FieldSetEntity fse) {
+        String invokeTarget = String.format("interfaceIntegrationService.timedTaskTrigger('%s')", fse.getUUID());
+        FieldSetEntity timedTaskFse = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_TIMED_TASK, String.format("%s=?", CmnConst.INVOKE_TARGET), new Object[]{invokeTarget}, false);
+        if (FieldSetEntity.isEmpty(timedTaskFse)) {
+            timedTaskFse = new FieldSetEntity(CmnConst.PRODUCT_SYS_TIMED_TASK);
+            timedTaskFse.setValue(CmnConst.JOB_GROUP, "system");
+            timedTaskFse.setValue(CmnConst.MISFIRE_POLICY, "3");
+            timedTaskFse.setValue(CmnConst.CONCURRENT, 0);
+            timedTaskFse.setValue(CmnConst.INVOKE_TARGET, invokeTarget);
+            BaseUtil.createCreatorAndCreationTime(timedTaskFse);
+        } else {
+            BaseUtil.updatedRegeneratorAndUpdateTime(SpringMVCContextHolder.getCurrentUser(), timedTaskFse);
+        }
+        timedTaskFse.setValue(CmnConst.JOB_NAME, String.format("鎺ュ彛闆嗘垚-%s", fse.getString(CmnConst.NAME)));
+        timedTaskFse.setValue(CmnConst.CRON_EXPRESSION, fse.getString(CmnConst.FREQUENCY));
+        timedTaskFse.setValue(CmnConst.IS_CONCEAL, 0);
+        timedTaskFse.setValue(CmnConst.STATUS, 1);
+        baseDao.saveFieldSetEntity(timedTaskFse);
+
+    }
+
+    /**
+     * 瀹氭椂浠诲姟瑙﹀彂鏂规硶
+     * @param uuid  鎺ュ彛闆嗘垚uuid
+     */
+    public void timedTaskTrigger(String uuid) {
+        String code = "";
+        String message = "";
+        StringBuilder content = new StringBuilder(128);
+        String errorInfo = null;
+        try {
+            // 鏁版嵁鍑嗗
+            FieldSetEntity paramFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION, uuid, true);
+            DataTableEntity requestParamDte = paramFse.getSubDataTable(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_REQUEST_PARAM);
+            DataTableEntity requestHederDte = paramFse.getSubDataTable(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_REQUEST_HEADER);
+            String requestType = paramFse.getString(CmnConst.REQUEST_TYPE);
+            String url = paramFse.getString(CmnConst.ADDRESS);
+            MultipartBody.Builder builder = new MultipartBody.Builder().setType(okhttp3.MultipartBody.FORM);
+            // 璇锋眰澶翠俊鎭�
+            Map<String, String> headerMap = Maps.newHashMap();
+            if (!DataTableEntity.isEmpty(requestHederDte)) {
+                for (int i = 0; i < requestHederDte.getRows(); i++) {
+                    FieldSetEntity fse = requestHederDte.getFieldSetEntity(i);
+                    headerMap.put(fse.getString(CmnConst.NAME), dealValue(fse.getString(CmnConst.VALUE)));
+                }
+            }
+            // 娣诲姞璇锋眰鍙傛暟淇℃伅
+            Map<String, String> paramMap = Maps.newHashMap();
+            if (!DataTableEntity.isEmpty(requestParamDte)) {
+                for (int i = 0; i < requestParamDte.getRows(); i++) {
+                    FieldSetEntity fse = requestParamDte.getFieldSetEntity(i);
+                    paramMap.put(fse.getString(CmnConst.NAME), dealValue(fse.getString(CmnConst.VALUE)));
+                }
+            }
+
+            // 璇锋眰鍙傛暟鏂规硶鑷畾涔夊鐞�
+            String customRequestParamInfo = paramFse.getString(CmnConst.REQUEST_PARAM_CUSTOM_METHOD);
+            if (!StringUtils.isEmpty(customRequestParamInfo)) {
+                String[] customMethodInfoArr = customRequestParamInfo.split("\\.");
+                String beanName = customMethodInfoArr[0];
+                String methodName = customMethodInfoArr[1];
+                ReflectUtil.invoke(beanName, methodName, new Object[]{headerMap, paramMap});
+                content.append(String.format("%s 鎵ц鑷畾涔夋柟娉昜%s]琛ュ厖澶勭悊璇锋眰鍙傛暟\n", BaseUtil.getCurTimeWithMill(), customRequestParamInfo));
+            }
+
+            // 鍙戣捣璇锋眰
+            Object requestResult;
+            try {
+                if ("post".equals(requestType)) {
+                    paramMap.forEach(builder::addFormDataPart);
+                    RequestBody requestBody = builder.build();
+                    requestResult = HttpRequestUtil.request(url, "POST", "multipart/form-data", requestBody, JSONObject.class, headerMap);
+                } else {
+                    StringBuilder urlParamPart = new StringBuilder(128);
+                    paramMap.forEach((name, value) -> {
+                        if (urlParamPart.length() > 0) {
+                            urlParamPart.append("&");
+                        } else {
+                            urlParamPart.append("?");
+                        }
+                        urlParamPart.append(name).append("=").append(value);
+                    });
+                    requestResult = HttpRequestUtil.request(url + urlParamPart, "GET", "application/json", null, JSONObject.class, headerMap);
+                }
+                System.out.println(requestResult);
+            } catch (Exception e) {
+                e.printStackTrace();
+                throw new BaseException(IntegrationCode.INTERFACE_INTEGRATION_REQUEST_DATA_FAIL);
+            }
+
+            // 鏁版嵁澶勭悊
+            String customResponseInfo = paramFse.getString(CmnConst.RESPONSE_CUSTOM_METHOD);
+            if (!StringUtils.isEmpty(customResponseInfo)) {
+                // 鑷畾涔夋柟娉曞鐞�
+                String[] customMethodInfoArr = customResponseInfo.split("\\.");
+                String beanName = customMethodInfoArr[0];
+                String methodName = customMethodInfoArr[1];
+                ReflectUtil.invoke(beanName, methodName, new Object[]{paramFse, requestResult});
+                content.append(String.format("%s 鎵ц鑷畾涔夋暟鎹鐞嗘柟娉昜%s]\n", BaseUtil.getCurTimeWithMill(), customResponseInfo));
+            } else {
+                // 榛樿鏂规硶澶勭悊
+                FieldSetEntity clientFse = baseDao.getFieldSetEntityByFilter("product_sys_clients", "1=1", new Object[]{}, false);
+                String clientUUID = clientFse.getUUID();
+
+                String coverSign = paramFse.getString(CmnConst.IS_COVER);
+                DataTableEntity responseInfoDte = paramFse.getSubDataTable(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_RESPONSE_INFO);
+                if (DataTableEntity.isEmpty(responseInfoDte)) {
+                    content.append(String.format("%s 鍝嶅簲缁撴瀯閰嶇疆淇℃伅涓虹┖\n", BaseUtil.getCurTimeWithMill()));
+                    return;
+                }
+                Map<String, String> keyMap = Maps.newHashMap();
+                for (Object key : responseInfoDte.getFieldSetEntity(0).getFields()) {
+                    keyMap.put(key.toString(), String.format("[%s]", key));
+                }
+                JSONObject structureObj = BaseUtil.dataTableToTreeDataObj(responseInfoDte, CmnConst.NAME, CmnConst.TRICODE, 3, keyMap, null, null);
+                if (structureObj.isEmpty()) {
+                    return;
+                }
+                JSONObject resultObj = (JSONObject) requestResult;
+                JSONObject dealtDataObj = dealResult(resultObj, structureObj);
+                for (Map.Entry<String, Object> entry : dealtDataObj.entrySet()) {
+                    String key = entry.getKey();
+                    Object value = entry.getValue();
+                    if (CmnConst.CODE.equals(key)) {
+                        code = value != null ? value.toString() : null;
+                    } else if (CmnConst.MESSAGE.equals(key)) {
+                        message = value != null ? value.toString() : null;
+                    } else {
+                        // 琛ㄥ鐞�
+                        JSONObject tableObj = (JSONObject) value;
+                        Set<String> uniqueFieldSet = (Set<String>) tableObj.get(CmnConst.UNIQUE_SIGN);
+                        DataTableEntity waitDealDte = (DataTableEntity) tableObj.get(CmnConst.TABLE);
+                        // 浼樺厛澶勭悊鏂囦欢鍐呭锛岄渶瑕佹牴鎹〃缁撴瀯淇℃伅杩涜澶勭悊
+                        dealFile(waitDealDte, clientUUID);
+                        String tableName = waitDealDte.getTableName().toString();
+                        if (uniqueFieldSet == null || uniqueFieldSet.isEmpty()) {
+                            if ("1".equals(coverSign)) {
+                                // 瑕嗙洊
+                                baseDao.executeUpdate(String.format("TRUNCATE TABLE %s", tableName));
+                                content.append(String.format("%s 寮�濮�-澶勭悊[%s]琛�-鏃犳爣璇嗕笖瑕嗙洊\n", BaseUtil.getCurTimeWithMill(), tableName));
+                                content.append(String.format("%s 娓呯悊[%s]琛╘n", BaseUtil.getCurTimeWithMill(), tableName));
+                            } else {
+                                content.append(String.format("%s 寮�濮�-澶勭悊[%s]琛�-鏃犳爣璇嗕笉瑕嗙洊\n", BaseUtil.getCurTimeWithMill(), tableName));
+                            }
+                            BaseUtil.generateTime(waitDealDte);
+                            baseDao.add(waitDealDte);
+                        } else {
+                            StringBuilder filter = new StringBuilder(128);
+                            List<String> paramList = Lists.newArrayList();
+                            for (int i = 0; i < waitDealDte.getRows(); i++) {
+                                FieldSetEntity waitDealFse = waitDealDte.getFieldSetEntity(i);
+                                if (filter.length() > 0) {
+                                    filter.append("\nOR ");
+                                }
+                                StringBuilder singleFilter = new StringBuilder(128);
+                                for (String uniqueField : uniqueFieldSet) {
+                                    if (singleFilter.length() > 0) {
+                                        singleFilter.append(" AND ");
+                                    }
+                                    singleFilter.append(uniqueField).append("=?");
+                                    paramList.add(waitDealFse.getString(uniqueField));
+                                }
+                                filter.append("(").append(singleFilter).append(")");
+                            }
+                            if ("1".equals(coverSign)) {
+                                // 瑕嗙洊
+                                content.append(String.format("%s 寮�濮�-澶勭悊[%s]琛�-鏃犳爣璇嗕笖瑕嗙洊\n", BaseUtil.getCurTimeWithMill(), tableName));
+                                baseDao.executeUpdate(String.format("DELETE FROM %s WHERE %s", tableName, filter), paramList.toArray());
+                                content.append(String.format("%s 鏍规嵁鍞竴鏍囪瘑瀛楁[%s]杩涜娓呯悊\n", BaseUtil.getCurTimeWithMill(), BaseUtil.collection2String(uniqueFieldSet)));
+                                baseDao.add(waitDealDte);
+                            } else {
+                                // 涓嶈鐩�
+                                content.append(String.format("%s 寮�濮�-澶勭悊[%s]琛�-鏃犳爣璇嗕笉瑕嗙洊\n", BaseUtil.getCurTimeWithMill(), tableName));
+                                DataTableEntity waitUpdateDte = baseDao.listTable(tableName, filter.toString(), paramList.toArray());
+                                int waitAddCount = 0;
+                                Map<JSONObject, FieldSetEntity> waitUpdateMap = Maps.newHashMap();
+                                for (int i = 0; i < waitUpdateDte.getRows(); i++) {
+                                    FieldSetEntity waitUpdateFse = waitUpdateDte.getFieldSetEntity(i);
+                                    JSONObject keyObj = extractFseAimField2Obj(waitUpdateFse, uniqueFieldSet);
+                                    waitUpdateMap.put(keyObj, waitUpdateFse);
+                                }
+                                for (int i = 0; i < waitDealDte.getRows(); i++) {
+                                    FieldSetEntity waitDealFse = waitDealDte.getFieldSetEntity(i);
+                                    JSONObject keyObj = extractFseAimField2Obj(waitDealFse, uniqueFieldSet);
+                                    FieldSetEntity waitUpdateFse = waitUpdateMap.get(keyObj);
+                                    if (waitUpdateFse != null) {
+                                        waitUpdateFse.getValues().forEach((fieldNameObj, fieldValue) -> {
+                                            String fieldName = fieldNameObj.toString();
+                                            if (StringUtils.isEmpty(waitDealFse.getString(fieldName))) {
+                                                waitDealFse.setValue(fieldName, fieldValue);
+                                            }
+                                        });
+                                        waitDealFse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
+                                    } else {
+                                        waitAddCount++;
+                                    }
+                                }
+                                baseDao.update(waitDealDte);
+                                content.append(String.format("%s 鏍规嵁[%s]琛ㄥ敮涓�鏍囪瘑瀛楁[%s]杩涜鏇存柊\n", BaseUtil.getCurTimeWithMill(), tableName, BaseUtil.collection2String(uniqueFieldSet)));
+                                content.append(String.format("%s 鏇存柊[%s]鏉℃暟鎹甛n", BaseUtil.getCurTimeWithMill(), waitUpdateDte.getRows()));
+                                content.append(String.format("%s 鏂板[%s]鏉℃暟鎹甛n", BaseUtil.getCurTimeWithMill(), waitAddCount));
+                            }
+                        }
+                        content.append(String.format("%s 瀹屾垚-鎵ц榛樿鏂规硶澶勭悊鏁版嵁-鎿嶄綔[%s]鏁版嵁锛屽叡[%s]鏉n", BaseUtil.getCurTimeWithMill(), tableName, waitDealDte.getRows()));
+                    }
+                }
+                code = dealtDataObj.getString(CmnConst.CODE);
+                message = dealtDataObj.getString(CmnConst.MESSAGE);
+            }
+
+            // 瀹屾垚鍚庢柟娉曡皟鐢�
+            String customAfterSaveInfo = paramFse.getString(CmnConst.AFTER_SAVE_CUSTOM_METHOD);
+            if (!StringUtils.isEmpty(customAfterSaveInfo)) {
+                String[] customMethodInfoArr = customAfterSaveInfo.split("\\.");
+                String beanName = customMethodInfoArr[0];
+                String methodName = customMethodInfoArr[1];
+                ReflectUtil.invoke(beanName, methodName, new Object[]{requestResult});
+                content.append(String.format("%s 鎵ц鑷畾涔変繚瀛樺悗鏂规硶[%s]\n", BaseUtil.getCurTimeWithMill(), customAfterSaveInfo));
+            }
+        } catch (BaseException e) {
+            errorInfo = ExceptionUtils.getStackTraceAsString(e);
+
+            e.printStackTrace();
+            throw new BaseException(e);
+        } catch (Exception e) {
+            errorInfo = ExceptionUtils.getStackTraceAsString(e);
+
+            e.printStackTrace();
+            throw new BaseException(IntegrationCode.INTERFACE_INTEGRATION_REQUEST_DEAL_DATA_FAIL);
+        } finally {
+            // 鏃ュ織璁板綍
+            recordLog(uuid, code, message, content.toString(), errorInfo);
+        }
+    }
+
+    /**
+     * 浼樺厛澶勭悊鏂囦欢鍐呭锛岄渶瑕佹牴鎹〃缁撴瀯淇℃伅杩涜澶勭悊
+     * @param waitDealDte
+     * @param clientUUID
+     * @throws IOException
+     */
+    private void dealFile(DataTableEntity waitDealDte, String clientUUID) throws IOException {
+        String tableName = waitDealDte.getTableName().toString();
+        DataTableEntity tableDte = DataPoolCacheImpl.getInstance().getCacheData("鎵�鏈夎〃淇℃伅", new String[]{tableName});
+        if (DataTableEntity.isEmpty(tableDte)) {
+            throw new BaseException(IntegrationCode.GET_SYSTEM_CACHE_TABLE_STRUCTURE_FAIL.getValue(), IntegrationCode.GET_SYSTEM_CACHE_TABLE_STRUCTURE_FAIL.getText() + ":" + tableName);
+        }
+        FieldSetEntity tableFse = tableDte.getFieldSetEntity(0);
+        DataTableEntity fieldDte = DataPoolCacheImpl.getInstance().getCacheData("鎵�鏈夊瓧娈典俊鎭苟鎸夎〃鍒嗙粍", new String[]{tableFse.getUUID()});
+        if (DataTableEntity.isEmpty(fieldDte)) {
+            throw new BaseException(IntegrationCode.GET_SYSTEM_CACHE_FIELD_INFO_FAIL.getValue(), IntegrationCode.GET_SYSTEM_CACHE_FIELD_INFO_FAIL.getText() + ":" + tableName);
+        }
+        Map<String, FieldSetEntity> fieldMap = BaseUtil.dte2Map(fieldDte, CmnConst.FIELD_NAME);
+        List<String> fileTypeList = Arrays.asList("file", "file-image", "blob-attachment");
+        for (int i = 0; i < waitDealDte.getRows(); i++) {
+            FieldSetEntity waitDealFse = waitDealDte.getFieldSetEntity(i);
+            for (Map.Entry<Object, Object> entry : waitDealFse.getValues().entrySet()) {
+                String fieldName = entry.getKey().toString();
+                String value = entry.getValue().toString();
+                FieldSetEntity fieldFse = fieldMap.get(fieldName);
+                if (fieldFse != null && fileTypeList.contains(fieldFse.getString(CmnConst.FIELD_TYPE))) {
+                    // 鏂囦欢澶勭悊
+                    String fileName = waitDealFse.getString(String.format("~%s~", fieldName));
+                    String attachmentUUID = saveFile(tableName, fieldName, fileName, value, clientUUID);
+                    waitDealFse.setValue(fieldName, attachmentUUID);
+                }
+            }
+        }
+    }
+
+    /**
+     * 淇濆瓨鏂囦欢杩斿洖uuid
+     * @param tableName         琛ㄥ悕
+     * @param fieldName         瀛楁鍚�
+     * @param fileName          鏂囦欢鍚�
+     * @param base64Content     鏂囦欢娴佸瓧绗︿覆
+     * @param clientUUID        瀹㈡埛uuid锛岄�氬父鏄粯璁ら《绾�
+     * @return
+     * @throws IOException
+     */
+    private String saveFile(String tableName, String fieldName, String fileName, String base64Content, String clientUUID) throws IOException {
+        String outPath = Global.getSystemConfig("upload.file.path", "") + File.separator + BaseUtil.getCurDateTime("yyyy/MM/dd") + File.separator + UUID.randomUUID() + "_" + fileName;
+        byte[] fileBytes = Base64.getDecoder().decode(base64Content);
+        FileUtils.writeByteArrayToFile(new File(outPath), fileBytes);
+
+        RequestParameterEntity requestParameterEntity = new RequestParameterEntity();
+        Map<String, File> fileMap = new HashMap<>();
+        fileMap.put(fileName, new File(outPath));
+        requestParameterEntity.setFiles(fileMap);
+        FieldSetEntity fseAttachment = new FieldSetEntity();
+        fseAttachment.setTableName(tableName);
+        fseAttachment.setValue("~field_name~", fieldName);
+        fseAttachment.setValue(UUID.randomUUID().toString(), fileName);
+        fseAttachment.setValue("client_uuid", clientUUID);
+        requestParameterEntity.setFormData(fseAttachment);
+        FieldSetEntity resultFse = fileManagerService.uploadFile(requestParameterEntity);
+
+        return resultFse.getString(fieldName);
+    }
+
+    /**
+     * 鎻愬彇fse涓寚瀹氬瓧娈典俊鎭浆鍖栦负JSONObject
+     * @param fse                   寰呭鐞嗘暟鎹�
+     * @param acceptCollection      鎺ユ敹瀛楁鐨勯泦鍚�
+     * @return
+     */
+    private JSONObject extractFseAimField2Obj(FieldSetEntity fse, Collection<String> acceptCollection) {
+        JSONObject resultObj = new JSONObject();
+        acceptCollection.forEach(fieldName -> resultObj.put(fieldName, fse.getString(fieldName)));
+        return resultObj;
+    }
+
+    /**
+     * 澶勭悊鍊硷紝鑻ユ槸鍚湁绯荤粺鍙傛暟锛岄偅涔堟浛鎹紝鑻ユ槸涓嶅惈锛屽垯鐩存帴杩斿洖
+     * @param value
+     * @return
+     */
+    private String dealValue(String value) {
+        if (value.contains("{")) {
+            return SystemParamReplace.systemParamsReplace(value);
+        } else {
+            return value;
+        }
+    }
+
+    /**
+     * 澶勭悊缁撴灉淇℃伅-榛樿鏂规硶
+     * @param resultObj     缁撴灉鍐呭obj
+     * @param structureObj  缁撴瀯淇℃伅arr
+     * @return
+     */
+    private JSONObject dealResult(JSONObject resultObj, JSONObject structureObj) {
+        JSONObject infoObj = new JSONObject();
+        dealResultPart(infoObj, resultObj, structureObj, "");
+        return infoObj;
+    }
+    private void dealResultPart(JSONObject infoObj, JSONObject resultObj, JSONObject structureObj, String curTableName) {
+        if (structureObj == null || resultObj.isEmpty()) {
+            return;
+        }
+        FieldSetEntity fse = null;
+        if (!StringUtils.isEmpty(curTableName)) {
+            fse = new FieldSetEntity(curTableName);
+            DataTableEntity dte = (DataTableEntity) infoObj.getJSONObject(curTableName).get(CmnConst.TABLE);
+            dte.addFieldSetEntity(fse);
+        }
+        for (Map.Entry<String, Object> entry : resultObj.entrySet()) {
+            String resultKey = entry.getKey();
+            Object resultValue = entry.getValue();
+            JSONObject singleStructureObj = structureObj.getJSONObject(resultKey);
+            if (singleStructureObj == null || singleStructureObj.isEmpty()) {
+                if (fse != null) {
+                    fse.setValue(resultKey, resultValue);
+                }
+            } else {
+                String dealtCodeField = String.format("[%s]", CmnConst.CODE);
+                String dealtMessageField = String.format("[%s]", CmnConst.MESSAGE);
+                String dealtTypeField = String.format("[%s]", CmnConst.TYPE);
+                String dealtDBInfoField = String.format("[%s]", CmnConst.DB_INFO);
+                if ("1".equals(singleStructureObj.getString(dealtTypeField)) && StringUtils.isEmpty(infoObj.getString(dealtCodeField))) {
+                    // 鐘舵�佺爜
+                    infoObj.put(CmnConst.CODE, resultValue);
+                } else if ("2".equals(singleStructureObj.getString(dealtTypeField)) && StringUtils.isEmpty(infoObj.getString(dealtMessageField))) {
+                    // 娑堟伅鍐呭
+                    infoObj.put(CmnConst.MESSAGE, resultValue);
+                } else if ("3".equals(singleStructureObj.getString(dealtTypeField))) {
+                    // 琛�
+                    JSONObject tableInfoObj = new JSONObject();
+                    curTableName = singleStructureObj.getString(dealtDBInfoField);
+                    infoObj.put(curTableName, tableInfoObj);
+                    DataTableEntity dte = new DataTableEntity();
+                    tableInfoObj.put(CmnConst.TABLE, dte);
+                    Set<String> uniqueSignSet = Sets.newHashSet();
+                    tableInfoObj.put(CmnConst.UNIQUE_SIGN, uniqueSignSet);
+                } else if ("4".equals(singleStructureObj.getString(dealtTypeField))) {
+                    // 瀛楁
+                    if (fse != null) {
+                        fse.setValue(singleStructureObj.getString(dealtDBInfoField), resultValue);
+                    }
+                    String dealtUniqueSignField = String.format("[%s]", CmnConst.UNIQUE_SIGN);
+                    if ("1".equals(singleStructureObj.getString(dealtUniqueSignField))) {
+                        Set<String> uniqueSignSet = (Set<String>) infoObj.getJSONObject(curTableName).get(CmnConst.UNIQUE_SIGN);
+                        uniqueSignSet.add(singleStructureObj.getString(dealtDBInfoField));
+                    }
+                }
+            }
+            if (resultValue instanceof JSONArray) {
+                JSONArray arr = (JSONArray) resultValue;
+                for (int i = 0; i < arr.size(); i++) {
+                    dealResultPart(infoObj, arr.getJSONObject(i), singleStructureObj, curTableName);
+                }
+            } else if (resultValue instanceof JSONObject) {
+                if (singleStructureObj != null) {
+                    dealResultPart(infoObj, (JSONObject) resultValue, singleStructureObj, curTableName);
+                }
+            }
+        }
+        JSONObject tableInfoObj = resultObj.getJSONObject(curTableName);
+        if (tableInfoObj != null) {
+            ((DataTableEntity) tableInfoObj.get(curTableName)).addFieldSetEntity(fse);
+        }
+    }
+
+    /**
+     * 鏃ュ織璁板綍
+     * @param configUUID    閰嶇疆uuid
+     * @param code          鐘舵�佺爜
+     * @param message       杩斿洖娑堟伅鍐呭
+     * @param content       鎵ц鏄庣粏鍐呭
+     */
+    private void recordLog(String configUUID, String code, String message, String content) {
+        recordLog(configUUID, code, message, content, null);
+    }
+
+    /**
+     * 鏃ュ織璁板綍
+     * @param configUUID    閰嶇疆uuid
+     * @param code          鐘舵�佺爜
+     * @param message       杩斿洖娑堟伅鍐呭
+     * @param content       鎵ц鏄庣粏鍐呭
+     * @param errorInfo     閿欒淇℃伅
+     */
+    private void recordLog(String configUUID, String code, String message, String content, String errorInfo) {
+        FieldSetEntity logFse = new FieldSetEntity(CmnConst.PRODUCT_SYS_INTERFACE_INTEGRATION_LOG);
+        logFse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
+        logFse.setValue(CmnConst.CONFIG_UUID, configUUID);
+        logFse.setValue(CmnConst.CODE, code);
+        logFse.setValue(CmnConst.MESSAGE, message);
+        if (!StringUtils.isEmpty(errorInfo)) {
+            content = BaseUtil.getCurTimeWithMill() + " 鎵ц澶辫触\n" + content;
+        } else {
+            content = BaseUtil.getCurTimeWithMill() + " 鎵ц鎴愬姛\n" + content;
+        }
+        logFse.setValue(CmnConst.CONTENT, content);
+        logFse.setValue(CmnConst.ERROR_INFO, errorInfo);
+        baseDao.saveFieldSetEntity(logFse);
+    }
 }

--
Gitblit v1.9.2