Commit 8a9d7222 by 侯昆

关联词页面整合

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