fix(search): 修复配置分类搜索路由参数错误

- HwSearchRebuildServiceImpl添加路由解析器支持配置类型转换
- HwSearchServiceImpl修正配置分类查询参数路由逻辑
- PortalSearchDocConverter支持配置类型搜索文档指定webCode
- PortalSearchEsServiceImpl修复config_type类型搜索路由查询参数
main
zangch@mesnac.com 4 months ago
parent 0c582363b1
commit 5cde38981b

@ -127,6 +127,11 @@ public class PortalSearchDocConverter
}
public PortalSearchDoc fromConfigType(HwPortalConfigType configType)
{
return fromConfigType(configType, null);
}
public PortalSearchDoc fromConfigType(HwPortalConfigType configType, String webCode)
{
PortalSearchDoc doc = initBase();
String id = "configType:" + configType.getConfigTypeId();
@ -135,9 +140,11 @@ public class PortalSearchDocConverter
doc.setSourceType(SOURCE_CONFIG_TYPE);
doc.setTitle(configType.getConfigTypeName());
doc.setContent(joinText(configType.getConfigTypeName(), configType.getHomeConfigTypeName(), configType.getConfigTypeDesc()));
doc.setWebCode(webCode);
doc.setTypeId(toString(configType.getConfigTypeId()));
doc.setRoute("/productCenter");
doc.setRouteQueryJson(toJson(Map.of("configTypeId", configType.getConfigTypeId())));
// 这里同时保留 id/configTypeId 两个键,前者兼容当前展示端路由,后者兼容既有搜索结果消费逻辑。
doc.setRouteQueryJson(toJson(buildConfigTypeRouteQuery(configType.getConfigTypeId(), webCode)));
doc.setUpdatedAt(new Date());
return doc;
}
@ -267,4 +274,14 @@ public class PortalSearchDocConverter
return "{}";
}
}
private Map<String, Object> buildConfigTypeRouteQuery(Long configTypeId, String webCode)
{
String routeWebCode = StringUtils.isNotBlank(webCode) ? webCode : toString(configTypeId);
if (StringUtils.isBlank(routeWebCode))
{
return Map.of();
}
return Map.of("id", routeWebCode, "configTypeId", routeWebCode);
}
}

