Merge branch 'refs/heads/main' into release-2024-04-25

# Conflicts:
#	luoo_music/src/main/java/com/luoo/music/controller/BaseExceptionHandler.java
#	luoo_user/src/main/java/com/luoo/user/controller/BaseExceptionHandler.java
release-2024-08-08
pikaqiudeshujia 7 months ago
commit 35ee47b668

@ -0,0 +1,16 @@
package com.luoo.comment.controller;
import api.StatusCode;
import controller.AbstractBaseExceptionHandler;
import org.springframework.web.bind.annotation.ControllerAdvice;
/**
*
*/
@ControllerAdvice
public class BaseExceptionHandler extends AbstractBaseExceptionHandler {
@Override
protected StatusCode getCommonFailedStatusCode() {
return StatusCode.COMMENT_COMMON_FAILED;
}
}

@ -0,0 +1,58 @@
package controller;
import java.util.Arrays;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletRequest;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import api.Result;
import api.StatusCode;
import dto.UserLoginDto;
import exception.BizException;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public abstract class AbstractBaseExceptionHandler extends BaseController {
@ExceptionHandler(value = Exception.class)
@ResponseBody
public Result<String> error(Exception e, HttpServletRequest request) {
log.error("{}user: {} 请求错误,请求地址: {}, 请求参数: {}, 错误信息: ", getDeviceType(request.getHeader("device_type")),
getUserId(request.getHeader("Authorization")), request.getRequestURL(),
getRequestParameter(request.getParameterMap()), e);
if (e instanceof BizException) {
BizException biz = (BizException) e;
StatusCode statusCode = null == biz.getCodeEnum() ? getCommonFailedStatusCode() : biz.getCodeEnum();
return Result.failed(statusCode, biz.getMessage());
}
return Result.failed(getCommonFailedStatusCode(), e.getMessage());
}
protected abstract StatusCode getCommonFailedStatusCode();
private String getRequestParameter(Map<String, String[]> parameterMap) {
if (CollectionUtils.isEmpty(parameterMap)) {
return "";
}
return parameterMap.entrySet().stream().map(this::getParameter).collect(Collectors.joining("|"));
}
private String getParameter(Entry<String, String[]> e) {
return e.getKey() + ":"
+ (null == e.getValue() ? "" : Arrays.stream(e.getValue()).collect(Collectors.joining(",")));
}
private String getDeviceType(String deviceType) {
return null == deviceType ? "" : (deviceType + " ");
}
private String getUserId(String authorization) {
UserLoginDto userLoginDto = getUserLoginDto(authorization);
return null == userLoginDto ? "" : (userLoginDto.getUserId() + "_" + userLoginDto.getNickName());
}
}

@ -1,61 +1,16 @@
package com.luoo.music.controller; package com.luoo.music.controller;
import api.Result;
import api.StatusCode; import api.StatusCode;
import exception.BizException; import controller.AbstractBaseExceptionHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.StringJoiner;
/** /**
* *
*/ */
@Slf4j
@ControllerAdvice @ControllerAdvice
public class BaseExceptionHandler { public class BaseExceptionHandler extends AbstractBaseExceptionHandler {
@ExceptionHandler(value = Exception.class) @Override
@ResponseBody protected StatusCode getCommonFailedStatusCode() {
public Result<Void> error(Exception e) { return StatusCode.MUSIC_COMMON_FAILED;
log.error("执行出错", e);
return Result.failed(StatusCode.MUSIC_COMMON_FAILED);
}
@ExceptionHandler(value = BizException.class)
@ResponseBody
public Result<String> error(BizException e) {
log.info("业务错误:{}", e.getMessage());
StatusCode statusCode = null == e.getCodeEnum() ? StatusCode.MUSIC_COMMON_FAILED : e.getCodeEnum();
return Result.failed(statusCode, e.getMessage());
}
/**
*
*
* @param e
*/
@ExceptionHandler(value = MethodArgumentNotValidException.class)
@ResponseBody
public Result<?> handle(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
StringJoiner joiner = new StringJoiner(";");
for (ObjectError error : bindingResult.getAllErrors()) {
String code = error.getCode();
String[] codes = error.getCodes();
String property = codes[1];
property = property.replace(code, "").replaceFirst(".", "");
String defaultMessage = error.getDefaultMessage();
joiner.add(property + defaultMessage);
}
return Result.failed(StatusCode.MUSIC_COMMON_FAILED, joiner.toString());
} }
} }

