From ade5569e4bab19ae7ead2ca9ab44792e2458d284 Mon Sep 17 00:00:00 2001
From: java110 <928255095@qq.com>
Date: 星期一, 27 三月 2023 19:41:31 +0800
Subject: [PATCH] optimize export excel bug

---
 java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java b/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
index 56d0a7c..5dc9aee 100755
--- a/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
+++ b/java110-service/src/main/java/com/java110/service/smo/impl/QueryServiceSMOImpl.java
@@ -4,17 +4,23 @@
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.alibaba.fastjson.JSONPath;
+import com.alibaba.fastjson.parser.Feature;
 import com.java110.core.factory.DataTransactionFactory;
+import com.java110.core.factory.GenerateCodeFactory;
 import com.java110.db.dao.IQueryServiceDAO;
+import com.java110.dto.logSystemError.LogSystemErrorDto;
 import com.java110.entity.service.ServiceSql;
+import com.java110.po.logSystemError.LogSystemErrorPo;
 import com.java110.service.context.DataQuery;
 import com.java110.service.smo.IQueryServiceSMO;
+import com.java110.service.smo.ISaveSystemErrorSMO;
 import com.java110.utils.cache.ServiceSqlCache;
 import com.java110.utils.constant.CommonConstant;
 import com.java110.utils.constant.ResponseConstant;
 import com.java110.utils.exception.BusinessException;
 import com.java110.utils.log.LoggerEngine;
 import com.java110.utils.util.Assert;
+import com.java110.utils.util.ExceptionUtil;
 import com.java110.utils.util.StringUtil;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.ibatis.ognl.Ognl;
@@ -49,6 +55,9 @@
 
     @Autowired
     private IQueryServiceDAO queryServiceDAOImpl;
+
+    @Autowired(required = false)
+    private ISaveSystemErrorSMO saveSystemErrorSMOImpl;
 
     @Override
     public void commonQueryService(DataQuery dataQuery) throws BusinessException {
@@ -124,13 +133,22 @@
     public ResponseEntity<String> fallBack(String fallBackInfo) throws BusinessException {
 
         JSONArray params = JSONArray.parseArray(fallBackInfo);
+        String sql = "";
         for (int paramIndex = 0; paramIndex < params.size(); paramIndex++) {
-            JSONObject param = params.getJSONObject(paramIndex);
-            String sql = param.getString("fallBackSql");
-            if (StringUtil.isEmpty(sql)) {
-                return new ResponseEntity<String>("鏈寘鍚玸ql淇℃伅", HttpStatus.BAD_REQUEST);
+            try {
+                JSONObject param = params.getJSONObject(paramIndex);
+                sql =  param.getString("fallBackSql");
+                if (StringUtil.isEmpty(sql)) {
+                    return new ResponseEntity<String>("鏈寘鍚玸ql淇℃伅", HttpStatus.BAD_REQUEST);
+                }
+                int flag = queryServiceDAOImpl.updateSql(sql, null);
+            }catch (Exception e){
+                LogSystemErrorPo logSystemErrorPo = new LogSystemErrorPo();
+                logSystemErrorPo.setErrId(GenerateCodeFactory.getGeneratorId(GenerateCodeFactory.CODE_PREFIX_errId));
+                logSystemErrorPo.setErrType(LogSystemErrorDto.ERR_TYPE_JOB);
+                logSystemErrorPo.setMsg(sql+ExceptionUtil.getStackTrace(e));
+                saveSystemErrorSMOImpl.saveLog(logSystemErrorPo);
             }
-            int flag = queryServiceDAOImpl.updateSql(sql, null);
 
         }
         return new ResponseEntity<String>("鍥為��鎴愬姛", HttpStatus.OK);
@@ -354,9 +372,9 @@
             List<String> columns = new ArrayList<>();
             Interpreter interpreter = new Interpreter();
             interpreter.eval(javaCode);
-            interpreter.set("params", params.toJSONString());
+            interpreter.set("params", params);
             interpreter.set("queryServiceDAOImpl",queryServiceDAOImpl);
-            JSONObject results = JSONObject.parseObject(interpreter.eval("execute(params,queryServiceDAOImpl)").toString());
+            JSONObject results = JSONObject.parseObject(interpreter.eval("execute(params,queryServiceDAOImpl)").toString(), Feature.OrderedField);
 
             JSONArray data = null;
             if (results == null || results.size() < 1) {
@@ -366,8 +384,10 @@
             }
 
             JSONArray th = new JSONArray();
-            for (String key : data.getJSONObject(0).keySet()) {
-                th.add(key);
+            if(data.size()>0) {
+                for (String key : data.getJSONObject(0).keySet()) {
+                    th.add(key);
+                }
             }
             JSONObject paramOut = new JSONObject();
             paramOut.put("th", th);
@@ -411,7 +431,7 @@
             }
             results = queryServiceDAOImpl.executeSql(currentSqlNew, currentParams.toArray(), columns);
         } catch (Exception e) {
-            logger.error("瑙f瀽sql 寮傚父", e);
+            logger.error("瑙f瀽sql 寮傚父"+currentSql, e);
             throw new BusinessException("1999", e.getLocalizedMessage());
         }
         JSONArray data = null;

--
Gitblit v1.8.0