@ -9,6 +9,7 @@ import com.ruoyi.portal.search.convert.PortalSearchDocConverter;
import com.ruoyi.portal.search.es.entity.PortalSearchDoc;
import com.ruoyi.portal.search.es.mapper.PortalSearchMapper;
import com.ruoyi.portal.search.service.PortalSearchEsService;
import com.ruoyi.portal.search.support.PortalSearchRouteResolver;
import com.ruoyi.portal.service.IHwSearchRebuildService;
import org.dromara.easyes.core.biz.EsPageInfo;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
@ -42,13 +43,17 @@ public class PortalSearchEsServiceImpl implements PortalSearchEsService
private final IHwSearchRebuildService hwSearchRebuildService;
private final PortalSearchRouteResolver routeResolver;
private final ObjectMapper objectMapper = new ObjectMapper();
public PortalSearchEsServiceImpl(PortalSearchMapper portalSearchMapper,
@Autowired(required = false) IHwSearchRebuildService hwSearchRebuildService)
@Autowired(required = false) IHwSearchRebuildService hwSearchRebuildService,
PortalSearchRouteResolver routeResolver)
{
this.portalSearchMapper = portalSearchMapper;
this.hwSearchRebuildService = hwSearchRebuildService;
this.routeResolver = routeResolver;
}
@Override
@ -137,7 +142,7 @@ public class PortalSearchEsServiceImpl implements PortalSearchEsService
result.setSnippet(buildSnippet(doc.getTitle(), doc.getContent(), keyword));
result.setScore(0);
result.setRoute(doc.getRoute());
result.setRouteQuery(parseRouteQuery(doc.getRouteQueryJson()));
result.setRouteQuery(buildRouteQuery(doc));
if (editMode)
{
result.setEditRoute(buildEditRoute(doc.getSourceType(), doc.getWebCode(), doc.getTypeId(), doc.getDeviceId(), doc.getMenuId(), doc.getDocumentId()));
@ -145,6 +150,25 @@ public class PortalSearchEsServiceImpl implements PortalSearchEsService
return result;
}
private Map<String, Object> buildRouteQuery(PortalSearchDoc doc)
{
Map<String, Object> routeQuery = parseRouteQuery(doc.getRouteQueryJson());
if (!PortalSearchDocConverter.SOURCE_CONFIG_TYPE.equals(doc.getSourceType()))
{
return routeQuery;
}
String routeWebCode = StringUtils.isNotBlank(doc.getWebCode()) ? doc.getWebCode() : routeResolver.resolveConfigTypeWebCode(doc.getTitle());
if (StringUtils.isBlank(routeWebCode))
{
return routeQuery;
}
// 这里在查询侧再次归一化一次,兼容历史 ES 文档尚未重建时仍然写着旧的 config_type_id。
Map<String, Object> normalizedQuery = new HashMap<>();
normalizedQuery.put("id", routeWebCode);
normalizedQuery.put("configTypeId", routeWebCode);
return normalizedQuery;
}
private Map<String, Object> parseRouteQuery(String json)
{
if (StringUtils.isBlank(json))

@ -14,6 +14,7 @@ import com.ruoyi.portal.mapper.HwWebMenuMapper;
import com.ruoyi.portal.search.convert.PortalSearchDocConverter;
import com.ruoyi.portal.search.es.entity.PortalSearchDoc;
import com.ruoyi.portal.search.es.mapper.PortalSearchMapper;
import com.ruoyi.portal.search.support.PortalSearchRouteResolver;
import com.ruoyi.portal.service.IHwSearchRebuildService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -48,9 +49,12 @@ public class HwSearchRebuildServiceImpl implements IHwSearchRebuildService
private final HwPortalConfigTypeMapper hwPortalConfigTypeMapper;
private final PortalSearchRouteResolver routeResolver;
public HwSearchRebuildServiceImpl(PortalSearchMapper portalSearchMapper, PortalSearchDocConverter converter,
HwWebMenuMapper hwWebMenuMapper, HwWebMapper hwWebMapper, HwWebMapper1 hwWebMapper1,
HwWebDocumentMapper hwWebDocumentMapper, HwPortalConfigTypeMapper hwPortalConfigTypeMapper)
HwWebDocumentMapper hwWebDocumentMapper, HwPortalConfigTypeMapper hwPortalConfigTypeMapper,
PortalSearchRouteResolver routeResolver)
{
this.portalSearchMapper = portalSearchMapper;
this.converter = converter;
@ -59,6 +63,7 @@ public class HwSearchRebuildServiceImpl implements IHwSearchRebuildService
this.hwWebMapper1 = hwWebMapper1;
this.hwWebDocumentMapper = hwWebDocumentMapper;
this.hwPortalConfigTypeMapper = hwPortalConfigTypeMapper;
this.routeResolver = routeResolver;
}
@Override
@ -101,7 +106,7 @@ public class HwSearchRebuildServiceImpl implements IHwSearchRebuildService
documents.forEach(item -> docs.add(converter.fromDocument(item)));
List<HwPortalConfigType> configTypes = hwPortalConfigTypeMapper.selectHwPortalConfigTypeList(new HwPortalConfigType());
configTypes.forEach(item -> docs.add(converter.fromConfigType(item)));
configTypes.forEach(item -> docs.add(converter.fromConfigType(item, routeResolver.resolveConfigTypeWebCode(item, menus))));
return docs;
}
}

@ -235,7 +235,10 @@ public class HwSearchServiceImpl implements IHwSearchService
}
if (PortalSearchDocConverter.SOURCE_CONFIG_TYPE.equals(sourceType))
{
query.put("configTypeId", raw.getTypeId());
String routeWebCode = StringUtils.isNotBlank(raw.getWebCode()) ? raw.getWebCode() : raw.getTypeId();
// 配置分类命中需要跳到页面 web_code对前端暴露分类主键会把分类查询参数误当成页面入口参数。
query.put("id", routeWebCode);
query.put("configTypeId", routeWebCode);
return query;
}
return query;

Loading…
Cancel
Save