opt:wql分切查询优化

This commit is contained in:
zhangzq
2025-02-12 14:41:26 +08:00
parent 0bc445e869
commit f0453b1194
6 changed files with 26 additions and 12 deletions

View File

@@ -32,16 +32,16 @@ public class MybatisPlusConfig {
public MybatisPlusInterceptor mybatisPlusInterceptor() { public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
// // 分页插件 //// // 分页插件
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
//乐观锁插件 //乐观锁插件
interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
return interceptor; return interceptor;
} }
@Bean // @Bean
ConfigurationCustomizer mybatisConfigurationCustomizer() { // ConfigurationCustomizer mybatisConfigurationCustomizer() {
return configuration -> configuration.addInterceptor(new PageInterceptor()); // return configuration -> configuration.addInterceptor(new PageInterceptor());
} // }
} }

View File

@@ -257,7 +257,7 @@ public class ResultBean implements Serializable, Cloneable {
int nTotalSize = 0; int nTotalSize = 0;
if (null != rows2 && rows2.size() > 0) { if (null != rows2 && rows2.size() > 0) {
JSONObject jrow2 = this.row2jsonobject((BasicDynaBean) rows2.get(0)); JSONObject jrow2 = this.row2jsonobject((BasicDynaBean) rows2.get(0));
nTotalSize = jrow2.getInteger("page_totalrecordnum"); nTotalSize = jrow2.getInteger("count(0)");
} }
jres.put("totalElements", nTotalSize); jres.put("totalElements", nTotalSize);
return jres; return jres;

View File

@@ -1,5 +1,6 @@
package org.nl.modules.wql.core.engine.syntax; package org.nl.modules.wql.core.engine.syntax;
import com.github.pagehelper.parser.CountSqlParser;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.modules.wql.WQLCore; import org.nl.modules.wql.WQLCore;
import org.nl.modules.wql.core.DataType; import org.nl.modules.wql.core.DataType;
@@ -410,7 +411,9 @@ public class wqlSELECT extends IWQL {
//对sql进行特殊处理找出和第一个select配对的from并把中间全部换为1 //对sql进行特殊处理找出和第一个select配对的from并把中间全部换为1
// String page_sql = change_1(wo.wp.sSQL); // String page_sql = change_1(wo.wp.sSQL);
String page_sql = wo.wp.sSQL; String page_sql = wo.wp.sSQL;
wo.wp.sSQL = "select count(*) PAGE_TOTALRECORDNUM from ( " + page_sql + ") TOTALRECORDVIEW"; CountSqlParser countSqlParser = new CountSqlParser();
String countSql = countSqlParser.getSmartCountSql(page_sql, "0");
wo.wp.sSQL = countSql;
} }
} }
//2.3、加session并执行 //2.3、加session并执行
@@ -658,7 +661,7 @@ public class wqlSELECT extends IWQL {
// this.wo = wo; // this.wo = wo;
// this.cmdLine = cmdLine; // this.cmdLine = cmdLine;
// this.list = list; // this.list = list;
// //
// } // }

View File

@@ -29,7 +29,7 @@ public interface RegionService {
* @param whereJson 条件参数 * @param whereJson 条件参数
* @return List<RegionDto> * @return List<RegionDto>
*/ */
List<RegionDto> queryAll(Map whereJson); List<RegionDto> queryAll(String whereJson);
/** /**
* 根据ID查询 * 根据ID查询

View File

@@ -10,6 +10,7 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.nl.common.utils.MapOf;
import org.nl.common.utils.SecurityUtils; import org.nl.common.utils.SecurityUtils;
import org.nl.modules.common.exception.BadRequestException; import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.FileUtil; import org.nl.modules.common.utils.FileUtil;
@@ -27,6 +28,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.*;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
/** /**
* @author ldjun * @author ldjun
@@ -59,13 +62,21 @@ public class PointServiceImpl implements PointService {
} }
JSONObject json = WQL.getWO("QSCH_BASE_POINT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "point_code asc"); JSONObject json = WQL.getWO("QSCH_BASE_POINT").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "point_code asc");
JSONArray content = json.getJSONArray("content"); JSONArray content = json.getJSONArray("content");
List<String> regionIds = new ArrayList<>();
for (int i = 0; i < content.size(); i++) {
JSONObject object = content.getJSONObject(i);
String region_id = object.getString("region_id");
regionIds.add(region_id);
}
List<RegionDto> regionDtos = regionService.queryAll("region_id in ('" + regionIds.stream().collect(Collectors.joining(",")) + "')");
Map<Long, RegionDto> attrMap = regionDtos.stream().collect(HashMap::new, (m, o) -> m.put(o.getRegion_id(), o), HashMap::putAll);
JSONArray res = new JSONArray(); JSONArray res = new JSONArray();
for (int i = 0; i < content.size(); i++) { for (int i = 0; i < content.size(); i++) {
JSONObject object = content.getJSONObject(i); JSONObject object = content.getJSONObject(i);
Long region_id = object.getLong("region_id"); Long region_id = object.getLong("region_id");
String point_status = object.getString("point_status"); String point_status = object.getString("point_status");
String point_type = object.getString("point_type"); String point_type = object.getString("point_type");
RegionDto regionDto = regionService.findById(region_id); RegionDto regionDto = attrMap.get(region_id);
String point_status_explain = regionDto.getPoint_status_explain(); String point_status_explain = regionDto.getPoint_status_explain();
String point_type_explain = regionDto.getPoint_type_explain(); String point_type_explain = regionDto.getPoint_type_explain();
// 获取点位状态名称 // 获取点位状态名称

View File

@@ -50,9 +50,9 @@ public class RegionServiceImpl implements RegionService {
} }
@Override @Override
public List<RegionDto> queryAll(Map whereJson) { public List<RegionDto> queryAll(String whereJson) {
WQLObject wo = WQLObject.getWQLObject("sch_base_region"); WQLObject wo = WQLObject.getWQLObject("sch_base_region");
JSONArray arr = wo.query().getResultJSONArray(0); JSONArray arr = wo.query(whereJson).getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) { if (ObjectUtil.isNotEmpty(arr)) {
return arr.toJavaList(RegionDto.class); return arr.toJavaList(RegionDto.class);
} }