优化树表性能,左树右表联动时,减少一次查询
This commit is contained in:
@@ -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 jakarta.servlet.http.HttpServletRequest;
|
||||
<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
|
||||
import jakarta.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}!"));
|
||||
|
||||
@@ -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[
|
||||
|
||||
@@ -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 jakarta.servlet.http.HttpServletRequest;
|
||||
<% if (!table.isTreeEntity || toBoolean(table.optionMap['isImportExport'])){ %>
|
||||
import jakarta.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}成功!"));
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ package ${packageName}.${moduleName}.web${isNotEmpty(subModuleName)?'.'+subModul
|
||||
<% if (table.isTreeEntity){ %>
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
<% }else{ %>
|
||||
<% } %>
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
<% if (!table.isTreeEntity){ %>
|
||||
import jakarta.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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
//# }
|
||||
|
||||
Reference in New Issue
Block a user