全文检索标题检索适用车辆、动力类型添加暂未分类字段

This commit is contained in:
梁琦涛
2024-08-29 14:07:16 +08:00
parent 9941512091
commit e82bdac72b
2 changed files with 79 additions and 20 deletions
@@ -66,17 +66,17 @@
<where>${ew.sqlSegment}</where> group by standard_class
union all
select 'dynamic_type' as field_name,dynamic_type,count(*) from
(SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( T1.dynamic_type, ',', T2.help_topic_id + 1 ), ',', - 1 ) AS dynamic_type ,standard_number,standard_name
(SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( IF(T1.dynamic_type is null,'',T1.dynamic_type), ',', T2.help_topic_id + 1 ), ',', - 1 ) AS dynamic_type ,standard_number,standard_name
FROM laws_domestic_standard T1
JOIN mysql.help_topic T2 ON T2.help_topic_id &lt; ( LENGTH( T1.dynamic_type ) - LENGTH( REPLACE ( T1.dynamic_type, ',', '' )) + 1)
JOIN mysql.help_topic T2 ON T2.help_topic_id &lt; ( LENGTH( IF(T1.dynamic_type is null,'',T1.dynamic_type) ) - LENGTH( REPLACE ( IF(T1.dynamic_type is null,'',T1.dynamic_type), ',', '' )) + 1)
<where>${ew.sqlSegment}</where>
) a
group by dynamic_type
union all
select 'applicable_vehicle' as field_name,applicable_vehicle,count(*) from
(SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( T1.applicable_vehicle, ',', T2.help_topic_id + 1 ), ',', - 1 ) AS applicable_vehicle ,standard_number,standard_name
(SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( IF(T1.applicable_vehicle is null,'',T1.applicable_vehicle), ',', T2.help_topic_id + 1 ), ',', - 1 ) AS applicable_vehicle ,standard_number,standard_name
FROM laws_domestic_standard T1
JOIN mysql.help_topic T2 ON T2.help_topic_id &lt; ( LENGTH( T1.applicable_vehicle ) - LENGTH( REPLACE ( T1.applicable_vehicle, ',', '' )) + 1)
JOIN mysql.help_topic T2 ON T2.help_topic_id &lt; ( LENGTH( IF(T1.applicable_vehicle is null,'',T1.applicable_vehicle) ) - LENGTH( REPLACE ( IF(T1.applicable_vehicle is null,'',T1.applicable_vehicle), ',', '' )) + 1)
<where>${ew.sqlSegment}</where>
) a
group by applicable_vehicle
@@ -92,9 +92,9 @@
<where>${ew.sqlSegment}</where> group by standard_class
union all
select 'applicable_vehicle' as field_name,applicable_vehicle,count(*) from
(SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( T1.applicable_vehicle, ',', T2.help_topic_id + 1 ), ',', - 1 ) AS applicable_vehicle ,standard_number,standard_name
(SELECT SUBSTRING_INDEX( SUBSTRING_INDEX( IF(T1.applicable_vehicle is null,'',T1.applicable_vehicle), ',', T2.help_topic_id + 1 ), ',', - 1 ) AS applicable_vehicle ,standard_number,standard_name
FROM laws_overseas_standard T1
JOIN mysql.help_topic T2 ON T2.help_topic_id &lt; ( LENGTH( T1.applicable_vehicle ) - LENGTH( REPLACE ( T1.applicable_vehicle, ',', '' )) + 1)
JOIN mysql.help_topic T2 ON T2.help_topic_id &lt; ( LENGTH( IF(T1.applicable_vehicle is null,'',T1.applicable_vehicle) ) - LENGTH( REPLACE ( IF(T1.applicable_vehicle is null,'',T1.applicable_vehicle), ',', '' )) + 1)
<where>${ew.sqlSegment}</where>
) a
group by applicable_vehicle
@@ -197,8 +197,16 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
queryWrapper.eq(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getResourceType()),RESOURCE_TYPE,lawsHomeNormalSearchDTO.getResourceType());
String str = "',','))";
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardClass()),"instr(concat(',',standard_class,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardClass() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getDynamicType()),"instr(concat(',',dynamic_type,','),concat(',','" + lawsHomeNormalSearchDTO.getDynamicType() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getApplicableVehicle()),"instr(concat(',',applicable_vehicle,','),concat(',','" + lawsHomeNormalSearchDTO.getApplicableVehicle() + str,0);
if(Objects.equals("暂未分类",lawsHomeNormalSearchDTO.getDynamicType())){
queryWrapper.and(o->o.isNull("dynamic_type").or().eq("dynamic_type",""));
}else{
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getDynamicType()),"instr(concat(',',dynamic_type,','),concat(',','" + lawsHomeNormalSearchDTO.getDynamicType() + str,0);
}
if(Objects.equals("暂未分类",lawsHomeNormalSearchDTO.getApplicableVehicle())){
queryWrapper.and(o->o.isNull("applicable_vehicle").or().eq("applicable_vehicle",""));
}else{
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getApplicableVehicle()),"instr(concat(',',applicable_vehicle,','),concat(',','" + lawsHomeNormalSearchDTO.getApplicableVehicle() + str,0);
}
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardProperty()),"instr(concat(',',standard_property,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardProperty() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardState()),"instr(concat(',',standard_state,','), concat(',','" + lawsHomeNormalSearchDTO.getStandardState() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardCode()),"instr(concat(',',standard_code,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardCode() + str,0);
@@ -517,8 +525,16 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
queryWrapper.eq("del_flag",0);
String str = "',','))";
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardClass()),"instr(concat(',',standard_class,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardClass() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getDynamicType()),"instr(concat(',',dynamic_type,','),concat(',','" + lawsHomeNormalSearchDTO.getDynamicType() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getApplicableVehicle()),"instr(concat(',',applicable_vehicle,','),concat(',','" + lawsHomeNormalSearchDTO.getApplicableVehicle() + str,0);
if(Objects.equals("暂未分类",lawsHomeNormalSearchDTO.getDynamicType())){
queryWrapper.and(o->o.isNull("dynamic_type").or().eq("dynamic_type",""));
}else{
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getDynamicType()),"instr(concat(',',dynamic_type,','),concat(',','" + lawsHomeNormalSearchDTO.getDynamicType() + str,0);
}
if(Objects.equals("暂未分类",lawsHomeNormalSearchDTO.getApplicableVehicle())){
queryWrapper.and(o->o.isNull("applicable_vehicle").or().eq("applicable_vehicle",""));
}else{
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getApplicableVehicle()),"instr(concat(',',applicable_vehicle,','),concat(',','" + lawsHomeNormalSearchDTO.getApplicableVehicle() + str,0);
}
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardProperty()),"instr(concat(',',standard_property,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardProperty() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardState()),"instr(concat(',',standard_state,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardState() + str,0);
queryWrapper.gt(!StringUtils.isEmpty(lawsHomeNormalSearchDTO.getStandardCode()),"instr(concat(',',standard_code,','),concat(',','" + lawsHomeNormalSearchDTO.getStandardCode() + str,0);
@@ -581,6 +597,8 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
}
// 适用车辆类型
List<LawsHomeNormalSearchStatisticsObjVO> list2 = addLawsHomeNormalSearchStatistics(list, "APPLICATIONS_OVERSEAS", APPLICABLE_VEHICLE);
// 添加暂未分类
list2 = addOther(list, list2, APPLICABLE_VEHICLE);
if(!CollectionUtils.isEmpty(list2)){
obj.setApplicableVehicle(list2);
}
@@ -591,6 +609,28 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
}
}
private List<LawsHomeNormalSearchStatisticsObjVO> addOther(List<LawsHomeNormalSearchCountVO> list, List<LawsHomeNormalSearchStatisticsObjVO> list2, String applicableVehicle) {
if (CollectionUtils.isEmpty(list2)) {
list2 = new ArrayList<>();
}
LawsHomeNormalSearchStatisticsObjVO objOther = new LawsHomeNormalSearchStatisticsObjVO();
List<LawsHomeNormalSearchCountVO> opList = list.stream().filter(o -> Objects.equals(o.getDict(), ",,")
&& Objects.equals(o.getFieldName(), applicableVehicle)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(opList)) {
Optional<Integer> str = opList.stream().map(o -> Integer.parseInt(StringUtils.isBlank(o.getCount()) ? "0"
: o.getCount())).reduce(Integer::sum);
str.ifPresent(integer -> objOther.setStatisticsCount(String.valueOf(integer)));
} else {
objOther.setStatisticsCount("0");
}
objOther.setItemText("暂未分类");
objOther.setItemValue("暂未分类");
if (!Objects.equals(objOther.getStatisticsCount(), "0")) {
list2.add(0, objOther);
}
return list2;
}
private void count1(List<LawsHomeNormalSearchCountVO> list, LawsHomeNormalSearchStatisticsVO obj) {
// 标准类别
List<LawsHomeNormalSearchStatisticsObjVO> list1 = addLawsHomeNormalSearchStatistics(list,STANDARD_TYPE, STANDARD_CLASS);
@@ -599,11 +639,14 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
}
// 动力类型
List<LawsHomeNormalSearchStatisticsObjVO> list2 = addLawsHomeNormalSearchStatistics(list, "POWER_TYPE_DOMESTIC", DYNAMIC_TYPE);
// 添加暂未分类
list2 = addOther(list, list2, DYNAMIC_TYPE);
if(!CollectionUtils.isEmpty(list2)){
obj.setDynamicType(list2);
}
// 适用车辆类型
List<LawsHomeNormalSearchStatisticsObjVO> list3 = addLawsHomeNormalSearchStatistics(list,"APPLICATIONS_DOMESTIC", APPLICABLE_VEHICLE);
list3 = addOther(list, list3, APPLICABLE_VEHICLE);
if(!CollectionUtils.isEmpty(list3)){
obj.setApplicableVehicle(list3);
}
@@ -631,7 +674,6 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(!CollectionUtils.isEmpty(opList)){
Optional<Integer> str = opList.stream().map(o->Integer.parseInt(StringUtils.isBlank(o.getCount()) ? "0" : o.getCount())).reduce((x,y) ->x+y);
str.ifPresent(integer -> objVO.setStatisticsCount(String.valueOf(integer)));
}else{
objVO.setStatisticsCount("0");
}
@@ -674,11 +716,19 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
if(!StringUtils.isBlank(homeNormalSearchDTO.getStandardClass())){
mapDict.put(STANDARD_CLASS,homeNormalSearchDTO.getStandardClass());
}
if(!StringUtils.isBlank(homeNormalSearchDTO.getDynamicType())){
mapDict.put(DYNAMIC_TYPE,homeNormalSearchDTO.getDynamicType());
if(Objects.equals("暂未分类",homeNormalSearchDTO.getDynamicType())){
mapDict.put(DYNAMIC_TYPE,"暂未分类");
}else{
if(!StringUtils.isBlank(homeNormalSearchDTO.getDynamicType())){
mapDict.put(DYNAMIC_TYPE,homeNormalSearchDTO.getDynamicType());
}
}
if(!StringUtils.isBlank(homeNormalSearchDTO.getApplicableVehicle())){
mapDict.put(APPLICABLE_VEHICLE,homeNormalSearchDTO.getApplicableVehicle());
if(Objects.equals("暂未分类",homeNormalSearchDTO.getApplicableVehicle())){
mapDict.put(APPLICABLE_VEHICLE,"暂未分类");
}else{
if(!StringUtils.isBlank(homeNormalSearchDTO.getApplicableVehicle())){
mapDict.put(APPLICABLE_VEHICLE,homeNormalSearchDTO.getApplicableVehicle());
}
}
if(!StringUtils.isBlank(homeNormalSearchDTO.getStandardProperty())){
mapDict.put(STANDARD_PROPERTY,homeNormalSearchDTO.getStandardProperty());
@@ -706,11 +756,20 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
queryMapJsonDict.add(map1);
}
mapDict.forEach((k,v)->{
Map<String, Object> map1 = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map2.put(k ,"," + v + ",");
map1.put("match_phrase",map2);
queryMapJsonDict.add(map1);
if((Objects.equals(k,"dynamic_type") && Objects.equals(v,"暂未分类")) ||
(Objects.equals(k,"applicable_vehicle") && Objects.equals(v,"暂未分类"))){
Map<String, Object> map1 = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map2.put(k + KEYWORD,",,");
map1.put("term",map2);
queryMapJsonDict.add(map1);
}else{
Map<String, Object> map1 = new HashMap<>();
Map<String, Object> map2 = new HashMap<>();
map2.put(k ,"," + v + ",");
map1.put("match_phrase",map2);
queryMapJsonDict.add(map1);
}
});
JSONArray queryMapJson = new JSONArray();