Commit 8a9d7222 by 侯昆

关联词页面整合

1 parent 8550ec52
......@@ -27,11 +27,14 @@ import com.dookay.cihai.core.word.dto.RecommendStatementDTO;
import com.dookay.cihai.core.word.query.CustomDictionaryQuery;
import com.dookay.cihai.core.word.query.WordQuery;
import com.dookay.cihai.core.word.service.ICustomDictionaryService;
import com.dookay.cihai.core.word.service.IWordRelationService;
import com.dookay.cihai.core.word.service.IWordService;
import com.dookay.coral.common.core.utils.lang.StringUtils;
import com.dookay.coral.common.web.controller.BaseController;
import com.dookay.coral.common.web.response.JsonResult;
import io.swagger.annotations.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MimeTypeUtils;
......@@ -57,6 +60,8 @@ public class HomeController extends BaseController {
@Autowired
private IWordService wordService;
@Autowired
private IWordRelationService wordRelationService;
@Autowired
private ICustomDictionaryService customDictionaryService;
@Autowired
private AipWordUtilBean aipWordUtilBean;
......@@ -98,9 +103,9 @@ public class HomeController extends BaseController {
wordQuery.setKeyword(null);
wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult(String.format("暂无\"%s\"检索结果", keyword));
return successResult("搜索结果", WordDTO.fromDomain(wordDomain));
return successResult("搜索结果", WordDTO.fromDomain(wordDomain, wordRelationService));
}
return successResult("success", WordDTO.fromDomain(wordDomain));
return successResult("success", WordDTO.fromDomain(wordDomain, wordRelationService));
} catch (Exception ex) {
return errorResult(String.format("暂无\"%s\"检索结果", keyword));
}
......@@ -135,7 +140,7 @@ public class HomeController extends BaseController {
wordDomain = wordService.getFirst(wordQuery);
if (wordDomain == null) return errorResult("暂无检索结果");
}
return successResult("搜索结果", WordDTO.fromDomain(wordDomain));
return successResult("搜索结果", WordDTO.fromDomain(wordDomain, wordRelationService));
} catch (Exception e) {
return errorResult("暂无检索结果");
}
......
......@@ -15,7 +15,6 @@ package com.dookay.cihai.app.controller;
****************************************/
import com.dookay.cihai.app.controller.dto.WordDTO;
import com.dookay.cihai.app.controller.vo.RelateWordsVO;
import com.dookay.cihai.app.controller.vo.WordPicsVO;
import com.dookay.cihai.core.word.domain.WordDomain;
import com.dookay.cihai.core.word.service.IWordRelationService;
......@@ -34,7 +33,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.stream.Collectors;
/**
* 词语控制器
......@@ -49,6 +47,8 @@ public class WordController extends BaseController {
@Autowired
private IWordService wordService;
@Autowired
private IWordRelationService wordRelationService;
/**
* 词信息
......@@ -60,7 +60,7 @@ public class WordController extends BaseController {
@ApiOperation(value = "词信息", httpMethod = "GET", response = WordDTO.class)
public JsonResult info(@PathVariable @ApiParam(value = "词的id", required = true) Long id) {
WordDomain wordDomain = wordService.get(id);
return successResult("词信息", WordDTO.fromDomain(wordDomain));
return successResult("词信息", WordDTO.fromDomain(wordDomain, wordRelationService));
}
/**
......
......@@ -20,7 +20,6 @@ import com.dookay.cihai.app.controller.vo.CharacterParaphVO;
import com.dookay.cihai.app.controller.vo.StatementBaikeVO;
import com.dookay.cihai.app.controller.vo.StatementParaphVO;
import com.dookay.cihai.core.word.domain.WordDomain;
import com.dookay.cihai.core.word.enums.WordType;
import com.dookay.cihai.core.word.service.IWordRelationService;
import com.dookay.cihai.core.word.service.IWordService;
import com.dookay.coral.common.web.controller.BaseController;
......@@ -32,7 +31,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
......@@ -115,7 +113,7 @@ public class WordHtmlController extends BaseController {
public ModelAndView relate(@PathVariable("id") Long id) {
WordDomain wordDomain = wordService.get(id);
List<WordDomain> relateWords = wordRelationService.getRelateWord(id);
List<WordDTO> vos = relateWords.stream().filter(r -> !r.getId().equals(id)).map(WordDTO::fromDomain).collect(Collectors.toList());
List<WordDTO> vos = relateWords.stream().filter(r -> !r.getId().equals(id)).map(word -> WordDTO.fromDomain(word, wordRelationService)).collect(Collectors.toList());
ModelAndView mv = new ModelAndView("/word/relate");
mv.addObject("word", wordDomain);
mv.addObject("vos", vos);
......
......@@ -16,10 +16,14 @@ package com.dookay.cihai.app.controller.dto;
import com.dookay.cihai.core.word.domain.WordDomain;
import com.dookay.cihai.core.word.enums.WordType;
import com.dookay.cihai.core.word.service.IWordRelationService;
import com.dookay.coral.common.core.utils.lang.CollectionUtils;
import com.dookay.coral.common.core.utils.lang.StringUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 词语 DTO
*
......@@ -39,8 +43,10 @@ public class WordDTO {
private Boolean hasParaph;
@ApiModelProperty("是否有百科页")
private Boolean hasBaike;
@ApiModelProperty("是否有相关词")
private Boolean hasRelated;
public static WordDTO fromDomain(WordDomain word) {
public static WordDTO fromDomain(WordDomain word, IWordRelationService wordRelationService) {
WordDTO wordDTO = new WordDTO();
wordDTO.setWordId(word.getId());
wordDTO.setWord(word.getWord());
......@@ -51,6 +57,8 @@ public class WordDTO {
wordDTO.setType(type);
wordDTO.setHasParaph(!StringUtils.isAllBlank(word.getBody(), word.getWordBrief()));
wordDTO.setHasBaike(!StringUtils.isAllBlank(word.getBaikeBrief(), word.getBaikeParaphrase()));
List<WordDomain> relateWord = wordRelationService.getRelateWord(word.getId());
wordDTO.setHasRelated(CollectionUtils.isNotEmpty(relateWord));
return wordDTO;
}
}
......@@ -62,7 +62,7 @@ public class CharacterBaikeVO {
.map(StringUtils::trim)
.collect(Collectors.toList());
dto.setSpell(spell);
List<String> body = Arrays.stream(StringUtils.split(word.getBaikeParaphrase(), '\r'))
List<String> body = Arrays.stream(StringUtils.split(word.getBaikeParaphrase(), '\n'))
.filter(StringUtils::isNoneBlank)
.map(StringUtils::trim)
.collect(Collectors.toList());
......
......@@ -57,7 +57,7 @@ public class StatementBaikeVO {
.collect(Collectors.toList());
dto.setBrief(brief);
dto.setSpell(word.getWordSpell());
List<String> body = Arrays.stream(StringUtils.split(word.getBaikeParaphrase(), '\r'))
List<String> body = Arrays.stream(StringUtils.split(word.getBaikeParaphrase(), '\n'))
.filter(StringUtils::isNoneBlank)
.map(StringUtils::trim)
.collect(Collectors.toList());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!