Commit 960658b9 authored by muhong's avatar muhong

修改 名称联想

parent 538ab83a
......@@ -13,7 +13,6 @@ import com.wwdz.ch.db.bean.EsPageInfo;
import com.wwdz.ch.db.bean.ItemOfEs;
import com.wwdz.ch.db.dao.*;
import com.wwdz.ch.db.domain.*;
import com.wwdz.ch.db.dto.request.CoinRequestDto;
import com.wwdz.ch.db.dto.request.EsSearchRequestDto;
import com.wwdz.ch.db.es.ItemEsDao;
import com.wwdz.ch.wx.entity.request.ItemRequestDto;
......@@ -71,9 +70,44 @@ public class ItemServiceImpl implements ItemService {
@Override
public Result nameList(ItemRequestDto dto) {
try {
CoinRequestDto coinRequestDto = new CoinRequestDto();
coinRequestDto.setName(dto.getName());
List<String> names = itemDao.findNames(coinRequestDto);
List<String> names = new ArrayList<>();
if (StringUtils.isNotBlank(dto.getName())) {
EsSearchRequestDto esSearchRequestDto = new EsSearchRequestDto();
esSearchRequestDto.setPage(1);
esSearchRequestDto.setSize(1000);
esSearchRequestDto.setContent(dto.getName());
EsPageInfo esPageInfo = itemEsDao.findList(esSearchRequestDto);
if (Objects.nonNull(esPageInfo) && CollectionUtils.isNotEmpty(esPageInfo.getDataList())) {
Set<String> set = new HashSet<>();
esPageInfo.getDataList().forEach(s -> {
ItemOfEs es = (ItemOfEs) s;
String name = es.getName();
// 处理特殊字符
name = name.replaceAll("\\s*|\r|\n|\t", "");
name = name.replaceAll("/P", "");
if (name.contains(",")) {
int index = name.indexOf(",");
name = name.substring(0, index);
}
// 超过15个字的截取前15个字符
if (name.length() > 15) {
name = name.substring(0, 15);
}
set.add(name);
});
// 取16个名称
if (set.size() <= 16) {
names = new ArrayList<>(set);
} else {
int i = 1;
Iterator<String> iterator = set.iterator();
while (i <= 16) {
names.add(iterator.next());
i++;
}
}
}
}
return Result.success(names);
} catch (Exception e) {
logger.error("查询藏品名称联想失败", e);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment