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

release-2024-08-08
pikaqiudeshujia 7 months ago
commit ef9e7f152a

@ -400,7 +400,7 @@ public class CommentController extends BaseController {
List<CommentResp> list = (List<CommentResp>) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN+"_"+parentId,page+"_"+size, key->getChildrenCommentList(parentId,page,size),true).getValue();
// List<CommentResp> list = getChildrenCommentList(parentId,page,size);
//验证是否登录并且拿到ID
Long count = (Long) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,parentId, key->getChildrenCommentListCount(parentId,page,size),true).getValue();
Integer count = (Integer) cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_COMMENT_PAGE_CHILDREN_COUNT,parentId, key->getChildrenCommentListCount(parentId,page,size),true).getValue();
UserLoginDto userLoginDto = getUserLoginDto(authorization);
if (null == userLoginDto) {
@ -409,7 +409,7 @@ public class CommentController extends BaseController {
String userId = userLoginDto.getUserId();
Set<String> publicationLikeSet = publicationLikeDao.findAllByUserId(userId).parallelStream().map(p->p.getLikedItemId()).collect(Collectors.toSet());
list = list.parallelStream().map(c->updateHaveThumbup(c,publicationLikeSet)).collect(Collectors.toList());
return Result.success(new PageResult<CommentResp>(count,list));
return Result.success(new PageResult<CommentResp>(Long.valueOf(count),list));
}

@ -7,10 +7,11 @@ spring:
uri: http://116.62.145.60:12000
# uri: http://127.0.0.1:12000
redis:
lettuce:
# 地址, 多个地址使用‘,’逗号分割
hosts: ${spring.redis.host}:${spring.redis.port}
password: ${spring.redis.password}
timeout: 180000
j2cache:
openSpringCache: true
@ -26,7 +27,7 @@ j2cache:
L2:
#使用springRedis替换二级缓存
provider_class: net.oschina.j2cache.cache.support.redis.SpringRedisProvider
config_section: redis
config_section: lettuce
#使用springRedis进行广播通知缓失效
broadcast: net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy

@ -13,6 +13,8 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.core.env.Environment;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableAsync;
import util.IdWorker;
import util.JwtUtil;
@ -27,6 +29,7 @@ import java.net.UnknownHostException;
@EnableFeignClients
@EnableJpaAuditing
@EnableCaching
@EnableAsync
public class MusicApplication {
static Logger logger= LoggerFactory.getLogger(MusicApplication.class);
public static void main(String[] args) throws UnknownHostException {

@ -9,6 +9,7 @@ import com.luoo.music.dto.request.cms.JournalPublishReq;
import com.luoo.music.dto.request.cms.JournalQueryModel;
import com.luoo.music.dto.response.cms.JournalListRespDto;
import com.luoo.music.dto.response.cms.JournalRespDto;
import com.luoo.music.listener.CleanJournalCache;
import com.luoo.music.service.CMSJournalService;
import com.luoo.music.service.S3Service;
import io.swagger.annotations.Api;
@ -35,9 +36,8 @@ public class CMSJournalController {
private CMSJournalService journalService;
@Autowired
private S3Service s3Service;
@Autowired
private CacheChannel cacheChannel;
private CleanJournalCache cleanJournalCache;
@ApiOperation(value = "查询期刊列表", notes = "查询期刊列表")
@RequestMapping(value="/search/{page}/{size}", method= RequestMethod.POST)
@ -50,20 +50,10 @@ public class CMSJournalController {
@ApiOperation(value = "新增期刊", notes = "新增期刊")
@RequestMapping(value = "/add", method = RequestMethod.POST)
public Result add(@ApiParam(value = "期刊信息", required = true) @Valid @RequestBody JournalAddModel addModel){
cleanCache();
cleanJournalCache.cleanCache();
return journalService.add(addModel);
}
private void cleanCache() {
try {
cacheChannel.evict("default", "journal_filter");
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE);
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_COUNT);
}catch(Exception e) {
e.printStackTrace();
}
}
@ApiOperation(value = "查询期刊详情", notes = "查询期刊详情")
@RequestMapping(value="/{id}",method= RequestMethod.GET)
public Result<JournalRespDto> findOne(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){
@ -74,7 +64,7 @@ public class CMSJournalController {
@RequestMapping(value = "/{id}", method = RequestMethod.PUT)
public Result update(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "期刊信息", required = true) @RequestBody JournalAddModel updateModel){
cleanCache(id);
cleanJournalCache.cleanCache(id);
return journalService.update(id, updateModel);
}
@ -82,36 +72,22 @@ public class CMSJournalController {
@RequestMapping(value="/publish/{id}",method= RequestMethod.PUT)
public Result publish(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "期刊发布请求对象", required = true) @RequestBody JournalPublishReq queryModel){
cleanCache(id);
cleanJournalCache.cleanCache(id);
return journalService.publish(id, queryModel);
}
private void cleanCache(String id) {
try {
cacheChannel.evict("default", "journal_filter");
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE);
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_COUNT);
cacheChannel.evict(constants.Constants.J2CACHE_REGION_JOURNAL_ID, id);
String journalNo=journalService.findJournalNoById(id);
cacheChannel.evict(constants.Constants.J2CACHE_REGION_JOURNAL_SONG_LIST, journalNo);
cacheChannel.evict(constants.Constants.J2CACHE_REGION_JOURNAL_NO,journalNo);
}catch(Exception e) {
e.printStackTrace();
}
}
@ApiOperation(value = "更新期刊启停状态", notes = "更新期刊启停状态")
@RequestMapping(value="/update/state/{id}",method= RequestMethod.PUT)
public Result updateColumnState(@ApiParam(value = "期刊ID", required = true) @PathVariable String id,
@ApiParam(value = "期刊启停状态0:停用1:启用", required = true) @RequestBody String state){
cleanCache(id);
cleanJournalCache.cleanCache(id);
return journalService.updateJournalState(id, state);
}
@ApiOperation(value = "删除单条期刊", notes = "物理删除")
@RequestMapping(value="/{id}", method= RequestMethod.DELETE)
public Result delete(@ApiParam(value = "期刊ID", required = true) @PathVariable String id){
cleanCache(id);
cleanJournalCache.cleanCache(id);
return journalService.deleteById(id);
}

@ -70,6 +70,9 @@ public class JournalController {
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
updateQuery(deviceType,user,queryReq);
Long count = journalService.countJournal(queryReq);
if(0==count) {
return Result.success(new PageResult<JournalRespDTO>(count, Collections.emptyList()));
}
List<JournalRespDTO> pageList=journalService.queryJournalByPage(queryReq);
Set<String> journalCollectSet = getJournalCollectSet(user);
updateCollectStatus(pageList,journalCollectSet);
@ -115,6 +118,9 @@ public class JournalController {
return Result.success(new PageResult<JournalRespDTO>(0L, Collections.emptyList()));
}
Long count = Long.valueOf(getJournalCollectSet(queryReq.getUserId()).size());
if(0==count) {
return Result.success(new PageResult<JournalRespDTO>(count, Collections.emptyList()));
}
List<Journal> pageList = journalService.orderByField(objectIds);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Set<String> journalCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);

@ -109,6 +109,9 @@ public class SongController {
return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList()));
}
Long count = (long) getSongCollectSet(queryUserId).size();
if(0==count) {
return Result.success(new PageResult<SongRespDTO>(count, Collections.emptyList()));
}
List<JournalSong> songs = journalSongService.orderByField(objectIds);
Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds,isJouranlSource);
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))

