|
@@ -1,7 +1,9 @@
|
|
package com.ruoyi.project.VRdemo.service.impl;
|
|
package com.ruoyi.project.VRdemo.service.impl;
|
|
|
|
|
|
import com.ruoyi.project.VRdemo.domain.Press;
|
|
import com.ruoyi.project.VRdemo.domain.Press;
|
|
|
|
+import com.ruoyi.project.VRdemo.domain.Research;
|
|
import com.ruoyi.project.VRdemo.domain.SearchData;
|
|
import com.ruoyi.project.VRdemo.domain.SearchData;
|
|
|
|
+import com.ruoyi.project.VRdemo.domain.Thesis;
|
|
import com.ruoyi.project.VRdemo.mapper.SearchDataMapper;
|
|
import com.ruoyi.project.VRdemo.mapper.SearchDataMapper;
|
|
import com.ruoyi.project.VRdemo.service.ISearchService;
|
|
import com.ruoyi.project.VRdemo.service.ISearchService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -18,36 +20,88 @@ public class SearchServiceImpl implements ISearchService {
|
|
private SearchDataMapper searchDataMapper;
|
|
private SearchDataMapper searchDataMapper;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public String analyticParameter(List<SearchData> searchData) {
|
|
|
|
- // 按照index排序
|
|
|
|
- searchData.sort(Comparator.comparingInt(SearchData::getIndex));
|
|
|
|
- StringBuilder sql = new StringBuilder("SELECT * FROM vr_press WHERE ");
|
|
|
|
|
|
+ public List<Object> MappingSelection(List<SearchData> searchData) {
|
|
|
|
+ String dataQueryType = searchData.get(0).getDataType();
|
|
|
|
+ // 匹配数据类型
|
|
|
|
+ switch (dataQueryType) {
|
|
|
|
+ case "periodicals":
|
|
|
|
+ return new ArrayList<>(handlePeriodicals(searchData));
|
|
|
|
+ case "study":
|
|
|
|
+ return new ArrayList<>(handleStudy(searchData));
|
|
|
|
+ case "thesis":
|
|
|
|
+ return new ArrayList<>(handleThesis(searchData));
|
|
|
|
+ default:
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 期刊逻辑
|
|
|
|
+ private List<Press> handlePeriodicals(List<SearchData> searchData) {
|
|
|
|
+ StringBuilder SQL = new StringBuilder("SELECT * FROM vr_press WHERE ");
|
|
|
|
+ analyticParameter(searchData, SQL);
|
|
|
|
+ return searchDataMapper.ExecuteSearchPressSql(SQL.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 研究逻辑
|
|
|
|
+ private List<Research> handleStudy(List<SearchData> searchData) {
|
|
|
|
+ StringBuilder SQL = new StringBuilder("SELECT * FROM vr_research WHERE ");
|
|
|
|
+ analyticParameter(searchData, SQL);
|
|
|
|
+ return searchDataMapper.ExecuteSearchResearchSql(SQL.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 论文逻辑
|
|
|
|
+ private List<Thesis> handleThesis(List<SearchData> searchData) {
|
|
|
|
+ StringBuilder SQL = new StringBuilder("SELECT * FROM vr_thesis WHERE ");
|
|
|
|
+ analyticParameter(searchData, SQL);
|
|
|
|
+ return searchDataMapper.ExecuteSearchThesisSql(SQL.toString());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
|
|
+ public static void analyticParameter(List<SearchData> searchData, StringBuilder sql) {
|
|
|
|
+ searchData.sort(Comparator.comparingInt(SearchData::getIndex));
|
|
int searchDataSize = searchData.size();
|
|
int searchDataSize = searchData.size();
|
|
|
|
+ int timeJudgment = 0;
|
|
for (int i = 0; i < searchDataSize; i++) {
|
|
for (int i = 0; i < searchDataSize; i++) {
|
|
SearchData query = searchData.get(i);
|
|
SearchData query = searchData.get(i);
|
|
- // 添加条件连接符
|
|
|
|
- if(i != 0){
|
|
|
|
- sql.append(" ").append(query.getQuery_concat()).append(" ");
|
|
|
|
|
|
+ if (query.getIndex() == 90) {
|
|
|
|
+ if (i == 0) {
|
|
|
|
+ sql.append(" ").append(query.getField_name()).append(" >= ").append("'").append(query.getText()).append("'");
|
|
|
|
+ } else {
|
|
|
|
+ sql.append(" AND ").append(query.getField_name()).append(" >= ").append("'").append(query.getText()).append("'");
|
|
|
|
+ }
|
|
|
|
+ timeJudgment++;
|
|
|
|
+ continue;
|
|
|
|
+ } else if (query.getIndex() == 100) {
|
|
|
|
+ timeJudgment++;
|
|
|
|
+ if (timeJudgment == 2) {
|
|
|
|
+ sql.append(" AND ").append(query.getField_name()).append(" <= ").append("'").append(query.getText()).append("'");
|
|
|
|
+ } else {
|
|
|
|
+ sql.append(" ").append(query.getField_name()).append(" <= ").append("'").append(query.getText()).append("'");
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ if (i != 0) {
|
|
|
|
+ if (query.getQuery_concat().equals("NOT")) {
|
|
|
|
+ if (query.getQuery_style().equals("fuzzy")) {
|
|
|
|
+ sql.append(" AND ").append(query.getField_name()).append(" NOT ").append("LIKE '%").append(query.getText()).append("%'");
|
|
|
|
+ } else {
|
|
|
|
+ sql.append(" AND ").append(query.getField_name()).append(" <> ").append("'").append(query.getText()).append("'");
|
|
|
|
+ }
|
|
|
|
+ continue;
|
|
|
|
+ } else {
|
|
|
|
+ sql.append(" ").append(query.getQuery_concat()).append(" ");
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- // 单项查询
|
|
|
|
- if(searchDataSize == 1){
|
|
|
|
- sql.append(parseLogicOperators(query.getField_name(),query.getText()));
|
|
|
|
- return sql.toString();
|
|
|
|
|
|
+ if (searchDataSize == 1) {
|
|
|
|
+ sql.append(parseLogicOperators(query.getField_name(), query.getText(), query.getQuery_style()));
|
|
|
|
+ return;
|
|
}
|
|
}
|
|
- // 添加查询条件
|
|
|
|
sql.append(handleQueryCondition(query));
|
|
sql.append(handleQueryCondition(query));
|
|
}
|
|
}
|
|
-
|
|
|
|
- return sql.toString();
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 处理单个查询条件并返回对应的SQL片段。
|
|
|
|
- * @param query 查询数据对象
|
|
|
|
- * @return SQL片段
|
|
|
|
- */
|
|
|
|
- private String handleQueryCondition(SearchData query) {
|
|
|
|
|
|
+ private static String handleQueryCondition(SearchData query) {
|
|
String text = query.getText();
|
|
String text = query.getText();
|
|
switch (query.getQuery_style()) {
|
|
switch (query.getQuery_style()) {
|
|
case "precise":
|
|
case "precise":
|
|
@@ -59,39 +113,39 @@ public class SearchServiceImpl implements ISearchService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- /**
|
|
|
|
- * 解析单项查询逻辑运算符并返回转换后的字符串。
|
|
|
|
- * @param text 输入字符串
|
|
|
|
- * @return 转换后的字符串
|
|
|
|
- */
|
|
|
|
- public StringBuilder parseLogicOperators(String fieldName, String text) {
|
|
|
|
-
|
|
|
|
- List<String> protectedContents = new ArrayList<>(); // 用于存储双引号内的内容
|
|
|
|
- String placeholder = "TEMP_PLUS_PLACEHOLDER"; // 占位符
|
|
|
|
-
|
|
|
|
- // 使用Pattern和Matcher来查找并处理双引号内的内容
|
|
|
|
|
|
+ public static StringBuilder parseLogicOperators(String fieldName, String text, String queryStyle) {
|
|
|
|
+ Map<String, String> replaceMap = new HashMap<>();
|
|
|
|
+ replaceMap.put("*", "AND");
|
|
|
|
+ replaceMap.put("+", "OR");
|
|
|
|
+ replaceMap.put("-", "NOT");
|
|
|
|
+ replaceMap.put("(", "(");
|
|
|
|
+ replaceMap.put(")", ")");
|
|
|
|
+ boolean needsReplacement = false;
|
|
|
|
+ for (Map.Entry<String, String> entry : replaceMap.entrySet()) {
|
|
|
|
+ if (text.contains(entry.getKey())) {
|
|
|
|
+ needsReplacement = true;
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
Pattern pattern = Pattern.compile("\"([^\"]*)\"");
|
|
Pattern pattern = Pattern.compile("\"([^\"]*)\"");
|
|
Matcher matcher = pattern.matcher(text);
|
|
Matcher matcher = pattern.matcher(text);
|
|
StringBuffer sb = new StringBuffer();
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
+ String placeholder = "TEMP_PLUS_PLACEHOLDER";
|
|
|
|
+ List<String> protectedContents = new ArrayList<>();
|
|
while (matcher.find()) {
|
|
while (matcher.find()) {
|
|
- String contentInsideQuotes = matcher.group(1); // 获取双引号内的内容
|
|
|
|
- protectedContents.add(contentInsideQuotes); // 保存内容
|
|
|
|
- matcher.appendReplacement(sb, placeholder); // 替换为占位符
|
|
|
|
|
|
+ protectedContents.add(matcher.group(1));
|
|
|
|
+ matcher.appendReplacement(sb, placeholder);
|
|
}
|
|
}
|
|
matcher.appendTail(sb);
|
|
matcher.appendTail(sb);
|
|
text = sb.toString();
|
|
text = sb.toString();
|
|
-
|
|
|
|
- // 替换逻辑运算符
|
|
|
|
- text = text.replace("*", "AND")
|
|
|
|
- .replace("+", "OR")
|
|
|
|
- .replace("-", "NOT");
|
|
|
|
-
|
|
|
|
- // 恢复双引号内的内容
|
|
|
|
|
|
+ if (needsReplacement) {
|
|
|
|
+ for (Map.Entry<String, String> entry : replaceMap.entrySet()) {
|
|
|
|
+ text = text.replace(entry.getKey(), entry.getValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
for (String protectedContent : protectedContents) {
|
|
for (String protectedContent : protectedContents) {
|
|
text = text.replaceFirst("TEMP_PLUS_PLACEHOLDER", protectedContent);
|
|
text = text.replaceFirst("TEMP_PLUS_PLACEHOLDER", protectedContent);
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 使用正则表达式拆分条件,并保留括号和逻辑运算符
|
|
|
|
List<String> conditions = new ArrayList<>();
|
|
List<String> conditions = new ArrayList<>();
|
|
Matcher conditionMatcher = Pattern.compile("\\(|\\)|\\bAND\\b|\\bOR\\b|\\bNOT\\b|[^\\s()]+").matcher(text);
|
|
Matcher conditionMatcher = Pattern.compile("\\(|\\)|\\bAND\\b|\\bOR\\b|\\bNOT\\b|[^\\s()]+").matcher(text);
|
|
while (conditionMatcher.find()) {
|
|
while (conditionMatcher.find()) {
|
|
@@ -100,25 +154,24 @@ public class SearchServiceImpl implements ISearchService {
|
|
conditions.add(match.trim());
|
|
conditions.add(match.trim());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- // 构建SQL条件
|
|
|
|
StringBuilder condition = new StringBuilder();
|
|
StringBuilder condition = new StringBuilder();
|
|
|
|
+ boolean notFlag = false;
|
|
for (String item : conditions) {
|
|
for (String item : conditions) {
|
|
- boolean isLogicalOperatorOrBracket = "AND".equals(item) || "OR".equals(item) || "NOT".equals(item) || "(".equals(item) || ")".equals(item);
|
|
|
|
|
|
+ if ("NOT".equals(item)) {
|
|
|
|
+ condition.append(" AND ").append(fieldName).append(" NOT ");
|
|
|
|
+ notFlag = true;
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ boolean isLogicalOperatorOrBracket = "AND".equals(item) || "OR".equals(item) || "(".equals(item) || ")".equals(item);
|
|
if (isLogicalOperatorOrBracket) {
|
|
if (isLogicalOperatorOrBracket) {
|
|
condition.append(" ").append(item).append(" ");
|
|
condition.append(" ").append(item).append(" ");
|
|
|
|
+ } else if (notFlag) {
|
|
|
|
+ condition.append("LIKE '%").append(item).append("%'");
|
|
|
|
+ notFlag = false;
|
|
} else {
|
|
} else {
|
|
condition.append(fieldName).append(" LIKE '%").append(item).append("%'");
|
|
condition.append(fieldName).append(" LIKE '%").append(item).append("%'");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
return condition;
|
|
return condition;
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- // 执行查询
|
|
|
|
- public List<Press> ExecuteSearchSql(String SqlString) {
|
|
|
|
- return searchDataMapper.ExecuteSearchSql(SqlString);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|