|
|
@@ -1,10 +1,12 @@
|
|
|
package com.cloud.sa.flow.commom.service.setting;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cloud.sa.flow.commom.common.Request.StHttpRequest;
|
|
|
import com.cloud.sa.flow.commom.common.model.StResult;
|
|
|
import com.cloud.sa.flow.commom.common.redis.StRedisCache;
|
|
|
import com.cloud.sa.flow.commom.common.system.StUserInfo;
|
|
|
@@ -24,9 +26,11 @@ import com.cloud.sa.flow.commom.domain.entity.setting.StSequence;
|
|
|
import com.cloud.sa.flow.commom.domain.mapper.*;
|
|
|
import com.cloud.sa.flow.commom.domain.virentity.StQueryMainDTO;
|
|
|
import com.cloud.sa.flow.commom.service.genSql.SqlGeneratorService;
|
|
|
+import com.sun.org.apache.bcel.internal.generic.NEW;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -34,8 +38,10 @@ import java.io.PrintWriter;
|
|
|
import java.io.StringWriter;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lc
|
|
|
@@ -65,6 +71,8 @@ public class StSettingService {
|
|
|
StPrintMapper printMapper;
|
|
|
@Autowired
|
|
|
StPrintHistoryMapper printHistoryMapper;
|
|
|
+ @Value("${server.port}")
|
|
|
+ private String port;
|
|
|
|
|
|
|
|
|
//region 数据查询
|
|
|
@@ -99,43 +107,102 @@ public class StSettingService {
|
|
|
}
|
|
|
|
|
|
private List<Map<String, String>> getQuerySData(StQueryMain singleQueryMain, String query, String queryMapField) {
|
|
|
- String sql = sqlGenerator.getQueryConcatSql(singleQueryMain.getQuerySql().replaceAll("\\s+$", "").replaceAll(";+$", ""), query);
|
|
|
- //将所有连续的空白字符替换为一个空格
|
|
|
- sql = sql.replaceAll("\\s{2,}", " ");
|
|
|
- if (StString.isNotEmpty(queryMapField)) {
|
|
|
- JSONArray jsonArray = JSONArray.parseArray(queryMapField);
|
|
|
- for (Object item : jsonArray) {
|
|
|
- JSONObject jsonObject = (JSONObject) item;
|
|
|
- String key = jsonObject.getString("key");
|
|
|
- String value = jsonObject.getString("value");
|
|
|
- if (StGlobalConstant.CurrentLoginUser.equals(value)) {
|
|
|
- //(1)当前登录人
|
|
|
- value = StUserInfo.getUserCode();
|
|
|
+ if ("1".equals(singleQueryMain.getQueryType())) {
|
|
|
+ try {
|
|
|
+ String url = "http://localhost:" + port + singleQueryMain.getQuerySql();
|
|
|
+ if (StString.isNotEmpty(queryMapField)) {
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(queryMapField);
|
|
|
+ for (Object item : jsonArray) {
|
|
|
+ JSONObject jsonObject = (JSONObject) item;
|
|
|
+ if (jsonObject.containsKey("key") && jsonObject.containsKey("value")) {
|
|
|
+ String key = jsonObject.getString("key");
|
|
|
+ String value = jsonObject.getString("value");
|
|
|
+ if (StString.isNotEmpty(key) && StString.isNotEmpty(value)) {
|
|
|
+ if (StGlobalConstant.CurrentLoginUser.equals(value)) {
|
|
|
+ //(1)当前登录人
|
|
|
+ value = StUserInfo.getUserCode();
|
|
|
+ }
|
|
|
+ if (url.contains("?")) {
|
|
|
+ url += "&" + key + "=" + value;
|
|
|
+ } else {
|
|
|
+ url += "?" + key + "=" + value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- if (value == null) {
|
|
|
- //value可能非必填,需要进行设置
|
|
|
- String fieldCode = key.replace("$", "").replace("{", "").replace("}", "");
|
|
|
- if (sql.contains("'%" + key + "%'") || sql.contains("'" + key + "%'") || sql.contains("'%" + key + "'")) {
|
|
|
- //like的情况
|
|
|
- value = "";
|
|
|
- sql = sql.replace(key, value);
|
|
|
- } else {
|
|
|
- if (sql.contains("'" + key + "'")) {
|
|
|
- key = "'" + key + "'";
|
|
|
+ String httpClient = StHttpRequest.getHttpClient(url);
|
|
|
+ List<Map<String, String>> resultList= new ArrayList<>();
|
|
|
+ if(httpClient!=null ){
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(httpClient);
|
|
|
+ resultList = jsonArray.stream()
|
|
|
+ .map(obj -> {
|
|
|
+ JSONObject jsonObject = (JSONObject) obj;
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
+ jsonObject.forEach((key, value) -> {
|
|
|
+ if (value instanceof String) {
|
|
|
+ map.put(key, StConvert.toStr(value));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return map;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (query != null && query.length() > 5) {
|
|
|
+ JSONArray queryArray = JSONArray.parseArray(query);
|
|
|
+ for (int i = 0; i < queryArray.size(); i++) {
|
|
|
+ JSONObject queryObj = (JSONObject) queryArray.get(i);
|
|
|
+ if (StString.isNotEmpty(queryObj.getString("value"))) {
|
|
|
+ resultList = resultList.stream().filter(f ->
|
|
|
+ f.get(queryObj.getString("field")) != null &&
|
|
|
+ f.get(queryObj.getString("field")).contains(queryObj.getString("value")))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String sql = sqlGenerator.getQueryConcatSql(singleQueryMain.getQuerySql().replaceAll("\\s+$", "").replaceAll(";+$", ""), query);
|
|
|
+ //将所有连续的空白字符替换为一个空格
|
|
|
+ sql = sql.replaceAll("\\s{2,}", " ");
|
|
|
+ if (StString.isNotEmpty(queryMapField)) {
|
|
|
+ JSONArray jsonArray = JSONArray.parseArray(queryMapField);
|
|
|
+ for (Object item : jsonArray) {
|
|
|
+ JSONObject jsonObject = (JSONObject) item;
|
|
|
+ String key = jsonObject.getString("key");
|
|
|
+ String value = jsonObject.getString("value");
|
|
|
+ if (StGlobalConstant.CurrentLoginUser.equals(value)) {
|
|
|
+ //(1)当前登录人
|
|
|
+ value = StUserInfo.getUserCode();
|
|
|
+ }
|
|
|
+ if (value == null) {
|
|
|
+ //value可能非必填,需要进行设置
|
|
|
+ String fieldCode = key.replace("$", "").replace("{", "").replace("}", "");
|
|
|
+ if (sql.contains("'%" + key + "%'") || sql.contains("'" + key + "%'") || sql.contains("'%" + key + "'")) {
|
|
|
+ //like的情况
|
|
|
+ value = "";
|
|
|
+ sql = sql.replace(key, value);
|
|
|
+ } else {
|
|
|
+ if (sql.contains("'" + key + "'")) {
|
|
|
+ key = "'" + key + "'";
|
|
|
+ }
|
|
|
+ sql = sql.replace(key, fieldCode);
|
|
|
+ sql = sql.replace(fieldCode + "=" + fieldCode, "1=1")
|
|
|
+ .replace(fieldCode + " = " + fieldCode, "1=1")
|
|
|
+ .replace(fieldCode + " =" + fieldCode, "1=1")
|
|
|
+ .replace(fieldCode + "= " + fieldCode, "1=1");
|
|
|
}
|
|
|
- sql = sql.replace(key, fieldCode);
|
|
|
- sql = sql.replace(fieldCode + "=" + fieldCode, "1=1")
|
|
|
- .replace(fieldCode + " = " + fieldCode, "1=1")
|
|
|
- .replace(fieldCode + " =" + fieldCode, "1=1")
|
|
|
- .replace(fieldCode + "= " + fieldCode, "1=1");
|
|
|
+ } else {
|
|
|
+ //有值,直接替换
|
|
|
+ sql = sql.replace(key, value);
|
|
|
}
|
|
|
- } else {
|
|
|
- //有值,直接替换
|
|
|
- sql = sql.replace(key, value);
|
|
|
}
|
|
|
}
|
|
|
+ return commonMapper.getQueryDataList(sql);
|
|
|
}
|
|
|
- return commonMapper.getQueryDataList(sql);
|
|
|
}
|
|
|
|
|
|
public void updateStQueryMain(StQueryMain queryMain) {
|