@ -3,6 +3,7 @@ package com.luoo.music.listener;
import constants.Constants;
import net.oschina.j2cache.CacheChannel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import com.luoo.music.dao.JournalDao;
@ -21,6 +22,36 @@ public class CleanJournalCache {
@Autowired
private JournalDao journalDao;
@Async
public void cleanCache() {
try {
cacheChannel.evict("default", "journal_filter");
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE);
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_COUNT);
}catch(Exception e) {
e.printStackTrace();
}
}
@Async
public void cleanCache(String id) {
try {
cacheChannel.evict("default", "journal_filter");
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE);
cacheChannel.clear(Constants.J2CACHE_REGION_JOURNAL_QUERY_COUNT);
cacheChannel.evict(constants.Constants.J2CACHE_REGION_JOURNAL_ID, id);
Optional<Journal> optional = journalDao.findById(id);
if (!optional.isPresent()) {
return;
}
String journalNo=optional.get().getJournalNo();
cacheChannel.evict(constants.Constants.J2CACHE_REGION_JOURNAL_SONG_LIST, journalNo);
cacheChannel.evict(constants.Constants.J2CACHE_REGION_JOURNAL_NO,journalNo);
}catch(Exception e) {
e.printStackTrace();
}
}
public void clean(String journalId) {
Optional<Journal> optional = journalDao.findById(journalId);
if (!optional.isPresent()) {

@ -23,6 +23,8 @@ import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import util.StringTools;
import com.luoo.music.dao.CommentDao;
@ -297,7 +299,11 @@ public class JournalService {
if(keyword.length()==1) {
return searchByLike(keyword,pageRequest);
}
return journalDao.fuzzySearch("+\""+keyword+"\"", pageRequest.getPageNumber()*pageRequest.getPageSize(), pageRequest.getPageSize());
List<Journal> fullTextFuzzySearchResults = journalDao.fuzzySearch("+\""+keyword+"\"", pageRequest.getPageNumber()*pageRequest.getPageSize(), pageRequest.getPageSize());
if(CollectionUtils.isEmpty(fullTextFuzzySearchResults)) {
return searchByLike(keyword, pageRequest);
}
return fullTextFuzzySearchResults;
}
public static boolean isNumeric(String str){
@ -351,9 +357,9 @@ public class JournalService {
@SuppressWarnings("unchecked")
public List<JournalRespDTO> queryJournalByPage(JournalQueryReq queryReq) {
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) , true).getValue() ;
return (List<JournalRespDTO>) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTOWithComment(queryReq) , false).getValue() ;
}
List<JournalRespDTO> list= (List<JournalRespDTO>) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTO(queryReq) , true).getValue() ;
List<JournalRespDTO> list= (List<JournalRespDTO>) this.cacheChannel.get(Constants.J2CACHE_REGION_JOURNAL_QUERY_PAGE, queryReq.toString(), key -> getJournalRespDTO(queryReq) , false).getValue() ;
list.parallelStream().forEach(j->{
updateComment(j);
});