@ -12,7 +12,6 @@ import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SongRespDTO; import com.luoo.music.dto.response.SongRespDTO;
import io.swagger.annotations.*; import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
@ -51,6 +50,9 @@ public class JournalController {
@Autowired @Autowired
private JournalService journalService; private JournalService journalService;
@Autowired
private JournalMapper journalMapper;
@Autowired @Autowired
private SongController songController; private SongController songController;
@ -124,7 +126,7 @@ public class JournalController {
List<Journal> pageList = journalService.orderByField(objectIds); List<Journal> pageList = journalService.orderByField(objectIds);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization); UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds); Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
List<JournalRespDTO> list = pageList.stream().map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) List<JournalRespDTO> list = pageList.stream().map(a -> journalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
// list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList()); // list = list.stream().map(journalRespDTO -> randomCDN(journalRespDTO)).collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(count, list)); return Result.success(new PageResult<JournalRespDTO>(count, list));
@ -278,7 +280,7 @@ public class JournalController {
List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList()); List<String> ids=journals.stream().map(Journal::getId).collect(Collectors.toList());
Set<String> journalCollectSet = null == user ? Collections.emptySet() Set<String> journalCollectSet = null == user ? Collections.emptySet()
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL); : userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.JOURNAL);
List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> JournalMapper.getJournalRespDTO(a, journalCollectSet)) List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> journalMapper.getJournalRespDTO(a, journalCollectSet))
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(list); return Result.success(list);
} }
@ -288,7 +290,7 @@ public class JournalController {
@GlobalInterceptor @GlobalInterceptor
public Result<List<JournalRespDTO>> recommend() { public Result<List<JournalRespDTO>> recommend() {
List<Journal> journals = journalService.recommend(); List<Journal> journals = journalService.recommend();
List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> JournalMapper.getJournalRespDTO(a)) List<JournalRespDTO> list = journals.stream().sorted(Comparator.comparing(Journal::getUserCollectCount).reversed()).map(a -> journalMapper.getJournalRespDTO(a))
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(list); return Result.success(list);
} }

@ -43,6 +43,9 @@ public class SearchController {
@Autowired @Autowired
private JournalService journalService; private JournalService journalService;
@Autowired
private JournalMapper journalMapper;
@Autowired @Autowired
private JournalSongService journalSongService; private JournalSongService journalSongService;
@ -89,7 +92,7 @@ public class SearchController {
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException { @VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize())); PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
List<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest); List<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest);
List<JournalRespDTO> list = pageResults.stream().map(JournalMapper::getJournalRespDTO) List<JournalRespDTO> list = pageResults.stream().map(journalMapper::getJournalRespDTO)
.collect(Collectors.toList()); .collect(Collectors.toList());
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list)); return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
} }

@ -32,7 +32,6 @@ public interface JournalTagDao extends JpaRepository<JournalTag,String>, JpaSpec
@Query(value = "select journal_id FROM tb_journal_tag where tag_id=?1 or tag_id in (select id from tb_tag_info where parent_id=?1)", nativeQuery = true) @Query(value = "select journal_id FROM tb_journal_tag where tag_id=?1 or tag_id in (select id from tb_tag_info where parent_id=?1)", nativeQuery = true)
List<String> getJournalIdByTagId(String tagId); List<String> getJournalIdByTagId(String tagId);
@Query(value = "select journal_id from tb_journal_tag where tag_id in (select tag_id from tb_journal_tag where journal_id=?1) and not journal_id=?1 order by rand() limit ?2", nativeQuery = true) @Query(value = "select journal_id from tb_journal_tag where tag_id in (select tag_id from tb_journal_tag where journal_id=?1) and not journal_id=?1 order by rand() limit ?2", nativeQuery = true)
List<String> recommendByJournalId(String journalId, Integer limit); List<String> recommendByJournalId(String journalId, Integer limit);
} }

@ -33,4 +33,7 @@ public interface TagDao extends JpaRepository<Tag, String>, JpaSpecificationExec
@Query(value = "select name_ch from tb_journal_tag,tb_tag_info where journal_id = ?1 and tb_journal_tag.tag_id =tb_tag_info.id ;", nativeQuery = true) @Query(value = "select name_ch from tb_journal_tag,tb_tag_info where journal_id = ?1 and tb_journal_tag.tag_id =tb_tag_info.id ;", nativeQuery = true)
List<String> getTagNameChByJournalId(String journalId); List<String> getTagNameChByJournalId(String journalId);
@Query(value = "select * from tb_tag_info where name_ch=?1 limit 1", nativeQuery = true)
Tag findByTagName(String tagName);
} }

@ -10,31 +10,60 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.luoo.music.client.UserClient; import com.luoo.music.client.UserClient;
import net.oschina.j2cache.CacheChannel; import net.oschina.j2cache.CacheChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import com.apifan.common.random.RandomSource; import com.apifan.common.random.RandomSource;
import com.apifan.common.random.entity.Poem; import com.apifan.common.random.entity.Poem;
import com.luoo.music.dao.CommentDao; import com.luoo.music.dao.CommentDao;
import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.response.CommentDTO; import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalFilterDTO;
import com.luoo.music.dto.response.JournalRespDTO; import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.TagDTO;
import com.luoo.music.pojo.Journal; import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag;
import com.luoo.music.service.TagService;
import constants.Constants; import constants.Constants;
import enums.DateTimePatternEnum; import enums.DateTimePatternEnum;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import util.DateUtil; import util.DateUtil;
import util.StringTools; import util.StringTools;
@Component
public class JournalMapper { public class JournalMapper {
public static JournalRespDTO getJournalRespDTO(Journal journal) { @Autowired
private RedisTemplate redisTemplate;
@Autowired
private CacheChannel cacheChannel;
@Autowired
private MongoTemplate mongoTemplate;
@Autowired
private CommentDao commentDao;
@Autowired
private TagDao tagDao;
@Autowired
private UserClient userClient;
public JournalRespDTO getJournalRespDTO(Journal journal) {
return getJournalRespDTO(journal, Collections.emptySet()); return getJournalRespDTO(journal, Collections.emptySet());
} }
public static JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) { public JournalRespDTO getJournalRespDTO(Journal journal, Set<String> journalCollectSet) {
JournalRespDTO journalRespDTO = new JournalRespDTO(); JournalRespDTO journalRespDTO = new JournalRespDTO();
journalRespDTO.setId(journal.getId()); journalRespDTO.setId(journal.getId());
journalRespDTO.setJournalNo(journal.getJournalNo()); journalRespDTO.setJournalNo(journal.getJournalNo());
@ -48,6 +77,8 @@ public class JournalMapper {
String nameChTags=journal.getNameChTags(); String nameChTags=journal.getNameChTags();
if(!StringTools.isEmpty(nameChTags)) { if(!StringTools.isEmpty(nameChTags)) {
List<String> tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList()); List<String> tags=Arrays.stream(nameChTags.split(",")).collect(Collectors.toList());
List<TagDTO> tagInfos = tags.stream().map(this::getTagDto).filter(Objects::nonNull).collect(Collectors.toList());
journalRespDTO.setTagInfos(tagInfos);
journalRespDTO.setTags(tags); journalRespDTO.setTags(tags);
} }
journalRespDTO.setContent(journal.getContent()); journalRespDTO.setContent(journal.getContent());
@ -56,9 +87,22 @@ public class JournalMapper {
return journalRespDTO; return journalRespDTO;
} }
private TagDTO getTagDto(String tagName) {
return (TagDTO) this.cacheChannel.get("tag", tagName, key -> getTagDtoByName(tagName), false).getValue();
}
private TagDTO getTagDtoByName(String tagName) {
Tag tag=tagDao.findByTagName(tagName);
if(null==tag) {
return null;
}
TagDTO tagDTO=new TagDTO();
tagDTO.setName(tag.getNameCh());
tagDTO.setId(tag.getId());
return tagDTO;
}
public static JournalRespDTO getJournalRespDTO(Journal journal, public JournalRespDTO getJournalRespDTOWithComment(Journal journal) {
MongoTemplate mongoTemplate, RedisTemplate redisTemplate, CommentDao commentDao, UserClient userClient, CacheChannel cacheChannel) {
JournalRespDTO journalRespDTO = getJournalRespDTO(journal); JournalRespDTO journalRespDTO = getJournalRespDTO(journal);
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao, CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate,userClient,cacheChannel); redisTemplate,userClient,cacheChannel);
@ -70,7 +114,7 @@ public class JournalMapper {
} }
private static String getPublishDate(Journal journal) { private String getPublishDate(Journal journal) {
LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime(); LocalDateTime date = null == journal.getPubTime() ? journal.getCreateTime() : journal.getPubTime();
return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern()); return DateUtil.format(date, DateTimePatternEnum.YYYY_DOT_MM_DOT_DD.getPattern());
} }

