完善自动补全

This commit is contained in:
2023-11-19 14:42:11 +08:00
parent c8931c7dcc
commit 861781686a
5 changed files with 38 additions and 20 deletions

View File

@@ -11,7 +11,6 @@ import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;
@@ -91,7 +90,11 @@ public class TreeDto {
private static List<TreeDto> getChildren(Object x) {
if (x instanceof TreeDto) {
return ((TreeDto) x).getChildren().stream().map(TreeDto::buildTree).toList();
List<TreeDto> list = ((TreeDto) x).getChildren();
if (list == null){
return new ArrayList<>();
}
return list.stream().map(TreeDto::buildTree).toList();
}
Object c = ReflectUtils.getFieldValue(x, "children");

View File

@@ -224,27 +224,34 @@ class DictionaryService extends BaseService<DictionaryEntity, DictionaryReposito
if (StringUtils.isNotEmpty(request.getOrganizationId())){
nativeQuery = entityManager.createNativeQuery(
"""
select distinct %s from %s where organization_id = %s and %s like '%%%s%%'
"""
.formatted(
request.getFieldName(),
request.getTableName(),
request.getOrganizationId(), ObjectUtils.defaultIfNull(request.getQuery(), "")));
"select distinct " +
request.getFieldName() +
" from " +
request.getTableName() +
" where " +
" organization_id = '" +
request.getOrganizationId() +
"'" +
" and " +
request.getFieldName() +
" like '%" +
ObjectUtils.defaultIfNull(request.getQuery(), "") +
"%'");
}else {
nativeQuery = entityManager.createNativeQuery(
"""
select distinct %s from %s where %s like '%%%s%%'
"select distinct " +
request.getFieldName() +
" from " +
request.getTableName() +
" where " +
request.getFieldName() +
" like '%" +
ObjectUtils.defaultIfNull(request.getQuery(), "") +
"%'");
"""
.formatted(
request.getFieldName(),
request.getTableName(), ObjectUtils.defaultIfNull(request.getQuery(), "")));
}

View File

@@ -15,6 +15,8 @@ import cn.lihongjie.coal.script.entity.ScriptEntity;
import cn.lihongjie.coal.script.mapper.ScriptMapper;
import cn.lihongjie.coal.script.repository.ScriptRepository;
import com.fasterxml.jackson.databind.ObjectMapper;
import groovy.lang.GroovyClassLoader;
import groovy.lang.Script;
@@ -25,6 +27,7 @@ import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.codehaus.groovy.control.CompilerConfiguration;
@@ -194,6 +197,9 @@ class ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
}
@Autowired
ObjectMapper objectMapper;
@SneakyThrows
public ScriptExecResultDto exec(ScriptExecResultDto json) throws ScriptException {
@@ -228,7 +234,7 @@ class ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
}
});
script.setProperty("params", json.getParams());
script.setProperty("params", ObjectUtils.defaultIfNull(json.getParams(), objectMapper.createObjectNode()));
script.setProperty("ioc", applicationContext);
long start = System.currentTimeMillis();

View File

@@ -1,5 +1,6 @@
package scripts.dict
import cn.lihongjie.coal.common.Ctx
import cn.lihongjie.coal.dictionary.dto.AutoCompleteRequest
import cn.lihongjie.coal.dictionary.service.DictionaryService
import org.springframework.context.ApplicationContext
@@ -11,5 +12,5 @@ def service = ioc.getBean(DictionaryService.class)
return service.autoComplete(new AutoCompleteRequest(tableName: "t_coal_washing_daily_analysis", fieldName: "name", query: params.get("query").asText()))
return service.autoComplete(new AutoCompleteRequest(tableName: "t_coal_washing_daily_analysis", fieldName: "name", organizationId: Ctx.currentUser().organizationId,query: params.get("query")?.asText()))

View File

@@ -1,5 +1,6 @@
package scripts.dict
import cn.lihongjie.coal.common.Ctx
import cn.lihongjie.coal.dictionary.dto.AutoCompleteRequest
import cn.lihongjie.coal.dictionary.service.DictionaryService
import org.springframework.context.ApplicationContext
@@ -11,5 +12,5 @@ def service = ioc.getBean(DictionaryService.class)
return service.autoComplete(new AutoCompleteRequest(tableName: "t_coal_washing_daily_analysis_kf_items", fieldName: "name", query: params.get("query").asText()))
return service.autoComplete(new AutoCompleteRequest(tableName: "t_coal_washing_daily_analysis_kf_items kf inner join t_coal_washing_daily_analysis a on kf.coal_washing_daily_analysis_id = a.id", fieldName: "kf.name",organizationId: Ctx.currentUser().organizationId, query: params.get("query")?.asText()))