优化树表性能,左树右表联动时,减少一次查询

This commit is contained in:
thinkgem
2025-03-31 09:42:17 +08:00
parent 198e76110b
commit 95b08d24cf
13 changed files with 142 additions and 77 deletions

View File

@@ -23,6 +23,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
@@ -43,7 +44,10 @@ public class BizCategoryController extends BaseController {
* 获取数据
*/
@ModelAttribute
public BizCategory get(String categoryCode, boolean isNewRecord) {
public BizCategory get(String categoryCode, boolean isNewRecord, HttpServletRequest request) {
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new BizCategory();
}
return bizCategoryService.get(categoryCode, isNewRecord);
}
@@ -77,7 +81,8 @@ public class BizCategoryController extends BaseController {
if (StringUtils.isBlank(bizCategory.getParentCode())) {
bizCategory.setParentCode(BizCategory.ROOT_CODE);
}
if (StringUtils.isNotBlank(bizCategory.getViewCode())
if (StringUtils.isNotBlank(bizCategory.getCategoryCode())
|| StringUtils.isNotBlank(bizCategory.getViewCode())
|| StringUtils.isNotBlank(bizCategory.getViewCode_like())
|| StringUtils.isNotBlank(bizCategory.getCategoryName())
|| StringUtils.isNotBlank(bizCategory.getRemarks())){
@@ -148,7 +153,7 @@ public class BizCategoryController extends BaseController {
public String disable(BizCategory bizCategory) {
BizCategory where = new BizCategory();
where.setStatus(BizCategory.STATUS_NORMAL);
where.setParentCodes("," + bizCategory.getId() + ",");
where.setParentCodes_rightLike(bizCategory.getParentCodes() + bizCategory.getId() + ",");
long count = bizCategoryService.findCount(where);
if (count > 0) {
return renderResult(Global.FALSE, text("该业务分类包含未停用的子业务分类!"));

View File

@@ -49,7 +49,10 @@ public class AreaController extends BaseController {
* 获取区域
*/
@ModelAttribute
public Area get(String areaCode, boolean isNewRecord) {
public Area get(String areaCode, boolean isNewRecord, HttpServletRequest request) {
if (StringUtils.endsWithAny(request.getRequestURI(), "listData", "listPageData")) {
return new Area();
}
return areaService.get(areaCode, isNewRecord);
}
@@ -173,7 +176,7 @@ public class AreaController extends BaseController {
public String disable(Area area) {
Area where = new Area();
where.setStatus(Area.STATUS_NORMAL);
where.setParentCodes("," + area.getId() + ",");
where.setParentCodes_rightLike(area.getParentCodes() + area.getId() + ",");
long count = areaService.findCount(where);
if (count > 0) {
return renderResult(Global.FALSE, text("该区域包含未停用的子区域!"));

View File

@@ -54,7 +54,10 @@ public class CompanyController extends BaseController {
* 获取公司
*/
@ModelAttribute
public Company get(String companyCode, boolean isNewRecord) {
public Company get(String companyCode, boolean isNewRecord, HttpServletRequest request) {
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new Company();
}
return companyService.get(companyCode, isNewRecord);
}
@@ -92,7 +95,8 @@ public class CompanyController extends BaseController {
if (StringUtils.isBlank(company.getParentCode())) {
company.setParentCode(Company.ROOT_CODE);
}
if (StringUtils.isNotBlank(company.getViewCode())
if (StringUtils.isNotBlank(company.getCompanyCode())
|| StringUtils.isNotBlank(company.getViewCode())
|| StringUtils.isNotBlank(company.getViewCode_like())
|| StringUtils.isNotBlank(company.getCompanyName())
|| StringUtils.isNotBlank(company.getFullName())){
@@ -181,7 +185,7 @@ public class CompanyController extends BaseController {
public String disable(Company company) {
Company where = new Company();
where.setStatus(Company.STATUS_NORMAL);
where.setParentCodes("," + company.getId() + ",");
where.setParentCodes_rightLike(company.getParentCodes() + company.getId() + ",");
long count = companyService.findCount(where);
if (count > 0) {
return renderResult(Global.FALSE, text("该公司包含未停用的子公司!"));

View File

@@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* 字典管理Controller
* @author ThinkGem
@@ -51,7 +52,10 @@ public class DictDataController extends BaseController {
* 获取数据
*/
@ModelAttribute
public DictData get(String dictCode, boolean isNewRecord) {
public DictData get(String dictCode, boolean isNewRecord, HttpServletRequest request) {
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new DictData();
}
return dictDataService.get(dictCode, isNewRecord);
}
@@ -185,7 +189,7 @@ public class DictDataController extends BaseController {
}
// DictData where = new DictData();
// where.setStatus(DictData.STATUS_NORMAL);
// where.setParentCodes("," + dictData.getId() + ",");
// where.setParentCodes_rightLike(dictData.getParentCodes() + dictData.getId() + ",");
// long count = dictDataService.findCount(where);
// if (count > 0) {
// return renderResult(Global.FALSE, text("该字典包含未停用的子字典!"));

View File

@@ -48,7 +48,10 @@ public class MenuController extends BaseController {
private ModuleService moduleService;
@ModelAttribute
public Menu get(String menuCode, boolean isNewRecord) {
public Menu get(String menuCode, boolean isNewRecord, HttpServletRequest request) {
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new Menu();
}
return menuService.get(menuCode, isNewRecord);
}
@@ -79,13 +82,10 @@ public class MenuController extends BaseController {
if (StringUtils.isBlank(menu.getParentCode())) {
menu.setParentCode(Menu.ROOT_CODE);
}
if (StringUtils.isNotBlank(menu.getMenuNameRaw())){
menu.setParentCode(null);
}
if (StringUtils.isNotBlank(menu.getMenuHref())){
menu.setParentCode(null);
}
if (StringUtils.isNotBlank(menu.getPermission())){
if (StringUtils.isNotBlank(menu.getMenuCode())
|| StringUtils.isNotBlank(menu.getMenuNameRaw())
|| StringUtils.isNotBlank(menu.getMenuHref())
|| StringUtils.isNotBlank(menu.getPermission())){
menu.setParentCode(null);
}
List<Menu> list = menuService.findList(menu);

View File

@@ -31,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;
@@ -57,7 +58,10 @@ public class OfficeController extends BaseController {
* 获取机构
*/
@ModelAttribute
public Office get(String officeCode, boolean isNewRecord) {
public Office get(String officeCode, boolean isNewRecord, HttpServletRequest request) {
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new Office();
}
return officeService.get(officeCode, isNewRecord);
}
@@ -95,7 +99,8 @@ public class OfficeController extends BaseController {
if (StringUtils.isBlank(office.getParentCode())){
office.setParentCode(Office.ROOT_CODE);
}
if (StringUtils.isNotBlank(office.getViewCode())
if (StringUtils.isNotBlank(office.getOfficeCode())
|| StringUtils.isNotBlank(office.getViewCode())
|| StringUtils.isNotBlank(office.getViewCode_like())
|| StringUtils.isNotBlank(office.getOfficeName())
|| StringUtils.isNotBlank(office.getFullName())
@@ -235,7 +240,7 @@ public class OfficeController extends BaseController {
public String disable(Office office) {
Office where = new Office();
where.setStatus(Office.STATUS_NORMAL);
where.setParentCodes("," + office.getId() + ",");
where.setParentCodes_rightLike(office.getParentCodes() + office.getId() + ",");
long count = officeService.findCount(where);
if (count > 0) {
return renderResult(Global.FALSE, text("该机构包含未停用的子机构!"));

View File

@@ -11,9 +11,11 @@ package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModul
<% if (table.isTreeEntity){ %>
import java.util.Map;
<% } %>
<% if (table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
import java.util.List;
<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
<% } %>
import javax.servlet.http.HttpServletRequest;
<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
import javax.servlet.http.HttpServletResponse;
<% } %>
@@ -71,7 +73,12 @@ public class ${ClassName}Controller extends BaseController {
* 获取数据
*/
@ModelAttribute
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord) {
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord<% if (table.isTreeEntity){ %>, HttpServletRequest request<% } %>) {
<% if (table.isTreeEntity){ %>
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new ${ClassName}();
}
<% } %>
<% if (table.pkList.~size == 1){ %>
return ${className}Service.get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrName}<% } %>, isNewRecord);
<% }else{ %>
@@ -117,19 +124,23 @@ public class ${ClassName}Controller extends BaseController {
if (StringUtils.isBlank(${className}.getParentCode())) {
${className}.setParentCode(${ClassName}.ROOT_CODE);
}
<% for(c in table.columnList){ %>
<% if(c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status'){ %>
<% if(c.attrType == 'String'){ %>
if (StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})){
<% var where = {
for(c in table.columnList){
if(c.isPk == "1" || (c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status')){
if(c.attrType == 'String'){ %>
|| StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})
<% }else{ %>
|| ${className}.${c.attrNameForGetMethod} != null
<% }
}
}
};
where = @StringUtils.trim(@ObjectUtils.toString(where));
if (isNotBlank(where)){ %>
if (${@StringUtils.substring(where, 3)}){
${className}.setParentCode(null);
}
<% }else{ %>
if (${className}.${c.attrNameForGetMethod} != null){
${className}.setParentCode(null);
}
<% } %>
<% } %>
<% } %>
<% } %>
List<${ClassName}> list = ${className}Service.findList(${className});
return list;
}
@@ -268,7 +279,7 @@ public class ${ClassName}Controller extends BaseController {
<% if(table.isTreeEntity){ %>
${ClassName} where = new ${ClassName}();
where.setStatus(${ClassName}.STATUS_NORMAL);
where.setParentCodes("," + ${className}.getId() + ",");
where.setParentCodes_rightLike(${className}.getParentCodes() + ${className}.getId() + ",");
long count = ${className}Service.findCount(where);
if (count > 0) {
return renderResult(Global.FALSE, text("该${functionNameSimple}包含未停用的子${functionNameSimple}"));

View File

@@ -2,7 +2,7 @@
<!-- Copyright (c) 2013-Now http://jeesite.com All rights reserved.
No deletion without permission, or be held responsible to law. -->
<template>
<name>controller</name>
<name>api</name>
<filePath>${baseDir}/${moduleName}-client/src/main/java/${packagePath}/${moduleName}/api/${subModuleName}</filePath>
<fileName>${ClassName}ServiceApi.java</fileName>
<content><![CDATA[

View File

@@ -11,9 +11,11 @@ package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModul
<% if (table.isTreeEntity){ %>
import java.util.Map;
<% } %>
<% if (table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
import java.util.List;
<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
<% } %>
import javax.servlet.http.HttpServletRequest;
<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
import javax.servlet.http.HttpServletResponse;
<% } %>
@@ -73,7 +75,12 @@ public class ${ClassName}Controller extends BaseController {
* 获取数据
*/
@ModelAttribute
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord) {
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord<% if (table.isTreeEntity){ %>, HttpServletRequest request<% } %>) {
<% if (table.isTreeEntity){ %>
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new ${ClassName}();
}
<% } %>
<% if (table.pkList.~size == 1){ %>
return ${className}Service.get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrName}<% } %>, isNewRecord);
<% }else{ %>
@@ -119,19 +126,23 @@ public class ${ClassName}Controller extends BaseController {
if (StringUtils.isBlank(${className}.getParentCode())) {
${className}.setParentCode(${ClassName}.ROOT_CODE);
}
<% for(c in table.columnList){ %>
<% if(c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status'){ %>
<% if(c.attrType == 'String'){ %>
if (StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})){
<% var where = {
for(c in table.columnList){
if(c.isPk == "1" || (c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status')){
if(c.attrType == 'String'){ %>
|| StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})
<% }else{ %>
|| ${className}.${c.attrNameForGetMethod} != null
<% }
}
}
};
where = @StringUtils.trim(@ObjectUtils.toString(where));
if (isNotBlank(where)){ %>
if (${@StringUtils.substring(where, 3)}){
${className}.setParentCode(null);
}
<% }else{ %>
if (${className}.${c.attrNameForGetMethod} != null){
${className}.setParentCode(null);
}
<% } %>
<% } %>
<% } %>
<% } %>
List<${ClassName}> list = ${className}Service.findList(${className});
return list;
}
@@ -273,7 +284,7 @@ public class ${ClassName}Controller extends BaseController {
<% if(table.isTreeEntity){ %>
${ClassName} where = new ${ClassName}();
where.setStatus(${ClassName}.STATUS_NORMAL);
where.setParentCodes("," + ${className}.getId() + ",");
where.setParentCodes_rightLike(${className}.getParentCodes() + ${className}.getId() + ",");
long count = ${className}Service.findCount(where);
if (count > 0) {
return renderResult(Global.FALSE, text("该${functionNameSimple}包含未停用的子${functionNameSimple}"));
@@ -307,6 +318,11 @@ public class ${ClassName}Controller extends BaseController {
@ResponseBody
@GlobalTransactional
public String delete(${ClassName} ${className}) {
<% if(toBoolean(table.optionMap['isBpmForm'])){ %>
if (!${ClassName}.STATUS_DRAFT.equals(${className}.getStatus())){
return renderResult(Global.FALSE, text("只能删除草稿状态的数据!"));
}
<% } %>
${className}Service.delete(${className});
return renderResult(Global.TRUE, text("删除${functionNameSimple}成功!"));
}

View File

@@ -11,8 +11,9 @@ package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModul
<% if (table.isTreeEntity){ %>
import java.util.List;
import java.util.Map;
<% }else{ %>
<% } %>
import javax.servlet.http.HttpServletRequest;
<% if (!table.isTreeEntity){ %>
import javax.servlet.http.HttpServletResponse;
<% } %>
@@ -57,7 +58,12 @@ public class ${ClassName}Controller extends BaseController {
* 获取数据
*/
@ModelAttribute
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord) {
public ${ClassName} get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrType} ${pk.simpleAttrName}<% } %>, boolean isNewRecord<% if (table.isTreeEntity){ %>, HttpServletRequest request<% } %>) {
<% if (table.isTreeEntity){ %>
if (StringUtils.endsWith(request.getRequestURI(), "listData")) {
return new ${ClassName}();
}
<% } %>
<% if (table.pkList.~size == 1){ %>
return ${className}Service.get(<% for(pk in table.pkList){ %>${pkLP.index!=1?', ':''}${pk.simpleAttrName}<% } %>, isNewRecord);
<% }else{ %>
@@ -103,19 +109,23 @@ public class ${ClassName}Controller extends BaseController {
if (StringUtils.isBlank(${className}.getParentCode())) {
${className}.setParentCode(${ClassName}.ROOT_CODE);
}
<% for(c in table.columnList){ %>
<% if(c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status'){ %>
<% if(c.attrType == 'String'){ %>
if (StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})){
<% var where = {
for(c in table.columnList){
if(c.isPk == "1" || (c.isQuery == "1" && !c.isTreeEntityColumn && c.attrName != 'status')){
if(c.attrType == 'String'){ %>
|| StringUtils.isNotBlank(${className}.${c.attrNameForGetMethod})
<% }else{ %>
|| ${className}.${c.attrNameForGetMethod} != null
<% }
}
}
};
where = @StringUtils.trim(@ObjectUtils.toString(where));
if (isNotBlank(where)){ %>
if (${@StringUtils.substring(where, 3)}){
${className}.setParentCode(null);
}
<% }else{ %>
if (${className}.${c.attrNameForGetMethod} != null){
${className}.setParentCode(null);
}
<% } %>
<% } %>
<% } %>
<% } %>
List<${ClassName}> list = ${className}Service.findList(${className});
return list;
}

View File

@@ -80,7 +80,7 @@
$('#dataGrid').dataGrid({
searchForm: $('#searchForm'),
columnModel: [
{header:'${text("菜单名称")}', name:'menuNameRaw', width:200, formatter: function(val, obj, row, act){
{header:'${text("菜单名称")}', name:'menuNameRaw', width:230, formatter: function(val, obj, row, act){
var icon = row.menuIcon || 'fa-circle-o opa08', iconHtml = '';
if (icon.indexOf('://') != -1){
iconHtml = '<img src="' + icon + '" width="20" height="20">';
@@ -96,11 +96,11 @@ $('#dataGrid').dataGrid({
return '<a href="javascript:" title="按模块查询" onclick="$(\'#moduleCodes\').val($(this).text());$(\'#dataGrid\').dataGrid(\'refreshTree\',1);">'+val+'</a>';
}},
{header:'${text("链接")}', name:'menuHref', width:150},
{header:'${text("排序")}', name:'treeSort', width:63, align:"center", classes:"clip p0", formatter: function(val, obj, row, act){
{header:'${text("排序")}', name:'treeSort', width:70, align:"center", classes:"clip p0", formatter: function(val, obj, row, act){
var html = [];
//# if(hasPermi('sys:menu:edit')){
html.push('<input type="hidden" name="ids" value="'+row.id+'"/>');
html.push('<input name="sorts" type="text" value="'+row.treeSort+'" style="width:50px;height:19px;margin:0;padding:0;text-align:center;border:1px solid #ddd">');
html.push('<input name="sorts" type="text" value="'+row.treeSort+'" style="width:40px;height:19px;margin:0;padding:0;text-align:center;border:1px solid #ddd;border-radius:4px">');
//# }else{
html.push(row.treeSort);
//# }