@ -12,6 +12,8 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
@ -144,7 +146,11 @@ public class JournalSongService {
if(keyword.length()==1) {
return searchByLike(keyword,pageRequest);
}
return journalSongDao.fuzzySearch("+\""+keyword+"\"", pageRequest.getPageNumber()*pageRequest.getPageSize(), pageRequest.getPageSize());
List<JournalSong> fullTextFuzzySearchResults = journalSongDao.fuzzySearch("+\""+keyword+"\"", pageRequest.getPageNumber()*pageRequest.getPageSize(), pageRequest.getPageSize());
if(CollectionUtils.isEmpty(fullTextFuzzySearchResults)) {
return searchByLike(keyword, pageRequest);
}
return fullTextFuzzySearchResults;
}
private List<JournalSong> searchByLike(String keyword, PageRequest pageRequest) {

@ -10,10 +10,11 @@ spring:
multipart:
max-file-size: 20MB
max-request-size: 200MB
redis:
lettuce:
# 地址, 多个地址使用‘,’逗号分割
hosts: ${spring.redis.host}:${spring.redis.port}
password: ${spring.redis.password}
timeout: 180000
j2cache:
openSpringCache: true
# 缓存中不存在时,运行缓存空对象
@ -28,7 +29,7 @@ j2cache:
L2:
#使用springRedis替换二级缓存
provider_class: net.oschina.j2cache.cache.support.redis.SpringRedisProvider
config_section: redis
config_section: lettuce
#使用springRedis进行广播通知缓失效
broadcast: net.oschina.j2cache.cache.support.redis.SpringRedisPubSubPolicy

Loading…
Cancel
Save