@ -33,6 +33,7 @@ public class JournalQueryReq implements Serializable {
public String countString() { public String countString() {
return getString(categoryId) + "_" + getString(journalNoRange); return getString(categoryId) + "_" + getString(journalNoRange);
} }
private String getString(String value) { private String getString(String value) {
return StringTools.isEmpty(value) ? null : value; return StringTools.isEmpty(value) ? null : value;
} }

@ -20,6 +20,8 @@ public class JournalRespDTO implements Serializable {
private String image; private String image;
@ApiModelProperty(value = "期刊标签") @ApiModelProperty(value = "期刊标签")
private List<String> tags; private List<String> tags;
@ApiModelProperty(value = "期刊标签信息")
private List<TagDTO> tagInfos;
@ApiModelProperty(value = "概要") @ApiModelProperty(value = "概要")
private String summary; private String summary;
@ApiModelProperty(value = "文案") @ApiModelProperty(value = "文案")

@ -1,6 +1,7 @@
package com.luoo.music.service; package com.luoo.music.service;
import java.util.*; import java.util.*;
import java.util.function.Function;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
@ -14,6 +15,8 @@ import constants.Constants;
import enums.JournalPublishEnum; import enums.JournalPublishEnum;
import enums.JournalStatusEnum; import enums.JournalStatusEnum;
import net.oschina.j2cache.CacheChannel; import net.oschina.j2cache.CacheChannel;
import net.oschina.j2cache.CacheObject;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -57,6 +60,9 @@ public class JournalService {
@Autowired @Autowired
private JournalSongDao journalSongDao; private JournalSongDao journalSongDao;
@Autowired
private JournalMapper journalMapper;
@Autowired @Autowired
private JournalTagDao journalTagDao; private JournalTagDao journalTagDao;
@Autowired @Autowired
@ -228,8 +234,6 @@ public class JournalService {
return Collections.emptyList(); return Collections.emptyList();
} }
public boolean isLatest10ByJournalNo(String journalNo) { public boolean isLatest10ByJournalNo(String journalNo) {
return null!=journalDao.isLatest10ByJournalNo(journalNo); return null!=journalDao.isLatest10ByJournalNo(journalNo);
} }
@ -349,23 +353,38 @@ public class JournalService {
return journalDao.orderByField(recommendIds); return journalDao.orderByField(recommendIds);
} }
public List<String> orderByJournalIdField(List<String> jouranlIds) { public List<String> orderByJournalIdField(List<String> jouranlIds) {
return journalSongDao.orderByJournalIdField(jouranlIds); return CollectionUtils.isEmpty(jouranlIds) ? Collections.emptyList()
: journalSongDao.orderByJournalIdField(jouranlIds);
} }
@SuppressWarnings("unchecked")
public List<JournalRespDTO> queryJournalByPage(JournalQueryReq queryReq) { public List<JournalRespDTO> queryJournalByPage(JournalQueryReq queryReq) {
if(StringTools.isEmpty(queryReq.getCategoryId())&&StringTools.isEmpty(queryReq.getJournalNoRange())) { if(StringTools.isEmpty(queryReq.getCategoryId())&&StringTools.isEmpty(queryReq.getJournalNoRange())) {
return (List<JournalRespDTO>) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTOWithComment(queryReq) , false).getValue() ; return queryJournalByPage(queryReq, key -> getJournalRespDTOWithComment(queryReq));
} }
List<JournalRespDTO> list= (List<JournalRespDTO>) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTO(queryReq) , false).getValue() ; List<JournalRespDTO> list= queryJournalByPage(queryReq,key -> getJournalRespDTO(queryReq)) ;
list.parallelStream().forEach(j->{ list.parallelStream().forEach(j->{
updateComment(j); updateComment(j);
}); });
return list; return list;
} }
@SuppressWarnings("unchecked")
private List<JournalRespDTO> queryJournalByPage(JournalQueryReq queryReq,
Function<JournalQueryReq, List<JournalRespDTO>> function) {
CacheObject cacheObject=this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString());
if(null==cacheObject||null==cacheObject.getValue()) {
List<JournalRespDTO> result = function.apply(queryReq);
if(CollectionUtils.isEmpty(result)) {
return Collections.emptyList();
}
this.cacheChannel.set(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), result);
return result;
}
return (List<JournalRespDTO>) cacheObject.getValue();
}
private void updateComment(JournalRespDTO journalRespDTO) { private void updateComment(JournalRespDTO journalRespDTO) {
CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao, CommentDTO commentDTO = CommentMapper.getCommentDTO(journalRespDTO.getId(), mongoTemplate, commentDao,
redisTemplate,userClient,cacheChannel); redisTemplate,userClient,cacheChannel);
@ -378,12 +397,12 @@ public class JournalService {
private List<JournalRespDTO> getJournalRespDTO(JournalQueryReq queryReq) { private List<JournalRespDTO> getJournalRespDTO(JournalQueryReq queryReq) {
List<Journal> pageList = queryPage(queryReq); List<Journal> pageList = queryPage(queryReq);
return pageList.stream().map(a -> return pageList.stream().map(a ->
JournalMapper.getJournalRespDTO(a)).collect(Collectors.toList()); journalMapper.getJournalRespDTO(a)).collect(Collectors.toList());
} }
private List<JournalRespDTO> getJournalRespDTOWithComment(JournalQueryReq queryReq) { private List<JournalRespDTO> getJournalRespDTOWithComment(JournalQueryReq queryReq) {
List<Journal> pageList = queryPage(queryReq); List<Journal> pageList = queryPage(queryReq);
return pageList.stream().map(journal -> JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel)).collect(Collectors.toList()); return pageList.stream().map(journal -> journalMapper.getJournalRespDTOWithComment(journal)).collect(Collectors.toList());
} }
@ -397,7 +416,7 @@ public class JournalService {
if(null==journal) { if(null==journal) {
return null; return null;
} }
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel); return journalMapper.getJournalRespDTOWithComment(journal);
} }
public JournalRespDTO queryJournalByJournalNo(String journalNo) { public JournalRespDTO queryJournalByJournalNo(String journalNo) {
@ -409,7 +428,7 @@ public class JournalService {
if(null==journal) { if(null==journal) {
return null; return null;
} }
return JournalMapper.getJournalRespDTO(journal,mongoTemplate,redisTemplate,commentDao,userClient,cacheChannel); return journalMapper.getJournalRespDTOWithComment(journal);
} }
public JournalFilterDTO getJournalFilterDTO() { public JournalFilterDTO getJournalFilterDTO() {

@ -3,3 +3,4 @@
梦幻诛仙 梦幻诛仙
梦幻诛仙2 梦幻诛仙2
大罗法咒 大罗法咒
黑暗

@ -1,62 +1,16 @@
package com.luoo.user.controller; package com.luoo.user.controller;
import exception.BizException;
import api.Result;
import api.StatusCode; import api.StatusCode;
import lombok.extern.slf4j.Slf4j; import controller.AbstractBaseExceptionHandler;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.StringJoiner;
/** /**
* *
*/ */
@Slf4j
@ControllerAdvice @ControllerAdvice
public class BaseExceptionHandler { public class BaseExceptionHandler extends AbstractBaseExceptionHandler {
@Override
@ExceptionHandler(value = Exception.class) protected StatusCode getCommonFailedStatusCode() {
@ResponseBody return StatusCode.USER_COMMON_FAILED;
public Result<Void> error(Exception e) {
log.error("执行出错", e);
return Result.failed(StatusCode.USER_COMMON_FAILED, e.getMessage());
}
@ExceptionHandler(value = BizException.class)
@ResponseBody
public Result<String> error(BizException e) {
log.info("业务错误:{}", e.getMessage());
StatusCode statusCode = null == e.getCodeEnum() ? StatusCode.USER_COMMON_FAILED : e.getCodeEnum();
return Result.failed(statusCode, e.getMessage());
}
/**
*
*
* @param e
*/
@ExceptionHandler(value = MethodArgumentNotValidException.class)
@ResponseBody
public Result<?> handle(MethodArgumentNotValidException e) {
BindingResult bindingResult = e.getBindingResult();
StringJoiner joiner = new StringJoiner(";");
for (ObjectError error : bindingResult.getAllErrors()) {
String code = error.getCode();
String[] codes = error.getCodes();
String property = codes[1];
property = property.replace(code, "").replaceFirst(".", "");
String defaultMessage = error.getDefaultMessage();
joiner.add(property + defaultMessage);
}
return Result.failed(StatusCode.MUSIC_COMMON_FAILED, joiner.toString());
} }
} }
Loading…
Cancel
Save